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

/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * Copyright © 2025 Johan Gay
 *
 * This file is part of GNOME Sudoku.
 *
 * GNOME Sudoku 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.
 *
 * GNOME Sudoku 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 GNOME Sudoku. If not, see <http://www.gnu.org/licenses/>.
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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
#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_SUDOKU_EARMARK (sudoku_earmark_get_type ())
#define SUDOKU_EARMARK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SUDOKU_EARMARK, SudokuEarmark))
#define SUDOKU_EARMARK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SUDOKU_EARMARK, SudokuEarmarkClass))
#define IS_SUDOKU_EARMARK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SUDOKU_EARMARK))
#define IS_SUDOKU_EARMARK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SUDOKU_EARMARK))
#define SUDOKU_EARMARK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SUDOKU_EARMARK, SudokuEarmarkClass))

typedef struct _SudokuEarmark SudokuEarmark;
typedef struct _SudokuEarmarkClass SudokuEarmarkClass;
typedef struct _SudokuEarmarkPrivate SudokuEarmarkPrivate;
enum  {
	SUDOKU_EARMARK_0_PROPERTY,
	SUDOKU_EARMARK_HIGHLIGHT_PROPERTY,
	SUDOKU_EARMARK_ERROR_PROPERTY,
	SUDOKU_EARMARK_NUM_PROPERTIES
};
static GParamSpec* sudoku_earmark_properties[SUDOKU_EARMARK_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _SudokuEarmark {
	AdwBin parent_instance;
	SudokuEarmarkPrivate * priv;
	GtkLabel* label;
};

struct _SudokuEarmarkClass {
	AdwBinClass parent_class;
};

struct _SudokuEarmarkPrivate {
	AdwTimedAnimation* hide_animation;
	gboolean _highlight;
	gboolean _error;
};

static gint SudokuEarmark_private_offset;
static gpointer sudoku_earmark_parent_class = NULL;

VALA_EXTERN GType sudoku_earmark_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SudokuEarmark, g_object_unref)
VALA_EXTERN SudokuEarmark* sudoku_earmark_new (const gchar* str);
VALA_EXTERN SudokuEarmark* sudoku_earmark_construct (GType object_type,
                                         const gchar* str);
static void sudoku_earmark_hide_animation_done (SudokuEarmark* self);
static void _sudoku_earmark_hide_animation_done_adw_animation_done (AdwAnimation* _sender,
                                                             gpointer self);
VALA_EXTERN void sudoku_earmark_play_hide_animation (SudokuEarmark* self);
VALA_EXTERN void sudoku_earmark_skip_animation (SudokuEarmark* self);
VALA_EXTERN gboolean sudoku_earmark_get_highlight (SudokuEarmark* self);
VALA_EXTERN void sudoku_earmark_set_highlight (SudokuEarmark* self,
                                   gboolean value);
VALA_EXTERN gboolean sudoku_earmark_get_error (SudokuEarmark* self);
VALA_EXTERN void sudoku_earmark_set_error (SudokuEarmark* self,
                               gboolean value);
static void sudoku_earmark_finalize (GObject * obj);
static GType sudoku_earmark_get_type_once (void);
static void _vala_sudoku_earmark_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec);
static void _vala_sudoku_earmark_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec);

static inline gpointer
sudoku_earmark_get_instance_private (SudokuEarmark* self)
{
	return G_STRUCT_MEMBER_P (self, SudokuEarmark_private_offset);
}

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

static void
_sudoku_earmark_hide_animation_done_adw_animation_done (AdwAnimation* _sender,
                                                        gpointer self)
{
	sudoku_earmark_hide_animation_done ((SudokuEarmark*) self);
}

