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

/*///////////////////////////////////////////////////////////////////////*/
/* Copyright 2011-2021 Simon Schneegans*/
/**/
/* Permission is hereby granted, free of charge, to any person obtaining*/
/* a copy of this software and associated documentation files (the*/
/* "Software"), to deal in the Software without restriction, including*/
/* without limitation the rights to use, copy, modify, merge, publish,*/
/* distribute, sublicense, and/or sell copies of the Software, and to*/
/* permit persons to whom the Software is furnished to do so, subject to*/
/* the following conditions:*/
/* */
/* The above copyright notice and this permission notice shall be*/
/* included in all copies or substantial portions of the Software.*/
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,*/
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF*/
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY*/
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,*/
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE*/
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
/*///////////////////////////////////////////////////////////////////////*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>

#define GNOME_PIE_TIP_VIEWER_fade_time 0.5
#define GNOME_PIE_TIP_VIEWER_frame_rate 20.0
#define GNOME_PIE_TIP_VIEWER_base_delay 3.0
#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 GNOME_PIE_TYPE_TIP_VIEWER (gnome_pie_tip_viewer_get_type ())
#define GNOME_PIE_TIP_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_PIE_TYPE_TIP_VIEWER, GnomePieTipViewer))
#define GNOME_PIE_TIP_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_PIE_TYPE_TIP_VIEWER, GnomePieTipViewerClass))
#define GNOME_PIE_IS_TIP_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_PIE_TYPE_TIP_VIEWER))
#define GNOME_PIE_IS_TIP_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_PIE_TYPE_TIP_VIEWER))
#define GNOME_PIE_TIP_VIEWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_PIE_TYPE_TIP_VIEWER, GnomePieTipViewerClass))

typedef struct _GnomePieTipViewer GnomePieTipViewer;
typedef struct _GnomePieTipViewerClass GnomePieTipViewerClass;
typedef struct _GnomePieTipViewerPrivate GnomePieTipViewerPrivate;

#define GNOME_PIE_TYPE_ANIMATED_VALUE (gnome_pie_animated_value_get_type ())
#define GNOME_PIE_ANIMATED_VALUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_PIE_TYPE_ANIMATED_VALUE, GnomePieAnimatedValue))
#define GNOME_PIE_ANIMATED_VALUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_PIE_TYPE_ANIMATED_VALUE, GnomePieAnimatedValueClass))
#define GNOME_PIE_IS_ANIMATED_VALUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_PIE_TYPE_ANIMATED_VALUE))
#define GNOME_PIE_IS_ANIMATED_VALUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_PIE_TYPE_ANIMATED_VALUE))
#define GNOME_PIE_ANIMATED_VALUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_PIE_TYPE_ANIMATED_VALUE, GnomePieAnimatedValueClass))

typedef struct _GnomePieAnimatedValue GnomePieAnimatedValue;
typedef struct _GnomePieAnimatedValueClass GnomePieAnimatedValueClass;
enum  {
	GNOME_PIE_TIP_VIEWER_0_PROPERTY,
	GNOME_PIE_TIP_VIEWER_NUM_PROPERTIES
};
static GParamSpec* gnome_pie_tip_viewer_properties[GNOME_PIE_TIP_VIEWER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GnomePieTipViewer {
	GtkLabel parent_instance;
	GnomePieTipViewerPrivate * priv;
};

struct _GnomePieTipViewerClass {
	GtkLabelClass parent_class;
};

struct _GnomePieTipViewerPrivate {
	gboolean playing;
	gchar** tips;
	gint tips_length1;
	gint _tips_size_;
	gint index;
	GnomePieAnimatedValue* alpha;
};

static gint GnomePieTipViewer_private_offset;
static gpointer gnome_pie_tip_viewer_parent_class = NULL;

VALA_EXTERN GType gnome_pie_tip_viewer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GnomePieTipViewer, g_object_unref)
VALA_EXTERN GType gnome_pie_animated_value_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GnomePieAnimatedValue, g_object_unref)
VALA_EXTERN GnomePieTipViewer* gnome_pie_tip_viewer_new (gchar** tips,
                                             gint tips_length1);
VALA_EXTERN GnomePieTipViewer* gnome_pie_tip_viewer_construct (GType object_type,
                                                   gchar** tips,
                                                   gint tips_length1);
static gchar** _vala_array_dup1 (gchar** self,
                          gssize length);
VALA_EXTERN GnomePieAnimatedValue* gnome_pie_animated_value_new_linear (gdouble start,
                                                            gdouble end,
                                                            gdouble duration);
VALA_EXTERN GnomePieAnimatedValue* gnome_pie_animated_value_construct_linear (GType object_type,
                                                                  gdouble start,
                                                                  gdouble end,
                                                                  gdouble duration);
VALA_EXTERN void gnome_pie_tip_viewer_start_slide_show (GnomePieTipViewer* self);
static void gnome_pie_tip_viewer_show_tip (GnomePieTipViewer* self);
VALA_EXTERN void gnome_pie_tip_viewer_stop_slide_show (GnomePieTipViewer* self);
static void gnome_pie_tip_viewer_fade_in (GnomePieTipViewer* self);
VALA_EXTERN gdouble gnome_pie_animated_value_get_val (GnomePieAnimatedValue* self);
static gboolean __lambda88_ (GnomePieTipViewer* self);
VALA_EXTERN void gnome_pie_animated_value_update (GnomePieAnimatedValue* self,
                                      gdouble time);
static gboolean ___lambda88__gsource_func (gpointer self);
static void gnome_pie_tip_viewer_fade_out (GnomePieTipViewer* self);
static gboolean __lambda90_ (GnomePieTipViewer* self);
static gboolean ___lambda90__gsource_func (gpointer self);
static void gnome_pie_tip_viewer_set_random_tip (GnomePieTipViewer* self);
static gboolean __lambda89_ (GnomePieTipViewer* self);
static gboolean ___lambda91_ (GnomePieTipViewer* self);
static gboolean ____lambda91__gsource_func (gpointer self);
static gboolean ___lambda89__gsource_func (gpointer self);
static void gnome_pie_tip_viewer_finalize (GObject * obj);
static GType gnome_pie_tip_viewer_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
gnome_pie_tip_viewer_get_instance_private (GnomePieTipViewer* self)
{
	return G_STRUCT_MEMBER_P (self, GnomePieTipViewer_private_offset);
}

static gchar**
_vala_array_dup1 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

GnomePieTipViewer*
gnome_pie_tip_viewer_construct (GType object_type,
                                gchar** tips,
                                gint tips_length1)
{
	GnomePieTipViewer * self = NULL;
	gchar** _tmp0_;
	gint _tmp0__length1;
	GnomePieAnimatedValue* _tmp1_;
	self = (GnomePieTipViewer*) g_object_new (object_type, NULL);
	_tmp0_ = (tips != NULL) ? _vala_array_dup1 (tips, tips_length1) : tips;
	_tmp0__length1 = tips_length1;
	self->priv->tips = (_vala_array_free (self->priv->tips, self->priv->tips_length1, (GDestroyNotify) g_free), NULL);
	self->priv->tips = _tmp0_;
	self->priv->tips_length1 = _tmp0__length1;
	self->priv->_tips_size_ = self->priv->tips_length1;
	_tmp1_ = gnome_pie_animated_value_new_linear (0.0, 1.0, GNOME_PIE_TIP_VIEWER_fade_time);
	_g_object_unref0 (self->priv->alpha);
	self->priv->alpha = _tmp1_;
	gtk_misc_set_alignment ((GtkMisc*) self, 0.0f, 0.5f);
	gtk_widget_set_opacity ((GtkWidget*) self, (gdouble) 0);
	g_object_set ((GtkLabel*) self, "wrap", TRUE, NULL);
	gtk_widget_set_valign ((GtkWidget*) self, GTK_ALIGN_END);
	gtk_label_set_use_markup ((GtkLabel*) self, TRUE);
	return self;
}

GnomePieTipViewer*
gnome_pie_tip_viewer_new (gchar** tips,
                          gint tips_length1)
{
	return gnome_pie_tip_viewer_construct (GNOME_PIE_TYPE_TIP_VIEWER, tips, tips_length1);
}

void
gnome_pie_tip_viewer_start_slide_show (GnomePieTipViewer* self)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (!self->priv->playing) {
		gchar** _tmp1_;
		gint _tmp1__length1;
		_tmp1_ = self->priv->tips;
		_tmp1__length1 = self->priv->tips_length1;
		_tmp0_ = _tmp1__length1 > 1;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		self->priv->playing = TRUE;
		gnome_pie_tip_viewer_show_tip (self);
	}
}

void
gnome_pie_tip_viewer_stop_slide_show (GnomePieTipViewer* self)
{
	g_return_if_fail (self != NULL);
	self->priv->playing = FALSE;
}

static gboolean
__lambda88_ (GnomePieTipViewer* self)
{
	GnomePieAnimatedValue* _tmp0_;
	GnomePieAnimatedValue* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	GnomePieAnimatedValue* _tmp4_;
	gdouble _tmp5_;
	gdouble _tmp6_;
	gboolean result;
	_tmp0_ = self->priv->alpha;
	gnome_pie_animated_value_update (_tmp0_, 1.0 / GNOME_PIE_TIP_VIEWER_frame_rate);
	_tmp1_ = self->priv->alpha;
	_tmp2_ = gnome_pie_animated_value_get_val (_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_widget_set_opacity ((GtkWidget*) self, _tmp3_);
	_tmp4_ = self->priv->alpha;
	_tmp5_ = gnome_pie_animated_value_get_val (_tmp4_);
	_tmp6_ = _tmp5_;
	result = _tmp6_ != 1.0;
	return result;
}

static gboolean
___lambda88__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda88_ ((GnomePieTipViewer*) self);
	return result;
}

static void
gnome_pie_tip_viewer_fade_in (GnomePieTipViewer* self)
{
	GnomePieAnimatedValue* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	GnomePieAnimatedValue* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->alpha;
	_tmp1_ = gnome_pie_animated_value_get_val (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = gnome_pie_animated_value_new_linear (_tmp2_, 1.0, GNOME_PIE_TIP_VIEWER_fade_time);
	_g_object_unref0 (self->priv->alpha);
	self->priv->alpha = _tmp3_;
	g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) (1000.0 / GNOME_PIE_TIP_VIEWER_frame_rate), ___lambda88__gsource_func, g_object_ref (self), g_object_unref);
}

static gboolean
__lambda90_ (GnomePieTipViewer* self)
{
	GnomePieAnimatedValue* _tmp0_;
	GnomePieAnimatedValue* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	GnomePieAnimatedValue* _tmp4_;
	gdouble _tmp5_;
	gdouble _tmp6_;
	gboolean result;
	_tmp0_ = self->priv->alpha;
	gnome_pie_animated_value_update (_tmp0_, 1.0 / GNOME_PIE_TIP_VIEWER_frame_rate);
	_tmp1_ = self->priv->alpha;
	_tmp2_ = gnome_pie_animated_value_get_val (_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_widget_set_opacity ((GtkWidget*) self, _tmp3_);
	_tmp4_ = self->priv->alpha;
	_tmp5_ = gnome_pie_animated_value_get_val (_tmp4_);
	_tmp6_ = _tmp5_;
	result = _tmp6_ != 0.0;
	return result;
}

static gboolean
___lambda90__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda90_ ((GnomePieTipViewer*) self);
	return result;
}

static void
gnome_pie_tip_viewer_fade_out (GnomePieTipViewer* self)
{
	GnomePieAnimatedValue* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	GnomePieAnimatedValue* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->alpha;
	_tmp1_ = gnome_pie_animated_value_get_val (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = gnome_pie_animated_value_new_linear (_tmp2_, 0.0, GNOME_PIE_TIP_VIEWER_fade_time);
	_g_object_unref0 (self->priv->alpha);
	self->priv->alpha = _tmp3_;
	g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) (1000.0 / GNOME_PIE_TIP_VIEWER_frame_rate), ___lambda90__gsource_func, g_object_ref (self), g_object_unref);
}

static gboolean
___lambda91_ (GnomePieTipViewer* self)
{
	gboolean result;
	gnome_pie_tip_viewer_show_tip (self);
	result = FALSE;
	return result;
}

static gboolean
____lambda91__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda91_ ((GnomePieTipViewer*) self);
	return result;
}

static gboolean
__lambda89_ (GnomePieTipViewer* self)
{
	gboolean result;
	gnome_pie_tip_viewer_fade_out (self);
	if (self->priv->playing) {
		g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) (1000.0 * GNOME_PIE_TIP_VIEWER_fade_time), ____lambda91__gsource_func, g_object_ref (self), g_object_unref);
	}
	result = FALSE;
	return result;
}

static gboolean
___lambda89__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda89_ ((GnomePieTipViewer*) self);
	return result;
}

static void
gnome_pie_tip_viewer_show_tip (GnomePieTipViewer* self)
{
	guint delay = 0U;
	gchar** _tmp0_;
	gint _tmp0__length1;
	const gchar* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	g_return_if_fail (self != NULL);
	gnome_pie_tip_viewer_set_random_tip (self);
	gnome_pie_tip_viewer_fade_in (self);
	_tmp0_ = self->priv->tips;
	_tmp0__length1 = self->priv->tips_length1;
	_tmp1_ = _tmp0_[self->priv->index];
	_tmp2_ = strlen (_tmp1_);
	_tmp3_ = _tmp2_;
	delay = ((guint) (GNOME_PIE_TIP_VIEWER_base_delay * 1000.0)) + (_tmp3_ * 30);
	g_timeout_add_full (G_PRIORITY_DEFAULT, delay, ___lambda89__gsource_func, g_object_ref (self), g_object_unref);
}

static void
gnome_pie_tip_viewer_set_random_tip (GnomePieTipViewer* self)
{
	gchar** _tmp0_;
	gint _tmp0__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->tips;
	_tmp0__length1 = self->priv->tips_length1;
	if (_tmp0__length1 > 1) {
		gint next_index = 0;
		gchar** _tmp3_;
		gint _tmp3__length1;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		next_index = -1;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				gchar** _tmp2_;
				gint _tmp2__length1;
				if (!_tmp1_) {
					if (!(next_index == self->priv->index)) {
						break;
					}
				}
				_tmp1_ = FALSE;
				_tmp2_ = self->priv->tips;
				_tmp2__length1 = self->priv->tips_length1;
				next_index = (gint) g_random_int_range ((gint32) 0, (gint32) _tmp2__length1);
			}
		}
		self->priv->index = next_index;
		_tmp3_ = self->priv->tips;
		_tmp3__length1 = self->priv->tips_length1;
		_tmp4_ = _tmp3_[self->priv->index];
		_tmp5_ = g_strconcat ("<small>", _tmp4_, NULL);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_strconcat (_tmp6_, "</small>", NULL);
		_tmp8_ = _tmp7_;
		gtk_label_set_label ((GtkLabel*) self, _tmp8_);
		_g_free0 (_tmp8_);
		_g_free0 (_tmp6_);
	}
}

static void
gnome_pie_tip_viewer_class_init (GnomePieTipViewerClass * klass,
                                 gpointer klass_data)
{
	gnome_pie_tip_viewer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GnomePieTipViewer_private_offset);
	G_OBJECT_CLASS (klass)->finalize = gnome_pie_tip_viewer_finalize;
}

static void
gnome_pie_tip_viewer_instance_init (GnomePieTipViewer * self,
                                    gpointer klass)
{
	self->priv = gnome_pie_tip_viewer_get_instance_private (self);
	self->priv->playing = FALSE;
	self->priv->index = -1;
}

static void
gnome_pie_tip_viewer_finalize (GObject * obj)
{
	GnomePieTipViewer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_PIE_TYPE_TIP_VIEWER, GnomePieTipViewer);
	self->priv->tips = (_vala_array_free (self->priv->tips, self->priv->tips_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (self->priv->alpha);
	G_OBJECT_CLASS (gnome_pie_tip_viewer_parent_class)->finalize (obj);
}

static GType
gnome_pie_tip_viewer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GnomePieTipViewerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gnome_pie_tip_viewer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GnomePieTipViewer), 0, (GInstanceInitFunc) gnome_pie_tip_viewer_instance_init, NULL };
	GType gnome_pie_tip_viewer_type_id;
	gnome_pie_tip_viewer_type_id = g_type_register_static (gtk_label_get_type (), "GnomePieTipViewer", &g_define_type_info, 0);
	GnomePieTipViewer_private_offset = g_type_add_instance_private (gnome_pie_tip_viewer_type_id, sizeof (GnomePieTipViewerPrivate));
	return gnome_pie_tip_viewer_type_id;
}

GType
gnome_pie_tip_viewer_get_type (void)
{
	static volatile gsize gnome_pie_tip_viewer_type_id__once = 0;
	if (g_once_init_enter (&gnome_pie_tip_viewer_type_id__once)) {
		GType gnome_pie_tip_viewer_type_id;
		gnome_pie_tip_viewer_type_id = gnome_pie_tip_viewer_get_type_once ();
		g_once_init_leave (&gnome_pie_tip_viewer_type_id__once, gnome_pie_tip_viewer_type_id);
	}
	return gnome_pie_tip_viewer_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

