Add raise/rest animations for part swaps

This commit is contained in:
2026-03-17 17:28:16 -04:00
parent 7ba832f2c5
commit 231d35e580

View File

@@ -17,10 +17,14 @@ static GBitmap *s_head_current;
static GBitmap *s_butt_current; static GBitmap *s_butt_current;
static GBitmap *s_head_next; static GBitmap *s_head_next;
static GBitmap *s_butt_next; static GBitmap *s_butt_next;
static GRect s_guy_head_grect_on = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(0, -16), 260, 115);
static GRect s_guy_head_grect_off = GRect(PBL_IF_ROUND_ELSE(-260, -230), PBL_IF_ROUND_ELSE(0, -16), 260, 115); // declare positions for animation stages
static GRect s_guy_butt_grect_on = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(145, 129), 260, 115); static GRect s_guy_head_grect_on_screen_raised = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(-15, -31), 260, 115);
static GRect s_guy_butt_grect_off = GRect(PBL_IF_ROUND_ELSE(260, 170), PBL_IF_ROUND_ELSE(145, 129), 260, 115); static GRect s_guy_head_grect_off_screen_raised = GRect(PBL_IF_ROUND_ELSE(-260, -230), PBL_IF_ROUND_ELSE(-15, -31), 260, 115);
static GRect s_guy_head_grect_on_screen_resting = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(0, -16), 260, 115);
static GRect s_guy_butt_grect_on_screen_raised = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(160, 144), 260, 115);
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 lookup tables // declare lookup tables
static const uint8_t s_head_count = 25; static const uint8_t s_head_count = 25;
@@ -91,12 +95,6 @@ static void update_minute_30_out_handler(Animation *animation, bool finished, vo
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current); bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current); bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);
// animate return
Animation *butt_in_anim = property_animation_get_animation(property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_butt_layer), &s_guy_butt_grect_off, &s_guy_butt_grect_on));
animation_set_curve(butt_in_anim, AnimationCurveEaseOut);
animation_set_duration(butt_in_anim, 350);
animation_schedule(butt_in_anim);
// calc next values // calc next values
s_butt_next = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]); s_butt_next = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // next color s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // next color
@@ -105,12 +103,25 @@ static void update_minute_30_out_handler(Animation *animation, bool finished, vo
static void update_minute_30() { static void update_minute_30() {
update_minute_1(); update_minute_1();
// swap the silly butt on half-hour intervals // animate silly butt swap
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, &s_guy_butt_grect_off)); //// 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_curve(butt_out_anim, AnimationCurveEaseOut);
animation_set_duration(butt_out_anim, 350); 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); animation_set_handlers(butt_out_anim, (AnimationHandlers){.stopped = update_minute_30_out_handler}, NULL);
animation_schedule(butt_out_anim); //// 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));
} }
static void update_minute_60_out_handler(Animation *animation, bool finished, void *context) { static void update_minute_60_out_handler(Animation *animation, bool finished, void *context) {
@@ -127,12 +138,6 @@ static void update_minute_60_out_handler(Animation *animation, bool finished, vo
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current); bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current); bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
// animate return
Animation *head_in_anim = property_animation_get_animation(property_animation_create_layer_frame(bitmap_layer_get_layer(s_guy_head_layer), &s_guy_head_grect_off, &s_guy_head_grect_on));
animation_set_curve(head_in_anim, AnimationCurveEaseOut);
animation_set_duration(head_in_anim, 350);
animation_schedule(head_in_anim);
// calc next values // calc next values
s_head_next = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]); s_head_next = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // next color s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // next color
@@ -141,12 +146,25 @@ static void update_minute_60_out_handler(Animation *animation, bool finished, vo
static void update_minute_60() { static void update_minute_60() {
update_minute_1(); update_minute_1();
// swap the silly head on hour intervals // animate silly butt swap
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, &s_guy_head_grect_off)); //// 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_curve(head_out_anim, AnimationCurveEaseOut);
animation_set_duration(head_out_anim, 350); 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); animation_set_handlers(head_out_anim, (AnimationHandlers){.stopped = update_minute_60_out_handler}, NULL);
animation_schedule(head_out_anim); //// 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));
} }
static void minute_handler(struct tm *tick_time, TimeUnits units_changed) { static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
@@ -169,8 +187,8 @@ static void main_window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window); Layer *window_layer = window_get_root_layer(window);
// format silly guy layers // format silly guy layers
s_guy_head_layer = bitmap_layer_create(s_guy_head_grect_on); s_guy_head_layer = bitmap_layer_create(s_guy_head_grect_on_screen_resting);
s_guy_butt_layer = bitmap_layer_create(s_guy_butt_grect_on); s_guy_butt_layer = bitmap_layer_create(s_guy_butt_grect_on_screen_resting);
bitmap_layer_set_compositing_mode(s_guy_head_layer, GCompOpSet); bitmap_layer_set_compositing_mode(s_guy_head_layer, GCompOpSet);
bitmap_layer_set_alignment(s_guy_head_layer, GAlignLeft); bitmap_layer_set_alignment(s_guy_head_layer, GAlignLeft);
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current); bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);