SudokuEarmark*
sudoku_earmark_construct (GType object_type,
                          const gchar* str)
{
	SudokuEarmark * self = NULL;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	AdwPropertyAnimationTarget* anim_target = NULL;
	AdwPropertyAnimationTarget* _tmp4_;
	AdwAnimationTarget* _tmp5_;
	AdwTimedAnimation* _tmp6_;
	AdwTimedAnimation* _tmp7_;
	self = (SudokuEarmark*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkLabel*) gtk_label_new (str);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->label);
	self->label = _tmp0_;
	_tmp1_ = self->label;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp1_);
	_tmp2_ = self->label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp2_, "earmark");
	_tmp3_ = self->label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp3_, "numeric");
	_tmp4_ = (AdwPropertyAnimationTarget*) adw_property_animation_target_new ((GObject*) self, "opacity");
	anim_target = _tmp4_;
	_tmp5_ = _g_object_ref0 ((AdwAnimationTarget*) anim_target);
	_tmp6_ = (AdwTimedAnimation*) adw_timed_animation_new ((GtkWidget*) self, (gdouble) 1, (gdouble) 0, (guint) 1000, _tmp5_);
	_g_object_unref0 (self->priv->hide_animation);
	self->priv->hide_animation = _tmp6_;
	_tmp7_ = self->priv->hide_animation;
	g_signal_connect_object ((AdwAnimation*) _tmp7_, "done", (GCallback) _sudoku_earmark_hide_animation_done_adw_animation_done, self, 0);
	_g_object_unref0 (anim_target);
	return self;
}

SudokuEarmark*
sudoku_earmark_new (const gchar* str)
{
	return sudoku_earmark_construct (TYPE_SUDOKU_EARMARK, str);
}

static void
sudoku_earmark_hide_animation_done (SudokuEarmark* self)
{
	g_return_if_fail (self != NULL);
	gtk_widget_set_visible ((GtkWidget*) self, FALSE);
	gtk_widget_set_opacity ((GtkWidget*) self, (gdouble) 1);
}

void
sudoku_earmark_play_hide_animation (SudokuEarmark* self)
{
	AdwTimedAnimation* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->hide_animation;
	adw_animation_play ((AdwAnimation*) _tmp0_);
}

void
sudoku_earmark_skip_animation (SudokuEarmark* self)
{
	AdwTimedAnimation* _tmp0_;
	AdwAnimationState _tmp1_;
	AdwAnimationState _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->hide_animation;
	_tmp1_ = adw_animation_get_state ((AdwAnimation*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == ADW_ANIMATION_PLAYING) {
		AdwTimedAnimation* _tmp3_;
		_tmp3_ = self->priv->hide_animation;
		adw_animation_skip ((AdwAnimation*) _tmp3_);
	}
}

gboolean
sudoku_earmark_get_highlight (SudokuEarmark* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_highlight;
	return result;
}

void
sudoku_earmark_set_highlight (SudokuEarmark* self,
                              gboolean value)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	self->priv->_highlight = value;
	if (value) {
		gboolean _tmp1_;
		gboolean _tmp2_;
		_tmp1_ = sudoku_earmark_get_error (self);
		_tmp2_ = _tmp1_;
		_tmp0_ = !_tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GtkLabel* _tmp3_;
		_tmp3_ = self->label;
		gtk_widget_add_css_class ((GtkWidget*) _tmp3_, "highlight-number");
	} else {
		GtkLabel* _tmp4_;
		_tmp4_ = self->label;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp4_, "highlight-number");
	}
	g_object_notify_by_pspec ((GObject *) self, sudoku_earmark_properties[SUDOKU_EARMARK_HIGHLIGHT_PROPERTY]);
}

gboolean
sudoku_earmark_get_error (SudokuEarmark* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_error;
	return result;
}

