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

/*
* Copyright (c) 2018-2026 (https://github.com/phase1geo/Minder)
*
* 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 2 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Trevor Williams <phase1geo@gmail.com>
*/

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gdk/gdk.h>
#include <graphene-gobject.h>
#include <gtk/gtk.h>
#include <cairo-gobject.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_LINK_DASH (link_dash_get_type ())
#define LINK_DASH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LINK_DASH, LinkDash))
#define LINK_DASH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LINK_DASH, LinkDashClass))
#define IS_LINK_DASH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LINK_DASH))
#define IS_LINK_DASH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LINK_DASH))
#define LINK_DASH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LINK_DASH, LinkDashClass))

typedef struct _LinkDash LinkDash;
typedef struct _LinkDashClass LinkDashClass;
typedef struct _LinkDashPrivate LinkDashPrivate;
enum  {
	LINK_DASH_0_PROPERTY,
	LINK_DASH_NUM_PROPERTIES
};
static GParamSpec* link_dash_properties[LINK_DASH_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _cairo_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_destroy (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __vala_graphene_rect_t_free0(var) ((var == NULL) ? NULL : (var = (_vala_graphene_rect_t_free (var), NULL)))

struct _LinkDash {
	GObject parent_instance;
	LinkDashPrivate * priv;
	gchar* name;
	gchar* display_name;
	gdouble* pattern;
	gint pattern_length1;
};

struct _LinkDashClass {
	GObjectClass parent_class;
};

static gpointer link_dash_parent_class = NULL;

VALA_EXTERN GType link_dash_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (LinkDash, g_object_unref)
VALA_EXTERN LinkDash* link_dash_new (const gchar* name,
                         const gchar* display_name,
                         gdouble* pattern,
                         gint pattern_length1);
VALA_EXTERN LinkDash* link_dash_construct (GType object_type,
                               const gchar* name,
                               const gchar* display_name,
                               gdouble* pattern,
                               gint pattern_length1);
static gdouble* _vala_array_dup3 (gdouble* self,
                           gssize length);
VALA_EXTERN GdkPaintable* link_dash_make_icon (LinkDash* self,
                                   gboolean dark);
static void _vala_graphene_rect_t_free (graphene_rect_t* self);
VALA_EXTERN void link_dash_set_context (LinkDash* self,
                            cairo_t* ctx,
                            gint line_width);
static void _vala_array_add4 (gdouble* * array,
                       gint* length,
                       gint* size,
                       gdouble value);
static void _vala_array_add5 (gdouble* * array,
                       gint* length,
                       gint* size,
                       gdouble value);
static void link_dash_finalize (GObject * obj);
static GType link_dash_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gdouble*
_vala_array_dup3 (gdouble* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gdouble));
	}
	return NULL;
}

LinkDash*
link_dash_construct (GType object_type,
                     const gchar* name,
                     const gchar* display_name,
                     gdouble* pattern,
                     gint pattern_length1)
{
	LinkDash * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gdouble* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (display_name != NULL, NULL);
	self = (LinkDash*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (name);
	_g_free0 (self->name);
	self->name = _tmp0_;
	_tmp1_ = g_strdup (display_name);
	_g_free0 (self->display_name);
	self->display_name = _tmp1_;
	_tmp2_ = (pattern != NULL) ? _vala_array_dup3 (pattern, pattern_length1) : pattern;
	_tmp2__length1 = pattern_length1;
	self->pattern = (g_free (self->pattern), NULL);
	self->pattern = _tmp2_;
	self->pattern_length1 = _tmp2__length1;
	return self;
}

LinkDash*
link_dash_new (const gchar* name,
               const gchar* display_name,
               gdouble* pattern,
               gint pattern_length1)
{
	return link_dash_construct (TYPE_LINK_DASH, name, display_name, pattern, pattern_length1);
}

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

static void
_vala_graphene_rect_t_free (graphene_rect_t* self)
{
	g_boxed_free (graphene_rect_get_type (), self);
}

GdkPaintable*
link_dash_make_icon (LinkDash* self,
                     gboolean dark)
{
	graphene_rect_t* rect = NULL;
	graphene_rect_t* _tmp0_;
	graphene_rect_t* _tmp1_;
	GtkSnapshot* snapshot = NULL;
	GtkSnapshot* _tmp2_;
	cairo_t* ctx = NULL;
	GtkSnapshot* _tmp3_;
	graphene_rect_t* _tmp4_;
	graphene_rect_t _tmp5_;
	cairo_t* _tmp6_;
	gdouble _tmp7_ = 0.0;
	gdouble color = 0.0;
	cairo_t* _tmp8_;
	cairo_t* _tmp9_;
	gdouble* _tmp10_;
	gint _tmp10__length1;
	cairo_t* _tmp11_;
	cairo_t* _tmp12_;
	cairo_t* _tmp13_;
	cairo_t* _tmp14_;
	cairo_t* _tmp15_;
	GtkSnapshot* _tmp16_;
	GtkSnapshot* _tmp17_;
	GdkPaintable* _tmp18_;
	GdkPaintable* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = graphene_rect_alloc ();
	rect = _tmp0_;
	_tmp1_ = rect;
	graphene_rect_init (_tmp1_, (gfloat) 0.0, (gfloat) 0.0, (gfloat) 100, (gfloat) 20);
	_tmp2_ = gtk_snapshot_new ();
	snapshot = _tmp2_;
	_tmp3_ = snapshot;
	_tmp4_ = rect;
	_tmp5_ = *_tmp4_;
	_tmp6_ = gtk_snapshot_append_cairo (_tmp3_, &_tmp5_);
	ctx = _tmp6_;
	if (dark) {
		_tmp7_ = 1.0;
	} else {
		_tmp7_ = 0.0;
	}
	color = _tmp7_;
	_tmp8_ = ctx;
	cairo_set_source_rgba (_tmp8_, color, color, color, (gdouble) 1);
	_tmp9_ = ctx;
	_tmp10_ = self->pattern;
	_tmp10__length1 = self->pattern_length1;
	cairo_set_dash (_tmp9_, _tmp10_, (gint) _tmp10__length1, (gdouble) 0);
	_tmp11_ = ctx;
	cairo_set_line_width (_tmp11_, (gdouble) 2);
	_tmp12_ = ctx;
	cairo_set_line_cap (_tmp12_, CAIRO_LINE_CAP_ROUND);
	_tmp13_ = ctx;
	cairo_move_to (_tmp13_, (gdouble) 10, (gdouble) 10);
	_tmp14_ = ctx;
	cairo_line_to (_tmp14_, (gdouble) 90, (gdouble) 10);
	_tmp15_ = ctx;
	cairo_stroke (_tmp15_);
	_tmp16_ = snapshot;
	_tmp17_ = _g_object_ref0 (_tmp16_);
	_tmp18_ = gtk_snapshot_free_to_paintable (_tmp17_, NULL);
	result = _tmp18_;
	_cairo_destroy0 (ctx);
	_g_object_unref0 (snapshot);
	__vala_graphene_rect_t_free0 (rect);
	return result;
}

static void
_vala_array_add4 (gdouble* * array,
                  gint* length,
                  gint* size,
                  gdouble value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gdouble, *array, *size);
	}
	(*array)[(*length)++] = value;
}

