/* BackgroundSelection.c generated by valac 0.56.17, the Vala compiler
 * generated from BackgroundSelection.vala, do not modify */

/*
Copyright (C) 2014 Johan Mattsson

This library is free software; you can redistribute it and/or modify 
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation; either version 3 of the 
License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
Lesser General Public License for more details.
*/

#include "birdfont.h"
#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	BIRD_FONT_BACKGROUND_SELECTION_0_PROPERTY,
	BIRD_FONT_BACKGROUND_SELECTION_X_PROPERTY,
	BIRD_FONT_BACKGROUND_SELECTION_Y_PROPERTY,
	BIRD_FONT_BACKGROUND_SELECTION_W_PROPERTY,
	BIRD_FONT_BACKGROUND_SELECTION_H_PROPERTY,
	BIRD_FONT_BACKGROUND_SELECTION_NUM_PROPERTIES
};
static GParamSpec* bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer bird_font_background_selection_parent_class = NULL;

static void bird_font_background_selection_finalize (GObject * obj);
static GType bird_font_background_selection_get_type_once (void);
static void _vala_bird_font_background_selection_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec);
static void _vala_bird_font_background_selection_set_property (GObject * object,
                                                        guint property_id,
                                                        const GValue * value,
                                                        GParamSpec * pspec);

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

BirdFontBackgroundSelection*
bird_font_background_selection_construct (GType object_type,
                                          BirdFontBackgroundImage* img,
                                          BirdFontBackgroundImage* parent_img,
                                          gdouble x,
                                          gdouble y,
                                          gdouble w,
                                          gdouble h)
{
	BirdFontBackgroundSelection * self = NULL;
	BirdFontBackgroundImage* _tmp0_;
	BirdFontBackgroundImage* _tmp1_;
	g_return_val_if_fail (parent_img != NULL, NULL);
	self = (BirdFontBackgroundSelection*) g_object_new (object_type, NULL);
	_g_free0 (self->assigned_glyph);
	self->assigned_glyph = NULL;
	_tmp0_ = _g_object_ref0 (parent_img);
	_g_object_unref0 (self->parent_image);
	self->parent_image = _tmp0_;
	_tmp1_ = _g_object_ref0 (img);
	_g_object_unref0 (self->image);
	self->image = _tmp1_;
	bird_font_background_selection_set_x (self, x);
	bird_font_background_selection_set_y (self, y);
	bird_font_background_selection_set_w (self, w);
	bird_font_background_selection_set_h (self, h);
	return self;
}

BirdFontBackgroundSelection*
bird_font_background_selection_new (BirdFontBackgroundImage* img,
                                    BirdFontBackgroundImage* parent_img,
                                    gdouble x,
                                    gdouble y,
                                    gdouble w,
                                    gdouble h)
{
	return bird_font_background_selection_construct (BIRD_FONT_TYPE_BACKGROUND_SELECTION, img, parent_img, x, y, w, h);
}

BirdFontBackgroundSelection*
bird_font_background_selection_construct_absolute (GType object_type,
                                                   BirdFontBackgroundImage* img,
                                                   BirdFontBackgroundImage* parent_img,
                                                   gdouble x_img,
                                                   gdouble y_img,
                                                   gdouble width,
                                                   gdouble height)
{
	BirdFontBackgroundSelection * self = NULL;
	BirdFontBackgroundImage* _tmp0_;
	BirdFontBackgroundImage* _tmp1_;
	g_return_val_if_fail (parent_img != NULL, NULL);
	self = (BirdFontBackgroundSelection*) g_object_new (object_type, NULL);
	_g_free0 (self->assigned_glyph);
	self->assigned_glyph = NULL;
	_tmp0_ = _g_object_ref0 (parent_img);
	_g_object_unref0 (self->parent_image);
	self->parent_image = _tmp0_;
	_tmp1_ = _g_object_ref0 (img);
	_g_object_unref0 (self->image);
	self->image = _tmp1_;
	self->x_img = x_img;
	self->y_img = y_img;
	self->width = width;
	self->height = height;
	return self;
}

BirdFontBackgroundSelection*
bird_font_background_selection_new_absolute (BirdFontBackgroundImage* img,
                                             BirdFontBackgroundImage* parent_img,
                                             gdouble x_img,
                                             gdouble y_img,
                                             gdouble width,
                                             gdouble height)
{
	return bird_font_background_selection_construct_absolute (BIRD_FONT_TYPE_BACKGROUND_SELECTION, img, parent_img, x_img, y_img, width, height);
}

