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

/* This file is part of GNOME Boxes. License: LGPLv2+*/

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


#define BOXES_TYPE_REVEALER (boxes_revealer_get_type ())
#define BOXES_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_REVEALER, BoxesRevealer))
#define BOXES_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_REVEALER, BoxesRevealerClass))
#define BOXES_IS_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_REVEALER))
#define BOXES_IS_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_REVEALER))
#define BOXES_REVEALER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_REVEALER, BoxesRevealerClass))

typedef struct _BoxesRevealer BoxesRevealer;
typedef struct _BoxesRevealerClass BoxesRevealerClass;
typedef struct _BoxesRevealerPrivate BoxesRevealerPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL)))
typedef struct _Block33Data Block33Data;

struct _BoxesRevealer {
	ClutterActor parent_instance;
	BoxesRevealerPrivate * priv;
	guint duration;
	gboolean resize;
};

struct _BoxesRevealerClass {
	ClutterActorClass parent_class;
};

struct _BoxesRevealerPrivate {
	gboolean horizontal;
	gboolean children_visible;
	gboolean _revealed;
};

struct _Block33Data {
	int _ref_count_;
	BoxesRevealer * self;
	ClutterActor* child;
};


static gpointer boxes_revealer_parent_class = NULL;

GType boxes_revealer_get_type (void) G_GNUC_CONST;
#define BOXES_REVEALER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BOXES_TYPE_REVEALER, BoxesRevealerPrivate))
enum  {
	BOXES_REVEALER_DUMMY_PROPERTY,
	BOXES_REVEALER_REVEALED
};
BoxesRevealer* boxes_revealer_new (gboolean horizontal);
BoxesRevealer* boxes_revealer_construct (GType object_type, gboolean horizontal);
static void __lambda3_ (BoxesRevealer* self, ClutterActor* child);
static void ___lambda3__clutter_container_actor_added (ClutterContainer* _sender, ClutterActor* actor, gpointer self);
void boxes_revealer_reveal (BoxesRevealer* self);
static void boxes_revealer_unreveal_child (BoxesRevealer* self, ClutterActor* child);
static Block33Data* block33_data_ref (Block33Data* _data33_);
static void block33_data_unref (void * _userdata_);
static void ___lambda4_ (Block33Data* _data33_);
static void ____lambda4__clutter_animation_completed (ClutterAnimation* _sender, gpointer self);
static void ___lambda5_ (Block33Data* _data33_);
static void ____lambda5__clutter_animation_completed (ClutterAnimation* _sender, gpointer self);
void boxes_revealer_unreveal (BoxesRevealer* self);
gboolean boxes_revealer_get_revealed (BoxesRevealer* self);
void boxes_revealer_set_revealed (BoxesRevealer* self, gboolean value);
static void boxes_revealer_finalize (GObject* obj);
static void _vala_boxes_revealer_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_boxes_revealer_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


static void __lambda3_ (BoxesRevealer* self, ClutterActor* child) {
	gboolean _tmp0_;
	g_return_if_fail (child != NULL);
	_tmp0_ = self->priv->children_visible;
	if (_tmp0_) {
		ClutterActor* _tmp1_;
		_tmp1_ = child;
		clutter_actor_show (_tmp1_);
	} else {
		ClutterActor* _tmp2_;
		_tmp2_ = child;
		clutter_actor_hide (_tmp2_);
	}
}


static void ___lambda3__clutter_container_actor_added (ClutterContainer* _sender, ClutterActor* actor, gpointer self) {
	__lambda3_ (self, actor);
}


BoxesRevealer* boxes_revealer_construct (GType object_type, gboolean horizontal) {
	BoxesRevealer * self = NULL;
	gboolean _tmp0_;
	gboolean _tmp1_;
	self = (BoxesRevealer*) g_object_new (object_type, NULL);
	_tmp0_ = horizontal;
	self->priv->horizontal = _tmp0_;
	clutter_actor_set_clip_to_allocation ((ClutterActor*) self, TRUE);
	self->priv->children_visible = TRUE;
	self->duration = (guint) 250;
	_tmp1_ = horizontal;
	if (_tmp1_) {
		ClutterBinLayout* _tmp2_;
		ClutterBinLayout* layout;
		ClutterBinLayout* _tmp3_;
		_tmp2_ = (ClutterBinLayout*) clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FIXED);
		g_object_ref_sink (_tmp2_);
		layout = _tmp2_;
		_tmp3_ = layout;
		clutter_actor_set_layout_manager ((ClutterActor*) self, (ClutterLayoutManager*) _tmp3_);
		_g_object_unref0 (layout);
	} else {
		ClutterBinLayout* _tmp4_;
		ClutterBinLayout* layout;
		ClutterBinLayout* _tmp5_;
		_tmp4_ = (ClutterBinLayout*) clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FIXED, CLUTTER_BIN_ALIGNMENT_FILL);
		g_object_ref_sink (_tmp4_);
		layout = _tmp4_;
		_tmp5_ = layout;
		clutter_actor_set_layout_manager ((ClutterActor*) self, (ClutterLayoutManager*) _tmp5_);
		_g_object_unref0 (layout);
	}
	g_signal_connect_object ((ClutterContainer*) self, "actor-added", (GCallback) ___lambda3__clutter_container_actor_added, self, 0);
	return self;
}


