apply_settings cleanup
This commit is contained in:
+28
-56
@@ -58,6 +58,12 @@ static const uint8_t s_bar_height = 8;
|
|||||||
static const uint8_t s_bar_width = 17;
|
static const uint8_t s_bar_width = 17;
|
||||||
static const uint8_t s_bar_spacing = s_bar_height + 1;
|
static const uint8_t s_bar_spacing = s_bar_height + 1;
|
||||||
|
|
||||||
|
// resource ID arrays for digit bitmaps
|
||||||
|
static const uint32_t s_digit_resource_ids[10] = {RESOURCE_ID_0, RESOURCE_ID_1, RESOURCE_ID_2, RESOURCE_ID_3, RESOURCE_ID_4,
|
||||||
|
RESOURCE_ID_5, RESOURCE_ID_6, RESOURCE_ID_7, RESOURCE_ID_8, RESOURCE_ID_9};
|
||||||
|
static const uint32_t s_digit_mini_resource_ids[10] = {RESOURCE_ID_0_M, RESOURCE_ID_1_M, RESOURCE_ID_2_M, RESOURCE_ID_3_M, RESOURCE_ID_4_M,
|
||||||
|
RESOURCE_ID_5_M, RESOURCE_ID_6_M, RESOURCE_ID_7_M, RESOURCE_ID_8_M, RESOURCE_ID_9_M};
|
||||||
|
|
||||||
static void toggle_fuel_warning_state(bool enable_warning, bool force) {
|
static void toggle_fuel_warning_state(bool enable_warning, bool force) {
|
||||||
if (!force && (enable_warning == s_fuel_is_warning)) {
|
if (!force && (enable_warning == s_fuel_is_warning)) {
|
||||||
return;
|
return;
|
||||||
@@ -304,6 +310,15 @@ static void peek_did_change(void *context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void recolor_digit_bitmaps(GBitmap **bitmaps, GColor *applied, GColor new_color) {
|
||||||
|
if (applied->argb == new_color.argb)
|
||||||
|
return;
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
replace_gbitmap_color(*applied, new_color, bitmaps[i], NULL);
|
||||||
|
}
|
||||||
|
*applied = new_color;
|
||||||
|
}
|
||||||
|
|
||||||
static void apply_settings() {
|
static void apply_settings() {
|
||||||
bool force_update_minutes = false;
|
bool force_update_minutes = false;
|
||||||
|
|
||||||
@@ -373,52 +388,28 @@ static void apply_settings() {
|
|||||||
// 1. check if the minute bitmaps are loaded and equal the hours
|
// 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])) {
|
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
|
// 2a. if loaded and unequal, we can just change the color of the loaded bitmaps
|
||||||
if (s_applied_minute.argb != settings.ColorMinutes.argb) {
|
recolor_digit_bitmaps(s_minute_bitmaps, &s_applied_minute, settings.ColorMinutes);
|
||||||
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 {
|
} 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)
|
// 2b. otherwise, load them and set the colors now
|
||||||
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) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
replace_gbitmap_color(s_applied_minute, settings.ColorMinutes, s_minute_bitmaps[i], NULL);
|
s_minute_bitmaps[i] = gbitmap_create_with_resource(s_digit_resource_ids[i]);
|
||||||
}
|
|
||||||
s_applied_minute = settings.ColorMinutes;
|
|
||||||
}
|
}
|
||||||
|
s_applied_minute = GColorWhite;
|
||||||
|
recolor_digit_bitmaps(s_minute_bitmaps, &s_applied_minute, settings.ColorMinutes);
|
||||||
force_update_minutes = true;
|
force_update_minutes = true;
|
||||||
}
|
}
|
||||||
} else {
|
} 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]) {
|
if (s_minute_bitmaps[0] != s_hour_bitmaps[0]) {
|
||||||
// 2. if not, check if they have been loaded
|
|
||||||
if (s_minute_bitmaps[0]) {
|
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) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
gbitmap_destroy(s_minute_bitmaps[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) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
s_minute_bitmaps[i] = s_hour_bitmaps[i];
|
s_minute_bitmaps[i] = s_hour_bitmaps[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// re-sub bt tracking (will update hour/month color; also minute/day if not unique)
|
// re-sub bt tracking (will update hour/month color; also minute/day if not unique)
|
||||||
connection_service_unsubscribe();
|
connection_service_unsubscribe();
|
||||||
if (settings.TrackBTStatus) {
|
if (settings.TrackBTStatus) {
|
||||||
@@ -450,25 +441,13 @@ static void apply_settings() {
|
|||||||
unobstructed_area_service_unsubscribe();
|
unobstructed_area_service_unsubscribe();
|
||||||
if (settings.EnablePeek) {
|
if (settings.EnablePeek) {
|
||||||
if (!s_minute_bitmaps_mini[0]) {
|
if (!s_minute_bitmaps_mini[0]) {
|
||||||
s_minute_bitmaps_mini[0] = gbitmap_create_with_resource(RESOURCE_ID_0_M);
|
for (int i = 0; i < 10; ++i) {
|
||||||
s_minute_bitmaps_mini[1] = gbitmap_create_with_resource(RESOURCE_ID_1_M);
|
s_minute_bitmaps_mini[i] = gbitmap_create_with_resource(s_digit_mini_resource_ids[i]);
|
||||||
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);
|
|
||||||
s_applied_minute_mini = GColorWhite;
|
s_applied_minute_mini = GColorWhite;
|
||||||
}
|
}
|
||||||
//// set bitmap color
|
//// set bitmap color
|
||||||
if (s_applied_minute_mini.argb != settings.ColorMinutes.argb) {
|
recolor_digit_bitmaps(s_minute_bitmaps_mini, &s_applied_minute_mini, settings.ColorMinutes);
|
||||||
for (int i = 0; i < 10; ++i) {
|
|
||||||
replace_gbitmap_color(s_applied_minute_mini, settings.ColorMinutes, s_minute_bitmaps_mini[i], NULL);
|
|
||||||
}
|
|
||||||
s_applied_minute_mini = settings.ColorMinutes;
|
|
||||||
}
|
|
||||||
force_update_minutes = true;
|
force_update_minutes = true;
|
||||||
|
|
||||||
// mg handling
|
// mg handling
|
||||||
@@ -712,16 +691,9 @@ static void init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load required bitmaps (hours and letters)
|
// load required bitmaps (hours and letters)
|
||||||
s_hour_bitmaps[0] = gbitmap_create_with_resource(RESOURCE_ID_0);
|
for (int i = 0; i < 10; ++i) {
|
||||||
s_hour_bitmaps[1] = gbitmap_create_with_resource(RESOURCE_ID_1);
|
s_hour_bitmaps[i] = gbitmap_create_with_resource(s_digit_resource_ids[i]);
|
||||||
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_c_icon = gbitmap_create_with_resource(RESOURCE_ID_C);
|
||||||
s_h_icon = gbitmap_create_with_resource(RESOURCE_ID_H);
|
s_h_icon = gbitmap_create_with_resource(RESOURCE_ID_H);
|
||||||
s_e_icon = gbitmap_create_with_resource(RESOURCE_ID_E);
|
s_e_icon = gbitmap_create_with_resource(RESOURCE_ID_E);
|
||||||
|
|||||||
Reference in New Issue
Block a user