void
sudoku_earmark_set_error (SudokuEarmark* self,
                          gboolean value)
{
	g_return_if_fail (self != NULL);
	self->priv->_error = value;
	if (value) {
		GtkLabel* _tmp0_;
		_tmp0_ = self->label;
		gtk_widget_add_css_class ((GtkWidget*) _tmp0_, "error");
	} else {
		GtkLabel* _tmp1_;
		_tmp1_ = self->label;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp1_, "error");
	}
	g_object_notify_by_pspec ((GObject *) self, sudoku_earmark_properties[SUDOKU_EARMARK_ERROR_PROPERTY]);
}

static void
sudoku_earmark_class_init (SudokuEarmarkClass * klass,
                           gpointer klass_data)
{
	sudoku_earmark_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SudokuEarmark_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_sudoku_earmark_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_sudoku_earmark_set_property;
	G_OBJECT_CLASS (klass)->finalize = sudoku_earmark_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SUDOKU_EARMARK_HIGHLIGHT_PROPERTY, sudoku_earmark_properties[SUDOKU_EARMARK_HIGHLIGHT_PROPERTY] = g_param_spec_boolean ("highlight", "highlight", "highlight", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SUDOKU_EARMARK_ERROR_PROPERTY, sudoku_earmark_properties[SUDOKU_EARMARK_ERROR_PROPERTY] = g_param_spec_boolean ("error", "error", "error", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
sudoku_earmark_instance_init (SudokuEarmark * self,
                              gpointer klass)
{
	self->priv = sudoku_earmark_get_instance_private (self);
	self->priv->_highlight = FALSE;
	self->priv->_error = FALSE;
}

static void
sudoku_earmark_finalize (GObject * obj)
{
	SudokuEarmark * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SUDOKU_EARMARK, SudokuEarmark);
	_g_object_unref0 (self->priv->hide_animation);
	_g_object_unref0 (self->label);
	G_OBJECT_CLASS (sudoku_earmark_parent_class)->finalize (obj);
}

static GType
sudoku_earmark_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SudokuEarmarkClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sudoku_earmark_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SudokuEarmark), 0, (GInstanceInitFunc) sudoku_earmark_instance_init, NULL };
	GType sudoku_earmark_type_id;
	sudoku_earmark_type_id = g_type_register_static (adw_bin_get_type (), "SudokuEarmark", &g_define_type_info, 0);
	SudokuEarmark_private_offset = g_type_add_instance_private (sudoku_earmark_type_id, sizeof (SudokuEarmarkPrivate));
	return sudoku_earmark_type_id;
}

GType
sudoku_earmark_get_type (void)
{
	static volatile gsize sudoku_earmark_type_id__once = 0;
	if (g_once_init_enter (&sudoku_earmark_type_id__once)) {
		GType sudoku_earmark_type_id;
		sudoku_earmark_type_id = sudoku_earmark_get_type_once ();
		g_once_init_leave (&sudoku_earmark_type_id__once, sudoku_earmark_type_id);
	}
	return sudoku_earmark_type_id__once;
}

static void
_vala_sudoku_earmark_get_property (GObject * object,
                                   guint property_id,
                                   GValue * value,
                                   GParamSpec * pspec)
{
	SudokuEarmark * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_SUDOKU_EARMARK, SudokuEarmark);
	switch (property_id) {
		case SUDOKU_EARMARK_HIGHLIGHT_PROPERTY:
		g_value_set_boolean (value, sudoku_earmark_get_highlight (self));
		break;
		case SUDOKU_EARMARK_ERROR_PROPERTY:
		g_value_set_boolean (value, sudoku_earmark_get_error (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_sudoku_earmark_set_property (GObject * object,
                                   guint property_id,
                                   const GValue * value,
                                   GParamSpec * pspec)
{
	SudokuEarmark * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_SUDOKU_EARMARK, SudokuEarmark);
	switch (property_id) {
		case SUDOKU_EARMARK_HIGHLIGHT_PROPERTY:
		sudoku_earmark_set_highlight (self, g_value_get_boolean (value));
		break;
		case SUDOKU_EARMARK_ERROR_PROPERTY:
		sudoku_earmark_set_error (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

