Commit b61832c8 authored by Francois Techene's avatar Francois Techene
Browse files

Animation delay + fade dices

parent 3499b41a
......@@ -20,6 +20,8 @@ struct _RandomizerAnimation
GtkWidget *widget;
gint64 delay;
gint64 start_time; /* ms */
gint64 end_time; /* ms */
gint64 duration; /* ms */
......@@ -173,6 +175,13 @@ update_animation (GtkWidget *widget,
frame_time = gdk_frame_clock_get_frame_time (frame_clock) / 1000;
if (frame_time < self->start_time) {
// Start is delayed
//
return should_continue;
}
if (frame_time >= self->end_time) {
value = self->value_to;
......@@ -201,6 +210,13 @@ on_update_animation_complete_cb(RandomizerAnimation *self)
*
*/
guint
randomizer_animation_set_delay(RandomizerAnimation *self,
gint64 delay)
{
self->delay = delay;
}
void
randomizer_animation_start(RandomizerAnimation *self,
......@@ -246,8 +262,8 @@ randomizer_animation_start(RandomizerAnimation *self,
frame_clock = gtk_widget_get_frame_clock (self->widget);
frame_time = gdk_frame_clock_get_frame_time (frame_clock);
self->start_time = frame_time / 1000;
self->end_time = self->start_time + self->duration;
self->start_time = (frame_time / 1000) + self->delay;
self->end_time = self->start_time + self->duration + self->delay;
// Don't register a new animation callback if one is already running.
......@@ -300,6 +316,7 @@ randomizer_animation_init (RandomizerAnimation *self)
self->animation_id = 0;
self->start_time = 0;
self->end_time = 0;
self->delay = 0;
}
static void
......
......@@ -40,6 +40,8 @@ typedef void (*RandomizerAnimationCompleteCallback) (Randomize
RandomizerAnimation * randomizer_animation_new (GtkWidget *widget,
animated_widget_property property);
guint randomizer_animation_set_delay (RandomizerAnimation *self,
gint64 delay);
void randomizer_animation_start (RandomizerAnimation *self,
animation_curve_type curve_type,
......
......@@ -36,6 +36,9 @@ struct _RandomizerWindow
guint number_of_dices;
GtkImage *dice_image_1;
GtkImage *dice_image_2;
GtkButton *dice_nb_toggle_btn;
RandomizerAnimation *fade_dice1_animation;
RandomizerAnimation *fade_dice2_animation;
......@@ -181,8 +184,29 @@ static void
dice_randomize_clicked_cb (GtkButton *btn,
RandomizerWindow *self)
{
gtk_widget_set_opacity (GTK_WIDGET (self->dice_image_1), 0);
gtk_widget_set_opacity (GTK_WIDGET (self->dice_image_2), 0);
randomize_dice_image(self->dice_image_1);
randomize_dice_image(self->dice_image_2);
randomizer_animation_set_delay (self->fade_dice1_animation, 500);
randomizer_animation_start (self->fade_dice1_animation,
LINEAR_ANIMATION,
0,
1,
1000,
NULL,
self);
randomizer_animation_set_delay (self->fade_dice2_animation, 1000);
randomizer_animation_start (self->fade_dice2_animation,
LINEAR_ANIMATION,
0,
1,
1000,
NULL,
self);
}
......@@ -217,8 +241,9 @@ init_answer_tab(RandomizerWindow *self)
static void
init_dice_tab(RandomizerWindow *self)
{
set_dice_image_with_value (self->dice_image_1, 1);
set_dice_image_with_value (self->dice_image_2, 1);
gtk_widget_hide( GTK_WIDGET(self->dice_image_2) );
gtk_button_set_label(self->dice_nb_toggle_btn, "Two Dices");
self->number_of_dices = 1;
}
static void
......@@ -255,6 +280,7 @@ randomizer_window_class_init (RandomizerWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, RandomizerWindow, answer_label);
gtk_widget_class_bind_template_child (widget_class, RandomizerWindow, dice_image_1);
gtk_widget_class_bind_template_child (widget_class, RandomizerWindow, dice_image_2);
gtk_widget_class_bind_template_child (widget_class, RandomizerWindow, dice_nb_toggle_btn);
gtk_widget_class_bind_template_callback (widget_class, answer_randomize_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, dice_randomize_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, dice_number_toggle_cb);
......@@ -268,15 +294,23 @@ randomizer_window_init (RandomizerWindow *self)
gtk_widget_init_template (GTK_WIDGET (self));
/* Init UI */
// Init Answer Tab
//
self->fade_answer_animation = randomizer_animation_new(GTK_WIDGET (self->answer_label),
OPACITY_ANIMATED_PROPERTY);
init_answer_tab(self);
gtk_widget_hide( GTK_WIDGET(self->dice_image_2) );
self->number_of_dices = 1;
// Init Dice Tab
//
self->fade_dice1_animation = randomizer_animation_new(GTK_WIDGET (self->dice_image_1),
OPACITY_ANIMATED_PROPERTY);
self->fade_dice2_animation = randomizer_animation_new(GTK_WIDGET (self->dice_image_2),
OPACITY_ANIMATED_PROPERTY);
init_dice_tab(self);
}
......
......@@ -164,7 +164,7 @@
<property name="spacing">24</property>
<child>
<object class="GtkButton">
<object class="GtkButton" id="dice_nb_toggle_btn">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Two Dices</property>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment