Add legacy animations support
This commit is contained in:
+38
-3
@@ -90,6 +90,12 @@ static void s_animate_icon(NeatBarLayer *neat_bar, uint8_t button_index, bool is
|
||||
*pressed = false;
|
||||
}
|
||||
|
||||
// legacy animation: no icon movement, just invert the background third
|
||||
if (neat_bar->animations_legacy_pressed_color) {
|
||||
layer_mark_dirty(neat_bar->main_layer);
|
||||
return;
|
||||
}
|
||||
|
||||
Layer *layer = bitmap_layer_get_layer(bitmap_layer);
|
||||
GRect home = s_get_home_frame(neat_bar, button_index);
|
||||
|
||||
@@ -139,9 +145,28 @@ static void s_select_up_handler(ClickRecognizerRef recognizer, void *context) {
|
||||
}
|
||||
|
||||
static void s_main_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
NeatBarLayer *neat_bar = s_current_neat_bar;
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
|
||||
graphics_context_set_antialiased(ctx, false);
|
||||
graphics_context_set_fill_color(ctx, s_current_neat_bar->background_color);
|
||||
graphics_fill_rect(ctx, layer_get_bounds(layer), s_current_neat_bar->corner_radius, s_current_neat_bar->x_offset > 0 ? GCornersAll : GCornersLeft);
|
||||
graphics_context_set_fill_color(ctx, neat_bar->background_color);
|
||||
graphics_fill_rect(ctx, bounds, neat_bar->corner_radius, neat_bar->x_offset > 0 ? GCornersAll : GCornersLeft);
|
||||
|
||||
// Legacy animation: invert the background third for any pressed button
|
||||
if (neat_bar->animations_legacy_pressed_color) {
|
||||
int16_t third_height = bounds.size.h / 3;
|
||||
graphics_context_set_fill_color(ctx, *neat_bar->animations_legacy_pressed_color);
|
||||
|
||||
if (neat_bar->up_pressed) {
|
||||
graphics_fill_rect(ctx, GRect(1, 1, bounds.size.w - 2, third_height - 2), 0, GCornerNone);
|
||||
}
|
||||
if (neat_bar->select_pressed) {
|
||||
graphics_fill_rect(ctx, GRect(1, third_height + 1, bounds.size.w - 2, third_height - 2), 0, GCornerNone);
|
||||
}
|
||||
if (neat_bar->down_pressed) {
|
||||
graphics_fill_rect(ctx, GRect(1, third_height * 2 + 1, bounds.size.w - 2, bounds.size.h - third_height * 2 - 2), 0, GCornerNone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void s_base_click_config_provider(void *config_context) {
|
||||
@@ -301,6 +326,15 @@ void neat_bar_layer_set_background_color(NeatBarLayer *neat_bar, GColor backgrou
|
||||
layer_mark_dirty(neat_bar->main_layer);
|
||||
}
|
||||
|
||||
// default: NULL (null disables legacy animations)
|
||||
void neat_bar_layer_set_animations_type(NeatBarLayer *neat_bar, GColor8 *pressed_color) {
|
||||
if (pressed_color->argb == neat_bar->animations_legacy_pressed_color->argb) {
|
||||
return;
|
||||
}
|
||||
neat_bar->animations_legacy_pressed_color = pressed_color;
|
||||
layer_mark_dirty(neat_bar->main_layer);
|
||||
}
|
||||
|
||||
// default: 0
|
||||
void neat_bar_layer_set_spread(NeatBarLayer *neat_bar, int8_t spread) {
|
||||
if (spread == neat_bar->spread) {
|
||||
@@ -366,9 +400,10 @@ NeatBarLayer *neat_bar_layer_create() {
|
||||
neat_bar->corner_radius = 0;
|
||||
neat_bar->x_offset = 0;
|
||||
neat_bar->spread = 0;
|
||||
neat_bar->animations_duration = 144;
|
||||
neat_bar->animations_move_on_y_axis = false;
|
||||
neat_bar->animations_move_distance = ANIM_DISTANCE;
|
||||
neat_bar->animations_duration = 144;
|
||||
neat_bar->animations_legacy_pressed_color = NULL;
|
||||
neat_bar->up_pressed = false;
|
||||
neat_bar->select_pressed = false;
|
||||
neat_bar->down_pressed = false;
|
||||
|
||||
Reference in New Issue
Block a user