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

/*
 * This file is part of gitg
 *
 * Copyright (C) 2012 - Jesse van den Kieboom
 *
 * gitg 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 2 of the License, or
 * (at your option) any later version.
 *
 * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include "libgitg.h"
#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.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

enum  {
	GITG_COLOR_0_PROPERTY,
	GITG_COLOR_R_PROPERTY,
	GITG_COLOR_G_PROPERTY,
	GITG_COLOR_B_PROPERTY,
	GITG_COLOR_NUM_PROPERTIES
};
static GParamSpec* gitg_color_properties[GITG_COLOR_NUM_PROPERTIES];

#define GITG_COLOR_TYPE_RGB (gitg_color_rgb_get_type ())
typedef struct _GitgColorRgb GitgColorRgb;

struct _GitgColorRgb {
	gushort r;
	gushort g;
	gushort b;
};

static gpointer gitg_color_parent_class = NULL;
static guint gitg_color_current_index;
static guint gitg_color_current_index = 0U;

static GType gitg_color_rgb_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static GitgColorRgb* gitg_color_rgb_dup (const GitgColorRgb* self);
static void gitg_color_rgb_free (GitgColorRgb* self);
static guint gitg_color_inc_index (void);
static void gitg_color_finalize (GObject * obj);
static GType gitg_color_get_type_once (void);
static void _vala_gitg_color_get_property (GObject * object,
                                    guint property_id,
                                    GValue * value,
                                    GParamSpec * pspec);

static const GitgColorRgb GITG_COLOR_palette[14] = {{(gushort) 196, (gushort) 160, (gushort) 0}, {(gushort) 78, (gushort) 154, (gushort) 6}, {(gushort) 206, (gushort) 92, (gushort) 0}, {(gushort) 32, (gushort) 74, (gushort) 135}, {(gushort) 108, (gushort) 53, (gushort) 102}, {(gushort) 164, (gushort) 0, (gushort) 0}, {(gushort) 138, (gushort) 226, (gushort) 52}, {(gushort) 252, (gushort) 175, (gushort) 62}, {(gushort) 114, (gushort) 159, (gushort) 207}, {(gushort) 252, (gushort) 233, (gushort) 79}, {(gushort) 136, (gushort) 138, (gushort) 133}, {(gushort) 173, (gushort) 127, (gushort) 168}, {(gushort) 233, (gushort) 185, (gushort) 110}, {(gushort) 239, (gushort) 41, (gushort) 41}};

void
gitg_color_reset (void)
{
	gitg_color_current_index = (guint) 0;
}

void
gitg_color_components (GitgColor* self,
                       gdouble* r,
                       gdouble* g,
                       gdouble* b)
{
	gdouble _vala_r = 0.0;
	gdouble _vala_g = 0.0;
	gdouble _vala_b = 0.0;
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	gdouble _tmp4_;
	gdouble _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gitg_color_get_r (self);
	_tmp1_ = _tmp0_;
	_vala_r = _tmp1_;
	_tmp2_ = gitg_color_get_g (self);
	_tmp3_ = _tmp2_;
	_vala_g = _tmp3_;
	_tmp4_ = gitg_color_get_b (self);
	_tmp5_ = _tmp4_;
	_vala_b = _tmp5_;
	if (r) {
		*r = _vala_r;
	}
	if (g) {
		*g = _vala_g;
	}
	if (b) {
		*b = _vala_b;
	}
}

static guint
gitg_color_inc_index (void)
{
	guint next = 0U;
	guint _tmp0_;
	guint result;
	_tmp0_ = gitg_color_current_index;
	gitg_color_current_index = _tmp0_ + 1;
	next = _tmp0_;
	if (gitg_color_current_index == ((guint) G_N_ELEMENTS (GITG_COLOR_palette))) {
		gitg_color_current_index = (guint) 0;
	}
	result = next;
	return result;
}

GitgColor*
gitg_color_next (void)
{
	GitgColor* ret = NULL;
	GitgColor* _tmp0_;
	GitgColor* result;
	_tmp0_ = gitg_color_new ();
	ret = _tmp0_;
	ret->idx = gitg_color_inc_index ();
	result = ret;
	return result;
}

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

GitgColor*
gitg_color_next_index (GitgColor* self)
{
	GitgColor* _tmp0_;
	GitgColor* result;
	g_return_val_if_fail (self != NULL, NULL);
	self->idx = gitg_color_inc_index ();
	_tmp0_ = _g_object_ref0 (self);
	result = _tmp0_;
	return result;
}

GitgColor*
gitg_color_copy (GitgColor* self)
{
	GitgColor* ret = NULL;
	GitgColor* _tmp0_;
	GitgColor* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gitg_color_new ();
	ret = _tmp0_;
	ret->idx = self->idx;
	result = ret;
	return result;
}

GitgColor*
gitg_color_construct (GType object_type)
{
	GitgColor * self = NULL;
	self = (GitgColor*) g_object_new (object_type, NULL);
	return self;
}

GitgColor*
gitg_color_new (void)
{
	return gitg_color_construct (GITG_TYPE_COLOR);
}

gdouble
gitg_color_get_r (GitgColor* self)
{
	gdouble result;
	GitgColorRgb _tmp0_;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = GITG_COLOR_palette[self->idx];
	result = _tmp0_.r / 255.0;
	return result;
}

gdouble
gitg_color_get_g (GitgColor* self)
{
	gdouble result;
	GitgColorRgb _tmp0_;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = GITG_COLOR_palette[self->idx];
	result = _tmp0_.g / 255.0;
	return result;
}

gdouble
gitg_color_get_b (GitgColor* self)
{
	gdouble result;
	GitgColorRgb _tmp0_;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = GITG_COLOR_palette[self->idx];
	result = _tmp0_.b / 255.0;
	return result;
}

static GitgColorRgb*
gitg_color_rgb_dup (const GitgColorRgb* self)
{
	GitgColorRgb* dup;
	dup = g_new0 (GitgColorRgb, 1);
	memcpy (dup, self, sizeof (GitgColorRgb));
	return dup;
}

static void
gitg_color_rgb_free (GitgColorRgb* self)
{
	g_free (self);
}

 G_GNUC_NO_INLINE static GType
gitg_color_rgb_get_type_once (void)
{
	GType gitg_color_rgb_type_id;
	gitg_color_rgb_type_id = g_boxed_type_register_static ("GitgColorRgb", (GBoxedCopyFunc) gitg_color_rgb_dup, (GBoxedFreeFunc) gitg_color_rgb_free);
	return gitg_color_rgb_type_id;
}

static GType
gitg_color_rgb_get_type (void)
{
	static gsize gitg_color_rgb_type_id__once = 0;
	if (g_once_init_enter (&gitg_color_rgb_type_id__once)) {
		GType gitg_color_rgb_type_id;
		gitg_color_rgb_type_id = gitg_color_rgb_get_type_once ();
		g_once_init_leave (&gitg_color_rgb_type_id__once, gitg_color_rgb_type_id);
	}
	return gitg_color_rgb_type_id__once;
}

static void
gitg_color_class_init (GitgColorClass * klass,
                       gpointer klass_data)
{
	gitg_color_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_gitg_color_get_property;
	G_OBJECT_CLASS (klass)->finalize = gitg_color_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_COLOR_R_PROPERTY, gitg_color_properties[GITG_COLOR_R_PROPERTY] = g_param_spec_double ("r", "r", "r", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_COLOR_G_PROPERTY, gitg_color_properties[GITG_COLOR_G_PROPERTY] = g_param_spec_double ("g", "g", "g", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_COLOR_B_PROPERTY, gitg_color_properties[GITG_COLOR_B_PROPERTY] = g_param_spec_double ("b", "b", "b", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
gitg_color_instance_init (GitgColor * self,
                          gpointer klass)
{
	self->idx = (guint) 0;
}

static void
gitg_color_finalize (GObject * obj)
{
	GitgColor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_COLOR, GitgColor);
	G_OBJECT_CLASS (gitg_color_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_color_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgColorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_color_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgColor), 0, (GInstanceInitFunc) gitg_color_instance_init, NULL };
	GType gitg_color_type_id;
	gitg_color_type_id = g_type_register_static (G_TYPE_OBJECT, "GitgColor", &g_define_type_info, 0);
	return gitg_color_type_id;
}

GType
gitg_color_get_type (void)
{
	static gsize gitg_color_type_id__once = 0;
	if (g_once_init_enter (&gitg_color_type_id__once)) {
		GType gitg_color_type_id;
		gitg_color_type_id = gitg_color_get_type_once ();
		g_once_init_leave (&gitg_color_type_id__once, gitg_color_type_id);
	}
	return gitg_color_type_id__once;
}

static void
_vala_gitg_color_get_property (GObject * object,
                               guint property_id,
                               GValue * value,
                               GParamSpec * pspec)
{
	GitgColor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GITG_TYPE_COLOR, GitgColor);
	switch (property_id) {
		case GITG_COLOR_R_PROPERTY:
		g_value_set_double (value, gitg_color_get_r (self));
		break;
		case GITG_COLOR_G_PROPERTY:
		g_value_set_double (value, gitg_color_get_g (self));
		break;
		case GITG_COLOR_B_PROPERTY:
		g_value_set_double (value, gitg_color_get_b (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

