Add alarm box highlighter
This commit is contained in:
+67
-17
@@ -18,7 +18,7 @@ static BitmapLayer *s_clock_bmp_layer;
|
||||
static BitmapLayer *s_check_bmp_layer;
|
||||
static TextLayer *s_countdown_txt_layer;
|
||||
static TextLayer *s_setter_txt_layer;
|
||||
static Layer *s_highlight_layer;
|
||||
static Layer *s_setter_highlight_layer;
|
||||
//// alarm
|
||||
static TextLayer *s_type_txt_layer;
|
||||
static TextLayer *s_theta_txt_layer;
|
||||
@@ -28,6 +28,7 @@ static Layer *s_drop_function_layer;
|
||||
static Layer *s_drop_over_layer;
|
||||
static Layer *s_drop_under_layer;
|
||||
static Layer *s_division_layer;
|
||||
static Layer *s_alarm_highlight_layer;
|
||||
|
||||
// fonts
|
||||
//// setter
|
||||
@@ -43,21 +44,23 @@ static GBitmap *s_clock_bmp;
|
||||
static GBitmap *s_check_bmp;
|
||||
|
||||
// global vars
|
||||
//// setter
|
||||
static GColor s_setter_highlight_color;
|
||||
static uint8_t s_highlight_pos = 0;
|
||||
static struct TheTime s_the_time;
|
||||
|
||||
// constants
|
||||
//// setter
|
||||
static const uint8_t s_edge_bar_height = ((PBL_DISPLAY_HEIGHT / 7) * 2);
|
||||
static const GRect s_top_bar_grect = GRect(0, 0, PBL_DISPLAY_WIDTH, s_edge_bar_height);
|
||||
static const GRect s_bottom_bar_grect = GRect(0, PBL_DISPLAY_HEIGHT - s_edge_bar_height, PBL_DISPLAY_WIDTH, s_edge_bar_height);
|
||||
static const GColor s_primary_color = GColorJaegerGreen;
|
||||
static const GColor s_highlight_color = GColorMediumAquamarine;
|
||||
#define STORAGE_KEY_ALARM_HOUR 0
|
||||
#define STORAGE_KEY_ALARM_MINUTE 1
|
||||
//// alarm
|
||||
static const uint8_t s_drop_height = 22;
|
||||
static const GRect s_drop_type_grect = GRect(PBL_IF_ROUND_ELSE(48, 62), (s_top_bar_grect.size.h / 2) - PBL_IF_ROUND_ELSE(-4, s_drop_height / 2), PBL_DISPLAY_WIDTH - PBL_IF_ROUND_ELSE(96, 70), s_drop_height);
|
||||
static const GRect s_drop_function_grect = GRect(PBL_IF_ROUND_ELSE(55, 45), s_bottom_bar_grect.origin.y + ((s_bottom_bar_grect.size.h / 2) - PBL_IF_ROUND_ELSE(s_drop_height - 1, s_drop_height / 2)), 50, s_drop_height);
|
||||
static const GRect s_drop_over_grect = GRect(s_drop_function_grect.origin.x + 78, s_drop_function_grect.origin.y - 13, s_drop_function_grect.size.w + 1, s_drop_function_grect.size.h);
|
||||
static const GRect s_drop_under_grect = GRect(s_drop_over_grect.origin.x, s_drop_over_grect.origin.y + s_drop_over_grect.size.h + 5, s_drop_function_grect.size.w, s_drop_over_grect.size.h);
|
||||
|
||||
/////////////////////////////////
|
||||
|
||||
@@ -199,7 +202,7 @@ static void setter_select_click_handler(void *recognizer, void *ctx) {
|
||||
} else {
|
||||
s_highlight_pos++;
|
||||
}
|
||||
layer_mark_dirty(s_highlight_layer);
|
||||
layer_mark_dirty(s_setter_highlight_layer);
|
||||
layer_mark_dirty(s_bottom_bar_layer);
|
||||
}
|
||||
|
||||
@@ -209,7 +212,7 @@ static void setter_back_click_handler(void *recognizer, void *ctx) {
|
||||
} else {
|
||||
s_highlight_pos--;
|
||||
}
|
||||
layer_mark_dirty(s_highlight_layer);
|
||||
layer_mark_dirty(s_setter_highlight_layer);
|
||||
layer_mark_dirty(s_bottom_bar_layer);
|
||||
}
|
||||
|
||||
@@ -226,7 +229,7 @@ static void top_bar_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
}
|
||||
|
||||
static void bottom_bar_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
graphics_context_set_fill_color(ctx, (s_highlight_pos == 2 ? s_highlight_color : s_primary_color));
|
||||
graphics_context_set_fill_color(ctx, (s_highlight_pos == 2 ? s_setter_highlight_color : s_primary_color));
|
||||
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
|
||||
}
|
||||
|
||||
@@ -250,11 +253,12 @@ static void highlight_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
fill_area.origin.x = fill_area.size.w;
|
||||
break;
|
||||
}
|
||||
graphics_context_set_fill_color(ctx, s_highlight_color);
|
||||
graphics_context_set_fill_color(ctx, s_setter_highlight_color);
|
||||
graphics_fill_rect(ctx, fill_area, 0, GCornerNone);
|
||||
}
|
||||
|
||||
static void setter_window_load() {
|
||||
s_setter_highlight_color = GColorMediumAquamarine;
|
||||
Layer *window_layer = window_get_root_layer(s_window);
|
||||
|
||||
// top&bottom bars
|
||||
@@ -286,9 +290,9 @@ static void setter_window_load() {
|
||||
update_countdown_display();
|
||||
|
||||
// highlighter
|
||||
s_highlight_layer = layer_create(GRect(0, s_top_bar_grect.size.h, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT - (2 * s_top_bar_grect.size.h)));
|
||||
layer_set_update_proc(s_highlight_layer, highlight_layer_update_proc);
|
||||
layer_add_child(window_layer, s_highlight_layer);
|
||||
s_setter_highlight_layer = layer_create(GRect(0, s_top_bar_grect.size.h, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT - (2 * s_top_bar_grect.size.h)));
|
||||
layer_set_update_proc(s_setter_highlight_layer, highlight_layer_update_proc);
|
||||
layer_add_child(window_layer, s_setter_highlight_layer);
|
||||
|
||||
// setter
|
||||
s_font_lecoish_big = fonts_load_custom_font(resource_get_handle(PBL_IF_ROUND_ELSE(RESOURCE_ID_FONT_LECOISH_MONO_BOLD_60, RESOURCE_ID_FONT_LECOISH_MONO_BOLD_40)));
|
||||
@@ -304,7 +308,7 @@ static void setter_window_load() {
|
||||
|
||||
static void setter_window_unload() {
|
||||
text_layer_destroy(s_setter_txt_layer);
|
||||
layer_destroy(s_highlight_layer);
|
||||
layer_destroy(s_setter_highlight_layer);
|
||||
text_layer_destroy(s_countdown_txt_layer);
|
||||
bitmap_layer_destroy(s_check_bmp_layer);
|
||||
bitmap_layer_destroy(s_clock_bmp_layer);
|
||||
@@ -347,7 +351,14 @@ static void division_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
graphics_draw_line(ctx, GPoint(bounds.origin.x, bounds.origin.y), GPoint(bounds.origin.x + bounds.size.w, bounds.origin.y));
|
||||
}
|
||||
|
||||
static void alarm_highlight_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
graphics_context_set_stroke_color(ctx, GColorRed);
|
||||
graphics_context_set_stroke_width(ctx, 3);
|
||||
graphics_draw_rect(ctx, layer_get_bounds(layer));
|
||||
}
|
||||
|
||||
static void alarm_window_load() {
|
||||
s_setter_highlight_color = s_primary_color;
|
||||
Layer *window_layer = window_get_root_layer(s_window);
|
||||
|
||||
// top&bottom bars
|
||||
@@ -374,22 +385,19 @@ static void alarm_window_load() {
|
||||
|
||||
// drop backgrounds
|
||||
//// type
|
||||
s_drop_type_layer = layer_create(GRect(PBL_IF_ROUND_ELSE(48, 62), (s_top_bar_grect.size.h / 2) - PBL_IF_ROUND_ELSE(-4, s_drop_height / 2), PBL_DISPLAY_WIDTH - PBL_IF_ROUND_ELSE(96, 70), s_drop_height));
|
||||
s_drop_type_layer = layer_create(s_drop_type_grect);
|
||||
layer_set_update_proc(s_drop_type_layer, drop_layer_update_proc);
|
||||
layer_add_child(window_layer, s_drop_type_layer);
|
||||
//// function
|
||||
GRect s_drop_function_grect = GRect(PBL_IF_ROUND_ELSE(55, 45), s_bottom_bar_grect.origin.y + ((s_bottom_bar_grect.size.h / 2) - PBL_IF_ROUND_ELSE(s_drop_height - 1, s_drop_height / 2)), 50, s_drop_height);
|
||||
s_drop_function_layer = layer_create(s_drop_function_grect);
|
||||
layer_set_update_proc(s_drop_function_layer, drop_layer_update_proc);
|
||||
layer_add_child(window_layer, s_drop_function_layer);
|
||||
//// over
|
||||
GRect s_drop_over_grect = GRect(s_drop_function_grect.origin.x + 78, s_drop_function_grect.origin.y - 13, s_drop_function_grect.size.w + 1, s_drop_function_grect.size.h);
|
||||
s_drop_over_layer = layer_create(s_drop_over_grect);
|
||||
layer_set_update_proc(s_drop_over_layer, drop_layer_update_proc);
|
||||
layer_add_child(window_layer, s_drop_over_layer);
|
||||
//// under
|
||||
s_drop_over_grect.origin.y += s_drop_over_grect.size.h + 5;
|
||||
s_drop_under_layer = layer_create(s_drop_over_grect);
|
||||
s_drop_under_layer = layer_create(s_drop_under_grect);
|
||||
layer_set_update_proc(s_drop_under_layer, drop_layer_update_proc);
|
||||
layer_add_child(window_layer, s_drop_under_layer);
|
||||
|
||||
@@ -407,11 +415,17 @@ static void alarm_window_load() {
|
||||
layer_set_update_proc(s_division_layer, division_layer_update_proc);
|
||||
layer_add_child(window_layer, s_division_layer);
|
||||
|
||||
// highlighter
|
||||
s_alarm_highlight_layer = layer_create(s_drop_type_grect);
|
||||
layer_set_update_proc(s_alarm_highlight_layer, alarm_highlight_layer_update_proc);
|
||||
layer_add_child(window_layer, s_alarm_highlight_layer);
|
||||
|
||||
schedule_fallback_alarm();
|
||||
tick_timer_service_subscribe(SECOND_UNIT, alarm_seconds_handler);
|
||||
}
|
||||
|
||||
static void alarm_window_unload() {
|
||||
layer_destroy(s_alarm_highlight_layer);
|
||||
layer_destroy(s_division_layer);
|
||||
text_layer_destroy(s_parenthesis_txt_layer);
|
||||
layer_destroy(s_drop_under_layer);
|
||||
@@ -426,6 +440,40 @@ static void alarm_window_unload() {
|
||||
fonts_unload_custom_font(s_font_mansalva_small);
|
||||
}
|
||||
|
||||
static void set_alarm_highlighter_frame() {
|
||||
switch (s_highlight_pos) {
|
||||
case 0:
|
||||
layer_set_frame(s_alarm_highlight_layer, s_drop_type_grect);
|
||||
break;
|
||||
case 1:
|
||||
layer_set_frame(s_alarm_highlight_layer, s_drop_function_grect);
|
||||
break;
|
||||
case 2:
|
||||
layer_set_frame(s_alarm_highlight_layer, s_drop_over_grect);
|
||||
break;
|
||||
case 3:
|
||||
layer_set_frame(s_alarm_highlight_layer, s_drop_under_grect);
|
||||
}
|
||||
}
|
||||
|
||||
static void alarm_up_click_handler(void *recognizer, void *ctx) {
|
||||
if (s_highlight_pos == 0) {
|
||||
s_highlight_pos = 3;
|
||||
} else {
|
||||
s_highlight_pos--;
|
||||
}
|
||||
set_alarm_highlighter_frame();
|
||||
}
|
||||
|
||||
static void alarm_down_click_handler(void *recognizer, void *ctx) {
|
||||
if (s_highlight_pos == 3) {
|
||||
s_highlight_pos = 0;
|
||||
} else {
|
||||
s_highlight_pos++;
|
||||
}
|
||||
set_alarm_highlighter_frame();
|
||||
}
|
||||
|
||||
// DEBUG: logic will eventually be mapped to when triangle is solved
|
||||
static void alarm_select_click_handler(void *recognizer, void *ctx) {
|
||||
wakeup_cancel_all();
|
||||
@@ -446,6 +494,8 @@ static void alarm_select_click_handler(void *recognizer, void *ctx) {
|
||||
|
||||
static void alarm_click_config_provider(void *ctx) {
|
||||
window_single_click_subscribe(BUTTON_ID_BACK, NULL);
|
||||
window_single_click_subscribe(BUTTON_ID_UP, alarm_up_click_handler);
|
||||
window_single_click_subscribe(BUTTON_ID_DOWN, alarm_down_click_handler);
|
||||
window_long_click_subscribe(BUTTON_ID_SELECT, 5000, alarm_select_click_handler, NULL);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user