Add graph paper background to alarm window

This commit is contained in:
2026-08-08 00:38:39 -04:00
parent 79701bffcb
commit 6b358c8ead
+20 -3
View File
@@ -22,6 +22,7 @@ static TextLayer *s_countdown_txt_layer;
static TextLayer *s_setter_txt_layer;
static Layer *s_setter_highlight_layer;
//// alarm
static Layer *s_graph_layer;
static TextLayer *s_theta_txt_layer;
static TextLayer *s_parenthesis_txt_layer;
static Layer *s_drop_bg_function_layer;
@@ -365,6 +366,16 @@ static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed)
vibes_short_pulse();
}
static void graph_layer_update_proc(Layer *layer, GContext *ctx) {
GRect bounds = layer_get_bounds(layer);
static const uint8_t s_pixel_gap = PBL_DISPLAY_WIDTH / 20;
graphics_context_set_stroke_color(ctx, GColorElectricBlue);
for (int i = s_pixel_gap; i < PBL_DISPLAY_WIDTH; i += s_pixel_gap) {
graphics_draw_line(ctx, GPoint(0, i), GPoint(bounds.size.w, i)); // horizontal line
graphics_draw_line(ctx, GPoint(i, 0), GPoint(i, bounds.size.h)); // vertical line
}
}
static void drop_layer_update_proc(Layer *layer, GContext *ctx) {
graphics_context_set_fill_color(ctx, GColorWhite);
graphics_fill_rect(ctx, layer_get_bounds(layer), 5, GCornersAll);
@@ -444,6 +455,11 @@ static void alarm_window_load() {
// change highlight color to avoid changing color of bottom bar
s_setter_highlight_color = s_primary_color;
// graph paper bg
s_graph_layer = layer_create(GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
layer_set_update_proc(s_graph_layer, graph_layer_update_proc);
layer_add_child(window_layer, s_graph_layer);
// top&bottom bars
add_bar_layers_to_window(window_layer, true);
@@ -511,12 +527,12 @@ static void alarm_window_load() {
layer_add_child(window_layer, s_alarm_highlight_layer);
// triangle
static const uint8_t small_top_bar_height = s_top_bar_grect.size.h / 2;
s_triangle_layer = right_triangle_layer_create(GRect(0, small_top_bar_height, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT - small_top_bar_height - s_bottom_bar_grect.size.h), GColorBlack);
static const uint8_t s_small_top_bar_height = s_top_bar_grect.size.h / 2;
s_triangle_layer = right_triangle_layer_create(GRect(0, s_small_top_bar_height, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT - s_small_top_bar_height - s_bottom_bar_grect.size.h), GColorBlack);
layer_add_child(window_layer, s_triangle_layer->layer);
// triangle measurements text layers
uint16_t bc_y = (PBL_DISPLAY_HEIGHT / 2) - small_top_bar_height;
uint16_t bc_y = (PBL_DISPLAY_HEIGHT / 2) - s_small_top_bar_height;
//// side_a
s_side_a_txt_layer = text_layer_create(GRect(0, s_bottom_bar_grect.origin.y - 26, PBL_DISPLAY_WIDTH, 26));
text_layer_set_background_color(s_side_a_txt_layer, GColorClear);
@@ -669,6 +685,7 @@ static void alarm_window_unload() {
text_layer_destroy(s_theta_txt_layer);
layer_destroy(s_bottom_bar_layer);
layer_destroy(s_top_bar_layer);
layer_destroy(s_graph_layer);
fonts_unload_custom_font(s_font_mansalva_big);
fonts_unload_custom_font(s_font_mansalva_small);
}