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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
 *
 * Copyright (C) 2012 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Michael Terry <michael.terry@canonical.com>
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <cairo-gobject.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pango.h>
#include <float.h>
#include <math.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_FADING_LABEL (fading_label_get_type ())
#define FADING_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FADING_LABEL, FadingLabel))
#define FADING_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FADING_LABEL, FadingLabelClass))
#define IS_FADING_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FADING_LABEL))
#define IS_FADING_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FADING_LABEL))
#define FADING_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FADING_LABEL, FadingLabelClass))

typedef struct _FadingLabel FadingLabel;
typedef struct _FadingLabelClass FadingLabelClass;
typedef struct _FadingLabelPrivate FadingLabelPrivate;
enum  {
	FADING_LABEL_0_PROPERTY,
	FADING_LABEL_NUM_PROPERTIES
};
static GParamSpec* fading_label_properties[FADING_LABEL_NUM_PROPERTIES];
#define _cairo_surface_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_surface_destroy (var), NULL)))
#define _cairo_pattern_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_pattern_destroy (var), NULL)))
#define _cairo_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_destroy (var), NULL)))

struct _FadingLabel {
	GtkLabel parent_instance;
	FadingLabelPrivate * priv;
};

struct _FadingLabelClass {
	GtkLabelClass parent_class;
};

struct _FadingLabelPrivate {
	cairo_surface_t* cached_surface;
};

static gint FadingLabel_private_offset;
static gpointer fading_label_parent_class = NULL;

VALA_EXTERN GType fading_label_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FadingLabel, g_object_unref)
VALA_EXTERN FadingLabel* fading_label_new (const gchar* text);
VALA_EXTERN FadingLabel* fading_label_construct (GType object_type,
                                     const gchar* text);
static void fading_label_real_get_preferred_width (GtkWidget* base,
                                            gint* minimum,
                                            gint* natural);
static void fading_label_real_get_preferred_width_for_height (GtkWidget* base,
                                                       gint height,
                                                       gint* minimum,
                                                       gint* natural);
static void fading_label_real_size_allocate (GtkWidget* base,
                                      GtkAllocation* allocation);
static cairo_surface_t* fading_label_make_surface (FadingLabel* self,
                                            cairo_t* orig_c);
static gboolean fading_label_real_draw (GtkWidget* base,
                                 cairo_t* c);
static void fading_label_finalize (GObject * obj);
static GType fading_label_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
fading_label_get_instance_private (FadingLabel* self)
{
	return G_STRUCT_MEMBER_P (self, FadingLabel_private_offset);
}

FadingLabel*
fading_label_construct (GType object_type,
                        const gchar* text)
{
	FadingLabel * self = NULL;
#line 24 "../src/fading-label.vala"
	g_return_val_if_fail (text != NULL, NULL);
#line 26 "../src/fading-label.vala"
	self = (FadingLabel*) g_object_new (object_type, "label", text, NULL);
#line 24 "../src/fading-label.vala"
	return self;
#line 127 "fading-label.c"
}

FadingLabel*
fading_label_new (const gchar* text)
{
#line 24 "../src/fading-label.vala"
	return fading_label_construct (TYPE_FADING_LABEL, text);
#line 135 "fading-label.c"
}

static void
fading_label_real_get_preferred_width (GtkWidget* base,
                                       gint* minimum,
                                       gint* natural)
{
	FadingLabel * self;
	gint _vala_minimum = 0;
	gint _vala_natural = 0;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
#line 29 "../src/fading-label.vala"
	self = (FadingLabel*) base;
#line 31 "../src/fading-label.vala"
	GTK_WIDGET_CLASS (fading_label_parent_class)->get_preferred_width ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_label_get_type (), GtkLabel), &_tmp0_, &_tmp1_);
#line 31 "../src/fading-label.vala"
	_vala_minimum = _tmp0_;
#line 31 "../src/fading-label.vala"
	_vala_natural = _tmp1_;
#line 32 "../src/fading-label.vala"
	_vala_minimum = 0;
