diff --git a/package.json b/package.json index 9080e69..5573c89 100644 --- a/package.json +++ b/package.json @@ -38,12 +38,12 @@ "spaceOptimization": "memory" }, { "type": "font", - "name": "FONT_TORO_38", + "name": "FONT_TORO_36", "file": "font_toro.ttf", "characterRange": "[0-9:]" }, { "type": "font", - "name": "FONT_KONEKO_TORO_28", + "name": "FONT_KONEKO_TORO_24", "file": "font_koneko_toro.ttf", "characterRange": "[0-9/WTFSMedhuriaton]" }] diff --git a/resources/font_koneko_toro.ttf b/resources/font_koneko_toro.ttf index 0c51d0c..f2528a1 100644 Binary files a/resources/font_koneko_toro.ttf and b/resources/font_koneko_toro.ttf differ diff --git a/src/c/bar_layer.c b/src/c/bar_layer.c new file mode 100644 index 0000000..3abf993 --- /dev/null +++ b/src/c/bar_layer.c @@ -0,0 +1,53 @@ +#include "bar_layer.h" + +#include "resources_service.h" + +#define BAR_PAD_W 8 + +static Layer *s_bar_layer; + +static void bar_layer_update_proc(Layer *layer, GContext *ctx) { + GRect window_rect = layer_get_unobstructed_bounds(layer); + + time_t tmp = time(NULL); + struct tm *time = localtime(&tmp); + + static char date_text[6], weekday_text[4]; + GFont font = resources_service_get_custom_font(CustomFontKonekoToro); + + strftime(date_text, sizeof(date_text), "%m/%d", time); + GSize date_text_size = graphics_text_layout_get_content_size( + date_text, font, window_rect, GTextOverflowModeFill, GTextAlignmentLeft); + GRect date_text_rect = GRect(0, 0, date_text_size.w, date_text_size.h); + grect_align(&date_text_rect, &window_rect, GAlignLeft, true); + + strftime(weekday_text, sizeof(weekday_text), "%a", time); + GSize weekday_text_size = graphics_text_layout_get_content_size( + weekday_text, font, window_rect, GTextOverflowModeFill, GTextAlignmentRight); + GRect weekday_text_rect = GRect(0, 0, weekday_text_size.w, weekday_text_size.h); + grect_align(&weekday_text_rect, &window_rect, GAlignRight, true); + + graphics_context_set_text_color(ctx, GColorBlack); + graphics_draw_text(ctx, date_text, font, date_text_rect, GTextOverflowModeFill, + GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, weekday_text, font, weekday_text_rect, GTextOverflowModeFill, + GTextAlignmentRight, NULL); +} + +void bar_layer_init(Window *window) { + Layer *window_layer = window_get_root_layer(window); + GRect window_rect = layer_get_unobstructed_bounds(window_layer); + + s_bar_layer = layer_create(GRect(BAR_PAD_W, 0, window_rect.size.w - (BAR_PAD_W * 2), 28)); + layer_set_update_proc(s_bar_layer, bar_layer_update_proc); + + layer_add_child(window_layer, s_bar_layer); +} + +void bar_layer_tick(void) { + layer_mark_dirty(s_bar_layer); +} + +void bar_layer_deinit(void) { + layer_destroy(s_bar_layer); +} diff --git a/src/c/bar_layer.h b/src/c/bar_layer.h new file mode 100644 index 0000000..ba45645 --- /dev/null +++ b/src/c/bar_layer.h @@ -0,0 +1,10 @@ +#ifndef BAR_LAYER_H_ +#define BAR_LAYER_H_ + +#include + +void bar_layer_init(Window *window); +void bar_layer_tick(void); +void bar_layer_deinit(void); + +#endif diff --git a/src/c/main_window.c b/src/c/main_window.c index 304cc2c..6a65444 100644 --- a/src/c/main_window.c +++ b/src/c/main_window.c @@ -1,4 +1,6 @@ #include "main_window.h" + +#include "bar_layer.h" #include "character_layer.h" #include "clock_layer.h" @@ -7,26 +9,27 @@ static Window *s_main_window; static void main_window_tick(struct tm *time, TimeUnits units) { character_layer_tick(); clock_layer_tick(); + bar_layer_tick(); } static void main_window_load(Window *window) { character_layer_init(s_main_window); clock_layer_init(s_main_window, GPoint(0, 40)); + bar_layer_init(s_main_window); tick_timer_service_subscribe(SECOND_UNIT, main_window_tick); } static void main_window_unload(Window *window) { tick_timer_service_unsubscribe(); clock_layer_deinit(); + bar_layer_deinit(); character_layer_deinit(); } void main_window_init(void) { s_main_window = window_create(); - window_set_window_handlers(s_main_window, (WindowHandlers) { - .load = main_window_load, - .unload = main_window_unload - }); + window_set_window_handlers( + s_main_window, (WindowHandlers){.load = main_window_load, .unload = main_window_unload}); window_stack_push(s_main_window, true); } diff --git a/src/c/resources_service.c b/src/c/resources_service.c index d0c13b8..12ac89c 100644 --- a/src/c/resources_service.c +++ b/src/c/resources_service.c @@ -12,9 +12,9 @@ static ResourcesService *s_resources_service; void resources_service_init(void) { s_resources_service = malloc(sizeof(ResourcesService)); s_resources_service->font_koneko_toro = - fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_KONEKO_TORO_28)); + fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_KONEKO_TORO_24)); s_resources_service->font_toro = - fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TORO_38)); + fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TORO_36)); s_resources_service->character_even = gbitmap_create_with_resource(RESOURCE_ID_CHARACTER_EVEN); s_resources_service->character_odd = gbitmap_create_with_resource(RESOURCE_ID_CHARACTER_ODD); }