BoxesRevealer* boxes_revealer_new (gboolean horizontal) {
	return boxes_revealer_construct (BOXES_TYPE_REVEALER, horizontal);
}


void boxes_revealer_reveal (BoxesRevealer* self) {
	gboolean _tmp0_;
	gfloat max;
	GList* _tmp2_ = NULL;
	gboolean _tmp26_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->resize;
	if (_tmp0_) {
		gboolean _tmp1_;
		_tmp1_ = self->priv->horizontal;
		if (_tmp1_) {
			clutter_actor_set_height ((ClutterActor*) self, 0.0f);
		} else {
			clutter_actor_set_width ((ClutterActor*) self, 0.0f);
		}
	}
	max = 0.0f;
	_tmp2_ = clutter_actor_get_children ((ClutterActor*) self);
	{
		GList* child_collection = NULL;
		GList* child_it = NULL;
		child_collection = _tmp2_;
		for (child_it = child_collection; child_it != NULL; child_it = child_it->next) {
			ClutterActor* child = NULL;
			child = (ClutterActor*) child_it->data;
			{
				gboolean _tmp3_;
				gboolean _tmp5_;
				_tmp3_ = self->priv->children_visible;
				if (!_tmp3_) {
					ClutterActor* _tmp4_;
					_tmp4_ = child;
					clutter_actor_show (_tmp4_);
				}
				_tmp5_ = self->priv->horizontal;
				if (_tmp5_) {
					gboolean _tmp6_;
					ClutterActor* _tmp14_;
					guint _tmp15_;
					_tmp6_ = self->priv->children_visible;
					if (!_tmp6_) {
						gfloat height = 0.0F;
						ClutterActor* _tmp7_;
						gfloat _tmp8_ = 0.0F;
						ClutterActor* _tmp9_;
						gfloat _tmp10_;
						gfloat _tmp11_;
						gfloat _tmp12_;
						gfloat _tmp13_ = 0.0F;
						_tmp7_ = child;
						clutter_actor_get_preferred_height (_tmp7_, (gfloat) (-1), NULL, &_tmp8_);
						height = _tmp8_;
						_tmp9_ = child;
						_tmp10_ = height;
						clutter_actor_set_y (_tmp9_, -_tmp10_);
						_tmp11_ = max;
						_tmp12_ = height;
						_tmp13_ = MAX (_tmp11_, _tmp12_);
						max = _tmp13_;
					}
					_tmp14_ = child;
					_tmp15_ = self->duration;
					clutter_actor_animate (_tmp14_, (gulong) CLUTTER_EASE_IN_QUAD, _tmp15_, "y", 0.f, NULL);
				} else {
					gboolean _tmp16_;
					ClutterActor* _tmp24_;
					guint _tmp25_;
					_tmp16_ = self->priv->children_visible;
					if (!_tmp16_) {
						gfloat width = 0.0F;
						ClutterActor* _tmp17_;
						gfloat _tmp18_ = 0.0F;
						ClutterActor* _tmp19_;
						gfloat _tmp20_;
						gfloat _tmp21_;
						gfloat _tmp22_;
						gfloat _tmp23_ = 0.0F;
						_tmp17_ = child;
						clutter_actor_get_preferred_width (_tmp17_, (gfloat) (-1), NULL, &_tmp18_);
						width = _tmp18_;
						_tmp19_ = child;
						_tmp20_ = width;
						clutter_actor_set_x (_tmp19_, -_tmp20_);
						_tmp21_ = max;
						_tmp22_ = width;
						_tmp23_ = MAX (_tmp21_, _tmp22_);
						max = _tmp23_;
					}
					_tmp24_ = child;
					_tmp25_ = self->duration;
					clutter_actor_animate (_tmp24_, (gulong) CLUTTER_EASE_IN_QUAD, _tmp25_, "x", 0.f, NULL);
				}
			}
		}
		_g_list_free0 (child_collection);
	}
	_tmp26_ = self->resize;
	if (_tmp26_) {
		gboolean _tmp27_;
		_tmp27_ = self->priv->horizontal;
		if (_tmp27_) {
			guint _tmp28_;
			gfloat _tmp29_;
			_tmp28_ = self->duration;
			_tmp29_ = max;
			clutter_actor_animate ((ClutterActor*) self, (gulong) CLUTTER_EASE_IN_QUAD, _tmp28_, "height", _tmp29_, NULL);
		} else {
			guint _tmp30_;
			gfloat _tmp31_;
			_tmp30_ = self->duration;
			_tmp31_ = max;
			clutter_actor_animate ((ClutterActor*) self, (gulong) CLUTTER_EASE_IN_QUAD, _tmp30_, "width", _tmp31_, NULL);
		}
	}
	self->priv->children_visible = TRUE;
}


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