#line 29 "../src/fading-label.vala"
	if (minimum) {
#line 29 "../src/fading-label.vala"
		*minimum = _vala_minimum;
#line 162 "fading-label.c"
	}
#line 29 "../src/fading-label.vala"
	if (natural) {
#line 29 "../src/fading-label.vala"
		*natural = _vala_natural;
#line 168 "fading-label.c"
	}
}

static void
fading_label_real_get_preferred_width_for_height (GtkWidget* base,
                                                  gint height,
                                                  gint* minimum,
                                                  gint* natural)
{
	FadingLabel * self;
	gint _vala_minimum = 0;
	gint _vala_natural = 0;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
#line 35 "../src/fading-label.vala"
	self = (FadingLabel*) base;
#line 37 "../src/fading-label.vala"
	GTK_WIDGET_CLASS (fading_label_parent_class)->get_preferred_width_for_height ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_label_get_type (), GtkLabel), height, &_tmp0_, &_tmp1_);
#line 37 "../src/fading-label.vala"
	_vala_minimum = _tmp0_;
#line 37 "../src/fading-label.vala"
	_vala_natural = _tmp1_;
#line 38 "../src/fading-label.vala"
	_vala_minimum = 0;
#line 35 "../src/fading-label.vala"
	if (minimum) {
#line 35 "../src/fading-label.vala"
		*minimum = _vala_minimum;
#line 197 "fading-label.c"
	}
#line 35 "../src/fading-label.vala"
	if (natural) {
#line 35 "../src/fading-label.vala"
		*natural = _vala_natural;
#line 203 "fading-label.c"
	}
}

static void
fading_label_real_size_allocate (GtkWidget* base,
                                 GtkAllocation* allocation)
{
	FadingLabel * self;
	GtkAllocation _tmp0_;
#line 41 "../src/fading-label.vala"
	self = (FadingLabel*) base;
#line 41 "../src/fading-label.vala"
	g_return_if_fail (allocation != NULL);
#line 43 "../src/fading-label.vala"
	_tmp0_ = *allocation;
#line 43 "../src/fading-label.vala"
	GTK_WIDGET_CLASS (fading_label_parent_class)->size_allocate ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_label_get_type (), GtkLabel), &_tmp0_);
#line 44 "../src/fading-label.vala"
	_cairo_surface_destroy0 (self->priv->cached_surface);
#line 44 "../src/fading-label.vala"
	self->priv->cached_surface = NULL;
#line 225 "fading-label.c"
}

static cairo_surface_t*
fading_label_make_surface (FadingLabel* self,
                           cairo_t* orig_c)
{
	gint w = 0;
	gint h = 0;
	PangoLayout* _tmp0_;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	gint bw = 0;
	gint bh = 0;
	cairo_surface_t* surface = NULL;
	cairo_surface_t* _tmp3_;
	cairo_surface_t* _tmp4_;
	cairo_t* c = NULL;
	cairo_surface_t* _tmp5_;
	cairo_t* _tmp6_;
	cairo_surface_t* result;
#line 47 "../src/fading-label.vala"
	g_return_val_if_fail (self != NULL, NULL);
#line 47 "../src/fading-label.vala"
	g_return_val_if_fail (orig_c != NULL, NULL);
#line 50 "../src/fading-label.vala"
	_tmp0_ = gtk_label_get_layout ((GtkLabel*) self);
#line 50 "../src/fading-label.vala"
	pango_layout_get_pixel_size (_tmp0_, &_tmp1_, &_tmp2_);
#line 50 "../src/fading-label.vala"
	w = _tmp1_;
#line 50 "../src/fading-label.vala"
	h = _tmp2_;
#line 52 "../src/fading-label.vala"
	bw = gtk_widget_get_allocated_width ((GtkWidget*) self);
#line 53 "../src/fading-label.vala"
	bh = gtk_widget_get_allocated_height ((GtkWidget*) self);
#line 55 "../src/fading-label.vala"
	_tmp3_ = cairo_get_target (orig_c);
#line 55 "../src/fading-label.vala"
	_tmp4_ = cairo_surface_create_similar (_tmp3_, CAIRO_CONTENT_COLOR_ALPHA, bw, bh);
#line 55 "../src/fading-label.vala"
	surface = _tmp4_;
#line 56 "../src/fading-label.vala"
	_tmp5_ = surface;
#line 56 "../src/fading-label.vala"
	_tmp6_ = cairo_create (_tmp5_);
#line 56 "../src/fading-label.vala"
	c = _tmp6_;
#line 58 "../src/fading-label.vala"
	if (w > bw) {
#line 276 "fading-label.c"
		cairo_t* _tmp7_;
		cairo_t* _tmp8_;
		cairo_t* _tmp9_;
		cairo_pattern_t* mask = NULL;
		cairo_pattern_t* _tmp10_;
		cairo_pattern_t* _tmp11_;
		cairo_pattern_t* _tmp12_;
		cairo_pattern_t* _tmp13_;
		cairo_t* _tmp14_;
		cairo_pattern_t* _tmp15_;
#line 60 "../src/fading-label.vala"
		_tmp7_ = c;
#line 60 "../src/fading-label.vala"
		cairo_push_group (_tmp7_);
#line 61 "../src/fading-label.vala"
		_tmp8_ = c;
#line 61 "../src/fading-label.vala"
		GTK_WIDGET_CLASS (fading_label_parent_class)->draw ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_label_get_type (), GtkLabel), _tmp8_);