gdouble
bird_font_background_selection_get_x (BirdFontBackgroundSelection* self)
{
	gdouble result;
	BirdFontBackgroundImage* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	BirdFontBackgroundImage* _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	g_return_val_if_fail (self != NULL, 0.0);
	_tmp0_ = self->parent_image;
	_tmp1_ = bird_font_background_image_get_img_scale_x (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->parent_image;
	_tmp4_ = bird_font_background_image_get_img_middle_x (_tmp3_);
	_tmp5_ = _tmp4_;
	result = (self->x_img * _tmp2_) + _tmp5_;
	return result;
}

void
bird_font_background_selection_set_x (BirdFontBackgroundSelection* self,
                                      gdouble value)
{
	BirdFontBackgroundImage* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	BirdFontBackgroundImage* _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->parent_image;
	_tmp1_ = bird_font_background_image_get_img_middle_x (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->parent_image;
	_tmp4_ = bird_font_background_image_get_img_scale_x (_tmp3_);
	_tmp5_ = _tmp4_;
	self->x_img = (value - _tmp2_) / _tmp5_;
	g_object_notify_by_pspec ((GObject *) self, bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_X_PROPERTY]);
}

gdouble
bird_font_background_selection_get_y (BirdFontBackgroundSelection* self)
{
	gdouble result;
	BirdFontBackgroundImage* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	BirdFontBackgroundImage* _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	g_return_val_if_fail (self != NULL, 0.0);
	_tmp0_ = self->parent_image;
	_tmp1_ = bird_font_background_image_get_img_scale_y (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->parent_image;
	_tmp4_ = bird_font_background_image_get_img_middle_y (_tmp3_);
	_tmp5_ = _tmp4_;
	result = (self->y_img * _tmp2_) + _tmp5_;
	return result;
}

void
bird_font_background_selection_set_y (BirdFontBackgroundSelection* self,
                                      gdouble value)
{
	BirdFontBackgroundImage* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	BirdFontBackgroundImage* _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->parent_image;
	_tmp1_ = bird_font_background_image_get_img_middle_y (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->parent_image;
	_tmp4_ = bird_font_background_image_get_img_scale_y (_tmp3_);
	_tmp5_ = _tmp4_;
	self->y_img = (value - _tmp2_) / _tmp5_;
	g_object_notify_by_pspec ((GObject *) self, bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_Y_PROPERTY]);
}

gdouble
bird_font_background_selection_get_w (BirdFontBackgroundSelection* self)
{
	gdouble result;
	BirdFontBackgroundImage* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	g_return_val_if_fail (self != NULL, 0.0);
	_tmp0_ = self->parent_image;
	_tmp1_ = bird_font_background_image_get_img_scale_x (_tmp0_);
	_tmp2_ = _tmp1_;
	result = self->width * _tmp2_;
	return result;
}

void
bird_font_background_selection_set_w (BirdFontBackgroundSelection* self,
                                      gdouble value)
{
	BirdFontBackgroundImage* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->parent_image;
	_tmp1_ = bird_font_background_image_get_img_scale_x (_tmp0_);
	_tmp2_ = _tmp1_;
	self->width = value / _tmp2_;
	g_object_notify_by_pspec ((GObject *) self, bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_W_PROPERTY]);
}

gdouble
bird_font_background_selection_get_h (BirdFontBackgroundSelection* self)
{
	gdouble result;
	BirdFontBackgroundImage* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	g_return_val_if_fail (self != NULL, 0.0);
	_tmp0_ = self->parent_image;
	_tmp1_ = bird_font_background_image_get_img_scale_y (_tmp0_);
	_tmp2_ = _tmp1_;
	result = self->height * _tmp2_;
	return result;
}

void
bird_font_background_selection_set_h (BirdFontBackgroundSelection* self,
                                      gdouble value)
{
	BirdFontBackgroundImage* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->parent_image;
	_tmp1_ = bird_font_background_image_get_img_scale_y (_tmp0_);
	_tmp2_ = _tmp1_;
	self->height = value / _tmp2_;
	g_object_notify_by_pspec ((GObject *) self, bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_H_PROPERTY]);
}