static Block33Data* block33_data_ref (Block33Data* _data33_) {
	g_atomic_int_inc (&_data33_->_ref_count_);
	return _data33_;
}


static void block33_data_unref (void * _userdata_) {
	Block33Data* _data33_;
	_data33_ = (Block33Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data33_->_ref_count_)) {
		BoxesRevealer * self;
		self = _data33_->self;
		_g_object_unref0 (_data33_->child);
		_g_object_unref0 (self);
		g_slice_free (Block33Data, _data33_);
	}
}


static void ___lambda4_ (Block33Data* _data33_) {
	BoxesRevealer * self;
	ClutterActor* _tmp0_;
	self = _data33_->self;
	_tmp0_ = _data33_->child;
	clutter_actor_hide (_tmp0_);
	self->priv->children_visible = FALSE;
}


static void ____lambda4__clutter_animation_completed (ClutterAnimation* _sender, gpointer self) {
	___lambda4_ (self);
}


static void ___lambda5_ (Block33Data* _data33_) {
	BoxesRevealer * self;
	ClutterActor* _tmp0_;
	self = _data33_->self;
	_tmp0_ = _data33_->child;
	clutter_actor_hide (_tmp0_);
	self->priv->children_visible = FALSE;
}


static void ____lambda5__clutter_animation_completed (ClutterAnimation* _sender, gpointer self) {
	___lambda5_ (self);
}


static void boxes_revealer_unreveal_child (BoxesRevealer* self, ClutterActor* child) {
	Block33Data* _data33_;
	ClutterActor* _tmp0_;
	ClutterActor* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp19_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (child != NULL);
	_data33_ = g_slice_new0 (Block33Data);
	_data33_->_ref_count_ = 1;
	_data33_->self = g_object_ref (self);
	_tmp0_ = child;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (_data33_->child);
	_data33_->child = _tmp1_;
	_tmp2_ = self->priv->horizontal;
	if (_tmp2_) {
		gfloat height = 0.0F;
		ClutterActor* _tmp3_;
		gfloat _tmp4_ = 0.0F;
		ClutterActor* _tmp5_;
		guint _tmp6_;
		gfloat _tmp7_;
		ClutterAnimation* _tmp8_ = NULL;
		ClutterAnimation* _tmp9_;
		ClutterAnimation* anim;
		ClutterAnimation* _tmp10_;
		_tmp3_ = _data33_->child;
		clutter_actor_get_preferred_height (_tmp3_, (gfloat) (-1), NULL, &_tmp4_);
		height = _tmp4_;
		_tmp5_ = _data33_->child;
		_tmp6_ = self->duration;
		_tmp7_ = height;
		_tmp8_ = clutter_actor_animate (_tmp5_, (gulong) CLUTTER_EASE_OUT_QUAD, _tmp6_, "y", -_tmp7_, NULL);
		_tmp9_ = _g_object_ref0 (_tmp8_);
		anim = _tmp9_;
		_tmp10_ = anim;
		g_signal_connect_data (_tmp10_, "completed", (GCallback) ____lambda4__clutter_animation_completed, block33_data_ref (_data33_), (GClosureNotify) block33_data_unref, 0);
		_g_object_unref0 (anim);
	} else {
		gfloat width = 0.0F;
		ClutterActor* _tmp11_;
		gfloat _tmp12_ = 0.0F;
		ClutterActor* _tmp13_;
		guint _tmp14_;
		gfloat _tmp15_;
		ClutterAnimation* _tmp16_ = NULL;
		ClutterAnimation* _tmp17_;
		ClutterAnimation* anim;
		ClutterAnimation* _tmp18_;
		_tmp11_ = _data33_->child;
		clutter_actor_get_preferred_width (_tmp11_, (gfloat) (-1), NULL, &_tmp12_);
		width = _tmp12_;
		_tmp13_ = _data33_->child;
		_tmp14_ = self->duration;
		_tmp15_ = width;
		_tmp16_ = clutter_actor_animate (_tmp13_, (gulong) CLUTTER_EASE_OUT_QUAD, _tmp14_, "x", -_tmp15_, NULL);
		_tmp17_ = _g_object_ref0 (_tmp16_);
		anim = _tmp17_;
		_tmp18_ = anim;
		g_signal_connect_data (_tmp18_, "completed", (GCallback) ____lambda5__clutter_animation_completed, block33_data_ref (_data33_), (GClosureNotify) block33_data_unref, 0);
		_g_object_unref0 (anim);
	}
	_tmp19_ = self->resize;
	if (_tmp19_) {
		gboolean _tmp20_;
		_tmp20_ = self->priv->horizontal;
		if (_tmp20_) {
			guint _tmp21_;
			_tmp21_ = self->duration;
			clutter_actor_animate ((ClutterActor*) self, (gulong) CLUTTER_EASE_OUT_QUAD, _tmp21_, "height", 0.0f, NULL);
		} else {
			guint _tmp22_;
			_tmp22_ = self->duration;
			clutter_actor_animate ((ClutterActor*) self, (gulong) CLUTTER_EASE_OUT_QUAD, _tmp22_, "width", 0.0f, NULL);
		}
	}
	block33_data_unref (_data33_);
	_data33_ = NULL;
}