#line 62 "../src/fading-label.vala"
		_tmp9_ = c;
#line 62 "../src/fading-label.vala"
		cairo_pop_group_to_source (_tmp9_);
#line 64 "../src/fading-label.vala"
		_tmp10_ = cairo_pattern_create_linear ((gdouble) 0, (gdouble) 0, (gdouble) bw, (gdouble) 0);
#line 64 "../src/fading-label.vala"
		mask = _tmp10_;
#line 65 "../src/fading-label.vala"
		_tmp11_ = mask;
#line 65 "../src/fading-label.vala"
		cairo_pattern_add_color_stop_rgba (_tmp11_, 1.0 - (27.0 / bw), 1.0, 1.0, 1.0, 1.0);
#line 66 "../src/fading-label.vala"
		_tmp12_ = mask;
#line 66 "../src/fading-label.vala"
		cairo_pattern_add_color_stop_rgba (_tmp12_, 1.0 - (21.6 / bw), 1.0, 1.0, 1.0, 0.5);
#line 67 "../src/fading-label.vala"
		_tmp13_ = mask;
#line 67 "../src/fading-label.vala"
		cairo_pattern_add_color_stop_rgba (_tmp13_, 1.0, 1.0, 1.0, 1.0, 0.0);
#line 69 "../src/fading-label.vala"
		_tmp14_ = c;
#line 69 "../src/fading-label.vala"
		_tmp15_ = mask;
#line 69 "../src/fading-label.vala"
		cairo_mask (_tmp14_, _tmp15_);
#line 58 "../src/fading-label.vala"
		_cairo_pattern_destroy0 (mask);
#line 323 "fading-label.c"
	} else {
		cairo_t* _tmp16_;
#line 72 "../src/fading-label.vala"
		_tmp16_ = c;
#line 72 "../src/fading-label.vala"
		GTK_WIDGET_CLASS (fading_label_parent_class)->draw ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_label_get_type (), GtkLabel), _tmp16_);
#line 330 "fading-label.c"
	}
#line 74 "../src/fading-label.vala"
	result = surface;
#line 74 "../src/fading-label.vala"
	_cairo_destroy0 (c);
#line 74 "../src/fading-label.vala"
	return result;
#line 338 "fading-label.c"
}

