/* preview.c generated by valac 0.25.4.4-19ea, the Vala compiler
 * generated from preview.vala, do not modify */

/*
 * Copyright (C) 2010-2013 Robert Ancell
 *
 * 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. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#include <glib.h>
#include <glib-object.h>
#include <clutter-gtk/clutter-gtk.h>
#include <clutter/clutter.h>
#include <gtk/gtk.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_PREVIEW (preview_get_type ())
#define PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PREVIEW, Preview))
#define PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PREVIEW, PreviewClass))
#define IS_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PREVIEW))
#define IS_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PREVIEW))
#define PREVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PREVIEW, PreviewClass))

typedef struct _Preview Preview;
typedef struct _PreviewClass PreviewClass;
typedef struct _PreviewPrivate PreviewPrivate;

#define TYPE_BLOCK_TEXTURE (block_texture_get_type ())
#define BLOCK_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BLOCK_TEXTURE, BlockTexture))
#define BLOCK_TEXTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BLOCK_TEXTURE, BlockTextureClass))
#define IS_BLOCK_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BLOCK_TEXTURE))
#define IS_BLOCK_TEXTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BLOCK_TEXTURE))
#define BLOCK_TEXTURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BLOCK_TEXTURE, BlockTextureClass))

typedef struct _BlockTexture BlockTexture;
typedef struct _BlockTextureClass BlockTextureClass;

#define TYPE_GAME (game_get_type ())
#define GAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GAME, Game))
#define GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GAME, GameClass))
#define IS_GAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GAME))
#define IS_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GAME))
#define GAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GAME, GameClass))

typedef struct _Game Game;
typedef struct _GameClass GameClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _GamePrivate GamePrivate;

#define TYPE_SHAPE (shape_get_type ())
#define SHAPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SHAPE, Shape))
#define SHAPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SHAPE, ShapeClass))
#define IS_SHAPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SHAPE))
#define IS_SHAPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SHAPE))
#define SHAPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SHAPE, ShapeClass))

typedef struct _Shape Shape;
typedef struct _ShapeClass ShapeClass;

#define TYPE_BLOCK (block_get_type ())
#define BLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BLOCK, Block))
#define BLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BLOCK, BlockClass))
#define IS_BLOCK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BLOCK))
#define IS_BLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BLOCK))
#define BLOCK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BLOCK, BlockClass))

typedef struct _Block Block;
typedef struct _BlockClass BlockClass;
typedef struct _ShapePrivate ShapePrivate;
typedef struct _BlockPrivate BlockPrivate;

struct _Preview {
	GtkClutterEmbed parent_instance;
	PreviewPrivate * priv;
};

struct _PreviewClass {
	GtkClutterEmbedClass parent_class;
};

struct _PreviewPrivate {
	BlockTexture** block_textures;
	gint block_textures_length1;
	gint _block_textures_size_;
	ClutterActor* piece;
	GtkFrame* parent_frame;
	Game* _game;
	gboolean _enabled;
};

struct _Game {
	GObject parent_instance;
	GamePrivate * priv;
	Shape* shape;
	Shape* next_shape;
	Block** blocks;
	gint blocks_length1;
	gint blocks_length2;
	gint n_lines_destroyed;
	gint score;
	gboolean game_over;
};

struct _GameClass {
	GObjectClass parent_class;
};

struct _Shape {
	GObject parent_instance;
	ShapePrivate * priv;
	gint x;
	gint y;
	gint rotation;
	gint type;
	GList* blocks;
};

struct _ShapeClass {
	GObjectClass parent_class;
};

struct _Block {
	GObject parent_instance;
	BlockPrivate * priv;
	gint x;
	gint y;
	gint color;
};

struct _BlockClass {
	GObjectClass parent_class;
};


static gpointer preview_parent_class = NULL;

GType preview_get_type (void) G_GNUC_CONST;
GType block_texture_get_type (void) G_GNUC_CONST;
GType game_get_type (void) G_GNUC_CONST;
#define PREVIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_PREVIEW, PreviewPrivate))
enum  {
	PREVIEW_DUMMY_PROPERTY,
	PREVIEW_THEME,
	PREVIEW_GAME,
	PREVIEW_ENABLED
};
Preview* preview_new (GtkFrame* parent);
Preview* preview_construct (GType object_type, GtkFrame* parent);
static void preview_size_allocate_cb (Preview* self, GtkAllocation* allocation);
static void _preview_size_allocate_cb_gtk_widget_size_allocate (GtkWidget* _sender, GtkAllocation* allocation, gpointer self);
#define NCOLORS 7
BlockTexture* block_texture_new (gint color);
BlockTexture* block_texture_construct (GType object_type, gint color);
static void preview_shape_added_cb (Preview* self);
static void preview_update_block (Preview* self);
Game* preview_get_game (Preview* self);
GType shape_get_type (void) G_GNUC_CONST;
GType block_get_type (void) G_GNUC_CONST;
gboolean preview_get_enabled (Preview* self);
void preview_set_visible (Preview* self, gboolean visible);
static gint preview_get_cell_size (Preview* self);
void preview_set_theme (Preview* self, const gchar* value);
void block_texture_set_theme (BlockTexture* self, const gchar* value);
void preview_set_game (Preview* self, Game* value);
static void _preview_shape_added_cb_game_shape_added (Game* _sender, gpointer self);
void preview_set_enabled (Preview* self, gboolean value);
static void preview_finalize (GObject* obj);
static void _vala_preview_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_preview_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static void _preview_size_allocate_cb_gtk_widget_size_allocate (GtkWidget* _sender, GtkAllocation* allocation, gpointer self) {
	preview_size_allocate_cb ((Preview*) self, allocation);
}


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


Preview* preview_construct (GType object_type, GtkFrame* parent) {
	Preview * self = NULL;
	GtkFrame* _tmp0_ = NULL;
	GtkFrame* _tmp1_ = NULL;
	ClutterStage* stage = NULL;
	ClutterActor* _tmp2_ = NULL;
	ClutterStage* _tmp3_ = NULL;
	ClutterColor stage_color = {0};
	ClutterColor _tmp4_ = {0};
	ClutterStage* _tmp5_ = NULL;
	ClutterColor _tmp6_ = {0};
	BlockTexture** _tmp7_ = NULL;
	self = (Preview*) g_object_new (object_type, NULL);
	g_signal_connect_object ((GtkWidget*) self, "size-allocate", (GCallback) _preview_size_allocate_cb_gtk_widget_size_allocate, self, 0);
	_tmp0_ = parent;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->parent_frame);
	self->priv->parent_frame = _tmp1_;
	gtk_widget_set_size_request ((GtkWidget*) self, 120, 120);
	_tmp2_ = gtk_clutter_embed_get_stage ((GtkClutterEmbed*) self);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, clutter_stage_get_type (), ClutterStage));
	stage = _tmp3_;
	_tmp4_.red = (guint8) 0x0;
	_tmp4_.green = (guint8) 0x0;
	_tmp4_.blue = (guint8) 0x0;
	_tmp4_.alpha = (guint8) 0xff;
	stage_color = _tmp4_;
	_tmp5_ = stage;
	_tmp6_ = stage_color;
	clutter_actor_set_background_color ((ClutterActor*) _tmp5_, &_tmp6_);
	_tmp7_ = g_new0 (BlockTexture*, NCOLORS + 1);
	self->priv->block_textures = (_vala_array_free (self->priv->block_textures, self->priv->block_textures_length1, (GDestroyNotify) g_object_unref), NULL);
	self->priv->block_textures = _tmp7_;
	self->priv->block_textures_length1 = NCOLORS;
	self->priv->_block_textures_size_ = self->priv->block_textures_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp8_ = FALSE;
			_tmp8_ = TRUE;
			while (TRUE) {
				gint _tmp10_ = 0;
				BlockTexture** _tmp11_ = NULL;
				gint _tmp11__length1 = 0;
				BlockTexture** _tmp12_ = NULL;
				gint _tmp12__length1 = 0;
				gint _tmp13_ = 0;
				gint _tmp14_ = 0;
				BlockTexture* _tmp15_ = NULL;
				BlockTexture* _tmp16_ = NULL;
				BlockTexture** _tmp17_ = NULL;
				gint _tmp17__length1 = 0;
				gint _tmp18_ = 0;
				BlockTexture* _tmp19_ = NULL;
				BlockTexture** _tmp20_ = NULL;
				gint _tmp20__length1 = 0;
				gint _tmp21_ = 0;
				BlockTexture* _tmp22_ = NULL;
				ClutterStage* _tmp23_ = NULL;
				BlockTexture** _tmp24_ = NULL;
				gint _tmp24__length1 = 0;
				gint _tmp25_ = 0;
				BlockTexture* _tmp26_ = NULL;
				if (!_tmp8_) {
					gint _tmp9_ = 0;
					_tmp9_ = i;
					i = _tmp9_ + 1;
				}
				_tmp8_ = FALSE;
				_tmp10_ = i;
				_tmp11_ = self->priv->block_textures;
				_tmp11__length1 = self->priv->block_textures_length1;
				if (!(_tmp10_ < _tmp11__length1)) {
					break;
				}
				_tmp12_ = self->priv->block_textures;
				_tmp12__length1 = self->priv->block_textures_length1;
				_tmp13_ = i;
				_tmp14_ = i;
				_tmp15_ = block_texture_new (_tmp14_);
				g_object_ref_sink (_tmp15_);
				_g_object_unref0 (_tmp12_[_tmp13_]);
				_tmp12_[_tmp13_] = _tmp15_;
				_tmp16_ = _tmp12_[_tmp13_];
				_tmp17_ = self->priv->block_textures;
				_tmp17__length1 = self->priv->block_textures_length1;
				_tmp18_ = i;
				_tmp19_ = _tmp17_[_tmp18_];
				clutter_cairo_texture_set_surface_size ((ClutterCairoTexture*) _tmp19_, (guint) 1, (guint) 1);
				_tmp20_ = self->priv->block_textures;
				_tmp20__length1 = self->priv->block_textures_length1;
				_tmp21_ = i;
				_tmp22_ = _tmp20_[_tmp21_];
				clutter_actor_hide ((ClutterActor*) _tmp22_);
				_tmp23_ = stage;
				_tmp24_ = self->priv->block_textures;
				_tmp24__length1 = self->priv->block_textures_length1;
				_tmp25_ = i;
				_tmp26_ = _tmp24_[_tmp25_];
				clutter_actor_add_child ((ClutterActor*) _tmp23_, (ClutterActor*) _tmp26_);
			}
		}
	}
	_g_object_unref0 (stage);
	return self;
}


Preview* preview_new (GtkFrame* parent) {
	return preview_construct (TYPE_PREVIEW, parent);
}


static void preview_shape_added_cb (Preview* self) {
	g_return_if_fail (self != NULL);
	preview_update_block (self);
}


static void preview_update_block (Preview* self) {
	ClutterActor* _tmp0_ = NULL;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	Game* _tmp4_ = NULL;
	Game* _tmp5_ = NULL;
	ClutterActor* _tmp13_ = NULL;
	ClutterStage* stage = NULL;
	ClutterActor* _tmp14_ = NULL;
	ClutterStage* _tmp15_ = NULL;
	ClutterStage* _tmp16_ = NULL;
	ClutterActor* _tmp17_ = NULL;
	gint min_width = 0;
	gint max_width = 0;
	gint min_height = 0;
	gint max_height = 0;
	Game* _tmp18_ = NULL;
	Game* _tmp19_ = NULL;
	Shape* _tmp20_ = NULL;
	GList* _tmp21_ = NULL;
	ClutterActor* _tmp60_ = NULL;
	ClutterActor* _tmp61_ = NULL;
	gint _tmp62_ = 0;
	gint _tmp63_ = 0;
	gint _tmp64_ = 0;
	gint _tmp65_ = 0;
	gint _tmp66_ = 0;
	gint _tmp67_ = 0;
	gint _tmp68_ = 0;
	gint _tmp69_ = 0;
	gint _tmp70_ = 0;
	gint _tmp71_ = 0;
	ClutterActor* _tmp72_ = NULL;
	ClutterActor* _tmp73_ = NULL;
	ClutterActor* _tmp74_ = NULL;
	ClutterActor* _tmp75_ = NULL;
	ClutterActor* _tmp76_ = NULL;
	ClutterActor* _tmp77_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->piece;
	if (_tmp0_ != NULL) {
		ClutterActor* _tmp1_ = NULL;
		_tmp1_ = self->priv->piece;
		clutter_actor_destroy (_tmp1_);
	}
	_tmp4_ = preview_get_game (self);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == NULL) {
		_tmp3_ = TRUE;
	} else {
		Game* _tmp6_ = NULL;
		Game* _tmp7_ = NULL;
		Shape* _tmp8_ = NULL;
		_tmp6_ = preview_get_game (self);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_->next_shape;
		_tmp3_ = _tmp8_ == NULL;
	}
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		gboolean _tmp9_ = FALSE;
		gboolean _tmp10_ = FALSE;
		_tmp9_ = preview_get_enabled (self);
		_tmp10_ = _tmp9_;
		_tmp2_ = !_tmp10_;
	}
	if (_tmp2_) {
		gboolean _tmp11_ = FALSE;
		gboolean _tmp12_ = FALSE;
		_tmp11_ = preview_get_enabled (self);
		_tmp12_ = _tmp11_;
		preview_set_visible (self, _tmp12_);
		return;
	}
	preview_set_visible (self, TRUE);
	_tmp13_ = clutter_actor_new ();
	g_object_ref_sink (_tmp13_);
	_g_object_unref0 (self->priv->piece);
	self->priv->piece = _tmp13_;
	_tmp14_ = gtk_clutter_embed_get_stage ((GtkClutterEmbed*) self);
	_tmp15_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, clutter_stage_get_type (), ClutterStage));
	stage = _tmp15_;
	_tmp16_ = stage;
	_tmp17_ = self->priv->piece;
	clutter_actor_add_child ((ClutterActor*) _tmp16_, _tmp17_);
	min_width = 4;
	max_width = 0;
	min_height = 4;
	max_height = 0;
	_tmp18_ = preview_get_game (self);
	_tmp19_ = _tmp18_;
	_tmp20_ = _tmp19_->next_shape;
	_tmp21_ = _tmp20_->blocks;
	{
		GList* b_collection = NULL;
		GList* b_it = NULL;
		b_collection = _tmp21_;
		for (b_it = b_collection; b_it != NULL; b_it = b_it->next) {
			Block* _tmp22_ = NULL;
			Block* b = NULL;
			_tmp22_ = _g_object_ref0 ((Block*) b_it->data);
			b = _tmp22_;
			{
				Block* _tmp23_ = NULL;
				gint _tmp24_ = 0;
				gint _tmp25_ = 0;
				gint _tmp26_ = 0;
				Block* _tmp27_ = NULL;
				gint _tmp28_ = 0;
				gint _tmp29_ = 0;
				gint _tmp30_ = 0;
				Block* _tmp31_ = NULL;
				gint _tmp32_ = 0;
				gint _tmp33_ = 0;
				gint _tmp34_ = 0;
				Block* _tmp35_ = NULL;
				gint _tmp36_ = 0;
				gint _tmp37_ = 0;
				gint _tmp38_ = 0;
				ClutterClone* a = NULL;
				BlockTexture** _tmp39_ = NULL;
				gint _tmp39__length1 = 0;
				Block* _tmp40_ = NULL;
				gint _tmp41_ = 0;
				BlockTexture* _tmp42_ = NULL;
				ClutterClone* _tmp43_ = NULL;
				ClutterClone* _tmp44_ = NULL;
				gint _tmp45_ = 0;
				gint _tmp46_ = 0;
				gint _tmp47_ = 0;
				gint _tmp48_ = 0;
				ClutterClone* _tmp49_ = NULL;
				Block* _tmp50_ = NULL;
				gint _tmp51_ = 0;
				gint _tmp52_ = 0;
				gint _tmp53_ = 0;
				Block* _tmp54_ = NULL;
				gint _tmp55_ = 0;
				gint _tmp56_ = 0;
				gint _tmp57_ = 0;
				ClutterActor* _tmp58_ = NULL;
				ClutterClone* _tmp59_ = NULL;
				_tmp23_ = b;
				_tmp24_ = _tmp23_->x;
				_tmp25_ = min_width;
				_tmp26_ = MIN (_tmp24_, _tmp25_);
				min_width = _tmp26_;
				_tmp27_ = b;
				_tmp28_ = _tmp27_->x;
				_tmp29_ = max_width;
				_tmp30_ = MAX (_tmp28_ + 1, _tmp29_);
				max_width = _tmp30_;
				_tmp31_ = b;
				_tmp32_ = _tmp31_->y;
				_tmp33_ = min_height;
				_tmp34_ = MIN (_tmp32_, _tmp33_);
				min_height = _tmp34_;
				_tmp35_ = b;
				_tmp36_ = _tmp35_->y;
				_tmp37_ = max_height;
				_tmp38_ = MAX (_tmp36_ + 1, _tmp37_);
				max_height = _tmp38_;
				_tmp39_ = self->priv->block_textures;
				_tmp39__length1 = self->priv->block_textures_length1;
				_tmp40_ = b;
				_tmp41_ = _tmp40_->color;
				_tmp42_ = _tmp39_[_tmp41_];
				_tmp43_ = (ClutterClone*) clutter_clone_new ((ClutterActor*) _tmp42_);
				g_object_ref_sink (_tmp43_);
				a = _tmp43_;
				_tmp44_ = a;
				_tmp45_ = preview_get_cell_size (self);
				_tmp46_ = _tmp45_;
				_tmp47_ = preview_get_cell_size (self);
				_tmp48_ = _tmp47_;
				clutter_actor_set_size ((ClutterActor*) _tmp44_, (gfloat) _tmp46_, (gfloat) _tmp48_);
				_tmp49_ = a;
				_tmp50_ = b;
				_tmp51_ = _tmp50_->x;
				_tmp52_ = preview_get_cell_size (self);
				_tmp53_ = _tmp52_;
				_tmp54_ = b;
				_tmp55_ = _tmp54_->y;
				_tmp56_ = preview_get_cell_size (self);
				_tmp57_ = _tmp56_;
				clutter_actor_set_position ((ClutterActor*) _tmp49_, (gfloat) (_tmp51_ * _tmp53_), (gfloat) (_tmp55_ * _tmp57_));
				_tmp58_ = self->priv->piece;
				_tmp59_ = a;
				clutter_actor_add_child (_tmp58_, (ClutterActor*) _tmp59_);
				_g_object_unref0 (a);
				_g_object_unref0 (b);
			}
		}
	}
	_tmp60_ = self->priv->piece;
	clutter_actor_set_pivot_point (_tmp60_, 0.5f, 0.5f);
	_tmp61_ = self->priv->piece;
	_tmp62_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
	_tmp63_ = min_width;
	_tmp64_ = max_width;
	_tmp65_ = preview_get_cell_size (self);
	_tmp66_ = _tmp65_;
	_tmp67_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
	_tmp68_ = min_height;
	_tmp69_ = max_height;
	_tmp70_ = preview_get_cell_size (self);
	_tmp71_ = _tmp70_;
	clutter_actor_set_position (_tmp61_, (gfloat) ((_tmp62_ - ((_tmp63_ + _tmp64_) * _tmp66_)) / 2), (gfloat) ((_tmp67_ - ((_tmp68_ + _tmp69_) * _tmp71_)) / 2));
	_tmp72_ = self->priv->piece;
	clutter_actor_set_scale (_tmp72_, 0.6, 0.6);
	_tmp73_ = self->priv->piece;
	clutter_actor_save_easing_state (_tmp73_);
	_tmp74_ = self->priv->piece;
	clutter_actor_set_easing_mode (_tmp74_, CLUTTER_EASE_IN_OUT_SINE);
	_tmp75_ = self->priv->piece;
	clutter_actor_set_easing_duration (_tmp75_, (guint) 180);
	_tmp76_ = self->priv->piece;
	clutter_actor_set_scale (_tmp76_, 1.0, 1.0);
	_tmp77_ = self->priv->piece;
	clutter_actor_restore_easing_state (_tmp77_);
	_g_object_unref0 (stage);
}


void preview_set_visible (Preview* self, gboolean visible) {
	gboolean _tmp0_ = FALSE;
	GtkFrame* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = visible;
	gtk_widget_set_visible ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_clutter_embed_get_type (), GtkClutterEmbed), _tmp0_);
	_tmp1_ = self->priv->parent_frame;
	if (_tmp1_ != NULL) {
		GtkFrame* _tmp2_ = NULL;
		gboolean _tmp3_ = FALSE;
		_tmp2_ = self->priv->parent_frame;
		_tmp3_ = visible;
		gtk_widget_set_visible ((GtkWidget*) _tmp2_, _tmp3_);
	}
}


static void preview_size_allocate_cb (Preview* self, GtkAllocation* allocation) {
	BlockTexture** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (allocation != NULL);
	_tmp0_ = self->priv->block_textures;
	_tmp0__length1 = self->priv->block_textures_length1;
	{
		BlockTexture** texture_collection = NULL;
		gint texture_collection_length1 = 0;
		gint _texture_collection_size_ = 0;
		gint texture_it = 0;
		texture_collection = _tmp0_;
		texture_collection_length1 = _tmp0__length1;
		for (texture_it = 0; texture_it < _tmp0__length1; texture_it = texture_it + 1) {
			BlockTexture* _tmp1_ = NULL;
			BlockTexture* texture = NULL;
			_tmp1_ = _g_object_ref0 (texture_collection[texture_it]);
			texture = _tmp1_;
			{
				BlockTexture* _tmp2_ = NULL;
				gint _tmp3_ = 0;
				gint _tmp4_ = 0;
				gint _tmp5_ = 0;
				gint _tmp6_ = 0;
				_tmp2_ = texture;
				_tmp3_ = preview_get_cell_size (self);
				_tmp4_ = _tmp3_;
				_tmp5_ = preview_get_cell_size (self);
				_tmp6_ = _tmp5_;
				clutter_actor_set_size ((ClutterActor*) _tmp2_, (gfloat) _tmp4_, (gfloat) _tmp6_);
				_g_object_unref0 (texture);
			}
		}
	}
	preview_update_block (self);
}


void preview_set_theme (Preview* self, const gchar* value) {
	BlockTexture** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->block_textures;
	_tmp0__length1 = self->priv->block_textures_length1;
	{
		BlockTexture** texture_collection = NULL;
		gint texture_collection_length1 = 0;
		gint _texture_collection_size_ = 0;
		gint texture_it = 0;
		texture_collection = _tmp0_;
		texture_collection_length1 = _tmp0__length1;
		for (texture_it = 0; texture_it < _tmp0__length1; texture_it = texture_it + 1) {
			BlockTexture* _tmp1_ = NULL;
			BlockTexture* texture = NULL;
			_tmp1_ = _g_object_ref0 (texture_collection[texture_it]);
			texture = _tmp1_;
			{
				BlockTexture* _tmp2_ = NULL;
				const gchar* _tmp3_ = NULL;
				_tmp2_ = texture;
				_tmp3_ = value;
				block_texture_set_theme (_tmp2_, _tmp3_);
				_g_object_unref0 (texture);
			}
		}
	}
	preview_update_block (self);
	g_object_notify ((GObject *) self, "theme");
}


static gint preview_get_cell_size (Preview* self) {
	gint result;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
	_tmp1_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
	result = ((_tmp0_ + _tmp1_) / 2) / 5;
	return result;
}


Game* preview_get_game (Preview* self) {
	Game* result;
	Game* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_game;
	result = _tmp0_;
	return result;
}


static void _preview_shape_added_cb_game_shape_added (Game* _sender, gpointer self) {
	preview_shape_added_cb ((Preview*) self);
}


void preview_set_game (Preview* self, Game* value) {
	Game* _tmp0_ = NULL;
	Game* _tmp2_ = NULL;
	Game* _tmp3_ = NULL;
	Game* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_game;
	if (_tmp0_ != NULL) {
		Game* _tmp1_ = NULL;
		_tmp1_ = self->priv->_game;
		g_signal_handlers_disconnect_matched (_tmp1_, G_SIGNAL_MATCH_DATA, (guint) 0, (GQuark) 0, NULL, NULL, self);
	}
	_tmp2_ = value;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_g_object_unref0 (self->priv->_game);
	self->priv->_game = _tmp3_;
	_tmp4_ = self->priv->_game;
	g_signal_connect_object (_tmp4_, "shape-added", (GCallback) _preview_shape_added_cb_game_shape_added, self, 0);
	preview_update_block (self);
	g_object_notify ((GObject *) self, "game");
}


gboolean preview_get_enabled (Preview* self) {
	gboolean result;
	gboolean _tmp0_ = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_enabled;
	result = _tmp0_;
	return result;
}


void preview_set_enabled (Preview* self, gboolean value) {
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_enabled = _tmp0_;
	preview_update_block (self);
	g_object_notify ((GObject *) self, "enabled");
}


static void preview_class_init (PreviewClass * klass) {
	preview_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (PreviewPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_preview_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_preview_set_property;
	G_OBJECT_CLASS (klass)->finalize = preview_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PREVIEW_THEME, g_param_spec_string ("theme", "theme", "theme", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PREVIEW_GAME, g_param_spec_object ("game", "game", "game", TYPE_GAME, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PREVIEW_ENABLED, g_param_spec_boolean ("enabled", "enabled", "enabled", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void preview_instance_init (Preview * self) {
	self->priv = PREVIEW_GET_PRIVATE (self);
	self->priv->piece = NULL;
	self->priv->parent_frame = NULL;
	self->priv->_game = NULL;
	self->priv->_enabled = TRUE;
}


static void preview_finalize (GObject* obj) {
	Preview * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PREVIEW, Preview);
	self->priv->block_textures = (_vala_array_free (self->priv->block_textures, self->priv->block_textures_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_object_unref0 (self->priv->piece);
	_g_object_unref0 (self->priv->parent_frame);
	_g_object_unref0 (self->priv->_game);
	G_OBJECT_CLASS (preview_parent_class)->finalize (obj);
}


GType preview_get_type (void) {
	static volatile gsize preview_type_id__volatile = 0;
	if (g_once_init_enter (&preview_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (PreviewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) preview_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Preview), 0, (GInstanceInitFunc) preview_instance_init, NULL };
		GType preview_type_id;
		preview_type_id = g_type_register_static (gtk_clutter_embed_get_type (), "Preview", &g_define_type_info, 0);
		g_once_init_leave (&preview_type_id__volatile, preview_type_id);
	}
	return preview_type_id__volatile;
}


static void _vala_preview_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	Preview * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PREVIEW, Preview);
	switch (property_id) {
		case PREVIEW_GAME:
		g_value_set_object (value, preview_get_game (self));
		break;
		case PREVIEW_ENABLED:
		g_value_set_boolean (value, preview_get_enabled (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_preview_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	Preview * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PREVIEW, Preview);
	switch (property_id) {
		case PREVIEW_THEME:
		preview_set_theme (self, g_value_get_string (value));
		break;
		case PREVIEW_GAME:
		preview_set_game (self, g_value_get_object (value));
		break;
		case PREVIEW_ENABLED:
		preview_set_enabled (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