static void
_vala_array_add5 (gdouble* * array,
                  gint* length,
                  gint* size,
                  gdouble value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gdouble, *array, *size);
	}
	(*array)[(*length)++] = value;
}

void
link_dash_set_context (LinkDash* self,
                       cairo_t* ctx,
                       gint line_width)
{
	gdouble* adjusted_pattern = NULL;
	gdouble* _tmp0_;
	gint adjusted_pattern_length1;
	gint _adjusted_pattern_size_;
	gint i = 0;
	gdouble* _tmp1_;
	gint _tmp1__length1;
	gdouble* _tmp3_;
	gint _tmp3__length1;
	g_return_if_fail (self != NULL);
	g_return_if_fail (ctx != NULL);
	_tmp0_ = g_new0 (gdouble, 0);
	adjusted_pattern = _tmp0_;
	adjusted_pattern_length1 = 0;
	_adjusted_pattern_size_ = adjusted_pattern_length1;
	i = 0;
	_tmp1_ = self->pattern;
	_tmp1__length1 = self->pattern_length1;
	{
		gdouble* val_collection = NULL;
		gint val_collection_length1 = 0;
		gint _val_collection_size_ = 0;
		gint val_it = 0;
		val_collection = _tmp1_;
		val_collection_length1 = _tmp1__length1;
		for (val_it = 0; val_it < val_collection_length1; val_it = val_it + 1) {
			gdouble val = 0.0;
			val = val_collection[val_it];
			{
				gint _tmp2_;
				if (i == 0) {
					_vala_array_add4 (&adjusted_pattern, &adjusted_pattern_length1, &_adjusted_pattern_size_, val);
				} else {
					_vala_array_add5 (&adjusted_pattern, &adjusted_pattern_length1, &_adjusted_pattern_size_, line_width + val);
				}
				_tmp2_ = i;
				i = _tmp2_ + 1;
			}
		}
	}
	_tmp3_ = adjusted_pattern;
	_tmp3__length1 = adjusted_pattern_length1;
	cairo_set_dash (ctx, _tmp3_, (gint) _tmp3__length1, (gdouble) 0);
	adjusted_pattern = (g_free (adjusted_pattern), NULL);
}

static void
link_dash_class_init (LinkDashClass * klass,
                      gpointer klass_data)
{
	link_dash_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = link_dash_finalize;
}

static void
link_dash_instance_init (LinkDash * self,
                         gpointer klass)
{
}

static void
link_dash_finalize (GObject * obj)
{
	LinkDash * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_LINK_DASH, LinkDash);
	_g_free0 (self->name);
	_g_free0 (self->display_name);
	self->pattern = (g_free (self->pattern), NULL);
	G_OBJECT_CLASS (link_dash_parent_class)->finalize (obj);
}

static GType
link_dash_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (LinkDashClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) link_dash_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LinkDash), 0, (GInstanceInitFunc) link_dash_instance_init, NULL };
	GType link_dash_type_id;
	link_dash_type_id = g_type_register_static (G_TYPE_OBJECT, "LinkDash", &g_define_type_info, 0);
	return link_dash_type_id;
}

GType
link_dash_get_type (void)
{
	static volatile gsize link_dash_type_id__once = 0;
	if (g_once_init_enter (&link_dash_type_id__once)) {
		GType link_dash_type_id;
		link_dash_type_id = link_dash_get_type_once ();
		g_once_init_leave (&link_dash_type_id__once, link_dash_type_id);
	}
	return link_dash_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

