diff --git a/src/c/main.c b/src/c/main.c index 37a4622..746514a 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -207,9 +207,10 @@ static void update_minute_1() { bitmap_layer_set_bitmap(s_digit_mg_layers[2], s_digit_mg_super8); bitmap_layer_set_bitmap(s_digit_mg_layers[3], s_digit_mg_super8); } - for (int i = 0; i < 4; ++i) { - bitmap_layer_set_bitmap(s_digit_fg_layers[i], s_hour_bitmaps[s_time_digits[i]]); - } + bitmap_layer_set_bitmap(s_digit_fg_layers[0], s_hour_bitmaps[s_time_digits[0]]); + bitmap_layer_set_bitmap(s_digit_fg_layers[1], s_hour_bitmaps[s_time_digits[1]]); + bitmap_layer_set_bitmap(s_digit_fg_layers[2], s_minute_bitmaps[s_time_digits[2]]); + bitmap_layer_set_bitmap(s_digit_fg_layers[3], s_minute_bitmaps[s_time_digits[3]]); } else { if (settings.ShowTimeMG) { bitmap_layer_set_bitmap(s_digit_mg_layers[2], s_digit_mg_super8_mini); @@ -243,9 +244,10 @@ static void accel_tap_handler(AccelAxisType axis, int32_t direction) { static char s_date_buffer[16]; strftime(s_date_buffer, sizeof(s_date_buffer), "%m%d", tick_time); if (!s_peek_active) { - for (int i = 0; i < 4; ++i) { - bitmap_layer_set_bitmap(s_digit_fg_layers[i], s_hour_bitmaps[s_date_buffer[i] - '0']); - } + bitmap_layer_set_bitmap(s_digit_fg_layers[0], s_hour_bitmaps[s_date_buffer[0] - '0']); + bitmap_layer_set_bitmap(s_digit_fg_layers[1], s_hour_bitmaps[s_date_buffer[1] - '0']); + bitmap_layer_set_bitmap(s_digit_fg_layers[2], s_minute_bitmaps[s_date_buffer[2] - '0']); + bitmap_layer_set_bitmap(s_digit_fg_layers[3], s_minute_bitmaps[s_date_buffer[3] - '0']); } else { bitmap_layer_set_bitmap(s_digit_fg_layers[0], s_hour_bitmaps[s_date_buffer[0] - '0']); bitmap_layer_set_bitmap(s_digit_fg_layers[1], s_hour_bitmaps[s_date_buffer[1] - '0']); @@ -361,7 +363,59 @@ static void apply_settings() { layer_mark_dirty(s_fuel_mg_layer); // FG & warning indicators - // time+date (re-sub bt tracking) + // manage minute-specific bitmaps if colors are unique + if (settings.ColorHours.argb != settings.ColorMinutes.argb) { + // if hours and minutes must be different colors... + // 1. check if the minute bitmaps are loaded and equal the hours + if (s_minute_bitmaps[0] && (s_minute_bitmaps[0] != s_hour_bitmaps[0])) { + // 2a. if loaded and unequal, we can just change the color of the loaded bitmaps + if (s_applied_minute.argb != settings.ColorMinutes.argb) { + for (int i = 0; i < 10; ++i) { + replace_gbitmap_color(s_applied_minute, settings.ColorMinutes, s_minute_bitmaps[i], NULL); + } + s_applied_minute = settings.ColorMinutes; + } + } else { + // 2b. otherwise, we must load them and set the colors now (they do not change with BT status so this must be managed here) + s_minute_bitmaps[0] = gbitmap_create_with_resource(RESOURCE_ID_0); + s_minute_bitmaps[1] = gbitmap_create_with_resource(RESOURCE_ID_1); + s_minute_bitmaps[2] = gbitmap_create_with_resource(RESOURCE_ID_2); + s_minute_bitmaps[3] = gbitmap_create_with_resource(RESOURCE_ID_3); + s_minute_bitmaps[4] = gbitmap_create_with_resource(RESOURCE_ID_4); + s_minute_bitmaps[5] = gbitmap_create_with_resource(RESOURCE_ID_5); + s_minute_bitmaps[6] = gbitmap_create_with_resource(RESOURCE_ID_6); + s_minute_bitmaps[7] = gbitmap_create_with_resource(RESOURCE_ID_7); + s_minute_bitmaps[8] = gbitmap_create_with_resource(RESOURCE_ID_8); + s_minute_bitmaps[9] = gbitmap_create_with_resource(RESOURCE_ID_9); + s_applied_minute = GColorWhite; + if (s_applied_minute.argb != settings.ColorMinutes.argb) { + for (int i = 0; i < 10; ++i) { + replace_gbitmap_color(s_applied_minute, settings.ColorMinutes, s_minute_bitmaps[i], NULL); + } + s_applied_minute = settings.ColorMinutes; + } + update_minute_1(); // immediately reference the new minute digits, as we would otherwise be using the stale pointers to the hours digits + } + } else { + // if hours and minutes must be the same color... + // 1. check if the minute bitmaps equal the hours + if (s_minute_bitmaps[0] != s_hour_bitmaps[0]) { + // 2. if not, check if they have been loaded + if (s_minute_bitmaps[0]) { + // 3a. if they have been, destroy them and set them as pointers to the hour bitmaps + for (int i = 0; i < 10; ++i) { + gbitmap_destroy(s_minute_bitmaps[i]); + s_minute_bitmaps[i] = s_hour_bitmaps[i]; + } + } else { + // 3b. otherwise, just point them to the hour bitmaps + for (int i = 0; i < 10; ++i) { + s_minute_bitmaps[i] = s_hour_bitmaps[i]; + } + } + } + } + // re-sub bt tracking (will update hour/month color; also minute/day if not unique) connection_service_unsubscribe(); if (settings.TrackBTStatus) { connection_service_subscribe((ConnectionHandlers){.pebble_app_connection_handler = bt_callback}); @@ -487,6 +541,11 @@ static void main_window_unload() { gbitmap_destroy(s_minute_bitmaps_mini[i]); } } + if (s_minute_bitmaps[0] != s_hour_bitmaps[0]) { + for (int i = 0; i < 10; ++i) { + gbitmap_destroy(s_minute_bitmaps[i]); + } + } connection_service_unsubscribe(); accel_tap_service_unsubscribe(); layer_destroy(s_fuel_mg_layer); @@ -620,7 +679,7 @@ static void init() { settings.ColorWarning = GColorChromeYellow; } - // load bitmaps + // load required bitmaps (hours and letters) s_hour_bitmaps[0] = gbitmap_create_with_resource(RESOURCE_ID_0); s_hour_bitmaps[1] = gbitmap_create_with_resource(RESOURCE_ID_1); s_hour_bitmaps[2] = gbitmap_create_with_resource(RESOURCE_ID_2);