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

/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-

   Gnome Nibbles: Gnome Worm Game
   Copyright (C) 2020 Arnaud Bonatti <arnaud.bonatti@gmail.com>

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

   This program 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 General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_SPEED (speed_get_type ())
#define SPEED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SPEED, Speed))
#define SPEED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SPEED, SpeedClass))
#define IS_SPEED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SPEED))
#define IS_SPEED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SPEED))
#define SPEED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SPEED, SpeedClass))

typedef struct _Speed Speed;
typedef struct _SpeedClass SpeedClass;
typedef struct _SpeedPrivate SpeedPrivate;
enum  {
	SPEED_0_PROPERTY,
	SPEED_NUM_PROPERTIES
};
static GParamSpec* speed_properties[SPEED_NUM_PROPERTIES];
typedef void (*GSimpleActionChangeStateCallback) (GSimpleAction* action, GVariant* value, gpointer user_data);
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

struct _Speed {
	GtkBox parent_instance;
	SpeedPrivate * priv;
};

struct _SpeedClass {
	GtkBoxClass parent_class;
};

struct _SpeedPrivate {
	GtkToggleButton* speed4;
	GtkToggleButton* speed3;
	GtkToggleButton* speed2;
	GtkToggleButton* speed1;
	GtkToggleButton* enable_fake_bonuses;
	GtkButton* next;
	GSimpleAction* speed_action;
	GSimpleAction* fakes_action;
};

static gint Speed_private_offset;
static gpointer speed_parent_class = NULL;

VALA_EXTERN GType speed_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Speed, g_object_unref)
static inline void speed_change_speed (Speed* self,
                         GSimpleAction* _speed_action,
                         GVariant* variant);
static void _speed_change_speed_gsimple_action_change_state_callback (GSimpleAction* action,
                                                               GVariant* value,
                                                               gpointer self);
static void speed_toggle_fakes (Speed* self,
                         GSimpleAction* _fakes_action,
                         GVariant* variant);
static void _speed_toggle_fakes_gsimple_action_change_state_callback (GSimpleAction* action,
                                                               GVariant* value,
                                                               gpointer self);
static void speed_setup_label (Speed* self,
                        GtkWidget* w);
VALA_EXTERN void speed_set_values (Speed* self,
                       gint speed,
                       gboolean fakes);
static GVariant* _variant_new8 (gint value);
static GVariant* _variant_new9 (gboolean value);
static void speed_set_frames (Speed* self,
                       gint speed);
VALA_EXTERN void speed_get_values (Speed* self,
                       gint* speed,
                       gboolean* fakes);
static GVariant* _variant_new10 (gint value);
static GVariant* _variant_new11 (gboolean value);
VALA_EXTERN Speed* speed_new (void);
VALA_EXTERN Speed* speed_construct (GType object_type);
static GObject * speed_constructor (GType type,
                             guint n_construct_properties,
                             GObjectConstructParam * construct_properties);
static void speed_finalize (GObject * obj);
static GType speed_get_type_once (void);

static const GActionEntry SPEED_players_action_entries[2] = {{"change-speed", NULL, "i", "4", _speed_change_speed_gsimple_action_change_state_callback}, {"toggle-fakes", NULL, NULL, "true", _speed_toggle_fakes_gsimple_action_change_state_callback}};

static inline gpointer
speed_get_instance_private (Speed* self)
{
	return G_STRUCT_MEMBER_P (self, Speed_private_offset);
}

static void
_speed_change_speed_gsimple_action_change_state_callback (GSimpleAction* action,
                                                          GVariant* value,
                                                          gpointer self)
{
	speed_change_speed ((Speed*) self, action, value);
}

static void
_speed_toggle_fakes_gsimple_action_change_state_callback (GSimpleAction* action,
                                                          GVariant* value,
                                                          gpointer self)
{
	speed_toggle_fakes ((Speed*) self, action, value);
}

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

