diff --git a/appinfo.json b/appinfo.json index 14adbca..a844f34 100644 --- a/appinfo.json +++ b/appinfo.json @@ -23,13 +23,13 @@ ] }, "sdkVersion": "3", - "shortName": "Natch", + "shortName": "Twatch", "targetPlatforms": [ "aplite", "basalt", "chalk" ], - "uuid": "901f4c61-772a-4591-8fbc-2f807e3fd6ba", + "uuid": "e0b60de0-c43e-4dcd-817b-b60c1be26cb5", "versionLabel": "1.0", "watchapp": { "watchface": true diff --git a/src/main.c b/src/main.c index 916f687..5017fba 100644 --- a/src/main.c +++ b/src/main.c @@ -5,8 +5,10 @@ static Window *window; static Layer *s_simple_bg_layer, *s_date_layer, *s_hands_layer; static TextLayer *s_bt_label, *s_day_label, *s_mon_label; -static GPath *s_tick_paths[NUM_CLOCK_TICKS]; -static GPath *s_minute_arrow, *s_hour_arrow; + + +static GPath *s_tic_path; +static GPath *s_second_arrow, *s_minute_arrow, *s_hour_arrow; static char s_mon_buffer[4], s_day_buffer[6]; static TextLayer *s_hour_label[4]; static char s_hour[4][4]; @@ -18,11 +20,24 @@ bool seconds = true; bool bt_connected = true; static void bg_update_proc(Layer *layer, GContext *ctx) { + // Fill background graphics_context_set_fill_color(ctx, bg); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); + + // Draw tics graphics_context_set_fill_color(ctx, fg); - for (int i = 0; i < NUM_CLOCK_TICKS; ++i) { - gpath_draw_filled(ctx, s_tick_paths[i]); + for (int i = 0; i < 12; i += 1) { + switch (i) { + case 0: + case 3: + case 6: + case 9: + break; + default: + gpath_rotate_to(s_tic_path, TRIG_MAX_ANGLE * i / 12); + gpath_draw_filled(ctx, s_tic_path); + break; + } } // Draw numbers @@ -52,21 +67,10 @@ static void hands_update_proc(Layer *layer, GContext *ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); - if (seconds) { - int32_t angle = TRIG_MAX_ANGLE * t->tm_sec / 60; - GPoint inside = gpoint_from_polar(bounds, GOvalScaleModeFitCircle, angle); - GPoint outside = gpoint_from_polar(bounds, GOvalScaleModeFillCircle, angle); - int16_t second_hand_length = bounds.size.w / 2; - - // second hand - graphics_context_set_stroke_color(ctx, fg); - graphics_draw_line(ctx, inside, outside); - } - - // minute/hour hand graphics_context_set_fill_color(ctx, fg); graphics_context_set_stroke_color(ctx, bg); + // minute/hour hand gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60); gpath_draw_filled(ctx, s_minute_arrow); gpath_draw_outline(ctx, s_minute_arrow); @@ -75,6 +79,16 @@ static void hands_update_proc(Layer *layer, GContext *ctx) { gpath_draw_filled(ctx, s_hour_arrow); gpath_draw_outline(ctx, s_hour_arrow); + if (seconds) { + // second hand +#ifdef PBL_COLOR + graphics_context_set_fill_color(ctx, GColorJaegerGreen); +#endif + gpath_rotate_to(s_second_arrow, TRIG_MAX_ANGLE * t->tm_sec / 60); + gpath_draw_filled(ctx, s_second_arrow); + //gpath_draw_outline(ctx, s_second_arrow); + } + // dot in the middle graphics_context_set_fill_color(ctx, fg); graphics_fill_circle(ctx, GPoint(bounds.size.w / 2, bounds.size.h / 2), 2); @@ -113,6 +127,9 @@ static void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) { static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); + + int xmax = bounds.size.w; + int ymax = bounds.size.h; s_simple_bg_layer = layer_create(bounds); layer_set_update_proc(s_simple_bg_layer, bg_update_proc); @@ -124,19 +141,19 @@ static void window_load(Window *window) { switch (i) { case 0: - x = 140 - (NUM_WIDTH); y = 80 - (NUM_HEIGHT/2) + BASELINE_OFFSET; + x = (xmax - NUM_WIDTH) - 2; y = (ymax - NUM_HEIGHT) / 2 + BASELINE_OFFSET; align = GTextAlignmentRight; break; case 1: - x = 72 - (NUM_WIDTH/2); y = 122 + BASELINE_OFFSET; + x = (xmax - NUM_WIDTH) / 2; y = ymax + BASELINE_OFFSET - NUM_HEIGHT; align = GTextAlignmentCenter; break; case 2: - x = 4; y = 80 - (NUM_HEIGHT/2) + BASELINE_OFFSET; + x = 2; y = (ymax - NUM_HEIGHT) / 2 + BASELINE_OFFSET; align = GTextAlignmentLeft; break; case 3: - x = 72 - (NUM_WIDTH/2); y = BASELINE_OFFSET; + x = (xmax - NUM_WIDTH) / 2; y = BASELINE_OFFSET; align = GTextAlignmentCenter; break; } @@ -154,7 +171,12 @@ static void window_load(Window *window) { layer_set_update_proc(s_date_layer, date_update_proc); layer_add_child(window_layer, s_date_layer); - s_bt_label = text_layer_create(GRect(15, 90, 52, 52)); + // Missing phone +#ifdef PBL_RECT + s_bt_label = text_layer_create(GRect(20, 95, 52, 52)); +#else + s_bt_label = text_layer_create(GRect(xmax/2 - 44, ymax/2 + 5, 52, 52)); +#endif text_layer_set_text_alignment(s_bt_label, GTextAlignmentLeft); text_layer_set_text(s_bt_label, ""); text_layer_set_background_color(s_bt_label, GColorClear); @@ -162,20 +184,32 @@ static void window_load(Window *window) { text_layer_set_font(s_bt_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYMBOLS_52))); layer_add_child(s_date_layer, text_layer_get_layer(s_bt_label)); - s_mon_label = text_layer_create(GRect(114, 140, 27, 24)); + // Month +#ifdef PBL_RECT + s_mon_label = text_layer_create(GRect(116, 145, 27, 18)); + text_layer_set_font(s_mon_label, fonts_get_system_font(FONT_KEY_GOTHIC_18)); +#else + s_mon_label = text_layer_create(GRect(124, 140, 27, 14)); + text_layer_set_font(s_mon_label, fonts_get_system_font(FONT_KEY_GOTHIC_14)); +#endif text_layer_set_text_alignment(s_mon_label, GTextAlignmentRight); - text_layer_set_text(s_mon_label, s_day_buffer); - text_layer_set_background_color(s_mon_label, bg); + text_layer_set_text(s_mon_label, s_mon_buffer); + text_layer_set_background_color(s_mon_label, GColorClear); text_layer_set_text_color(s_mon_label, fg); - text_layer_set_font(s_mon_label, fonts_get_system_font(FONT_KEY_GOTHIC_24)); layer_add_child(s_date_layer, text_layer_get_layer(s_mon_label)); + // Day +#ifdef PBL_RECT s_day_label = text_layer_create(GRect(121, 122, 20, 24)); + text_layer_set_font(s_day_label, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); +#else + s_day_label = text_layer_create(GRect(135, 124, 20, 18)); + text_layer_set_font(s_day_label, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); +#endif text_layer_set_text_alignment(s_day_label, GTextAlignmentRight); text_layer_set_text(s_day_label, s_day_buffer); text_layer_set_background_color(s_day_label, GColorClear); text_layer_set_text_color(s_day_label, fg); - text_layer_set_font(s_day_label, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(s_date_layer, text_layer_get_layer(s_day_label)); s_hands_layer = layer_create(bounds); @@ -214,20 +248,20 @@ static void init() { s_day_buffer[0] = '\0'; s_mon_buffer[0] = '\0'; - // init hand paths + // init paths + s_tic_path = gpath_create(&TIC_POINTS); + s_second_arrow = gpath_create(&SECOND_HAND_POINTS); s_minute_arrow = gpath_create(&MINUTE_HAND_POINTS); s_hour_arrow = gpath_create(&HOUR_HAND_POINTS); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); GPoint center = grect_center_point(&bounds); + gpath_move_to(s_tic_path, center); + gpath_move_to(s_second_arrow, center); gpath_move_to(s_minute_arrow, center); gpath_move_to(s_hour_arrow, center); - for (int i = 0; i < NUM_CLOCK_TICKS; ++i) { - s_tick_paths[i] = gpath_create(&ANALOG_BG_POINTS[i]); - } - bluetooth_connection_service_subscribe(bt_handler); bt_connected = bluetooth_connection_service_peek(); @@ -239,13 +273,11 @@ static void init() { } static void deinit() { + gpath_destroy(s_tic_path); + gpath_destroy(s_second_arrow); gpath_destroy(s_minute_arrow); gpath_destroy(s_hour_arrow); - for (int i = 0; i < NUM_CLOCK_TICKS; ++i) { - gpath_destroy(s_tick_paths[i]); - } - tick_timer_service_unsubscribe(); window_destroy(window); } diff --git a/src/twatch.h b/src/twatch.h index 3b1ae7a..dfedbf1 100644 --- a/src/twatch.h +++ b/src/twatch.h @@ -1,66 +1,23 @@ #include #pragma once -#define NUM_CLOCK_TICKS 8 - -static const struct GPathInfo ANALOG_BG_POINTS[] = { - { 4, (GPoint []){ - {112, 10}, - {114, 12}, - {108, 23}, - {106, 21} - } - }, - { 4, (GPoint []){ - {132, 47}, - {144, 40}, - {144, 44}, - {135, 49} - } - }, - { 4, (GPoint []){ - {135, 118}, - {144, 123}, - {144, 126}, - {132, 120} - } - }, - { 4, (GPoint []){ - {108, 144}, - {114, 154}, - {112, 157}, - {106, 147} - } - }, - { 4, (GPoint []){ - {32, 10}, - {30, 12}, - {36, 23}, - {38, 21} - } - }, - { 4, (GPoint []){ - {12, 47}, - {-1, 40}, - {-1, 44}, - {9, 49} - } - }, - { 4, (GPoint []){ - {9, 118}, - {-1, 123}, - {-1, 126}, - {12, 120} - } - }, - { 4, (GPoint []){ - {36, 144}, - {30, 154}, - {32, 157}, - {38, 147} - } - }, +static const struct GPathInfo TIC_POINTS = { + 4, (GPoint []){ + {-3, -100}, + {3, -100}, + {3, -80}, + {-3, -80} + } +}; +static const GPathInfo SECOND_HAND_POINTS = { + 4, + (GPoint []) { + {0, -60}, + {4, -65}, + {0, -70}, + {-4, -65} + } }; static const GPathInfo MINUTE_HAND_POINTS = {