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


#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;
#define _block_unref0(var) ((var == NULL) ? NULL : (var = (block_unref (var), NULL)))

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_;
	ClutterGroup* piece;
	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 {
	GTypeInstance parent_instance;
	volatile int ref_count;
	ShapePrivate * priv;
	gint x;
	gint y;
	gint rotation;
	gint type;
	GList* blocks;
};

struct _ShapeClass {
	GTypeClass parent_class;
	void (*finalize) (Shape *self);
};

struct _Block {
	GTypeInstance parent_instance;
	volatile int ref_count;
	BlockPrivate * priv;
	gint x;
	gint y;
	gint color;
};

struct _BlockClass {
	GTypeClass parent_class;
	void (*finalize) (Block *self);
};


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 (void);
Preview* preview_construct (GType object_type);
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);
gpointer shape_ref (gpointer instance);
void shape_unref (gpointer instance);
GParamSpec* param_spec_shape (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_shape (GValue* value, gpointer v_object);
void value_take_shape (GValue* value, gpointer v_object);
gpointer value_get_shape (const GValue* value);
GType shape_get_type (void) G_GNUC_CONST;
gpointer block_ref (gpointer instance);
void block_unref (gpointer instance);
GParamSpec* param_spec_block (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_block (GValue* value, gpointer v_object);
void value_take_block (GValue* value, gpointer v_object);
gpointer value_get_block (const GValue* value);
GType block_get_type (void) G_GNUC_CONST;
gboolean preview_get_enabled (Preview* self);
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 (self, allocation);
}


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


Preview* preview_construct (GType object_type) {
	Preview * self = NULL;
	ClutterActor* _tmp0_ = NULL;
	ClutterStage* _tmp1_;
	ClutterStage* stage;
	ClutterColor _tmp2_ = {0};
	ClutterColor stage_color;
	ClutterStage* _tmp3_;
	ClutterColor _tmp4_;
	BlockTexture** _tmp5_ = 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);
	gtk_widget_set_size_request ((GtkWidget*) self, 120, 120);
	_tmp0_ = gtk_clutter_embed_get_stage ((GtkClutterEmbed*) self);
	_tmp1_ = _g_object_ref0 (CLUTTER_STAGE (_tmp0_));
	stage = _tmp1_;
	_tmp2_.red = (guint8) 0x0;
	_tmp2_.green = (guint8) 0x0;
	_tmp2_.blue = (guint8) 0x0;
	_tmp2_.alpha = (guint8) 0xff;
	stage_color = _tmp2_;
	_tmp3_ = stage;
	_tmp4_ = stage_color;
	clutter_stage_set_color (_tmp3_, &_tmp4_);
	_tmp5_ = 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 = _tmp5_;
	self->priv->block_textures_length1 = NCOLORS;
	self->priv->_block_textures_size_ = self->priv->block_textures_length1;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp6_;
			_tmp6_ = TRUE;
			while (TRUE) {
				gboolean _tmp7_;
				gint _tmp9_;
				BlockTexture** _tmp10_;
				gint _tmp10__length1;
				BlockTexture** _tmp11_;
				gint _tmp11__length1;
				gint _tmp12_;
				gint _tmp13_;
				BlockTexture* _tmp14_;
				BlockTexture* _tmp15_;
				BlockTexture* _tmp16_;
				BlockTexture** _tmp17_;
				gint _tmp17__length1;
				gint _tmp18_;
				BlockTexture* _tmp19_;
				BlockTexture** _tmp20_;
				gint _tmp20__length1;
				gint _tmp21_;
				BlockTexture* _tmp22_;
				ClutterStage* _tmp23_;
				BlockTexture** _tmp24_;
				gint _tmp24__length1;
				gint _tmp25_;
				BlockTexture* _tmp26_;
				_tmp7_ = _tmp6_;
				if (!_tmp7_) {
					gint _tmp8_;
					_tmp8_ = i;
					i = _tmp8_ + 1;
				}
				_tmp6_ = FALSE;
				_tmp9_ = i;
				_tmp10_ = self->priv->block_textures;
				_tmp10__length1 = self->priv->block_textures_length1;
				if (!(_tmp9_ < _tmp10__length1)) {
					break;
				}
				_tmp11_ = self->priv->block_textures;
				_tmp11__length1 = self->priv->block_textures_length1;
				_tmp12_ = i;
				_tmp13_ = i;
				_tmp14_ = block_texture_new (_tmp13_);
				_tmp15_ = g_object_ref_sink (_tmp14_);
				_g_object_unref0 (_tmp11_[_tmp12_]);
				_tmp11_[_tmp12_] = _tmp15_;
				_tmp16_ = _tmp11_[_tmp12_];
				_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_container_add_actor ((ClutterContainer*) _tmp23_, (ClutterActor*) _tmp26_);
			}
		}
	}
	_g_object_unref0 (stage);
	return self;
}


Preview* preview_new (void) {
	return preview_construct (TYPE_PREVIEW);
}


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


static gpointer _block_ref0 (gpointer self) {
	return self ? block_ref (self) : NULL;
}


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


static void preview_size_allocate_cb (Preview* self, GtkAllocation* allocation) {
	BlockTexture** _tmp0_;
	gint _tmp0__length1;
	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_;
			BlockTexture* texture = NULL;
			_tmp1_ = _g_object_ref0 (texture_collection[texture_it]);
			texture = _tmp1_;
			{
				BlockTexture* _tmp2_;
				gint _tmp3_;
				gint _tmp4_;
				gint _tmp5_;
				gint _tmp6_;
				_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_;
	gint _tmp0__length1;
	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_;
			BlockTexture* texture = NULL;
			_tmp1_ = _g_object_ref0 (texture_collection[texture_it]);
			texture = _tmp1_;
			{
				BlockTexture* _tmp2_;
				const gchar* _tmp3_;
				_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_;
	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 (self);
}


void preview_set_game (Preview* self, Game* value) {
	Game* _tmp0_;
	Game* _tmp2_;
	Game* _tmp3_;
	Game* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_game;
	if (_tmp0_ != NULL) {
		Game* _tmp1_;
		_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_;
	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_;
	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->_game = NULL;
	self->priv->_enabled = TRUE;
}


static void preview_finalize (GObject* obj) {
	Preview * self;
	self = PREVIEW (obj);
	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->_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 = PREVIEW (object);
	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 = PREVIEW (object);
	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);
}