static void
speed_setup_label (Speed* self,
                   GtkWidget* w)
{
	GtkLabel* label = NULL;
	GtkLabel* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (w != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (w, gtk_label_get_type (), GtkLabel));
	label = _tmp0_;
	_tmp1_ = gtk_label_get_text (label);
	_tmp2_ = g_strconcat ("<b><span size=\"14.0pt\" font-family=\"Sans\">", _tmp1_, NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp3_, "</span></b>", NULL);
	_tmp5_ = _tmp4_;
	gtk_label_set_markup (label, _tmp5_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	gtk_widget_set_margin_top ((GtkWidget*) label, 14);
	gtk_widget_set_margin_bottom ((GtkWidget*) label, 14);
	gtk_widget_set_margin_start ((GtkWidget*) label, 14);
	gtk_widget_set_halign ((GtkWidget*) label, GTK_ALIGN_START);
	_g_object_unref0 (label);
}

static GVariant*
_variant_new8 (gint value)
{
	return g_variant_ref_sink (g_variant_new_int32 (value));
}

static GVariant*
_variant_new9 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

inline void
speed_set_values (Speed* self,
                  gint speed,
                  gboolean fakes)
{
	GSimpleAction* _tmp0_;
	GVariant* _tmp1_;
	GSimpleAction* _tmp2_;
	GVariant* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->speed_action;
	_tmp1_ = _variant_new8 (speed);
	g_simple_action_set_state (_tmp0_, _tmp1_);
	_g_variant_unref0 (_tmp1_);
	_tmp2_ = self->priv->fakes_action;
	_tmp3_ = _variant_new9 (fakes);
	g_simple_action_set_state (_tmp2_, _tmp3_);
	_g_variant_unref0 (_tmp3_);
	speed_set_frames (self, speed);
}

inline void
speed_get_values (Speed* self,
                  gint* speed,
                  gboolean* fakes)
{
	gint _vala_speed = 0;
	gboolean _vala_fakes = FALSE;
	GSimpleAction* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp2_;
	GSimpleAction* _tmp3_;
	GVariant* _tmp4_;
	GVariant* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->speed_action;
	_tmp1_ = g_action_get_state ((GAction*) _tmp0_);
	_tmp2_ = _tmp1_;
	_vala_speed = (gint) g_variant_get_int32 (_tmp2_);
	_g_variant_unref0 (_tmp2_);
	_tmp3_ = self->priv->fakes_action;
	_tmp4_ = g_action_get_state ((GAction*) _tmp3_);
	_tmp5_ = _tmp4_;
	_vala_fakes = g_variant_get_boolean (_tmp5_);
	_g_variant_unref0 (_tmp5_);
	if (speed) {
		*speed = _vala_speed;
	}
	if (fakes) {
		*fakes = _vala_fakes;
	}
}

static GVariant*
_variant_new10 (gint value)
{
	return g_variant_ref_sink (g_variant_new_int32 (value));
}

static inline void
speed_change_speed (Speed* self,
                    GSimpleAction* _speed_action,
                    GVariant* variant)
{
	gint speed = 0;
	gboolean _tmp0_ = FALSE;
	GVariant* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (_speed_action != NULL);
	g_return_if_fail (variant != NULL);
	speed = (gint) g_variant_get_int32 (variant);
	if (speed < 1) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = speed > 4;
	}
	if (_tmp0_) {
		g_assert_not_reached ();
	}
	_tmp1_ = _variant_new10 (speed);
	g_simple_action_set_state (_speed_action, _tmp1_);
	_g_variant_unref0 (_tmp1_);
	speed_set_frames (self, speed);
}

static void
speed_set_frames (Speed* self,
                  gint speed)
{
	GtkToggleButton* _tmp0_;
	GtkToggleButton* _tmp1_;
	GtkToggleButton* _tmp2_;
	GtkToggleButton* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->speed4;
	gtk_button_set_has_frame ((GtkButton*) _tmp0_, speed == 4);
	_tmp1_ = self->priv->speed3;
	gtk_button_set_has_frame ((GtkButton*) _tmp1_, speed == 3);
	_tmp2_ = self->priv->speed2;
	gtk_button_set_has_frame ((GtkButton*) _tmp2_, speed == 2);
	_tmp3_ = self->priv->speed1;
	gtk_button_set_has_frame ((GtkButton*) _tmp3_, speed == 1);
}

static GVariant*
_variant_new11 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static void
speed_toggle_fakes (Speed* self,
                    GSimpleAction* _fakes_action,
                    GVariant* variant)
{
	GVariant* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (_fakes_action != NULL);
	g_return_if_fail (variant != NULL);
	_tmp0_ = g_action_get_state ((GAction*) _fakes_action);
	_tmp1_ = _tmp0_;
	_tmp2_ = _variant_new11 (!g_variant_get_boolean (_tmp1_));
	g_simple_action_set_state (_fakes_action, _tmp2_);
	_g_variant_unref0 (_tmp2_);
	_g_variant_unref0 (_tmp1_);
}

Speed*
speed_construct (GType object_type)
{
	Speed * self = NULL;
	self = (Speed*) g_object_new (object_type, NULL);
	return self;
}

Speed*
speed_new (void)
{
	return speed_construct (TYPE_SPEED);
}