static gboolean
fading_label_real_draw (GtkWidget* base,
                        cairo_t* c)
{
	FadingLabel * self;
	cairo_surface_t* _tmp0_;
	cairo_surface_t* _tmp2_;
	gboolean result;
#line 77 "../src/fading-label.vala"
	self = (FadingLabel*) base;
#line 77 "../src/fading-label.vala"
	g_return_val_if_fail (c != NULL, FALSE);
#line 79 "../src/fading-label.vala"
	_tmp0_ = self->priv->cached_surface;
#line 79 "../src/fading-label.vala"
	if (_tmp0_ == NULL) {
#line 357 "fading-label.c"
		cairo_surface_t* _tmp1_;
#line 80 "../src/fading-label.vala"
		_tmp1_ = fading_label_make_surface (self, c);
#line 80 "../src/fading-label.vala"
		_cairo_surface_destroy0 (self->priv->cached_surface);
#line 80 "../src/fading-label.vala"
		self->priv->cached_surface = _tmp1_;
#line 365 "fading-label.c"
	}
#line 81 "../src/fading-label.vala"
	_tmp2_ = self->priv->cached_surface;
#line 81 "../src/fading-label.vala"
	cairo_set_source_surface (c, _tmp2_, (gdouble) 0, (gdouble) 0);
#line 82 "../src/fading-label.vala"
	cairo_paint (c);
#line 83 "../src/fading-label.vala"
	result = FALSE;
#line 83 "../src/fading-label.vala"
	return result;
#line 377 "fading-label.c"
}

static void
fading_label_class_init (FadingLabelClass * klass,
                         gpointer klass_data)
{
#line 20 "../src/fading-label.vala"
	fading_label_parent_class = g_type_class_peek_parent (klass);
#line 20 "../src/fading-label.vala"
	g_type_class_adjust_private_offset (klass, &FadingLabel_private_offset);
#line 20 "../src/fading-label.vala"
	((GtkWidgetClass *) klass)->get_preferred_width = (void (*) (GtkWidget*, gint*, gint*)) fading_label_real_get_preferred_width;
#line 20 "../src/fading-label.vala"
	((GtkWidgetClass *) klass)->get_preferred_width_for_height = (void (*) (GtkWidget*, gint, gint*, gint*)) fading_label_real_get_preferred_width_for_height;
#line 20 "../src/fading-label.vala"
	((GtkWidgetClass *) klass)->size_allocate = (void (*) (GtkWidget*, GtkAllocation*)) fading_label_real_size_allocate;
#line 20 "../src/fading-label.vala"
	((GtkWidgetClass *) klass)->draw = (gboolean (*) (GtkWidget*, cairo_t*)) fading_label_real_draw;
#line 20 "../src/fading-label.vala"
	G_OBJECT_CLASS (klass)->finalize = fading_label_finalize;
#line 398 "fading-label.c"
}

static void
fading_label_instance_init (FadingLabel * self,
                            gpointer klass)
{
#line 20 "../src/fading-label.vala"
	self->priv = fading_label_get_instance_private (self);
#line 407 "fading-label.c"
}

static void
fading_label_finalize (GObject * obj)
{
	FadingLabel * self;
#line 20 "../src/fading-label.vala"
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FADING_LABEL, FadingLabel);
#line 22 "../src/fading-label.vala"
	_cairo_surface_destroy0 (self->priv->cached_surface);
#line 20 "../src/fading-label.vala"
	G_OBJECT_CLASS (fading_label_parent_class)->finalize (obj);
#line 420 "fading-label.c"
}

static GType
fading_label_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FadingLabelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fading_label_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FadingLabel), 0, (GInstanceInitFunc) fading_label_instance_init, NULL };
	GType fading_label_type_id;
	fading_label_type_id = g_type_register_static (gtk_label_get_type (), "FadingLabel", &g_define_type_info, 0);
	FadingLabel_private_offset = g_type_add_instance_private (fading_label_type_id, sizeof (FadingLabelPrivate));
	return fading_label_type_id;
}

GType
fading_label_get_type (void)
{
	static volatile gsize fading_label_type_id__once = 0;
	if (g_once_init_enter (&fading_label_type_id__once)) {
		GType fading_label_type_id;
		fading_label_type_id = fading_label_get_type_once ();
		g_once_init_leave (&fading_label_type_id__once, fading_label_type_id);
	}
	return fading_label_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;
}

