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

/*
Copyright (C) 2015 Johan Mattsson

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

This library 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 
Lesser General Public License for more details.
*/

#include "birdfont.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <cairo-gobject.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.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

typedef struct _BirdFontParamSpecScreen BirdFontParamSpecScreen;

struct _BirdFontParamSpecScreen {
	GParamSpec parent_instance;
};

static gpointer bird_font_screen_parent_class = NULL;

static void bird_font_screen_finalize (BirdFontScreen * obj);
static GType bird_font_screen_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

gdouble
bird_font_screen_get_scale (void)
{
	BirdFontNativeWindow* _tmp0_;
	gdouble result;
	_tmp0_ = bird_font_main_window_native_window;
	result = bird_font_native_window_get_screen_scale (_tmp0_);
	return result;
}

cairo_surface_t*
bird_font_screen_create_background_surface (gint w,
                                            gint h)
{
	gint width = 0;
	gint height = 0;
	cairo_surface_t* _tmp0_;
	cairo_surface_t* result;
	width = (gint) (bird_font_screen_get_scale () * w);
	height = (gint) (bird_font_screen_get_scale () * h);
	_tmp0_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
	result = _tmp0_;
	return result;
}

void
bird_font_screen_paint_background_surface (cairo_t* cr,
                                           cairo_surface_t* s,
                                           gint x,
                                           gint y)
{
	g_return_if_fail (cr != NULL);
	g_return_if_fail (s != NULL);
	cairo_save (cr);
	cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
	cairo_scale (cr, 1 / bird_font_screen_get_scale (), 1 / bird_font_screen_get_scale ());
	cairo_set_source_surface (cr, s, (gdouble) ((gint) (x * bird_font_screen_get_scale ())), (gdouble) ((gint) (y * bird_font_screen_get_scale ())));
	cairo_paint (cr);
	cairo_restore (cr);
}

BirdFontScreen*
bird_font_screen_construct (GType object_type)
{
	BirdFontScreen* self = NULL;
	self = (BirdFontScreen*) g_type_create_instance (object_type);
	return self;
}

BirdFontScreen*
bird_font_screen_new (void)
{
	return bird_font_screen_construct (BIRD_FONT_TYPE_SCREEN);
}

static void
bird_font_value_screen_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
bird_font_value_screen_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		bird_font_screen_unref (value->data[0].v_pointer);
	}
}

static void
bird_font_value_screen_copy_value (const GValue* src_value,
                                   GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = bird_font_screen_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
bird_font_value_screen_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
bird_font_value_screen_collect_value (GValue* value,
                                      guint n_collect_values,
                                      GTypeCValue* collect_values,
                                      guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		BirdFontScreen * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = bird_font_screen_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
bird_font_value_screen_lcopy_value (const GValue* value,
                                    guint n_collect_values,
                                    GTypeCValue* collect_values,
                                    guint collect_flags)
{
	BirdFontScreen ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = bird_font_screen_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
bird_font_param_spec_screen (const gchar* name,
                             const gchar* nick,
                             const gchar* blurb,
                             GType object_type,
                             GParamFlags flags)
{
	BirdFontParamSpecScreen* spec;
	g_return_val_if_fail (g_type_is_a (object_type, BIRD_FONT_TYPE_SCREEN), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
bird_font_value_get_screen (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BIRD_FONT_TYPE_SCREEN), NULL);
	return value->data[0].v_pointer;
}

void
bird_font_value_set_screen (GValue* value,
                            gpointer v_object)
{
	BirdFontScreen * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BIRD_FONT_TYPE_SCREEN));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, BIRD_FONT_TYPE_SCREEN));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		bird_font_screen_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		bird_font_screen_unref (old);
	}
}

void
bird_font_value_take_screen (GValue* value,
                             gpointer v_object)
{
	BirdFontScreen * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BIRD_FONT_TYPE_SCREEN));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, BIRD_FONT_TYPE_SCREEN));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		bird_font_screen_unref (old);
	}
}

static void
bird_font_screen_class_init (BirdFontScreenClass * klass,
                             gpointer klass_data)
{
	bird_font_screen_parent_class = g_type_class_peek_parent (klass);
	((BirdFontScreenClass *) klass)->finalize = bird_font_screen_finalize;
}

static void
bird_font_screen_instance_init (BirdFontScreen * self,
                                gpointer klass)
{
	self->ref_count = 1;
}

static void
bird_font_screen_finalize (BirdFontScreen * obj)
{
	BirdFontScreen * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_SCREEN, BirdFontScreen);
	g_signal_handlers_destroy (self);
}

static GType
bird_font_screen_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { bird_font_value_screen_init, bird_font_value_screen_free_value, bird_font_value_screen_copy_value, bird_font_value_screen_peek_pointer, "p", bird_font_value_screen_collect_value, "p", bird_font_value_screen_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontScreenClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_screen_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontScreen), 0, (GInstanceInitFunc) bird_font_screen_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType bird_font_screen_type_id;
	bird_font_screen_type_id = g_type_register_fundamental (g_type_fundamental_next (), "BirdFontScreen", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return bird_font_screen_type_id;
}

GType
bird_font_screen_get_type (void)
{
	static volatile gsize bird_font_screen_type_id__once = 0;
	if (g_once_init_enter (&bird_font_screen_type_id__once)) {
		GType bird_font_screen_type_id;
		bird_font_screen_type_id = bird_font_screen_get_type_once ();
		g_once_init_leave (&bird_font_screen_type_id__once, bird_font_screen_type_id);
	}
	return bird_font_screen_type_id__once;
}

gpointer
bird_font_screen_ref (gpointer instance)
{
	BirdFontScreen * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
bird_font_screen_unref (gpointer instance)
{
	BirdFontScreen * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		BIRD_FONT_SCREEN_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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;
}

