/* CloseButton.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from CloseButton.vala, do not modify */

/*
 * Copyright 2024 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "gala.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <clutter/clutter.h>
#include <glib-object.h>
#include <meta/common.h>
#include <graphene-gobject.h>

#define GALA_CLOSE_BUTTON_ANIMATION_DURATION ((guint) 100)
#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  {
	GALA_CLOSE_BUTTON_0_PROPERTY,
	GALA_CLOSE_BUTTON_MONITOR_SCALE_PROPERTY,
	GALA_CLOSE_BUTTON_NUM_PROPERTIES
};
static GParamSpec* gala_close_button_properties[GALA_CLOSE_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	GALA_CLOSE_BUTTON_TRIGGERED_SIGNAL,
	GALA_CLOSE_BUTTON_NUM_SIGNALS
};
static guint gala_close_button_signals[GALA_CLOSE_BUTTON_NUM_SIGNALS] = {0};

struct _GalaCloseButtonPrivate {
	gfloat _monitor_scale;
	GalaIcon* icon;
	ClutterClickAction* click_action;
};

static gint GalaCloseButton_private_offset;
static gpointer gala_close_button_parent_class = NULL;

static void gala_close_button_on_clicked (GalaCloseButton* self);
static void gala_close_button_on_pressed_changed (GalaCloseButton* self);
static GObject * gala_close_button_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties);
static void _gala_close_button_on_clicked_clutter_click_action_clicked (ClutterClickAction* _sender,
                                                                 ClutterActor* actor,
                                                                 gpointer self);
static void _gala_close_button_on_pressed_changed_g_object_notify (GObject* _sender,
                                                            GParamSpec* pspec,
                                                            gpointer self);
static void gala_close_button_finalize (GObject * obj);
static GType gala_close_button_get_type_once (void);
static void _vala_gala_close_button_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_gala_close_button_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);

static inline gpointer
gala_close_button_get_instance_private (GalaCloseButton* self)
{
	return G_STRUCT_MEMBER_P (self, GalaCloseButton_private_offset);
}

GalaCloseButton*
gala_close_button_construct (GType object_type,
                             gfloat monitor_scale)
{
	GalaCloseButton * self = NULL;
	self = (GalaCloseButton*) g_object_new (object_type, "monitor-scale", monitor_scale, NULL);
	return self;
}

GalaCloseButton*
gala_close_button_new (gfloat monitor_scale)
{
	return gala_close_button_construct (GALA_TYPE_CLOSE_BUTTON, monitor_scale);
}

static void
gala_close_button_on_clicked (GalaCloseButton* self)
{
	g_return_if_fail (self != NULL);
	g_signal_emit (self, gala_close_button_signals[GALA_CLOSE_BUTTON_TRIGGERED_SIGNAL], 0, (guint32) META_CURRENT_TIME);
}

static void
gala_close_button_on_pressed_changed (GalaCloseButton* self)
{
	guint estimated_duration = 0U;
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_ = 0.0;
	ClutterClickAction* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gdouble scale = 0.0;
	GalaIcon* _tmp6_;
	GalaIcon* _tmp7_;
	GalaIcon* _tmp8_;
	GalaIcon* _tmp9_;
	GalaIcon* _tmp10_;
	g_return_if_fail (self != NULL);
	g_object_get ((ClutterActor*) self, "scale-x", &_tmp0_, NULL);
	_tmp1_ = _tmp0_;
	estimated_duration = gala_utils_get_animation_duration ((guint) ((GALA_CLOSE_BUTTON_ANIMATION_DURATION * (_tmp1_ - 0.8)) / 0.2));
	_tmp3_ = self->priv->click_action;
	g_object_get (_tmp3_, "pressed", &_tmp4_, NULL);
	_tmp5_ = _tmp4_;
	if (_tmp5_) {
		_tmp2_ = 0.8;
	} else {
		_tmp2_ = 1.0;
	}
	scale = _tmp2_;
	_tmp6_ = self->priv->icon;
	clutter_actor_save_easing_state ((ClutterActor*) _tmp6_);
	_tmp7_ = self->priv->icon;
	clutter_actor_set_easing_duration ((ClutterActor*) _tmp7_, estimated_duration);
	_tmp8_ = self->priv->icon;
	clutter_actor_set_easing_mode ((ClutterActor*) _tmp8_, CLUTTER_EASE_IN_OUT);
	_tmp9_ = self->priv->icon;
	clutter_actor_set_scale ((ClutterActor*) _tmp9_, scale, scale);
	_tmp10_ = self->priv->icon;
	clutter_actor_restore_easing_state ((ClutterActor*) _tmp10_);
}

gfloat
gala_close_button_get_monitor_scale (GalaCloseButton* self)
{
	gfloat result;
	g_return_val_if_fail (self != NULL, 0.0F);
	result = self->priv->_monitor_scale;
	return result;
}

void
gala_close_button_set_monitor_scale (GalaCloseButton* self,
                                     gfloat value)
{
	gfloat old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_close_button_get_monitor_scale (self);
	if (old_value != value) {
		self->priv->_monitor_scale = value;
		g_object_notify_by_pspec ((GObject *) self, gala_close_button_properties[GALA_CLOSE_BUTTON_MONITOR_SCALE_PROPERTY]);
	}
}

static void
_gala_close_button_on_clicked_clutter_click_action_clicked (ClutterClickAction* _sender,
                                                            ClutterActor* actor,
                                                            gpointer self)
{
	gala_close_button_on_clicked ((GalaCloseButton*) self);
}

static void
_gala_close_button_on_pressed_changed_g_object_notify (GObject* _sender,
                                                       GParamSpec* pspec,
                                                       gpointer self)
{
	gala_close_button_on_pressed_changed ((GalaCloseButton*) self);
}

static GObject *
gala_close_button_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaCloseButton * self;
	gfloat _tmp0_;
	graphene_point_t _tmp1_ = {0};
	GalaIcon* _tmp2_ = NULL;
	GalaIcon* _tmp3_;
	ClutterClickAction* _tmp4_;
	ClutterClickAction* _tmp5_;
	ClutterClickAction* _tmp6_;
	ClutterClickAction* _tmp7_;
	parent_class = G_OBJECT_CLASS (gala_close_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_CLOSE_BUTTON, GalaCloseButton);
	clutter_actor_set_reactive ((ClutterActor*) self, TRUE);
	_tmp0_ = self->priv->_monitor_scale;
	_tmp1_.x = 0.5f;
	_tmp1_.y = 0.5f;
	_tmp2_ = gala_icon_new_from_resource (GALA_UTILS_BUTTON_SIZE, _tmp0_, "/org/pantheon/desktop/gala/buttons/close.svg");
	g_object_set ((ClutterActor*) _tmp2_, "pivot-point", &_tmp1_, NULL);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->icon);
	self->priv->icon = _tmp2_;
	_tmp3_ = self->priv->icon;
	clutter_actor_add_child ((ClutterActor*) self, (ClutterActor*) _tmp3_);
	_tmp4_ = (ClutterClickAction*) clutter_click_action_new ();
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->click_action);
	self->priv->click_action = _tmp4_;
	_tmp5_ = self->priv->click_action;
	clutter_actor_add_action ((ClutterActor*) self, (ClutterAction*) _tmp5_);
	_tmp6_ = self->priv->click_action;
	g_signal_connect_object (_tmp6_, "clicked", (GCallback) _gala_close_button_on_clicked_clutter_click_action_clicked, self, 0);
	_tmp7_ = self->priv->click_action;
	g_signal_connect_object ((GObject*) _tmp7_, "notify::pressed", (GCallback) _gala_close_button_on_pressed_changed_g_object_notify, self, 0);
	return obj;
}

static void
gala_close_button_class_init (GalaCloseButtonClass * klass,
                              gpointer klass_data)
{
	gala_close_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaCloseButton_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_close_button_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_close_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_close_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_close_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_CLOSE_BUTTON_MONITOR_SCALE_PROPERTY, gala_close_button_properties[GALA_CLOSE_BUTTON_MONITOR_SCALE_PROPERTY] = g_param_spec_float ("monitor-scale", "monitor-scale", "monitor-scale", -G_MAXFLOAT, G_MAXFLOAT, 0.0F, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	gala_close_button_signals[GALA_CLOSE_BUTTON_TRIGGERED_SIGNAL] = g_signal_new ("triggered", GALA_TYPE_CLOSE_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT);
}

static void
gala_close_button_instance_init (GalaCloseButton * self,
                                 gpointer klass)
{
	self->priv = gala_close_button_get_instance_private (self);
}

static void
gala_close_button_finalize (GObject * obj)
{
	GalaCloseButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_CLOSE_BUTTON, GalaCloseButton);
	_g_object_unref0 (self->priv->icon);
	_g_object_unref0 (self->priv->click_action);
	G_OBJECT_CLASS (gala_close_button_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_close_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaCloseButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_close_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaCloseButton), 0, (GInstanceInitFunc) gala_close_button_instance_init, NULL };
	GType gala_close_button_type_id;
	gala_close_button_type_id = g_type_register_static (clutter_actor_get_type (), "GalaCloseButton", &g_define_type_info, 0);
	GalaCloseButton_private_offset = g_type_add_instance_private (gala_close_button_type_id, sizeof (GalaCloseButtonPrivate));
	return gala_close_button_type_id;
}

GType
gala_close_button_get_type (void)
{
	static gsize gala_close_button_type_id__once = 0;
	if (g_once_init_enter (&gala_close_button_type_id__once)) {
		GType gala_close_button_type_id;
		gala_close_button_type_id = gala_close_button_get_type_once ();
		g_once_init_leave (&gala_close_button_type_id__once, gala_close_button_type_id);
	}
	return gala_close_button_type_id__once;
}

static void
_vala_gala_close_button_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	GalaCloseButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_CLOSE_BUTTON, GalaCloseButton);
	switch (property_id) {
		case GALA_CLOSE_BUTTON_MONITOR_SCALE_PROPERTY:
		g_value_set_float (value, gala_close_button_get_monitor_scale (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_close_button_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	GalaCloseButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_CLOSE_BUTTON, GalaCloseButton);
	switch (property_id) {
		case GALA_CLOSE_BUTTON_MONITOR_SCALE_PROPERTY:
		gala_close_button_set_monitor_scale (self, g_value_get_float (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

