diff --git a/src/c/main.c b/src/c/main.c index 8a24fdc..37a4622 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -5,8 +5,8 @@ // window statics static Window *s_main_window; static Layer *s_window_layer; -static BitmapLayer *s_time_mg_layers[4]; -static BitmapLayer *s_time_fg_layers[4]; +static BitmapLayer *s_digit_mg_layers[4]; +static BitmapLayer *s_digit_fg_layers[4]; static BitmapLayer *s_c_layer; static BitmapLayer *s_h_layer; static BitmapLayer *s_e_layer; @@ -17,22 +17,24 @@ static Layer *s_fuel_mg_layer; static Layer *s_fuel_layer; static const uint8_t s_x_r = (PBL_DISPLAY_WIDTH / 2) + 2; static const uint8_t s_x_l = (s_x_r - 2 * (69 / 2)) - 5; -static const GRect s_time_grects[4] = {GRect(s_x_l, 2, 69, 110), GRect(s_x_r, 2, 69, 110), GRect(s_x_l, 116, 69, 110), GRect(s_x_r, 116, 69, 110)}; // emery +static const GRect s_digit_grects[4] = {GRect(s_x_l, 2, 69, 110), GRect(s_x_r, 2, 69, 110), GRect(s_x_l, 116, 69, 110), GRect(s_x_r, 116, 69, 110)}; // emery static const uint8_t s_temp_guage_x_pos = 6; static const uint16_t s_fuel_guage_x_pos = PBL_DISPLAY_WIDTH - 23; // settings statics static ClaySettings settings; -static GColor s_applied_time_mg = GColorDarkGray; +static GColor s_applied_digits_mg = GColorDarkGray; static GColor s_applied_e_f = GColorWhite; static GColor s_applied_c_h = GColorWhite; -static GColor s_applied_time_date = GColorWhite; +static GColor s_applied_hour = GColorWhite; +static GColor s_applied_minute = GColorWhite; // bitmap statics -static GBitmap *s_font_bitmaps[10]; -static GBitmap *s_font_bitmaps_mini[10]; -static GBitmap *s_time_mg_super8; -static GBitmap *s_time_mg_super8_mini; +static GBitmap *s_hour_bitmaps[10]; +static GBitmap *s_minute_bitmaps[10]; +static GBitmap *s_minute_bitmaps_mini[10]; +static GBitmap *s_digit_mg_super8; +static GBitmap *s_digit_mg_super8_mini; static GBitmap *s_c_icon; static GBitmap *s_h_icon; static GBitmap *s_e_icon; @@ -88,18 +90,18 @@ static void toggle_temp_warning_state(bool enable_warning, bool force) { static void bt_callback(bool connected) { GColor dst = connected ? settings.ColorHours : settings.ColorWarning; - if (s_first_settings_application && connected && dst.argb == s_applied_time_date.argb) { + if (s_first_settings_application && connected && dst.argb == s_applied_hour.argb) { // at startup, s_applied_time_date.argb is GColorWhite // for those using white fg, do not pointlessly replace white at startup if that is the destination anyway return; } for (int i = 0; i < 10; ++i) { - replace_gbitmap_color(s_applied_time_date, dst, s_font_bitmaps[i], NULL); + replace_gbitmap_color(s_applied_hour, dst, s_hour_bitmaps[i], NULL); } for (int i = 0; i < 4; ++i) { - layer_mark_dirty(bitmap_layer_get_layer(s_time_fg_layers[i])); + layer_mark_dirty(bitmap_layer_get_layer(s_digit_fg_layers[i])); } - s_applied_time_date = dst; + s_applied_hour = dst; } static void batt_callback(BatteryChargeState state) { @@ -202,21 +204,21 @@ static void update_minute_1() { if (!s_peek_active) { if (settings.ShowTimeMG) { - bitmap_layer_set_bitmap(s_time_mg_layers[2], s_time_mg_super8); - bitmap_layer_set_bitmap(s_time_mg_layers[3], s_time_mg_super8); + 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_time_fg_layers[i], s_font_bitmaps[s_time_digits[i]]); + bitmap_layer_set_bitmap(s_digit_fg_layers[i], s_hour_bitmaps[s_time_digits[i]]); } } else { if (settings.ShowTimeMG) { - bitmap_layer_set_bitmap(s_time_mg_layers[2], s_time_mg_super8_mini); - bitmap_layer_set_bitmap(s_time_mg_layers[3], s_time_mg_super8_mini); + bitmap_layer_set_bitmap(s_digit_mg_layers[2], s_digit_mg_super8_mini); + bitmap_layer_set_bitmap(s_digit_mg_layers[3], s_digit_mg_super8_mini); } - bitmap_layer_set_bitmap(s_time_fg_layers[0], s_font_bitmaps[s_time_digits[0]]); - bitmap_layer_set_bitmap(s_time_fg_layers[1], s_font_bitmaps[s_time_digits[1]]); - bitmap_layer_set_bitmap(s_time_fg_layers[2], s_font_bitmaps_mini[s_time_digits[2]]); - bitmap_layer_set_bitmap(s_time_fg_layers[3], s_font_bitmaps_mini[s_time_digits[3]]); + 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_mini[s_time_digits[2]]); + bitmap_layer_set_bitmap(s_digit_fg_layers[3], s_minute_bitmaps_mini[s_time_digits[3]]); } } @@ -242,13 +244,13 @@ static void accel_tap_handler(AccelAxisType axis, int32_t direction) { 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_time_fg_layers[i], s_font_bitmaps[s_date_buffer[i] - '0']); + bitmap_layer_set_bitmap(s_digit_fg_layers[i], s_hour_bitmaps[s_date_buffer[i] - '0']); } } else { - bitmap_layer_set_bitmap(s_time_fg_layers[0], s_font_bitmaps[s_date_buffer[0] - '0']); - bitmap_layer_set_bitmap(s_time_fg_layers[1], s_font_bitmaps[s_date_buffer[1] - '0']); - bitmap_layer_set_bitmap(s_time_fg_layers[2], s_font_bitmaps_mini[s_date_buffer[2] - '0']); - bitmap_layer_set_bitmap(s_time_fg_layers[3], s_font_bitmaps_mini[s_date_buffer[3] - '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_mini[s_date_buffer[2] - '0']); + bitmap_layer_set_bitmap(s_digit_fg_layers[3], s_minute_bitmaps_mini[s_date_buffer[3] - '0']); } s_showing_date = true; @@ -274,19 +276,19 @@ static void peek_will_change(GRect final_unobstructed_screen_area, void *context static void peek_change(AnimationProgress progress, void *context) { // animate the moving of the minute layers depending on s_peek_active if (!s_peek_active) { - layer_set_frame(bitmap_layer_get_layer(s_time_fg_layers[2]), s_time_grects[2]); - layer_set_frame(bitmap_layer_get_layer(s_time_fg_layers[3]), s_time_grects[3]); + layer_set_frame(bitmap_layer_get_layer(s_digit_fg_layers[2]), s_digit_grects[2]); + layer_set_frame(bitmap_layer_get_layer(s_digit_fg_layers[3]), s_digit_grects[3]); if (settings.ShowTimeMG) { - layer_set_frame(bitmap_layer_get_layer(s_time_mg_layers[2]), s_time_grects[2]); - layer_set_frame(bitmap_layer_get_layer(s_time_mg_layers[3]), s_time_grects[3]); + layer_set_frame(bitmap_layer_get_layer(s_digit_mg_layers[2]), s_digit_grects[2]); + layer_set_frame(bitmap_layer_get_layer(s_digit_mg_layers[3]), s_digit_grects[3]); } } else { - uint8_t y = s_time_grects[2].origin.y - 1; - layer_set_frame(bitmap_layer_get_layer(s_time_fg_layers[2]), GRect(s_time_grects[2].origin.x, y, 69, 54)); - layer_set_frame(bitmap_layer_get_layer(s_time_fg_layers[3]), GRect(s_time_grects[3].origin.x, y, 69, 54)); + uint8_t y = s_digit_grects[2].origin.y - 1; + layer_set_frame(bitmap_layer_get_layer(s_digit_fg_layers[2]), GRect(s_digit_grects[2].origin.x, y, 69, 54)); + layer_set_frame(bitmap_layer_get_layer(s_digit_fg_layers[3]), GRect(s_digit_grects[3].origin.x, y, 69, 54)); if (settings.ShowTimeMG) { - layer_set_frame(bitmap_layer_get_layer(s_time_mg_layers[2]), GRect(s_time_grects[2].origin.x, y, 69, 54)); - layer_set_frame(bitmap_layer_get_layer(s_time_mg_layers[3]), GRect(s_time_grects[3].origin.x, y, 69, 54)); + layer_set_frame(bitmap_layer_get_layer(s_digit_mg_layers[2]), GRect(s_digit_grects[2].origin.x, y, 69, 54)); + layer_set_frame(bitmap_layer_get_layer(s_digit_mg_layers[3]), GRect(s_digit_grects[3].origin.x, y, 69, 54)); } } } @@ -310,47 +312,47 @@ static void apply_settings() { // TIME MG if (settings.ShowTimeMG) { //// load bitmap if not already loaded - if (!s_time_mg_super8) { - s_time_mg_super8 = gbitmap_create_with_resource(RESOURCE_ID_SUPER8); - s_applied_time_mg = GColorWhite; + if (!s_digit_mg_super8) { + s_digit_mg_super8 = gbitmap_create_with_resource(RESOURCE_ID_SUPER8); + s_applied_digits_mg = GColorDarkGray; } //// create and insert any mg layer that does not already exist Layer *sibling_layer = NULL; if (s_first_settings_application) { sibling_layer = s_window_layer; } else { - sibling_layer = bitmap_layer_get_layer(s_time_fg_layers[0]); + sibling_layer = bitmap_layer_get_layer(s_digit_fg_layers[0]); } for (int i = 0; i < 4; ++i) { - if (!s_time_mg_layers[i]) { - s_time_mg_layers[i] = bitmap_layer_create(s_time_grects[i]); - bitmap_layer_set_bitmap(s_time_mg_layers[i], s_time_mg_super8); - bitmap_layer_set_compositing_mode(s_time_mg_layers[i], GCompOpSet); + if (!s_digit_mg_layers[i]) { + s_digit_mg_layers[i] = bitmap_layer_create(s_digit_grects[i]); + bitmap_layer_set_bitmap(s_digit_mg_layers[i], s_digit_mg_super8); + bitmap_layer_set_compositing_mode(s_digit_mg_layers[i], GCompOpSet); if (s_first_settings_application) { - layer_add_child(sibling_layer, bitmap_layer_get_layer(s_time_mg_layers[i])); + layer_add_child(sibling_layer, bitmap_layer_get_layer(s_digit_mg_layers[i])); } else { - layer_insert_below_sibling(bitmap_layer_get_layer(s_time_mg_layers[i]), sibling_layer); + layer_insert_below_sibling(bitmap_layer_get_layer(s_digit_mg_layers[i]), sibling_layer); } } } //// set bitmap color and mark layers dirty - if (s_time_mg_super8 && settings.ColorMGTime.argb != s_applied_time_mg.argb) { - replace_gbitmap_color(s_applied_time_mg, settings.ColorMGTime, s_time_mg_super8, NULL); + if (s_digit_mg_super8 && settings.ColorMGTime.argb != s_applied_digits_mg.argb) { + replace_gbitmap_color(s_applied_digits_mg, settings.ColorMGTime, s_digit_mg_super8, NULL); for (int i = 0; i < 4; ++i) { - if (s_time_mg_layers[i]) { - layer_mark_dirty(bitmap_layer_get_layer(s_time_mg_layers[i])); + if (s_digit_mg_layers[i]) { + layer_mark_dirty(bitmap_layer_get_layer(s_digit_mg_layers[i])); } } - s_applied_time_mg = settings.ColorMGTime; + s_applied_digits_mg = settings.ColorMGTime; } } else { - if (s_time_mg_super8) { + if (s_digit_mg_super8) { for (int i = 0; i < 4; ++i) { - bitmap_layer_destroy(s_time_mg_layers[i]); - s_time_mg_layers[i] = NULL; + bitmap_layer_destroy(s_digit_mg_layers[i]); + s_digit_mg_layers[i] = NULL; } - gbitmap_destroy(s_time_mg_super8); - s_time_mg_super8 = NULL; + gbitmap_destroy(s_digit_mg_super8); + s_digit_mg_super8 = NULL; } } @@ -387,29 +389,29 @@ static void apply_settings() { } // re-sub timeline peek and create/destroy resources as needed - // TODO fix fg and mg color not applying to mini varients; fix time mg color restore on face reload + // TODO fix fg and mg color not applying to mini varients unobstructed_area_service_unsubscribe(); if (settings.EnablePeek) { - if (!s_font_bitmaps_mini[0]) { - s_font_bitmaps_mini[0] = gbitmap_create_with_resource(RESOURCE_ID_0_M); - s_font_bitmaps_mini[1] = gbitmap_create_with_resource(RESOURCE_ID_1_M); - s_font_bitmaps_mini[2] = gbitmap_create_with_resource(RESOURCE_ID_2_M); - s_font_bitmaps_mini[3] = gbitmap_create_with_resource(RESOURCE_ID_3_M); - s_font_bitmaps_mini[4] = gbitmap_create_with_resource(RESOURCE_ID_4_M); - s_font_bitmaps_mini[5] = gbitmap_create_with_resource(RESOURCE_ID_5_M); - s_font_bitmaps_mini[6] = gbitmap_create_with_resource(RESOURCE_ID_6_M); - s_font_bitmaps_mini[7] = gbitmap_create_with_resource(RESOURCE_ID_7_M); - s_font_bitmaps_mini[8] = gbitmap_create_with_resource(RESOURCE_ID_8_M); - s_font_bitmaps_mini[9] = gbitmap_create_with_resource(RESOURCE_ID_9_M); + if (!s_minute_bitmaps_mini[0]) { + s_minute_bitmaps_mini[0] = gbitmap_create_with_resource(RESOURCE_ID_0_M); + s_minute_bitmaps_mini[1] = gbitmap_create_with_resource(RESOURCE_ID_1_M); + s_minute_bitmaps_mini[2] = gbitmap_create_with_resource(RESOURCE_ID_2_M); + s_minute_bitmaps_mini[3] = gbitmap_create_with_resource(RESOURCE_ID_3_M); + s_minute_bitmaps_mini[4] = gbitmap_create_with_resource(RESOURCE_ID_4_M); + s_minute_bitmaps_mini[5] = gbitmap_create_with_resource(RESOURCE_ID_5_M); + s_minute_bitmaps_mini[6] = gbitmap_create_with_resource(RESOURCE_ID_6_M); + s_minute_bitmaps_mini[7] = gbitmap_create_with_resource(RESOURCE_ID_7_M); + s_minute_bitmaps_mini[8] = gbitmap_create_with_resource(RESOURCE_ID_8_M); + s_minute_bitmaps_mini[9] = gbitmap_create_with_resource(RESOURCE_ID_9_M); } - if (!s_time_mg_super8_mini) { + if (!s_digit_mg_super8_mini) { if (settings.ShowTimeMG) { - s_time_mg_super8_mini = gbitmap_create_with_resource(RESOURCE_ID_SUPER8_M); + s_digit_mg_super8_mini = gbitmap_create_with_resource(RESOURCE_ID_SUPER8_M); } } else { if (!settings.ShowTimeMG) { - gbitmap_destroy(s_time_mg_super8_mini); - s_time_mg_super8_mini = NULL; + gbitmap_destroy(s_digit_mg_super8_mini); + s_digit_mg_super8_mini = NULL; } } peek_will_change(layer_get_unobstructed_bounds(s_window_layer), NULL); @@ -425,15 +427,15 @@ static void apply_settings() { peek_will_change(layer_get_bounds(s_window_layer), NULL); peek_change(0, NULL); peek_did_change(NULL); - if (s_font_bitmaps_mini[0]) { + if (s_minute_bitmaps_mini[0]) { for (int i = 0; i < 10; ++i) { - gbitmap_destroy(s_font_bitmaps_mini[i]); - s_font_bitmaps_mini[i] = NULL; + gbitmap_destroy(s_minute_bitmaps_mini[i]); + s_minute_bitmaps_mini[i] = NULL; } } - if (s_time_mg_super8_mini) { - gbitmap_destroy(s_time_mg_super8_mini); - s_time_mg_super8_mini = NULL; + if (s_digit_mg_super8_mini) { + gbitmap_destroy(s_digit_mg_super8_mini); + s_digit_mg_super8_mini = NULL; } } @@ -466,7 +468,7 @@ static void main_window_load() { apply_settings(); for (int i = 0; i < 4; ++i) { - layer_add_child(s_window_layer, bitmap_layer_get_layer(s_time_fg_layers[i])); + layer_add_child(s_window_layer, bitmap_layer_get_layer(s_digit_fg_layers[i])); } layer_add_child(s_window_layer, bitmap_layer_get_layer(s_c_layer)); layer_add_child(s_window_layer, bitmap_layer_get_layer(s_h_layer)); @@ -482,7 +484,7 @@ static void main_window_unload() { if (settings.EnablePeek) { unobstructed_area_service_unsubscribe(); for (int i = 0; i < 10; ++i) { - gbitmap_destroy(s_font_bitmaps_mini[i]); + gbitmap_destroy(s_minute_bitmaps_mini[i]); } } connection_service_unsubscribe(); @@ -493,13 +495,13 @@ static void main_window_unload() { bitmap_layer_destroy(s_e_layer); bitmap_layer_destroy(s_h_layer); bitmap_layer_destroy(s_c_layer); - if (s_time_mg_super8_mini) { - gbitmap_destroy(s_time_mg_super8_mini); + if (s_digit_mg_super8_mini) { + gbitmap_destroy(s_digit_mg_super8_mini); } - if (s_time_mg_super8) { - gbitmap_destroy(s_time_mg_super8); + if (s_digit_mg_super8) { + gbitmap_destroy(s_digit_mg_super8); for (int i = 0; i < 4; ++i) { - bitmap_layer_destroy(s_time_mg_layers[i]); + bitmap_layer_destroy(s_digit_mg_layers[i]); } } } @@ -619,24 +621,24 @@ static void init() { } // load bitmaps - s_font_bitmaps[0] = gbitmap_create_with_resource(RESOURCE_ID_0); - s_font_bitmaps[1] = gbitmap_create_with_resource(RESOURCE_ID_1); - s_font_bitmaps[2] = gbitmap_create_with_resource(RESOURCE_ID_2); - s_font_bitmaps[3] = gbitmap_create_with_resource(RESOURCE_ID_3); - s_font_bitmaps[4] = gbitmap_create_with_resource(RESOURCE_ID_4); - s_font_bitmaps[5] = gbitmap_create_with_resource(RESOURCE_ID_5); - s_font_bitmaps[6] = gbitmap_create_with_resource(RESOURCE_ID_6); - s_font_bitmaps[7] = gbitmap_create_with_resource(RESOURCE_ID_7); - s_font_bitmaps[8] = gbitmap_create_with_resource(RESOURCE_ID_8); - s_font_bitmaps[9] = gbitmap_create_with_resource(RESOURCE_ID_9); + 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); + s_hour_bitmaps[3] = gbitmap_create_with_resource(RESOURCE_ID_3); + s_hour_bitmaps[4] = gbitmap_create_with_resource(RESOURCE_ID_4); + s_hour_bitmaps[5] = gbitmap_create_with_resource(RESOURCE_ID_5); + s_hour_bitmaps[6] = gbitmap_create_with_resource(RESOURCE_ID_6); + s_hour_bitmaps[7] = gbitmap_create_with_resource(RESOURCE_ID_7); + s_hour_bitmaps[8] = gbitmap_create_with_resource(RESOURCE_ID_8); + s_hour_bitmaps[9] = gbitmap_create_with_resource(RESOURCE_ID_9); s_c_icon = gbitmap_create_with_resource(RESOURCE_ID_C); s_h_icon = gbitmap_create_with_resource(RESOURCE_ID_H); s_e_icon = gbitmap_create_with_resource(RESOURCE_ID_E); s_f_icon = gbitmap_create_with_resource(RESOURCE_ID_F); for (int i = 0; i < 4; ++i) { - s_time_fg_layers[i] = bitmap_layer_create(s_time_grects[i]); - bitmap_layer_set_compositing_mode(s_time_fg_layers[i], GCompOpSet); + s_digit_fg_layers[i] = bitmap_layer_create(s_digit_grects[i]); + bitmap_layer_set_compositing_mode(s_digit_fg_layers[i], GCompOpSet); } s_temp_layer = layer_create(GRect(s_temp_guage_x_pos, 0, s_bar_width, PBL_DISPLAY_HEIGHT)); layer_set_update_proc(s_temp_layer, temp_update_proc); @@ -670,10 +672,10 @@ static void deinit() { gbitmap_destroy(s_h_icon); gbitmap_destroy(s_c_icon); for (int i = 0; i < 4; ++i) { - bitmap_layer_destroy(s_time_fg_layers[i]); + bitmap_layer_destroy(s_digit_fg_layers[i]); } for (int i = 0; i < 10; ++i) { - gbitmap_destroy(s_font_bitmaps[i]); + gbitmap_destroy(s_hour_bitmaps[i]); } window_destroy(s_main_window); }