static void
bird_font_background_selection_class_init (BirdFontBackgroundSelectionClass * klass,
                                           gpointer klass_data)
{
	bird_font_background_selection_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_bird_font_background_selection_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_bird_font_background_selection_set_property;
	G_OBJECT_CLASS (klass)->finalize = bird_font_background_selection_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BIRD_FONT_BACKGROUND_SELECTION_X_PROPERTY, bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_X_PROPERTY] = g_param_spec_double ("x", "x", "x", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), BIRD_FONT_BACKGROUND_SELECTION_Y_PROPERTY, bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_Y_PROPERTY] = g_param_spec_double ("y", "y", "y", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), BIRD_FONT_BACKGROUND_SELECTION_W_PROPERTY, bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_W_PROPERTY] = g_param_spec_double ("w", "w", "w", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), BIRD_FONT_BACKGROUND_SELECTION_H_PROPERTY, bird_font_background_selection_properties[BIRD_FONT_BACKGROUND_SELECTION_H_PROPERTY] = g_param_spec_double ("h", "h", "h", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
bird_font_background_selection_instance_init (BirdFontBackgroundSelection * self,
                                              gpointer klass)
{
}

static void
bird_font_background_selection_finalize (GObject * obj)
{
	BirdFontBackgroundSelection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_BACKGROUND_SELECTION, BirdFontBackgroundSelection);
	_g_free0 (self->assigned_glyph);
	_g_object_unref0 (self->image);
	_g_object_unref0 (self->parent_image);
	G_OBJECT_CLASS (bird_font_background_selection_parent_class)->finalize (obj);
}

static GType
bird_font_background_selection_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontBackgroundSelectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_background_selection_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontBackgroundSelection), 0, (GInstanceInitFunc) bird_font_background_selection_instance_init, NULL };
	GType bird_font_background_selection_type_id;
	bird_font_background_selection_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontBackgroundSelection", &g_define_type_info, 0);
	return bird_font_background_selection_type_id;
}

GType
bird_font_background_selection_get_type (void)
{
	static volatile gsize bird_font_background_selection_type_id__once = 0;
	if (g_once_init_enter (&bird_font_background_selection_type_id__once)) {
		GType bird_font_background_selection_type_id;
		bird_font_background_selection_type_id = bird_font_background_selection_get_type_once ();
		g_once_init_leave (&bird_font_background_selection_type_id__once, bird_font_background_selection_type_id);
	}
	return bird_font_background_selection_type_id__once;
}

static void
_vala_bird_font_background_selection_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec)
{
	BirdFontBackgroundSelection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BIRD_FONT_TYPE_BACKGROUND_SELECTION, BirdFontBackgroundSelection);
	switch (property_id) {
		case BIRD_FONT_BACKGROUND_SELECTION_X_PROPERTY:
		g_value_set_double (value, bird_font_background_selection_get_x (self));
		break;
		case BIRD_FONT_BACKGROUND_SELECTION_Y_PROPERTY:
		g_value_set_double (value, bird_font_background_selection_get_y (self));
		break;
		case BIRD_FONT_BACKGROUND_SELECTION_W_PROPERTY:
		g_value_set_double (value, bird_font_background_selection_get_w (self));
		break;
		case BIRD_FONT_BACKGROUND_SELECTION_H_PROPERTY:
		g_value_set_double (value, bird_font_background_selection_get_h (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_bird_font_background_selection_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec)
{
	BirdFontBackgroundSelection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BIRD_FONT_TYPE_BACKGROUND_SELECTION, BirdFontBackgroundSelection);
	switch (property_id) {
		case BIRD_FONT_BACKGROUND_SELECTION_X_PROPERTY:
		bird_font_background_selection_set_x (self, g_value_get_double (value));
		break;
		case BIRD_FONT_BACKGROUND_SELECTION_Y_PROPERTY:
		bird_font_background_selection_set_y (self, g_value_get_double (value));
		break;
		case BIRD_FONT_BACKGROUND_SELECTION_W_PROPERTY:
		bird_font_background_selection_set_w (self, g_value_get_double (value));
		break;
		case BIRD_FONT_BACKGROUND_SELECTION_H_PROPERTY:
		bird_font_background_selection_set_h (self, g_value_get_double (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

