Add initial temperature bar (not currently functional)
This commit is contained in:
@@ -46,6 +46,20 @@
|
||||
"spaceOptimization": "storage",
|
||||
"type": "bitmap"
|
||||
},
|
||||
{
|
||||
"file": "C.png",
|
||||
"memoryFormat": "Smallest",
|
||||
"name": "C",
|
||||
"spaceOptimization": "storage",
|
||||
"type": "bitmap"
|
||||
},
|
||||
{
|
||||
"file": "H.png",
|
||||
"memoryFormat": "Smallest",
|
||||
"name": "H",
|
||||
"spaceOptimization": "storage",
|
||||
"type": "bitmap"
|
||||
},
|
||||
{
|
||||
"file": "0.png",
|
||||
"memoryFormat": "Smallest",
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 108 B |
Binary file not shown.
|
Before Width: | Height: | Size: 107 B After Width: | Height: | Size: 107 B |
Binary file not shown.
|
After Width: | Height: | Size: 90 B |
+79
-21
@@ -6,10 +6,14 @@
|
||||
static Window *s_main_window;
|
||||
static BitmapLayer *s_time_mg_layers[4];
|
||||
static BitmapLayer *s_time_fg_layers[4];
|
||||
static BitmapLayer *s_c_layer;
|
||||
static BitmapLayer *s_h_layer;
|
||||
static BitmapLayer *s_e_layer;
|
||||
static BitmapLayer *s_f_layer;
|
||||
static Layer *s_batt_mg_layer;
|
||||
static Layer *s_batt_layer;
|
||||
static Layer *s_temp_mg_layer;
|
||||
static Layer *s_temp_layer;
|
||||
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;
|
||||
#if PBL_DISPLAY_HEIGHT == 260
|
||||
@@ -19,6 +23,7 @@ static const GRect s_time_grects[4] = {GRect(s_x_l, -22, 69, 110), GRect(s_x_r,
|
||||
#else
|
||||
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)};
|
||||
#endif
|
||||
static const uint8_t s_temp_guage_x_pos = 6;
|
||||
static const uint16_t s_fuel_guage_x_pos = PBL_DISPLAY_WIDTH - 23;
|
||||
|
||||
// persist statics&defines
|
||||
@@ -32,6 +37,8 @@ static GColor8 s_fg_color;
|
||||
|
||||
// bitmaps
|
||||
static GBitmap *s_font_bitmaps[10];
|
||||
static GBitmap *s_c_icon;
|
||||
static GBitmap *s_h_icon;
|
||||
static GBitmap *s_e_icon;
|
||||
static GBitmap *s_f_icon;
|
||||
|
||||
@@ -43,7 +50,14 @@ static const uint8_t s_bar_height = 8;
|
||||
static const uint8_t s_bar_width = 17;
|
||||
static const uint8_t s_bar_spacing = s_bar_height + 1;
|
||||
|
||||
static void batt_update_proc(Layer *layer, GContext *ctx) {
|
||||
static void batt_callback(BatteryChargeState state) {
|
||||
s_batt_level = state.charge_percent;
|
||||
layer_mark_dirty(s_fuel_layer);
|
||||
layer_mark_dirty(s_temp_layer); // TODO temporary!!
|
||||
}
|
||||
|
||||
// TODO use temperature (for now it updates with battery usage)
|
||||
static void temp_update_proc(Layer *layer, GContext *ctx) {
|
||||
graphics_context_set_fill_color(ctx, GColorWhite);
|
||||
const uint8_t bar_count = s_batt_level / 5;
|
||||
uint16_t bar_bottom_pos = 195;
|
||||
@@ -54,21 +68,43 @@ static void batt_update_proc(Layer *layer, GContext *ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
static void batt_callback(BatteryChargeState state) {
|
||||
s_batt_level = state.charge_percent;
|
||||
layer_mark_dirty(s_batt_layer);
|
||||
static void fuel_update_proc(Layer *layer, GContext *ctx) {
|
||||
graphics_context_set_fill_color(ctx, GColorWhite);
|
||||
const uint8_t bar_count = s_batt_level / 5;
|
||||
uint16_t bar_bottom_pos = 195;
|
||||
|
||||
for (uint8_t i = 0; i < bar_count; ++i) {
|
||||
graphics_fill_rect(ctx, GRect(0, bar_bottom_pos, s_bar_width, s_bar_height), 0, GCornerNone);
|
||||
bar_bottom_pos -= s_bar_spacing;
|
||||
}
|
||||
}
|
||||
|
||||
static void batt_mg_update_proc(Layer *layer, GContext *ctx) {
|
||||
static void temp_fuel_mg_update_proc_helper(Layer *layer, GContext *ctx, bool isFuel) {
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
graphics_context_set_fill_color(ctx, s_mg_color);
|
||||
graphics_fill_rect(ctx, bounds, 0, GCornerNone);
|
||||
if (isFuel) {
|
||||
graphics_context_set_stroke_color(ctx, GColorRed);
|
||||
const uint16_t red_y = bounds.origin.y + 183;
|
||||
graphics_draw_line(ctx, GPoint(bounds.origin.x + 1, red_y), GPoint(bounds.origin.x + s_bar_width, red_y));
|
||||
} else {
|
||||
graphics_context_set_stroke_color(ctx, GColorDukeBlue);
|
||||
const uint16_t blue_y = bounds.origin.y + 1;
|
||||
graphics_draw_line(ctx, GPoint(bounds.origin.x + 1, blue_y), GPoint(bounds.origin.x + s_bar_width, blue_y));
|
||||
}
|
||||
const uint16_t bottom_color_y = bounds.origin.y + 183;
|
||||
graphics_draw_line(ctx, GPoint(bounds.origin.x + 1, bottom_color_y), GPoint(bounds.origin.x + s_bar_width, bottom_color_y));
|
||||
if (isFuel) {
|
||||
graphics_context_set_stroke_color(ctx, GColorDukeBlue);
|
||||
} else {
|
||||
graphics_context_set_stroke_color(ctx, GColorRed);
|
||||
}
|
||||
const uint16_t top_color_y = bounds.origin.y + 1;
|
||||
graphics_draw_line(ctx, GPoint(bounds.origin.x + 1, top_color_y), GPoint(bounds.origin.x + s_bar_width, top_color_y));
|
||||
}
|
||||
|
||||
static void temp_mg_update_proc(Layer *layer, GContext *ctx) {
|
||||
temp_fuel_mg_update_proc_helper(layer, ctx, false);
|
||||
}
|
||||
|
||||
static void fuel_mg_update_proc(Layer *layer, GContext *ctx) {
|
||||
temp_fuel_mg_update_proc_helper(layer, ctx, true);
|
||||
}
|
||||
|
||||
static void main_window_load() {
|
||||
@@ -86,8 +122,10 @@ static void main_window_load() {
|
||||
window_set_background_color(s_main_window, GColorBlue);
|
||||
}
|
||||
|
||||
s_batt_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_batt_mg_layer, batt_mg_update_proc);
|
||||
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);
|
||||
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);
|
||||
|
||||
if (persist_read_bool(storage_key_show_time_mg)) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
@@ -97,10 +135,16 @@ static void main_window_load() {
|
||||
}
|
||||
}
|
||||
|
||||
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_e_layer = bitmap_layer_create(GRect(s_fuel_guage_x_pos, PBL_DISPLAY_HEIGHT - 18, 17, 15));
|
||||
s_f_layer = bitmap_layer_create(GRect(s_fuel_guage_x_pos, 4, 17, 13));
|
||||
s_f_layer = bitmap_layer_create(GRect(s_fuel_guage_x_pos, 3, 17, 14));
|
||||
bitmap_layer_set_bitmap(s_c_layer, s_c_icon);
|
||||
bitmap_layer_set_bitmap(s_h_layer, s_h_icon);
|
||||
bitmap_layer_set_bitmap(s_e_layer, s_e_icon);
|
||||
bitmap_layer_set_bitmap(s_f_layer, s_f_icon);
|
||||
bitmap_layer_set_compositing_mode(s_c_layer, GCompOpSet);
|
||||
bitmap_layer_set_compositing_mode(s_h_layer, GCompOpSet);
|
||||
bitmap_layer_set_compositing_mode(s_e_layer, GCompOpSet);
|
||||
bitmap_layer_set_compositing_mode(s_f_layer, GCompOpSet);
|
||||
|
||||
@@ -108,26 +152,35 @@ static void main_window_load() {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
replace_gbitmap_color(GColorWhite, s_fg_color, s_font_bitmaps[i], NULL);
|
||||
}
|
||||
replace_gbitmap_color(GColorWhite, s_fg_color, s_c_icon, NULL);
|
||||
replace_gbitmap_color(GColorWhite, s_fg_color, s_h_icon, NULL);
|
||||
replace_gbitmap_color(GColorWhite, s_fg_color, s_e_icon, NULL);
|
||||
replace_gbitmap_color(GColorWhite, s_fg_color, s_e_icon, NULL);
|
||||
replace_gbitmap_color(GColorWhite, s_fg_color, s_f_icon, NULL);
|
||||
}
|
||||
|
||||
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_c_layer));
|
||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_h_layer));
|
||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_e_layer));
|
||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_f_layer));
|
||||
layer_add_child(window_layer, s_batt_mg_layer);
|
||||
layer_add_child(window_layer, s_batt_layer);
|
||||
layer_add_child(window_layer, s_temp_mg_layer);
|
||||
layer_add_child(window_layer, s_temp_layer);
|
||||
layer_add_child(window_layer, s_fuel_mg_layer);
|
||||
layer_add_child(window_layer, s_fuel_layer);
|
||||
}
|
||||
|
||||
static void main_window_unload() {
|
||||
layer_destroy(s_batt_mg_layer);
|
||||
layer_destroy(s_fuel_mg_layer);
|
||||
bitmap_layer_destroy(s_f_layer);
|
||||
bitmap_layer_destroy(s_e_layer);
|
||||
bitmap_layer_destroy(s_h_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,6 +247,8 @@ static void init() {
|
||||
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_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);
|
||||
|
||||
@@ -201,8 +256,10 @@ static void init() {
|
||||
s_time_fg_layers[i] = bitmap_layer_create(s_time_grects[i]);
|
||||
bitmap_layer_set_compositing_mode(s_time_fg_layers[i], GCompOpSet);
|
||||
}
|
||||
s_batt_layer = layer_create(GRect(s_fuel_guage_x_pos, 0, s_bar_width, PBL_DISPLAY_HEIGHT));
|
||||
layer_set_update_proc(s_batt_layer, batt_update_proc);
|
||||
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);
|
||||
s_fuel_layer = layer_create(GRect(s_fuel_guage_x_pos, 0, s_bar_width, PBL_DISPLAY_HEIGHT));
|
||||
layer_set_update_proc(s_fuel_layer, fuel_update_proc);
|
||||
|
||||
update_minute_1();
|
||||
batt_callback(battery_state_service_peek());
|
||||
@@ -214,7 +271,8 @@ static void init() {
|
||||
static void deinit() {
|
||||
battery_state_service_unsubscribe();
|
||||
tick_timer_service_unsubscribe();
|
||||
layer_destroy(s_batt_layer);
|
||||
layer_destroy(s_fuel_layer);
|
||||
layer_destroy(s_temp_layer);
|
||||
gbitmap_destroy(s_f_icon);
|
||||
gbitmap_destroy(s_e_icon);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user