static GObject *
speed_constructor (GType type,
                   guint n_construct_properties,
                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	Speed * self;
	GtkToggleButton* _tmp0_;
	GtkWidget* _tmp1_;
	GtkToggleButton* _tmp2_;
	GtkWidget* _tmp3_;
	GtkToggleButton* _tmp4_;
	GtkWidget* _tmp5_;
	GtkToggleButton* _tmp6_;
	GtkWidget* _tmp7_;
	GtkToggleButton* _tmp8_;
	GtkWidget* _tmp9_;
	GtkButton* _tmp10_;
	GtkButton* _tmp11_;
	GSimpleActionGroup* action_group = NULL;
	GSimpleActionGroup* _tmp14_;
	GSimpleActionGroup* _tmp15_;
	GSimpleActionGroup* _tmp16_;
	GSimpleActionGroup* _tmp17_;
	GAction* _tmp18_;
	GSimpleAction* _tmp19_;
	GSimpleActionGroup* _tmp20_;
	GAction* _tmp21_;
	GSimpleAction* _tmp22_;
	parent_class = G_OBJECT_CLASS (speed_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SPEED, Speed);
	_tmp0_ = self->priv->speed4;
	_tmp1_ = gtk_button_get_child ((GtkButton*) _tmp0_);
	speed_setup_label (self, _tmp1_);
	_tmp2_ = self->priv->speed3;
	_tmp3_ = gtk_button_get_child ((GtkButton*) _tmp2_);
	speed_setup_label (self, _tmp3_);
	_tmp4_ = self->priv->speed2;
	_tmp5_ = gtk_button_get_child ((GtkButton*) _tmp4_);
	speed_setup_label (self, _tmp5_);
	_tmp6_ = self->priv->speed1;
	_tmp7_ = gtk_button_get_child ((GtkButton*) _tmp6_);
	speed_setup_label (self, _tmp7_);
	_tmp8_ = self->priv->enable_fake_bonuses;
	_tmp9_ = gtk_button_get_child ((GtkButton*) _tmp8_);
	speed_setup_label (self, _tmp9_);
	_tmp10_ = self->priv->next;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp10_, 14);
	_tmp11_ = self->priv->next;
	if (gtk_widget_has_css_class ((GtkWidget*) _tmp11_, "play")) {
		GtkButton* _tmp12_;
		GtkButton* _tmp13_;
		_tmp12_ = self->priv->next;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp12_, "play");
		_tmp13_ = self->priv->next;
		gtk_widget_add_css_class ((GtkWidget*) _tmp13_, "pill");
	}
	_tmp14_ = g_simple_action_group_new ();
	action_group = _tmp14_;
	_tmp15_ = action_group;
	g_action_map_add_action_entries ((GActionMap*) _tmp15_, SPEED_players_action_entries, (gint) G_N_ELEMENTS (SPEED_players_action_entries), self);
	_tmp16_ = action_group;
	gtk_widget_insert_action_group ((GtkWidget*) self, "speed", (GActionGroup*) _tmp16_);
	_tmp17_ = action_group;
	_tmp18_ = g_action_map_lookup_action ((GActionMap*) _tmp17_, "change-speed");
	_tmp19_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp18_, g_simple_action_get_type (), GSimpleAction));
	_g_object_unref0 (self->priv->speed_action);
	self->priv->speed_action = _tmp19_;
	_tmp20_ = action_group;
	_tmp21_ = g_action_map_lookup_action ((GActionMap*) _tmp20_, "toggle-fakes");
	_tmp22_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, g_simple_action_get_type (), GSimpleAction));
	_g_object_unref0 (self->priv->fakes_action);
	self->priv->fakes_action = _tmp22_;
	_g_object_unref0 (action_group);
	return obj;
}

static void
speed_class_init (SpeedClass * klass,
                  gpointer klass_data)
{
	speed_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &Speed_private_offset);
	G_OBJECT_CLASS (klass)->constructor = speed_constructor;
	G_OBJECT_CLASS (klass)->finalize = speed_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Nibbles/ui/speed.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "speed4", FALSE, Speed_private_offset + G_STRUCT_OFFSET (SpeedPrivate, speed4));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "speed3", FALSE, Speed_private_offset + G_STRUCT_OFFSET (SpeedPrivate, speed3));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "speed2", FALSE, Speed_private_offset + G_STRUCT_OFFSET (SpeedPrivate, speed2));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "speed1", FALSE, Speed_private_offset + G_STRUCT_OFFSET (SpeedPrivate, speed1));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "enable_fake_bonuses", FALSE, Speed_private_offset + G_STRUCT_OFFSET (SpeedPrivate, enable_fake_bonuses));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "next", FALSE, Speed_private_offset + G_STRUCT_OFFSET (SpeedPrivate, next));
}

static void
speed_instance_init (Speed * self,
                     gpointer klass)
{
	self->priv = speed_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
speed_finalize (GObject * obj)
{
	Speed * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SPEED, Speed);
	_g_object_unref0 (self->priv->speed_action);
	_g_object_unref0 (self->priv->fakes_action);
	G_OBJECT_CLASS (speed_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
speed_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SpeedClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) speed_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Speed), 0, (GInstanceInitFunc) speed_instance_init, NULL };
	GType speed_type_id;
	speed_type_id = g_type_register_static (gtk_box_get_type (), "Speed", &g_define_type_info, G_TYPE_FLAG_NONE);
	Speed_private_offset = g_type_add_instance_private (speed_type_id, sizeof (SpeedPrivate));
	return speed_type_id;
}

GType
speed_get_type (void)
{
	static GType speed_type_id__once = 0;
	if (g_once_init_enter_pointer (&speed_type_id__once)) {
		GType speed_type_id;
		speed_type_id = speed_get_type_once ();
		g_once_init_leave_pointer (&speed_type_id__once, speed_type_id);
	}
	return speed_type_id__once;
}