void boxes_revealer_unreveal (BoxesRevealer* self) {
	gboolean _tmp0_;
	gboolean found_child;
	GList* _tmp1_ = NULL;
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->children_visible;
	if (!_tmp0_) {
		return;
	}
	found_child = FALSE;
	_tmp1_ = clutter_actor_get_children ((ClutterActor*) self);
	{
		GList* child_collection = NULL;
		GList* child_it = NULL;
		child_collection = _tmp1_;
		for (child_it = child_collection; child_it != NULL; child_it = child_it->next) {
			ClutterActor* child = NULL;
			child = (ClutterActor*) child_it->data;
			{
				ClutterActor* _tmp2_;
				found_child = TRUE;
				_tmp2_ = child;
				boxes_revealer_unreveal_child (self, _tmp2_);
			}
		}
		_g_list_free0 (child_collection);
	}
	_tmp3_ = found_child;
	if (!_tmp3_) {
		self->priv->children_visible = FALSE;
	}
}


gboolean boxes_revealer_get_revealed (BoxesRevealer* self) {
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_revealed;
	result = _tmp0_;
	return result;
}


void boxes_revealer_set_revealed (BoxesRevealer* self, gboolean value) {
	gboolean _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_revealed;
	_tmp1_ = value;
	if (_tmp0_ == _tmp1_) {
		return;
	}
	_tmp2_ = value;
	self->priv->_revealed = _tmp2_;
	_tmp3_ = value;
	if (_tmp3_) {
		boxes_revealer_reveal (self);
	} else {
		boxes_revealer_unreveal (self);
	}
	g_object_notify ((GObject *) self, "revealed");
}


static void boxes_revealer_class_init (BoxesRevealerClass * klass) {
	boxes_revealer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (BoxesRevealerPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_boxes_revealer_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_boxes_revealer_set_property;
	G_OBJECT_CLASS (klass)->finalize = boxes_revealer_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BOXES_REVEALER_REVEALED, g_param_spec_boolean ("revealed", "revealed", "revealed", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void boxes_revealer_instance_init (BoxesRevealer * self) {
	self->priv = BOXES_REVEALER_GET_PRIVATE (self);
}


static void boxes_revealer_finalize (GObject* obj) {
	BoxesRevealer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BOXES_TYPE_REVEALER, BoxesRevealer);
	G_OBJECT_CLASS (boxes_revealer_parent_class)->finalize (obj);
}


GType boxes_revealer_get_type (void) {
	static volatile gsize boxes_revealer_type_id__volatile = 0;
	if (g_once_init_enter (&boxes_revealer_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (BoxesRevealerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) boxes_revealer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BoxesRevealer), 0, (GInstanceInitFunc) boxes_revealer_instance_init, NULL };
		GType boxes_revealer_type_id;
		boxes_revealer_type_id = g_type_register_static (clutter_actor_get_type (), "BoxesRevealer", &g_define_type_info, 0);
		g_once_init_leave (&boxes_revealer_type_id__volatile, boxes_revealer_type_id);
	}
	return boxes_revealer_type_id__volatile;
}


static void _vala_boxes_revealer_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	BoxesRevealer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BOXES_TYPE_REVEALER, BoxesRevealer);
	switch (property_id) {
		case BOXES_REVEALER_REVEALED:
		g_value_set_boolean (value, boxes_revealer_get_revealed (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_boxes_revealer_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	BoxesRevealer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BOXES_TYPE_REVEALER, BoxesRevealer);
	switch (property_id) {
		case BOXES_REVEALER_REVEALED:
		boxes_revealer_set_revealed (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



