/* StrokeTask.c generated by valac 0.56.17, the Vala compiler
 * generated from StrokeTask.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-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  {
	BIRD_FONT_STROKE_TASK_0_PROPERTY,
	BIRD_FONT_STROKE_TASK_NUM_PROPERTIES
};
static GParamSpec* bird_font_stroke_task_properties[BIRD_FONT_STROKE_TASK_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block62Data Block62Data;
#define _g_source_unref0(var) ((var == NULL) ? NULL : (var = (g_source_unref (var), NULL)))

struct _BirdFontStrokeTaskPrivate {
	BirdFontPath* original;
	BirdFontPath* background_path;
};

struct _Block62Data {
	int _ref_count_;
	BirdFontStrokeTask* self;
	BirdFontPathList* stroke;
};

static gint BirdFontStrokeTask_private_offset;
static gpointer bird_font_stroke_task_parent_class = NULL;

static void bird_font_stroke_task_real_run (BirdFontTask* base);
static Block62Data* block62_data_ref (Block62Data* _data62_);
static void block62_data_unref (void * _userdata_);
static gboolean __lambda36_ (Block62Data* _data62_);
static gboolean ___lambda36__gsource_func (gpointer self);
static void bird_font_stroke_task_finalize (GObject * obj);
static GType bird_font_stroke_task_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_stroke_task_get_instance_private (BirdFontStrokeTask* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontStrokeTask_private_offset);
}

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

BirdFontStrokeTask*
bird_font_stroke_task_construct (GType object_type,
                                 BirdFontPath* path)
{
	BirdFontStrokeTask * self = NULL;
	BirdFontPath* _tmp0_;
	BirdFontPath* _tmp1_;
	g_return_val_if_fail (path != NULL, NULL);
	self = (BirdFontStrokeTask*) bird_font_task_construct (object_type, NULL, NULL, NULL, TRUE);
	_tmp0_ = _g_object_ref0 (path);
	_g_object_unref0 (self->priv->original);
	self->priv->original = _tmp0_;
	_tmp1_ = bird_font_path_copy (path);
	_g_object_unref0 (self->priv->background_path);
	self->priv->background_path = _tmp1_;
	return self;
}

BirdFontStrokeTask*
bird_font_stroke_task_new (BirdFontPath* path)
{
	return bird_font_stroke_task_construct (BIRD_FONT_TYPE_STROKE_TASK, path);
}

BirdFontStrokeTask*
bird_font_stroke_task_construct_none (GType object_type)
{
	BirdFontStrokeTask * self = NULL;
	BirdFontPath* _tmp0_;
	BirdFontPath* _tmp1_;
	self = (BirdFontStrokeTask*) bird_font_task_construct (object_type, NULL, NULL, NULL, TRUE);
	_tmp0_ = bird_font_path_new ();
	_g_object_unref0 (self->priv->original);
	self->priv->original = _tmp0_;
	_tmp1_ = bird_font_path_new ();
	_g_object_unref0 (self->priv->background_path);
	self->priv->background_path = _tmp1_;
	return self;
}

BirdFontStrokeTask*
bird_font_stroke_task_new_none (void)
{
	return bird_font_stroke_task_construct_none (BIRD_FONT_TYPE_STROKE_TASK);
}

static Block62Data*
block62_data_ref (Block62Data* _data62_)
{
	g_atomic_int_inc (&_data62_->_ref_count_);
	return _data62_;
}

static void
block62_data_unref (void * _userdata_)
{
	Block62Data* _data62_;
	_data62_ = (Block62Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data62_->_ref_count_)) {
		BirdFontStrokeTask* self;
		self = _data62_->self;
		_g_object_unref0 (_data62_->stroke);
		_g_object_unref0 (self);
		g_slice_free (Block62Data, _data62_);
	}
}

static gboolean
__lambda36_ (Block62Data* _data62_)
{
	BirdFontStrokeTask* self;
	gboolean result;
	self = _data62_->self;
	if (!bird_font_task_is_cancelled ((BirdFontTask*) self)) {
		BirdFontPath* _tmp0_;
		BirdFontPathList* _tmp1_;
		_tmp0_ = self->priv->original;
		_tmp1_ = _g_object_ref0 (_data62_->stroke);
		_g_object_unref0 (_tmp0_->full_stroke);
		_tmp0_->full_stroke = _tmp1_;
		bird_font_glyph_canvas_redraw ();
	}
	result = FALSE;
	return result;
}

static gboolean
___lambda36__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda36_ (self);
	return result;
}

static void
bird_font_stroke_task_real_run (BirdFontTask* base)
{
	BirdFontStrokeTask * self;
	Block62Data* _data62_;
	gdouble w = 0.0;
	BirdFontStrokeTool* tool = NULL;
	BirdFontStrokeTool* _tmp0_;
	BirdFontPath* _tmp1_;
	gdouble _tmp2_;
	gdouble _tmp3_;
	BirdFontPath* _tmp4_;
	BirdFontPathList* _tmp5_;
	GSource* idle = NULL;
	GSource* _tmp6_;
	self = (BirdFontStrokeTask*) base;
	_data62_ = g_slice_new0 (Block62Data);
	_data62_->_ref_count_ = 1;
	_data62_->self = g_object_ref (self);
	_tmp0_ = bird_font_stroke_tool_new_with_task (self);
	tool = _tmp0_;
	_tmp1_ = self->priv->background_path;
	_tmp2_ = bird_font_path_get_stroke (_tmp1_);
	_tmp3_ = _tmp2_;
	w = _tmp3_;
	_tmp4_ = self->priv->background_path;
	_tmp5_ = bird_font_stroke_tool_get_stroke (tool, _tmp4_, w);
	_g_object_unref0 (_data62_->stroke);
	_data62_->stroke = _tmp5_;
	_tmp6_ = g_idle_source_new ();
	idle = _tmp6_;
	g_source_set_callback (idle, ___lambda36__gsource_func, block62_data_ref (_data62_), block62_data_unref);
	g_source_attach (idle, NULL);
	_g_source_unref0 (idle);
	_g_object_unref0 (tool);
	block62_data_unref (_data62_);
	_data62_ = NULL;
}

static void
bird_font_stroke_task_class_init (BirdFontStrokeTaskClass * klass,
                                  gpointer klass_data)
{
	bird_font_stroke_task_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontStrokeTask_private_offset);
	((BirdFontTaskClass *) klass)->run = (void (*) (BirdFontTask*)) bird_font_stroke_task_real_run;
	G_OBJECT_CLASS (klass)->finalize = bird_font_stroke_task_finalize;
}

static void
bird_font_stroke_task_instance_init (BirdFontStrokeTask * self,
                                     gpointer klass)
{
	self->priv = bird_font_stroke_task_get_instance_private (self);
}

static void
bird_font_stroke_task_finalize (GObject * obj)
{
	BirdFontStrokeTask * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_STROKE_TASK, BirdFontStrokeTask);
	_g_object_unref0 (self->priv->original);
	_g_object_unref0 (self->priv->background_path);
	G_OBJECT_CLASS (bird_font_stroke_task_parent_class)->finalize (obj);
}

static GType
bird_font_stroke_task_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontStrokeTaskClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_stroke_task_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontStrokeTask), 0, (GInstanceInitFunc) bird_font_stroke_task_instance_init, NULL };
	GType bird_font_stroke_task_type_id;
	bird_font_stroke_task_type_id = g_type_register_static (BIRD_FONT_TYPE_TASK, "BirdFontStrokeTask", &g_define_type_info, 0);
	BirdFontStrokeTask_private_offset = g_type_add_instance_private (bird_font_stroke_task_type_id, sizeof (BirdFontStrokeTaskPrivate));
	return bird_font_stroke_task_type_id;
}

GType
bird_font_stroke_task_get_type (void)
{
	static volatile gsize bird_font_stroke_task_type_id__once = 0;
	if (g_once_init_enter (&bird_font_stroke_task_type_id__once)) {
		GType bird_font_stroke_task_type_id;
		bird_font_stroke_task_type_id = bird_font_stroke_task_get_type_once ();
		g_once_init_leave (&bird_font_stroke_task_type_id__once, bird_font_stroke_task_type_id);
	}
	return bird_font_stroke_task_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;
}

