From 3627069998d27e7193529baee4034e1bba9a82d9 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 20 Mar 2026 00:19:13 -0400 Subject: [PATCH] Animation cleanup --- src/c/main.c | 118 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 79 insertions(+), 39 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index cc8c823..df5bf91 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -31,6 +31,20 @@ static GRect s_guy_butt_grect_on_screen_raised = GRect(PBL_IF_ROUND_ELSE(0, -30) static GRect s_guy_butt_grect_off_screen_raised = GRect(PBL_IF_ROUND_ELSE(260, 170), PBL_IF_ROUND_ELSE(160, 144), 260, 115); static GRect s_guy_butt_grect_on_screen_resting = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(145, 129), 260, 115); +// declare animations +static Animation *s_head_raise_anim; +static Animation *s_head_out_anim; +static Animation *s_head_in_anim; +static Animation *s_head_rest_anim; +static PropertyAnimation *s_head_y_prop_anim; +static PropertyAnimation *s_head_x_prop_anim; +static Animation *s_butt_raise_anim; +static Animation *s_butt_out_anim; +static Animation *s_butt_in_anim; +static Animation *s_butt_rest_anim; +static PropertyAnimation *s_butt_y_prop_anim; +static PropertyAnimation *s_butt_x_prop_anim; + // declare lookup tables static const uint8_t s_head_count = 25; static const uint32_t s_random_heads[] = { @@ -113,25 +127,35 @@ static void update_minute_30_out_handler(Animation *animation, bool finished, vo static void update_minute_30() { update_minute_1(); - // animate silly butt swap - //// raise - Animation *butt_raise_anim = property_animation_get_animation(property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_butt_layer), &s_guy_butt_grect_on_screen_resting, &s_guy_butt_grect_on_screen_raised)); - animation_set_curve(butt_raise_anim, AnimationCurveEaseOut); - animation_set_duration(butt_raise_anim, 350); - //// out - Animation *butt_out_anim = property_animation_get_animation(property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_butt_layer), &s_guy_butt_grect_on_screen_raised, &s_guy_butt_grect_off_screen_raised)); - animation_set_curve(butt_out_anim, AnimationCurveEaseOut); - animation_set_duration(butt_out_anim, 350); - //// back in - Animation *butt_in_anim = animation_clone(butt_out_anim); - animation_set_reverse(butt_in_anim, true); - //// set handler on out (after clone) - animation_set_handlers(butt_out_anim, (AnimationHandlers){.stopped = update_minute_30_out_handler}, NULL); - //// back to resting - Animation *butt_rest_anim = animation_clone(butt_raise_anim); - animation_set_reverse(butt_rest_anim, true); - //// do it! - animation_schedule(animation_sequence_create(butt_raise_anim, butt_out_anim, butt_in_anim, butt_rest_anim, NULL)); + // raise + s_butt_y_prop_anim = property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_butt_layer), &s_guy_butt_grect_on_screen_resting, &s_guy_butt_grect_on_screen_raised); + s_butt_raise_anim = property_animation_get_animation(s_butt_y_prop_anim); + animation_set_curve(s_butt_raise_anim, AnimationCurveEaseOut); + animation_set_duration(s_butt_raise_anim, 350); + // out + s_butt_x_prop_anim = property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_butt_layer), &s_guy_butt_grect_on_screen_raised, &s_guy_butt_grect_off_screen_raised); + s_butt_out_anim = property_animation_get_animation(s_butt_x_prop_anim); + animation_set_curve(s_butt_out_anim, AnimationCurveEaseOut); + animation_set_duration(s_butt_out_anim, 350); + // back in + s_butt_in_anim = animation_clone(s_butt_out_anim); + animation_set_reverse(s_butt_in_anim, true); + // set handler on out (after clone) + animation_set_handlers(s_butt_out_anim, (AnimationHandlers){.stopped = update_minute_30_out_handler}, NULL); + // back to resting + s_butt_rest_anim = animation_clone(s_butt_raise_anim); + animation_set_reverse(s_butt_rest_anim, true); + + // run animations + animation_schedule(animation_sequence_create(s_butt_raise_anim, s_butt_out_anim, s_butt_in_anim, s_butt_rest_anim, NULL)); + + // cleanup + animation_destroy(s_butt_raise_anim); + animation_destroy(s_butt_out_anim); + animation_destroy(s_butt_in_anim); + animation_destroy(s_butt_rest_anim); + property_animation_destroy(s_butt_y_prop_anim); + property_animation_destroy(s_butt_x_prop_anim); } static void update_minute_60_out_handler(Animation *animation, bool finished, void *context) { @@ -156,25 +180,35 @@ static void update_minute_60_out_handler(Animation *animation, bool finished, vo static void update_minute_60() { update_minute_1(); - // animate silly butt swap - //// raise - Animation *head_raise_anim = property_animation_get_animation(property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_head_layer), &s_guy_head_grect_on_screen_resting, &s_guy_head_grect_on_screen_raised)); - animation_set_curve(head_raise_anim, AnimationCurveEaseOut); - animation_set_duration(head_raise_anim, 350); - //// out - Animation *head_out_anim = property_animation_get_animation(property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_head_layer), &s_guy_head_grect_on_screen_raised, &s_guy_head_grect_off_screen_raised)); - animation_set_curve(head_out_anim, AnimationCurveEaseOut); - animation_set_duration(head_out_anim, 350); - //// back in - Animation *head_in_anim = animation_clone(head_out_anim); - animation_set_reverse(head_in_anim, true); - //// set handler on out (after clone) - animation_set_handlers(head_out_anim, (AnimationHandlers){.stopped = update_minute_60_out_handler}, NULL); - //// back to resting - Animation *head_rest_anim = animation_clone(head_raise_anim); - animation_set_reverse(head_rest_anim, true); - //// do it! - animation_schedule(animation_sequence_create(head_raise_anim, head_out_anim, head_in_anim, head_rest_anim, NULL)); + // raise + s_head_y_prop_anim = property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_head_layer), &s_guy_head_grect_on_screen_resting, &s_guy_head_grect_on_screen_raised); + s_head_raise_anim = property_animation_get_animation(s_head_y_prop_anim); + animation_set_curve(s_head_raise_anim, AnimationCurveEaseOut); + animation_set_duration(s_head_raise_anim, 350); + // out + s_head_x_prop_anim = property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_head_layer), &s_guy_head_grect_on_screen_raised, &s_guy_head_grect_off_screen_raised); + s_head_out_anim = property_animation_get_animation(s_head_x_prop_anim); + animation_set_curve(s_head_out_anim, AnimationCurveEaseOut); + animation_set_duration(s_head_out_anim, 350); + // back in + s_head_in_anim = animation_clone(s_head_out_anim); + animation_set_reverse(s_head_in_anim, true); + // set handler on out (after clone) + animation_set_handlers(s_head_out_anim, (AnimationHandlers){.stopped = update_minute_30_out_handler}, NULL); + // back to resting + s_head_rest_anim = animation_clone(s_head_raise_anim); + animation_set_reverse(s_head_rest_anim, true); + + // run animations + animation_schedule(animation_sequence_create(s_head_raise_anim, s_head_out_anim, s_head_in_anim, s_head_rest_anim, NULL)); + + // cleanup + animation_destroy(s_head_raise_anim); + animation_destroy(s_head_out_anim); + animation_destroy(s_head_in_anim); + animation_destroy(s_head_rest_anim); + property_animation_destroy(s_head_y_prop_anim); + property_animation_destroy(s_head_x_prop_anim); } static void minute_handler(struct tm *tick_time, TimeUnits units_changed) { @@ -250,12 +284,12 @@ static void main_window_load(Window *window) { // free memory on Window close static void main_window_unload(Window *window) { + // destroy layers bitmap_layer_destroy(s_guy_head_layer); bitmap_layer_destroy(s_guy_butt_layer); text_layer_destroy(s_time_layer); text_layer_destroy(s_date_layer); layer_destroy(s_time_bar_layer); - fonts_unload_custom_font(s_custom_font); // DEBUG memory usage layer text_layer_destroy(s_memory_layer); @@ -323,11 +357,17 @@ static void init() { // free memory on app exit static void deinit() { + // unload font + fonts_unload_custom_font(s_custom_font); + + // destroy gbitmaps gbitmap_destroy(s_head_current); gbitmap_destroy(s_butt_current); gbitmap_destroy(s_head_next); gbitmap_destroy(s_butt_next); gbitmap_destroy(s_bt); + + // destroy window window_destroy(s_main_window); }