Remove need for soft_reload
This commit is contained in:
+81
-60
@@ -28,6 +28,8 @@ static const uint16_t s_fuel_guage_x_pos = PBL_DISPLAY_WIDTH - 23;
|
|||||||
|
|
||||||
// settings statics
|
// settings statics
|
||||||
static ClaySettings settings;
|
static ClaySettings settings;
|
||||||
|
static GColor s_applied_fg = GColorWhite;
|
||||||
|
static GColor s_applied_time_mg = GColorWhite;
|
||||||
|
|
||||||
// bitmap statics
|
// bitmap statics
|
||||||
static GBitmap *s_font_bitmaps[10];
|
static GBitmap *s_font_bitmaps[10];
|
||||||
@@ -36,8 +38,6 @@ static GBitmap *s_c_icon;
|
|||||||
static GBitmap *s_h_icon;
|
static GBitmap *s_h_icon;
|
||||||
static GBitmap *s_e_icon;
|
static GBitmap *s_e_icon;
|
||||||
static GBitmap *s_f_icon;
|
static GBitmap *s_f_icon;
|
||||||
static GColor s_applied_fg = GColorWhite;
|
|
||||||
static GColor s_applied_time_mg = GColorWhite;
|
|
||||||
|
|
||||||
// tracking statics
|
// tracking statics
|
||||||
static int s_batt_level;
|
static int s_batt_level;
|
||||||
@@ -104,55 +104,86 @@ static void fuel_mg_update_proc(Layer *layer, GContext *ctx) {
|
|||||||
temp_fuel_mg_update_proc_helper(layer, ctx, true);
|
temp_fuel_mg_update_proc_helper(layer, ctx, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void apply_fg_color(GColor new_color) {
|
static void apply_settings(bool first_run) {
|
||||||
if (new_color.argb == s_applied_fg.argb) {
|
// LED&BG
|
||||||
return;
|
light_set_color(settings.ColorLED); // no-op on unsupported platforms
|
||||||
|
window_set_background_color(s_main_window, settings.ColorBG);
|
||||||
|
|
||||||
|
// TIME MG
|
||||||
|
if (settings.ShowTimeMG) {
|
||||||
|
//// load bitmap if not already loaded
|
||||||
|
if (!s_time_mg_8) {
|
||||||
|
s_time_mg_8 = gbitmap_create_with_resource(RESOURCE_ID_8);
|
||||||
|
s_applied_time_mg = GColorWhite;
|
||||||
|
}
|
||||||
|
//// create and insert any mg layer that does not already exist
|
||||||
|
Layer *sibling_layer = NULL;
|
||||||
|
if (first_run) {
|
||||||
|
sibling_layer = window_get_root_layer(s_main_window);
|
||||||
|
} else {
|
||||||
|
sibling_layer = bitmap_layer_get_layer(s_time_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_8);
|
||||||
|
bitmap_layer_set_compositing_mode(s_time_mg_layers[i], GCompOpSet);
|
||||||
|
if (first_run) {
|
||||||
|
layer_add_child(sibling_layer, bitmap_layer_get_layer(s_time_mg_layers[i]));
|
||||||
|
} else {
|
||||||
|
layer_insert_below_sibling(bitmap_layer_get_layer(s_time_mg_layers[i]), sibling_layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//// set bitmap color and mark layers dirty
|
||||||
|
if (s_time_mg_8 && settings.ColorMGTime.argb != s_applied_time_mg.argb) {
|
||||||
|
replace_gbitmap_color(s_applied_time_mg, settings.ColorMGTime, s_time_mg_8, 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]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s_applied_time_mg = settings.ColorMGTime;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (s_time_mg_8) {
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
bitmap_layer_destroy(s_time_mg_layers[i]);
|
||||||
|
s_time_mg_layers[i] = NULL;
|
||||||
|
}
|
||||||
|
gbitmap_destroy(s_time_mg_8);
|
||||||
|
s_time_mg_8 = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i) {
|
// BAR MG
|
||||||
replace_gbitmap_color(s_applied_fg, new_color, s_font_bitmaps[i], NULL);
|
layer_mark_dirty(s_temp_mg_layer);
|
||||||
|
layer_mark_dirty(s_fuel_mg_layer);
|
||||||
|
|
||||||
|
// FG
|
||||||
|
if (settings.ColorFG.argb != s_applied_fg.argb) {
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_font_bitmaps[i], NULL);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
layer_mark_dirty(bitmap_layer_get_layer(s_time_fg_layers[i]));
|
||||||
|
}
|
||||||
|
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_c_icon, s_c_layer);
|
||||||
|
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_h_icon, s_h_layer);
|
||||||
|
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_e_icon, s_e_layer);
|
||||||
|
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_f_icon, s_f_layer);
|
||||||
|
s_applied_fg = settings.ColorFG;
|
||||||
}
|
}
|
||||||
replace_gbitmap_color(s_applied_fg, new_color, s_c_icon, NULL);
|
|
||||||
replace_gbitmap_color(s_applied_fg, new_color, s_h_icon, NULL);
|
|
||||||
replace_gbitmap_color(s_applied_fg, new_color, s_e_icon, NULL);
|
|
||||||
replace_gbitmap_color(s_applied_fg, new_color, s_f_icon, NULL);
|
|
||||||
|
|
||||||
s_applied_fg = new_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void apply_time_mg_color(GColor new_color) {
|
|
||||||
if (!s_time_mg_8 || new_color.argb == s_applied_time_mg.argb) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_gbitmap_color(s_applied_time_mg, new_color, s_time_mg_8, NULL);
|
|
||||||
s_applied_time_mg = new_color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void main_window_load() {
|
static void main_window_load() {
|
||||||
Layer *window_layer = window_get_root_layer(s_main_window);
|
Layer *window_layer = window_get_root_layer(s_main_window);
|
||||||
|
|
||||||
// background (+led) colors
|
|
||||||
light_set_color(settings.ColorLED); // no-op on unsupported platforms
|
|
||||||
window_set_background_color(s_main_window, settings.ColorBG);
|
|
||||||
|
|
||||||
s_temp_mg_layer = layer_create(GRect(s_temp_guage_x_pos - 1, 21, s_bar_width + 2, PBL_DISPLAY_HEIGHT - 43));
|
s_temp_mg_layer = layer_create(GRect(s_temp_guage_x_pos - 1, 21, s_bar_width + 2, PBL_DISPLAY_HEIGHT - 43));
|
||||||
layer_set_update_proc(s_temp_mg_layer, temp_mg_update_proc);
|
layer_set_update_proc(s_temp_mg_layer, temp_mg_update_proc);
|
||||||
s_fuel_mg_layer = layer_create(GRect(s_fuel_guage_x_pos - 1, 21, s_bar_width + 2, PBL_DISPLAY_HEIGHT - 43));
|
s_fuel_mg_layer = layer_create(GRect(s_fuel_guage_x_pos - 1, 21, s_bar_width + 2, PBL_DISPLAY_HEIGHT - 43));
|
||||||
layer_set_update_proc(s_fuel_mg_layer, fuel_mg_update_proc);
|
layer_set_update_proc(s_fuel_mg_layer, fuel_mg_update_proc);
|
||||||
|
|
||||||
if (settings.ShowTimeMG) {
|
|
||||||
s_time_mg_8 = gbitmap_create_with_resource(RESOURCE_ID_8);
|
|
||||||
s_applied_time_mg = GColorWhite;
|
|
||||||
apply_time_mg_color(settings.ColorMGTime);
|
|
||||||
for (int i = 0; i < 4; ++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_8);
|
|
||||||
bitmap_layer_set_compositing_mode(s_time_mg_layers[i], GCompOpSet);
|
|
||||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_mg_layers[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s_c_layer = bitmap_layer_create(GRect(s_temp_guage_x_pos, PBL_DISPLAY_HEIGHT - 18, 17, 15));
|
s_c_layer = bitmap_layer_create(GRect(s_temp_guage_x_pos, PBL_DISPLAY_HEIGHT - 18, 17, 15));
|
||||||
s_h_layer = bitmap_layer_create(GRect(s_temp_guage_x_pos, 3, 17, 14));
|
s_h_layer = bitmap_layer_create(GRect(s_temp_guage_x_pos, 3, 17, 14));
|
||||||
s_e_layer = bitmap_layer_create(GRect(s_fuel_guage_x_pos, PBL_DISPLAY_HEIGHT - 18, 17, 15));
|
s_e_layer = bitmap_layer_create(GRect(s_fuel_guage_x_pos, PBL_DISPLAY_HEIGHT - 18, 17, 15));
|
||||||
@@ -166,7 +197,7 @@ static void main_window_load() {
|
|||||||
bitmap_layer_set_compositing_mode(s_e_layer, GCompOpSet);
|
bitmap_layer_set_compositing_mode(s_e_layer, GCompOpSet);
|
||||||
bitmap_layer_set_compositing_mode(s_f_layer, GCompOpSet);
|
bitmap_layer_set_compositing_mode(s_f_layer, GCompOpSet);
|
||||||
|
|
||||||
apply_fg_color(settings.ColorFG);
|
apply_settings(true);
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_fg_layers[i]));
|
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_fg_layers[i]));
|
||||||
@@ -188,15 +219,11 @@ static void main_window_unload() {
|
|||||||
bitmap_layer_destroy(s_e_layer);
|
bitmap_layer_destroy(s_e_layer);
|
||||||
bitmap_layer_destroy(s_h_layer);
|
bitmap_layer_destroy(s_h_layer);
|
||||||
bitmap_layer_destroy(s_c_layer);
|
bitmap_layer_destroy(s_c_layer);
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
if (s_time_mg_layers[i]) {
|
|
||||||
bitmap_layer_destroy(s_time_mg_layers[i]);
|
|
||||||
s_time_mg_layers[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (s_time_mg_8) {
|
if (s_time_mg_8) {
|
||||||
gbitmap_destroy(s_time_mg_8);
|
gbitmap_destroy(s_time_mg_8);
|
||||||
s_time_mg_8 = NULL;
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
bitmap_layer_destroy(s_time_mg_layers[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,18 +255,6 @@ static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
|
|||||||
update_minute_1();
|
update_minute_1();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void soft_reload(bool first_load) {
|
|
||||||
if (!first_load) {
|
|
||||||
window_stack_remove(s_main_window, false);
|
|
||||||
window_destroy(s_main_window);
|
|
||||||
}
|
|
||||||
s_main_window = window_create();
|
|
||||||
window_set_window_handlers(
|
|
||||||
s_main_window,
|
|
||||||
(WindowHandlers){.load = main_window_load, .unload = main_window_unload});
|
|
||||||
window_stack_push(s_main_window, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||||
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
|
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
|
||||||
if (ready_tuple) {
|
if (ready_tuple) {
|
||||||
@@ -280,7 +295,7 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|||||||
settings.ColorFG = GColorFromHEX(color_fg_tuple->value->int32);
|
settings.ColorFG = GColorFromHEX(color_fg_tuple->value->int32);
|
||||||
}
|
}
|
||||||
persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
|
persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
|
||||||
soft_reload(false);
|
apply_settings(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
@@ -327,7 +342,11 @@ static void init() {
|
|||||||
app_message_register_inbox_received(inbox_received_handler);
|
app_message_register_inbox_received(inbox_received_handler);
|
||||||
app_message_open(255, 64);
|
app_message_open(255, 64);
|
||||||
|
|
||||||
soft_reload(true);
|
s_main_window = window_create();
|
||||||
|
window_set_window_handlers(
|
||||||
|
s_main_window,
|
||||||
|
(WindowHandlers){.load = main_window_load, .unload = main_window_unload});
|
||||||
|
window_stack_push(s_main_window, false);
|
||||||
|
|
||||||
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
|
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
|
||||||
battery_state_service_subscribe(batt_callback);
|
battery_state_service_subscribe(batt_callback);
|
||||||
@@ -340,6 +359,8 @@ static void deinit() {
|
|||||||
layer_destroy(s_temp_layer);
|
layer_destroy(s_temp_layer);
|
||||||
gbitmap_destroy(s_f_icon);
|
gbitmap_destroy(s_f_icon);
|
||||||
gbitmap_destroy(s_e_icon);
|
gbitmap_destroy(s_e_icon);
|
||||||
|
gbitmap_destroy(s_h_icon);
|
||||||
|
gbitmap_destroy(s_c_icon);
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
bitmap_layer_destroy(s_time_fg_layers[i]);
|
bitmap_layer_destroy(s_time_fg_layers[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user