From e706692ecbbd966e230aac123c287ce9413189ec Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Fri, 15 Jan 2016 20:00:51 -0500 Subject: [PATCH] Better Pebble Time Round support Completely new way of drawing hour/minute marks, no longer using PDCs. --- appinfo.json | 25 +----- resources/data/hour_marks.pdc | Bin 220 -> 0 bytes resources/data/minute_marks.pdc | Bin 832 -> 0 bytes src/engineering.c | 132 +++++++++++++++++++------------- src/engineering.h | 36 ++++++++- src/pebble-app-js.js | 2 +- 6 files changed, 116 insertions(+), 79 deletions(-) delete mode 100644 resources/data/hour_marks.pdc delete mode 100644 resources/data/minute_marks.pdc diff --git a/appinfo.json b/appinfo.json index 0dfb9a0..9702b6e 100644 --- a/appinfo.json +++ b/appinfo.json @@ -21,28 +21,7 @@ "longName": "Engineering", "projectType": "native", "resources": { - "media": [ - { - "file": "data/minute_marks.pdc", - "name": "MINUTE_MARKS", - "targetPlatforms": [ - "aplite", - "basalt", - "chalk" - ], - "type": "raw" - }, - { - "file": "data/hour_marks.pdc", - "name": "HOUR_MARKS", - "targetPlatforms": [ - "aplite", - "basalt", - "chalk" - ], - "type": "raw" - } - ] + "media": [] }, "sdkVersion": "3", "shortName": "Engineering", @@ -52,7 +31,7 @@ "chalk" ], "uuid": "ff541ca4-a444-4513-879a-35ff9ec48a1b", - "versionLabel": "1.4", + "versionLabel": "1.5", "watchapp": { "watchface": true } diff --git a/resources/data/hour_marks.pdc b/resources/data/hour_marks.pdc deleted file mode 100644 index 567675a82b51e5dce2da3aad1e19c7f54f97de3f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 220 zcmWG=arV5zz`(%BFo9tO0}qgX#SA2v7(5sz0r4zk0bZbhC_+Gkp^HIFaL?r|IA^c(?X!dZ<6;m3yzs-e{=We&3*>ku%e#R#aatq{6nG=gr-3HR zG*~fE*7*`&1}=zF*FAnpl@BU>8>q2FjhKN5MZ)YD@VMoPj)6t?2(oKn!VP1t4TL$; z=Fq@YFY&lC5aJX#F)-tjXMMhDM3G@d`@oabljMA`sK}tAeK3*KSaLoH&m&s~rjqjJ za{p5gDH1n!CaGu1`FFI`OWW-wt9jGqOWF9o-kbDgidy_D2T+3lsKUTSVH z74=eedx>$cLqiiAv88R!K!OKd`DkFk27NXSq%^>!2H-!g#~OF68_4MKX{H9ctg48# sfuTG`u18cJG1sFnkAdqEmq)_&xRXcE^+?Ji<$84F(RDr2^2o^J4?nYI&j0`b diff --git a/src/engineering.c b/src/engineering.c index fcefff8..ec806b2 100644 --- a/src/engineering.c +++ b/src/engineering.c @@ -8,8 +8,6 @@ static TextLayer *s_day_label, *s_num_label; static GPath *s_minute_arrow, *s_hour_arrow; static char s_date_buffer[7], s_temp_buffer[5]; -static GDrawCommandImage *s_command_image_hour_marks; -static GDrawCommandImage *s_command_image_minute_marks; static AppSync s_sync; static uint8_t s_sync_buffer[64]; @@ -88,7 +86,6 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) { if(temperature_t) { snprintf(s_temp_buffer, 5, "%d°", temperature_t->value->int16); APP_LOG(APP_LOG_LEVEL_INFO, s_temp_buffer); - //strcpy(s_temp_buffer, temperature_t->value->cstring); } Tuple *show_numbers_t = dict_find(iter, KEY_SHOW_NUMBERS); @@ -180,30 +177,85 @@ static bool color_minute_marks(GDrawCommand *command, uint32_t index, void *cont return true; } + +static int32_t get_angle_for_hour(int hour) { + // Progress through 12 hours, out of 360 degrees + return (hour * 360) / 12; +} + +static int32_t get_angle_for_minute(int hour) { + // Progress through 60 miunutes, out of 360 degrees + return (hour * 360) / 60; +} + + static void bg_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); - GPoint origin = GPoint((bounds.size.w - 144) / 2, (bounds.size.h - 168) / 2); - - if (s_command_image_hour_marks) { - // Draw it - gdraw_command_list_iterate(gdraw_command_image_get_command_list(s_command_image_hour_marks), color_hour_marks, &ctx); - gdraw_command_image_draw(ctx, s_command_image_hour_marks, origin); + GRect frame = grect_inset(bounds, GEdgeInsets(4 * INSET)); + GRect inner_hour_frame = grect_inset(bounds, GEdgeInsets((4 * INSET) + 8)); + GRect inner_minute_frame = grect_inset(bounds, GEdgeInsets((4 * INSET) + 6)); + + graphics_context_set_stroke_color(ctx, gcolor_hour_marks); + graphics_context_set_stroke_width(ctx, 3); + + // Hours marks + for(int i = 0; i < 12; i++) { + int hour_angle = get_angle_for_hour(i); + GPoint p0 = gpoint_from_polar(frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_angle)); + GPoint p1 = gpoint_from_polar(inner_hour_frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_angle)); + graphics_draw_line(ctx, p0, p1); } - if (s_command_image_minute_marks) { - // Draw it - gdraw_command_list_iterate(gdraw_command_image_get_command_list(s_command_image_minute_marks), color_minute_marks, &ctx); - gdraw_command_image_draw(ctx, s_command_image_minute_marks, origin); + + // Minute Marks + graphics_context_set_stroke_color(ctx, gcolor_minute_marks); + graphics_context_set_stroke_width(ctx, 1); + for(int i = 0; i < 60; i++) { + if (i % 5) { + int minute_angle = get_angle_for_minute(i); + GPoint p0 = gpoint_from_polar(frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(minute_angle)); + GPoint p1 = gpoint_from_polar(inner_minute_frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(minute_angle)); + graphics_draw_line(ctx, p0, p1); + } + } + + // numbers + if (b_show_numbers) { + graphics_context_set_text_color(ctx, gcolor_numbers); + +#ifdef PBL_RECT + graphics_draw_text(ctx, "12", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(63, 18, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); + graphics_draw_text(ctx, "1", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(85, 23, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "2", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(104, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "3", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(112, 68, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "4", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(104, 93, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "5", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(85, 110, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "6", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(62, 118, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); + graphics_draw_text(ctx, "7", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(39, 110, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, "8", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 93, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, "9", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(14, 68, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, "10", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, "11", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(39, 23, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); +#else + graphics_draw_text(ctx, "12", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(80, 10, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); + graphics_draw_text(ctx, "1", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(107, 20, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "2", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(130, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "3", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(140, 74, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "4", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(130, 106, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "5", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(107, 126, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, "6", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(81, 136, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); + graphics_draw_text(ctx, "7", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(53, 124, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, "8", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(29, 106, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, "9", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 74, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, "10", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(28, 42, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); + graphics_draw_text(ctx, "11", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(50, 22, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); +#endif } } static void hands_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); - GPoint origin = GPoint((bounds.size.w - 144) / 2, (bounds.size.h - 168) / 2); int16_t second_hand_length = bounds.size.w / 2 - 5; - if (second_hand_length > 67) { - second_hand_length = 67; - } int16_t second_hand_tail_length = 15; time_t now = time(NULL); @@ -220,33 +272,24 @@ static void hands_update_proc(Layer *layer, GContext *ctx) { .y = (int16_t)(-cos_lookup(second_angle_tail) * (int32_t)second_hand_tail_length / TRIG_MAX_RATIO) + center.y, }; - // numbers - if (b_show_numbers) { - graphics_context_set_text_color(ctx, gcolor_numbers); - graphics_draw_text(ctx, "12", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 63, origin.y + 18, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); - graphics_draw_text(ctx, "1", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 85, origin.y + 23, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); - graphics_draw_text(ctx, "2", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 104, origin.y + 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); - graphics_draw_text(ctx, "3", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 112, origin.y + 68, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); - graphics_draw_text(ctx, "4", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 104, origin.y + 93, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); - graphics_draw_text(ctx, "5", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 85, origin.y + 110, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); - graphics_draw_text(ctx, "6", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 62, origin.y + 118, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); - graphics_draw_text(ctx, "7", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 39, origin.y + 110, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); - graphics_draw_text(ctx, "8", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 20, origin.y + 93, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); - graphics_draw_text(ctx, "9", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 14, origin.y + 68, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); - graphics_draw_text(ctx, "10", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 20, origin.y + 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); - graphics_draw_text(ctx, "11", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(origin.x + 39, origin.y + 23, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); - } - // date if (b_show_date) { int offset = !b_show_numbers * 10; - graphics_draw_text(ctx, s_date_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(origin.x + 80, origin.y + 75, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); +#ifdef PBL_RECT + graphics_draw_text(ctx, s_date_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(80, 75, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); +#else + graphics_draw_text(ctx, s_date_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(104, 78, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); +#endif } // temperature if (b_show_temperature) { int offset = !b_show_numbers * 10; - graphics_draw_text(ctx, s_temp_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(origin.x + 27 - offset, origin.y + 75, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); +#ifdef PBL_RECT + graphics_draw_text(ctx, s_temp_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(27 - offset, 75, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); +#else + graphics_draw_text(ctx, s_temp_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(40 - offset, 78, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); +#endif } // minute hand @@ -267,10 +310,8 @@ static void hands_update_proc(Layer *layer, GContext *ctx) { } // dot in the middle - //graphics_context_set_stroke_color(ctx, GColorDarkCandyAppleRed); graphics_context_set_fill_color(ctx, gcolor_second_hand); graphics_fill_circle(ctx, GPoint(bounds.size.w / 2, bounds.size.h / 2), 4); - //graphics_draw_circle(ctx, GPoint(bounds.size.w / 2, bounds.size.h / 2), 4); } static void date_update_proc(Layer *layer, GContext *ctx) { @@ -295,16 +336,6 @@ static void window_load(Window *window) { window_set_background_color(window, gcolor_background); - // Load the image and check it was succcessful - s_command_image_hour_marks = gdraw_command_image_create_with_resource(RESOURCE_ID_HOUR_MARKS); - if (!s_command_image_hour_marks) { - APP_LOG(APP_LOG_LEVEL_ERROR, "Image is NULL!"); - } - s_command_image_minute_marks = gdraw_command_image_create_with_resource(RESOURCE_ID_MINUTE_MARKS); - if (!s_command_image_minute_marks) { - APP_LOG(APP_LOG_LEVEL_ERROR, "Image is NULL!"); - } - s_date_layer = layer_create(bounds); layer_set_update_proc(s_date_layer, date_update_proc); layer_add_child(window_layer, s_date_layer); @@ -314,7 +345,6 @@ static void window_load(Window *window) { layer_add_child(window_layer, s_hands_layer); load_persisted_values(); - } static void window_unload(Window *window) { @@ -325,10 +355,6 @@ static void window_unload(Window *window) { text_layer_destroy(s_num_label); layer_destroy(s_hands_layer); - - // Destroy the image - gdraw_command_image_destroy(s_command_image_hour_marks); - gdraw_command_image_destroy(s_command_image_minute_marks); } static void init() { diff --git a/src/engineering.h b/src/engineering.h index 9728a3e..014fb9d 100644 --- a/src/engineering.h +++ b/src/engineering.h @@ -14,8 +14,12 @@ #define KEY_COLOR_MINUTE_HAND 10 #define KEY_COLOR_SECOND_HAND 11 +#define INSET PBL_IF_ROUND_ELSE(1, 0) +#define HOURS_RADIUS 3 + char *uppercase(char *str); +#ifdef PBL_RECT static const GPathInfo MINUTE_HAND_POINTS = { 9, (GPoint []) { @@ -30,7 +34,6 @@ static const GPathInfo MINUTE_HAND_POINTS = { { -2, -20 } } }; - static const GPathInfo HOUR_HAND_POINTS = { 9, (GPoint []){ { -2, 0 }, @@ -43,4 +46,33 @@ static const GPathInfo HOUR_HAND_POINTS = { { -4, -15 }, { -2, -15 } } -}; \ No newline at end of file +}; +#else +static const GPathInfo MINUTE_HAND_POINTS = { + 9, + (GPoint []) { + { -2, 0}, + { 2, 0 }, + { 2, -25 }, + { 4, -25 }, + { 4, -75 }, + { 0, -79 }, + { -4, -75 }, + { -4, -25 }, + { -2, -25 } + } +}; +static const GPathInfo HOUR_HAND_POINTS = { + 9, (GPoint []){ + { -2, 0 }, + { 2, 0 }, + { 2, -20 }, + { 4, -20 }, + { 4, -59 }, + { 0, -63 }, + { -4, -59 }, + { -4, -20 }, + { -2, -20 } + } +}; +#endif \ No newline at end of file diff --git a/src/pebble-app-js.js b/src/pebble-app-js.js index 460d7c3..423e43d 100644 --- a/src/pebble-app-js.js +++ b/src/pebble-app-js.js @@ -39,7 +39,7 @@ Pebble.addEventListener('ready',function(e) { ); Pebble.addEventListener('showConfiguration', function() { - var url = 'https://rawgit.com/nguyer/pebble-engineering/621b017f0d31412dd9cca3bc23195a05791251ad/config/index.html'; + var url = 'https://rawgit.com/nguyer/pebble-engineering/1.5/config/index.html'; console.log('Showing configuration page: ' + url); Pebble.openURL(url);