static void draw_watchface(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); uint16_t width = bounds.size.w - (2 * PADDING); //this is 120 on basalt uint16_t vert_padding = (bounds.size.h - ((NUM_BARS - 1)*PADDING) - (NUM_BARS*HEIGHT)) / 2; //set the colour graphics_context_set_fill_color(ctx, COLOR_FALLBACK(s_top_bar_color, GColorRed)); int8_t cur_hour = s_hour % 12; if (cur_hour == 0) { cur_hour = 12; } //display the hour bar graphics_fill_rect(ctx, GRect(PADDING,vert_padding,((cur_hour) * width)/12, HEIGHT), 0, 0); //set the colour graphics_context_set_fill_color(ctx, COLOR_FALLBACK(s_middle_bar_color, GColorGreen)); //display the minute bar graphics_fill_rect(ctx, GRect(PADDING,vert_padding+(HEIGHT + PADDING),(s_min * width)/60, HEIGHT), 0, 0); //set the colour graphics_context_set_fill_color(ctx, COLOR_FALLBACK(s_bottom_bar_color, GColorBlue)); //display the second bar graphics_fill_rect(ctx, GRect(PADDING,vert_padding + (2*HEIGHT) + (2 * PADDING),(s_sec * width)/60, HEIGHT), 0, 0); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_icon_layer = bitmap_layer_create(GRect(32, 10, 80, 80)); layer_add_child(window_layer, bitmap_layer_get_layer(s_icon_layer)); s_temperature_layer = text_layer_create(GRect(0, 90, bounds.size.w, 32)); text_layer_set_text_color(s_temperature_layer, COLOR_FALLBACK(GColorBlack, GColorWhite)); text_layer_set_background_color(s_temperature_layer, GColorClear); text_layer_set_font(s_temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text_alignment(s_temperature_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_temperature_layer)); s_city_layer = text_layer_create(GRect(0, 122, bounds.size.w, 32)); text_layer_set_text_color(s_city_layer, COLOR_FALLBACK(GColorBlack, GColorWhite)); text_layer_set_background_color(s_city_layer, GColorClear); text_layer_set_font(s_city_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text_alignment(s_city_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_city_layer)); Tuplet initial_values[] = { TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1), TupletCString(WEATHER_TEMPERATURE_KEY, "1234\u00B0C"), TupletCString(WEATHER_CITY_KEY, "St Pebblesburg"), }; app_sync_init(&s_sync, s_sync_buffer, sizeof(s_sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL); request_weather(); }
static void window_load(Window *window) { s_palette = malloc(sizeof(Palette)); *s_palette = (Palette) { COLOR_FALLBACK(GColorRichBrilliantLavender, GColorWhite), COLOR_FALLBACK(GColorVividViolet, GColorWhite), COLOR_FALLBACK(GColorBlueMoon, GColorWhite) }; s_layer = layer_create(layer_get_bounds(window_get_root_layer(s_window))); layer_add_child(window_get_root_layer(s_window), s_layer); layer_set_update_proc(s_layer, update_display); }
static void initialise_ui(void) { s_window = window_create(); Layer *root_layer = window_get_root_layer(s_window); GRect bounds = layer_get_bounds(root_layer); window_set_background_color(s_window, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack)); IF_2(window_set_fullscreen(s_window, false)); #ifdef PBL_ROUND int dev_layer_left = (bounds.size.w - DEV_LAYER_WIDTH)/2; int dev_layer_top = (bounds.size.h - DEV_LAYER_HEIGHT)/2; #else int dev_layer_left = ((bounds.size.w - DEV_LAYER_WIDTH - ACTION_BAR_WIDTH)/2) + 4; int dev_layer_top = ((bounds.size.h - DEV_LAYER_HEIGHT - 14)/2) + IF_32(14, 0); #endif s_rect_above = GRect(dev_layer_left, -(DEV_LAYER_HEIGHT+2), DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT); s_rect_onscreen = GRect(dev_layer_left, dev_layer_top, DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT); s_rect_below = GRect(dev_layer_left, bounds.size.h+2, DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT); // s_devicecard_layer s_devicecard_layer = devicecard_layer_create(s_rect_onscreen); layer_add_child(root_layer, s_devicecard_layer->layer); // s_layer_spots s_layer_spots = layer_create(PBL_IF_RECT_ELSE(GRect((dev_layer_left/2)-SPOT_RADIUS, dev_layer_top, (SPOT_RADIUS*2)+1 , DEV_LAYER_HEIGHT), bounds)); layer_add_child(root_layer, (Layer *)s_layer_spots); #ifndef PBL_SDK_2 s_status_bar = status_bar_layer_create(); status_bar_layer_set_colors(s_status_bar, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack), GColorWhite); layer_add_child(root_layer, status_bar_layer_get_layer(s_status_bar)); #endif s_res_image_action_up = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_UP); s_res_image_action_set = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_SET); s_res_image_action_down = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_DOWN); // s_actionbar_main s_actionbar_main = action_bar_layer_create(); action_bar_layer_add_to_window(s_actionbar_main, s_window); action_bar_layer_set_background_color(s_actionbar_main, GColorWhite); action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_UP, s_res_image_action_up); action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_SELECT, s_res_image_action_set); action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_DOWN, s_res_image_action_down); #ifdef PBL_RECT layer_set_frame(action_bar_layer_get_layer(s_actionbar_main), GRect(bounds.size.w-20, 0, 20, bounds.size.h)); IF_3(layer_set_bounds(action_bar_layer_get_layer(s_actionbar_main), GRect(-5, 0, 30, bounds.size.h))); #endif layer_add_child(root_layer, (Layer *)s_actionbar_main); }
void battery_layer_update_callback(Layer *layer, GContext *ctx) { // Draw the battery: graphics_context_set_stroke_color(ctx, COLOR_FALLBACK((charge_state.charge_percent > 20 ? GColorIslamicGreen : GColorRed) , GColorWhite)); graphics_draw_rect(ctx, GRect(6, 4, 14, 8)); graphics_draw_line(ctx, GPoint(20, 6), GPoint(20, 9)); charge_state = battery_state_service_peek(); int width = (charge_state.charge_percent * 10 / 100); graphics_context_set_fill_color(ctx, COLOR_FALLBACK((charge_state.charge_percent > 20 ? GColorIslamicGreen : GColorRed), GColorWhite)); graphics_fill_rect(ctx, GRect(8, 6, width, 4), 0, GCornerNone); }
static void window_load(Window *window) { read_settings_from_memory(); GRect bounds = layer_get_bounds(window_get_root_layer(window)); time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(7, 0), bounds.size.w, 55)); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_text_color(time_layer, COLOR_FALLBACK(GColorFromHEX(0x1200ff), GColorBlack)); text_layer_set_text(time_layer, "nnn"); text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); date_layer = text_layer_create(GRect(0, 55, bounds.size.w, 20)); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_text_color(date_layer, COLOR_FALLBACK(GColorFromHEX(0x9b0000), GColorBlack)); text_layer_set_text(date_layer, "mm-dd-yyyy"); text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); line = layer_create(GRect(PBL_IF_ROUND_ELSE(12, 8), 90, PBL_IF_ROUND_ELSE(155, 128), 2)); layer_set_update_proc(line, draw_line); condition_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(5, 0), 105, bounds.size.w/2, 168)); text_layer_set_background_color(condition_layer, GColorClear); text_layer_set_text_color(condition_layer, COLOR_FALLBACK(GColorFromHEX(0x666159), GColorBlack)); text_layer_set_text_alignment(condition_layer, GTextAlignmentCenter); text_layer_set_font(condition_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text(condition_layer, "Loading"); temperature_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(5, 0), 125, bounds.size.w/2, 168)); text_layer_set_text_alignment(temperature_layer, GTextAlignmentCenter); text_layer_set_background_color(temperature_layer, GColorClear); text_layer_set_text_color(temperature_layer, COLOR_FALLBACK(GColorFromHEX(0x666159), GColorBlack)); text_layer_set_font(temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text(temperature_layer, "---"); battery = gbitmap_create_with_resource(BATTERY[0]); battery_layer = bitmap_layer_create(GRect(PBL_IF_ROUND_ELSE(72, 67), 90, bounds.size.w/2, 78)); bitmap_layer_set_compositing_mode(battery_layer, GCompOpSet); bitmap_layer_set_bitmap(battery_layer, battery); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); layer_add_child(window_get_root_layer(window), line); layer_add_child(window_get_root_layer(window), text_layer_get_layer(condition_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(temperature_layer)); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(battery_layer)); update_time(); handle_date(); handle_battery(); }
static void set_colors() { text_layer_set_text(s_cond_layer, s_cond); window_set_background_color(s_main_window, COLOR_FALLBACK(bg, bwbg)); set_all_text_layer(text); for(int i = 1; i <= ppl_total; i++){ if (strcmp(s_ppl[i], "0")==0){ text_layer_set_background_color(sa_name_layer[i], COLOR_FALLBACK(bg, GColorWhite)); text_layer_set_text_color(sa_name_layer[i], text); } else { text_layer_set_background_color(sa_name_layer[i], COLOR_FALLBACK(text, bwbg)); text_layer_set_text_color(sa_name_layer[i], bg); } } }
static void draw_info(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorPictonBlue, GColorBlack)); graphics_fill_rect(ctx, layer_get_bounds(layer), 8, GCornersAll); IF_B(graphics_context_set_stroke_width(ctx, 3)); graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorBlueMoon, GColorWhite)); graphics_draw_round_rect(ctx, layer_get_bounds(layer), 8); graphics_context_set_text_color(ctx, COLOR_FALLBACK(GColorBlack, GColorWhite)); GSize text_size = graphics_text_layout_get_content_size(s_info, s_res_gothic_18_bold, GRect(5, 5, bounds.size.w-10, bounds.size.h-10), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter); graphics_draw_text(ctx, s_info, s_res_gothic_18_bold, GRect(5, ((bounds.size.h-text_size.h)/2)-4, bounds.size.w-10, text_size.h), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); }
void update_window_color() { GColor colors[] = { GColorDarkGray, GColorLightGray, GColorBulgarianRose, GColorDarkCandyAppleRed, GColorOxfordBlue, GColorImperialPurple, GColorWindsorTan, GColorSunsetOrange, GColorVividViolet, GColorVividCerulean, GColorMediumAquamarine, GColorMelon, GColorOrange, GColorChromeYellow, GColorRajah, }; GColor complementary_colors[] = { GColorLightGray, GColorDarkGray, GColorSunsetOrange, GColorMelon, GColorPictonBlue, GColorLavenderIndigo, GColorBrass, GColorRajah, GColorRichBrilliantLavender, GColorBabyBlueEyes, GColorMintGreen, GColorPastelYellow, GColorChromeYellow, GColorOrange, GColorArmyGreen, }; int array_offset = rand() % sizeof(colors); s_background_color = COLOR_FALLBACK(colors[array_offset], GColorWhite); window_set_background_color(s_main_window, s_background_color); APP_LOG(APP_LOG_LEVEL_DEBUG, "setting window color to %d, %d, %d", s_background_color.r, s_background_color.g, s_background_color.b); s_complementary_color = COLOR_FALLBACK(complementary_colors[array_offset], GColorBlack); }
void graph_layer_update_callback(Layer *layer, GContext* ctx) { // Fill the background: graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorYellow, GColorWhite)); graphics_fill_rect(ctx, GRect(0, 0, BOX_WIDTH, BOX_HEIGHT), 2, GCornersAll); // graph graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, s_graph_path_ptr); }
static void init() { s_main_window = window_create(); #ifdef PBL_SDK_2 window_set_fullscreen(s_main_window, true); #endif window_set_background_color(s_main_window, COLOR_FALLBACK(GColorBlue, GColorBlack)); window_set_window_handlers(s_main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload, });
static void mainForegroundUpdateProc(Layer* this_layer, GContext *ctx) { GRect b = layer_get_bounds(this_layer); #ifdef PBL_ROUND b.size.h -= 16; // Because of the time at the top, default position is too low on a round screen #endif // Draw the three lives GPoint lives = GPoint( b.size.w/2 - PIECE_PIXELS, b.size.h - 6); for (int L=0; L<3; ++L) { GColor in; GColor out; if (s_score.lives >= (3 - L)) { if (L == 0) { in = COLOR_FALLBACK(GColorMintGreen, GColorWhite); out = COLOR_FALLBACK(GColorDarkGreen, GColorBlack); } else if (L == 1) { in = COLOR_FALLBACK(GColorRajah, GColorWhite); out = COLOR_FALLBACK(GColorWindsorTan, GColorBlack); } else { in = COLOR_FALLBACK(GColorMelon, GColorWhite); out = COLOR_FALLBACK(GColorDarkCandyAppleRed, GColorBlack); } } else { in = COLOR_FALLBACK(GColorLightGray, GColorBlack); out = COLOR_FALLBACK(GColorDarkGray, GColorBlack); } GPoint p = lives; p.x += PIECE_PIXELS * L; graphics_context_set_stroke_color(ctx, out); graphics_context_set_fill_color(ctx, in); graphics_context_set_stroke_width(ctx, 3); graphics_fill_circle(ctx, p, 3); graphics_draw_circle(ctx, p, 3); // Animation? if (s_spentLifeAnimRadius > 0 && s_score.lives == (3 - L)) { graphics_context_set_stroke_width(ctx, 5); graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(in,out)); graphics_draw_circle(ctx, p, s_spentLifeAnimRadius / SUB_PIXEL ); } } // Draw the game over message if (s_gameOverMessage == true) { static const char txtGame[] = "GAME"; static const char txtOver[] = "OVER"; b.origin.y += 30; draw3DText(ctx, b, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD), txtGame, 1, GTextAlignmentCenter, true, GColorWhite, GColorBlack); b.origin.y += 40; draw3DText(ctx, b, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD), txtOver, 1, GTextAlignmentCenter, true, GColorWhite, GColorBlack); } }
static void set_all_text_layer(GColor color) { text_layer_set_text_color(s_time_layer, COLOR_FALLBACK(color, GColorWhite)); text_layer_set_text_color(s_date_layer, COLOR_FALLBACK(color, GColorWhite)); text_layer_set_text_color(s_temp_layer, COLOR_FALLBACK(color, GColorWhite)); text_layer_set_text_color(s_cond_layer, COLOR_FALLBACK(color, GColorWhite)); text_layer_set_text_color(s_hilo_layer, COLOR_FALLBACK(color, GColorWhite)); text_layer_set_text_color(s_batt_layer, COLOR_FALLBACK(color, GColorWhite)); }
static void draw_bat(Layer *this_layer, GContext *ctx, int y) { GRect bounds = layer_get_bounds(this_layer); BatteryChargeState bat = battery_state_service_peek(); int16_t width = bounds.size.w; int16_t offset = bounds.size.w/2 - (100 - bat.charge_percent)*width/100; // APP_LOG(APP_LOG_LEVEL_INFO, "o: %d y: %d w: %d", offset, y, width); int g = 50; // 100-50 int ye = 25; // 50-25 int r = 25; // 25-0 #ifdef PBL_COLOR int height = 8; #else int height = 4; #endif GRect green = GRect(offset, y, width*g/100, height); GRect yellow = GRect(green.origin.x+green.size.w, y, width*ye/100, height); #ifndef PBL_COLOR height /= 2; #endif GRect red = GRect(yellow.origin.x+yellow.size.w, y, width*r/100, height); graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorGreen, GColorWhite)); graphics_fill_rect(ctx, green, 0, GCornerNone); graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorYellow, GColorLightGray)); graphics_fill_rect(ctx, yellow, 0, GCornerNone); graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorRed, GColorDarkGray)); graphics_fill_rect(ctx, red, 0, GCornerNone); }
static void init() { // Create main Window element and assign to pointer s_main_window = window_create(); #ifdef PBL_SDK_2 window_set_fullscreen(s_main_window, true); #endif window_set_background_color(s_main_window, COLOR_FALLBACK(GColorBlue, GColorBlack)); // Set handlers to manage the elements inside the Window window_set_window_handlers(s_main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload });
static void draw_header_callback(GContext *ctx, const Layer *cell_layer, uint16_t section_index, void *callback_context) { GRect bounds = layer_get_bounds(cell_layer); graphics_context_set_text_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorLightGray, GColorBlack)); int lowerY = bounds.origin.y + bounds.size.h - 1; graphics_draw_line(ctx, GPoint(0, bounds.origin.y), GPoint(bounds.size.w, bounds.origin.y)); graphics_draw_line(ctx, GPoint(0, lowerY), GPoint(bounds.size.w, lowerY)); graphics_draw_text(ctx, stationName, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(0, -2, bounds.size.w, 18), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); }
static void init() { s_main_window = window_create(); WindowHandlers handlers = { .load = main_window_load, .unload = main_window_unload }; window_set_window_handlers(s_main_window, handlers); fg_color = COLOR_FALLBACK(GColorRed, GColorBlack); bg_color = GColorWhite; #ifdef PBL_SDK_3 inverter_layer_compat_set_colors(bg_color, fg_color); #endif tick_timer_service_subscribe(SECOND_UNIT, tick_handler); window_stack_push(s_main_window, true); }
static void initialise_ui(void) { s_window = window_create(); Layer *root_layer = window_get_root_layer(s_window); GRect bounds = layer_get_bounds(root_layer); window_set_background_color(s_window, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack)); IF_2(window_set_fullscreen(s_window, true)); s_res_gothic_24_bold = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); // msg_layer msg_layer = text_layer_create(GRect(6, 12, bounds.size.w-12, bounds.size.h-24)); text_layer_set_text(msg_layer, "Sent to Phone. Go to the Draw app Settings in the Pebble phone app"); text_layer_set_text_alignment(msg_layer, GTextAlignmentCenter); text_layer_set_font(msg_layer, s_res_gothic_24_bold); text_layer_set_text_color(msg_layer, GColorWhite); text_layer_set_background_color(msg_layer, GColorClear); layer_add_child(root_layer, (Layer *)msg_layer); #ifdef PBL_ROUND text_layer_enable_screen_text_flow_and_paging(msg_layer, 2); #endif }
// Draw menu section headers static void menu_draw_header_callback(GContext* ctx, const Layer *cell_layer, uint16_t section_index, void *data) { graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorLightGray, GColorWhite)); graphics_context_set_text_color(ctx, GColorBlack); graphics_fill_rect(ctx, layer_get_bounds(cell_layer), 0, GCornerNone); switch (section_index) { case MENU_ALARM_SECTION: menu_cell_basic_header_draw(ctx, cell_layer, NULL); break; case MENU_MISC_SECTION: graphics_draw_text(ctx, "Misc Settings", s_header_font, layer_get_bounds(cell_layer), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); //menu_cell_basic_header_draw(ctx, cell_layer, "Misc Settings"); break; case MENU_SMART_SECTION: graphics_draw_text(ctx, "Smart Alarm", s_header_font, layer_get_bounds(cell_layer), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); //menu_cell_basic_header_draw(ctx, cell_layer, "Smart Alarm"); break; case MENU_DST_SECTION: graphics_draw_text(ctx, "DST Check", s_header_font, layer_get_bounds(cell_layer), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); //menu_cell_basic_header_draw(ctx, cell_layer, "DST Check"); break; } }
static void draw_onoff(Layer *layer, GContext *ctx) { GColor border_color; GColor fill_color; #ifdef PBL_COLOR switch (s_onoff_mode) { case MODE_OFF: border_color = GColorRed; fill_color = GColorMelon; break; case MODE_ON: border_color = GColorJaegerGreen; fill_color = GColorMintGreen; break; case MODE_ACTIVE: border_color = GColorChromeYellow; fill_color = GColorPastelYellow; break; } #else border_color = GColorWhite; fill_color = GColorBlack; #endif draw_box(layer, ctx, border_color, fill_color, COLOR_FALLBACK(GColorBlack, GColorWhite), s_onoff_text); }
static void draw_onoff(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GColor border_color; GColor fill_color; #ifdef PBL_COLOR switch (s_onoff_mode) { case MODE_OFF: border_color = GColorRed; fill_color = GColorMelon; break; case MODE_ON: border_color = GColorJaegerGreen; fill_color = GColorMintGreen; break; case MODE_ACTIVE: border_color = GColorChromeYellow; fill_color = GColorPastelYellow; break; } #else border_color = GColorWhite; fill_color = GColorBlack; #endif graphics_context_set_fill_color(ctx, fill_color); graphics_fill_rect(ctx, layer_get_bounds(layer), 8, GCornersAll); IF_B(graphics_context_set_stroke_width(ctx, 3)); graphics_context_set_stroke_color(ctx, border_color); graphics_draw_round_rect(ctx, layer_get_bounds(layer), 8); graphics_context_set_text_color(ctx, COLOR_FALLBACK(GColorBlack, GColorWhite)); GSize text_size = graphics_text_layout_get_content_size(s_onoff_text, s_res_gothic_18_bold, GRect(5, 5, bounds.size.w-10, bounds.size.h-10), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter); graphics_draw_text(ctx, s_onoff_text, s_res_gothic_18_bold, GRect(5, ((bounds.size.h-text_size.h)/2)-4, bounds.size.w-10, text_size.h), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); }
static void handle_battery(BatteryChargeState charge_state) { static char battery_text[] = "100% chrgd"; switch (charge_state.charge_percent) { case 100: text_layer_set_size(s_battery_layer, GSize(144, 10)); break; case 90: text_layer_set_size(s_battery_layer, GSize(130, 10)); break; case 80: text_layer_set_size(s_battery_layer, GSize(116, 10)); break; case 70: text_layer_set_size(s_battery_layer, GSize(102, 10)); break; case 60: text_layer_set_size(s_battery_layer, GSize(88, 10)); break; case 50: text_layer_set_size(s_battery_layer, GSize(72, 10)); break; case 40: text_layer_set_size(s_battery_layer, GSize(58, 10)); break; case 30: text_layer_set_size(s_battery_layer, GSize(44, 10)); break; case 20: //text_layer_set_background_color(s_battery_layer, COLOR_FALLBACK(GColorRed, GColorWhite)); text_layer_set_size(s_battery_layer, GSize(32, 10)); break; case 10: text_layer_set_size(s_battery_layer, GSize(18, 10)); break; case 0: text_layer_set_size(s_battery_layer, GSize(5, 10)); break; } if (charge_state.charge_percent > 50) { text_layer_set_text_color(battery_text_layer, GColorBlack); } else if (charge_state.charge_percent <= 20) { text_layer_set_text_color(battery_text_layer, COLOR_FALLBACK(GColorRed, GColorWhite)); text_layer_set_background_color(s_battery_layer, COLOR_FALLBACK(GColorRed, GColorWhite)); } else { text_layer_set_text_color(battery_text_layer, COLOR_FALLBACK(GColorWhite, GColorWhite)); text_layer_set_background_color(s_battery_layer, COLOR_FALLBACK(GColorYellow, GColorWhite)); } if (charge_state.is_charging) { snprintf(battery_text, sizeof(battery_text),"%d%%chrg", charge_state.charge_percent); } else { snprintf(battery_text, sizeof(battery_text), "%d%%", charge_state.charge_percent); } text_layer_set_text(battery_text_layer, ""); }
static void draw_row_callback(GContext *ctx, Layer *cell_layer, MenuIndex *idx, void *context) { GRect bounds = layer_get_bounds(cell_layer); #if defined(PBL_ROUND) // get info of pixel row in the middle of menu row GBitmap *fb = graphics_capture_frame_buffer(ctx); GPoint sc_coord = layer_convert_point_to_screen(cell_layer, GPoint(0, bounds.size.h/2)); GBitmapDataRowInfo info = gbitmap_get_data_row_info(fb, sc_coord.y); graphics_release_frame_buffer(ctx, fb); // adapt bounds for round displays bounds.origin.x = info.min_x + PADDING; bounds.size.w = info.max_x - info.min_x - PADDING; #endif GRect frame = GRect( bounds.origin.x + ICON_SIZE + 3*PADDING, 0, bounds.size.w - 2*ICON_SIZE - PADDING, bounds.size.h/2 ); // draw direction // expand frame width if countdown on the right is small if(deps_items[idx->row].countdown > 0 && deps_items[idx->row].countdown < 10) { frame.size.w += 10; } graphics_draw_text(ctx, deps_items[idx->row].direction, fonts_get_system_font(FONT_KEY_GOTHIC_14), frame, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); // draw time of scheduled departure plus delay frame.origin.y += 12; graphics_draw_text(ctx, deps_items[idx->row].time, fonts_get_system_font(FONT_KEY_GOTHIC_18), frame, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); // draw time until real time departure frame.origin.x = bounds.origin.x + bounds.size.w - ICON_SIZE - PADDING; frame.origin.y = 0; frame.size.w = ICON_SIZE; frame.size.h = ICON_SIZE; if(deps_items[idx->row].countdown == 0) { // draw icon if departure is imminent char* icon_number; if (strcmp(deps_items[idx->row].icon, "bus") == 0) { icon_number = "1"; } else if (strcmp(deps_items[idx->row].icon, "tram") == 0) { icon_number = "2"; } else if (strcmp(deps_items[idx->row].icon, "train") == 0) { icon_number = "3"; } else if (strcmp(deps_items[idx->row].icon, "boat") == 0) { icon_number = "4"; } else if (strcmp(deps_items[idx->row].icon, "funicular") == 0) { icon_number = "5"; } else if (strcmp(deps_items[idx->row].icon, "cable_car") == 0) { icon_number = "6"; } else { icon_number = ""; } frame.origin.x = bounds.origin.x + bounds.size.w - ICON_SIZE; frame.origin.y = 0; frame.size.w = ICON_SIZE+2; frame.size.h = ICON_SIZE; graphics_draw_text(ctx, icon_number, s_icons, frame, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); } else { static char s_buff[16]; if(deps_items[idx->row].countdown > 60) { strncpy(s_buff, ">1h", 16); } else if(deps_items[idx->row].countdown > 0) { snprintf(s_buff, sizeof(s_buff), "%d'", deps_items[idx->row].countdown); } graphics_draw_text(ctx, s_buff, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), frame, GTextOverflowModeFill, GTextAlignmentRight, NULL); } // draw line icon with colors frame.origin.x = bounds.origin.x + PADDING; frame.origin.y = (bounds.size.h / 2) - (ICON_SIZE / 2); frame.size.w = ICON_SIZE; frame.size.h = ICON_SIZE; GColor color_bg; // correct some coloring switch(deps_items[idx->row].color_bg) { case 9090335 : color_bg = GColorSpringBud; break; case 12703135 : color_bg = GColorInchworm; break; default : color_bg = GColorFromHEX(deps_items[idx->row].color_bg); } GColor color_fg = GColorFromHEX(deps_items[idx->row].color_fg); graphics_context_set_fill_color(ctx, COLOR_FALLBACK(color_bg, GColorClear)); graphics_fill_rect(ctx, frame, 3, GCornersAll); if(!gcolor_equal(color_bg, GColorWhite) || menu_cell_layer_is_highlighted(cell_layer)) { graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorWhite, GColorClear)); } graphics_draw_round_rect(ctx, frame, 3); graphics_context_set_text_color(ctx, COLOR_FALLBACK(color_fg, GColorBlack)); char * name = deps_items[idx->row].name; GFont font; if(strlen(name) == 1) { frame.origin.x += 1; frame.origin.y += 3; /*font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);*/ font = s_helvetic_bold; } else if(strlen(name) == 2) { // correct position if 2nd digit is "1" if (strstr(name+1, "1") != NULL) { frame.origin.x += 2; } frame.origin.y += 3; /*font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);*/ font = s_helvetic_bold; /*if(strlen(name) == 1) { frame.origin.x += 1; }*/ } else if(strlen(name) == 3){ frame.origin.y += 3; font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); } else { frame.origin.y += 6; font = fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD); } graphics_draw_text(ctx, name, font, frame, GTextOverflowModeFill, GTextAlignmentCenter, NULL); }
void setTimeColor(myTimeLayer *mtl, GColor c) { c = COLOR_FALLBACK(c, GColorWhite); text_layer_set_text_color(mtl->big_digits->tl_obj,c); text_layer_set_text_color(mtl->exp_digits->tl_obj,c); }
GColor colour_time_colour() { return COLOR_FALLBACK(GColorBlue, GColorBlack); }
void handle_init(void) { APP_LOG(APP_LOG_LEVEL_ERROR, "In Init * * * * * "); GColor BGCOLOR = COLOR_FALLBACK(GColorDukeBlue, GColorBlack); BGColorHold = BGCOLOR; GColor TEXTCOLOR = COLOR_FALLBACK(GColorWhite, GColorWhite); TextColorHold = TEXTCOLOR; window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, BGCOLOR); fontHelvNewLight20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELV_NEW_LIGHT_20)); fontRobotoBoldSubset40 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_40)); fontRobotoBoldSubset45 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_45)); Layer *window_layer = window_get_root_layer(window); // Register callbacks app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); app_message_register_outbox_failed(outbox_failed_callback); app_message_register_outbox_sent(outbox_sent_callback); // Open AppMessage app_message_open(64, 64); // Date #ifdef PBL_PLATFORM_CHALK text_date_layer = text_layer_create(GRect(1, 94, 180, 28)); #else text_date_layer = text_layer_create(GRect(1, 94, 144, 28)); #endif text_layer_set_text_color(text_date_layer, TEXTCOLOR); text_layer_set_background_color(text_date_layer, BGCOLOR); text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter);; text_layer_set_font(text_date_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); //Persistent Value Date Format: if (persist_exists(MESSAGE_KEY_DATE_FORMAT_KEY)) { persist_read_string(MESSAGE_KEY_DATE_FORMAT_KEY , PersistDateFormat, sizeof(PersistDateFormat)); APP_LOG(APP_LOG_LEVEL_INFO, " Set Date Format to %s - Persistent - 0 = US, 1 = Int'l", PersistDateFormat); } else { APP_LOG(APP_LOG_LEVEL_INFO, " Set Date Format to 0 - Default - US"); strcpy(PersistDateFormat, "0"); //Default } if (strcmp(PersistDateFormat, "0") == 0) { // US strcpy(date_format, "%b %e %Y"); } else { strcpy(date_format, "%e %b %Y"); } //Persistent Value Vib On BTLoss if(persist_exists(MESSAGE_KEY_BT_VIBRATE_KEY)) { PersistBTLoss = persist_read_int(MESSAGE_KEY_BT_VIBRATE_KEY); APP_LOG(APP_LOG_LEVEL_INFO, " Set BT Vibrate To %d - Persistent - 0 = NO Vib, 1 = Vib", PersistBTLoss); } else { PersistBTLoss = 0; // Default APP_LOG(APP_LOG_LEVEL_INFO, " Set BT Vibrate To 0 - Default - No Vibrate"); } //Persistent Value Vib on Low Batt if(persist_exists(MESSAGE_KEY_LOW_BATTERY_KEY)) { PersistLow_Batt = persist_read_int(MESSAGE_KEY_LOW_BATTERY_KEY); APP_LOG(APP_LOG_LEVEL_INFO, " Set Low Batt Vibrate To %d - Persistent - 0 = NO Vib, 1 = Vib", PersistLow_Batt); } else { PersistLow_Batt = 0; // Default APP_LOG(APP_LOG_LEVEL_INFO, " Set Low Batt Vibrate To 0 - Default - No Vibrate"); } // Time of Day #ifdef PBL_PLATFORM_CHALK text_time_layer = text_layer_create(GRect(1, 120, 180, 45)); text_layer_set_font(text_time_layer,fontRobotoBoldSubset40); #else text_time_layer = text_layer_create(GRect(1, 120, 144, 45)); text_layer_set_font(text_time_layer,fontRobotoBoldSubset45); #endif text_layer_set_text_color(text_time_layer, TEXTCOLOR); text_layer_set_background_color(text_time_layer, BGCOLOR); text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); // Dayname #ifdef PBL_PLATFORM_CHALK text_dayname_layer = text_layer_create(GRect(1, 74, 180, 26)); #else text_dayname_layer = text_layer_create(GRect(1, 74, 144, 26)); #endif text_layer_set_text_color(text_dayname_layer, TEXTCOLOR); text_layer_set_text_alignment(text_dayname_layer, GTextAlignmentCenter); text_layer_set_background_color(text_dayname_layer, BGCOLOR); text_layer_set_font(text_dayname_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); layer_add_child(window_layer, text_layer_get_layer(text_dayname_layer)); // Planetary Logo image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PLANETARY_LOGO); #ifdef PBL_PLATFORM_CHALK image_layer = bitmap_layer_create(GRect(1, 29, 180, 49)); #else image_layer = bitmap_layer_create(GRect(1, 29, 144, 49)); #endif bitmap_layer_set_bitmap(image_layer, image); bitmap_layer_set_alignment(image_layer, GAlignCenter); layer_add_child(window_layer, bitmap_layer_get_layer(image_layer)); // Line #ifdef PBL_PLATFORM_CHALK GRect line_frame = GRect(38, 122, 104, 6); #else GRect line_frame = GRect(22, 122, 104, 6); #endif BatteryLineLayer = layer_create(line_frame); layer_set_update_proc(BatteryLineLayer, battery_line_layer_update_callback); layer_add_child(window_layer, BatteryLineLayer); tick_timer_service_subscribe(SECOND_UNIT, handle_tick); //Bluetooth Logo Setup area #ifdef PBL_PLATFORM_CHALK GRect BTArea = GRect(55, 5, 20, 20); #else GRect BTArea = GRect(1, 5, 20, 20); #endif BTLayer = layer_create(BTArea); layer_add_child(window_layer, BTLayer); layer_set_update_proc(BTLayer, BTLine_update_callback); bluetooth_connection_service_subscribe(&handle_bluetooth); //Battery Text #ifdef PBL_PLATFORM_CHALK text_battery_layer = text_layer_create(GRect(80,2,55,28)); #else text_battery_layer = text_layer_create(GRect(85,2,55,28)); #endif text_layer_set_text_color(text_battery_layer, TEXTCOLOR); text_layer_set_background_color(text_battery_layer, BGCOLOR); text_layer_set_font(text_battery_layer, fontHelvNewLight20 ); text_layer_set_text_alignment(text_battery_layer, GTextAlignmentRight); layer_add_child(window_layer, text_layer_get_layer(text_battery_layer)); battery_state_service_subscribe(&handle_battery); bluetooth_connection_service_subscribe(&handle_bluetooth); app_focus_service_subscribe(&handle_appfocus); handle_battery(battery_state_service_peek()); handle_bluetooth(bluetooth_connection_service_peek()); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_tick(current_time, SECOND_UNIT); }
static void canvas_update_proc(Layer *this_layer, GContext *ctx) { GRect bounds = layer_get_bounds(this_layer); uint16_t ms_start = time_ms(NULL, NULL); graphics_context_set_antialiased(ctx, true); if (!isBtConnected) { graphics_context_set_fill_color(ctx, GColorDukeBlue); graphics_fill_rect(ctx, bounds, 0, GCornerNone); } else { graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, bounds, 0, GCornerNone); } graphics_context_set_fill_color(ctx, GColorBlack); uint16_t ms_fill = time_ms(NULL, NULL); graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorRed, GColorWhite)); #if defined(PBL_PLATFORM_APLITE) || defined(PBL_PLATFORM_DIORITE) graphics_context_set_stroke_width(ctx, 1); #else graphics_context_set_stroke_width(ctx, 3); #endif graphics_draw_line(ctx, GPoint(bounds.size.w/2, 0), GPoint(bounds.size.w/2, bounds.size.h)); graphics_context_set_stroke_color(ctx, GColorWhite); int hour_loc = bounds.size.h/2; if(ctick_time->tm_min < 20) draw_hour(this_layer, ctx, -1, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); draw_hour(this_layer, ctx, 0, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); draw_hour(this_layer, ctx, 1, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); if(ctick_time->tm_min > 50) draw_hour(this_layer, ctx, 2, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); graphics_context_set_stroke_width(ctx, 1); uint16_t ms_hour = time_ms(NULL, NULL); draw_minutes(this_layer, ctx, bounds.size.h/2+49/2+5); uint16_t ms_day = time_ms(NULL, NULL); int day_loc = bounds.size.h/2-49/2-12; draw_day(this_layer, ctx, -1, day_loc); draw_day(this_layer, ctx, 0, day_loc); draw_day(this_layer, ctx, 1, day_loc); draw_day(this_layer, ctx, 2, day_loc); draw_day_ticks(this_layer, ctx, bounds.size.h/2-49/2-12); if (temp != INVALID_TEMP) { draw_temp(this_layer, ctx, bounds.size.h/2+75); } getWeather(); getForecast(); uint16_t ms_end = time_ms(NULL, NULL); draw_bat(this_layer, ctx, 0); #if defined(PBL_HEALTH) // Check step data is available HealthServiceAccessibilityMask mask = health_service_metric_accessible(HealthMetricStepCount, time_start_of_today(), cur_time); if(mask & HealthServiceAccessibilityMaskAvailable) { // Data is available! int total_steps = (int)health_service_sum_today(HealthMetricStepCount); draw_step(this_layer, ctx, 22, total_steps); } time_t end_time = time(NULL); time_t start_time = end_time - 600; HealthServiceAccessibilityMask hr = health_service_metric_accessible(HealthMetricHeartRateBPM, start_time, end_time); if (hr & HealthServiceAccessibilityMaskAvailable) { uint32_t bpm = health_service_peek_current_value(HealthMetricHeartRateBPM); APP_LOG(APP_LOG_LEVEL_INFO, "HR: %d", (int)bpm); draw_bpm(this_layer, ctx, 9, bpm); } #endif static int repaints = 0; ++repaints; ms_fill = ms_fill < ms_start ? ms_fill + 1000 : ms_fill; ms_hour = ms_hour < ms_start ? ms_hour + 1000 : ms_hour; ms_day = ms_day < ms_start ? ms_day + 1000 : ms_day; ms_end = ms_end < ms_start ? ms_end + 1000 : ms_end; static uint16_t tt_max = 0; if ((ms_end-ms_start) > tt_max) tt_max = ms_end-ms_start; }
//********************************** Handle Init ************************** void handle_init(void) { if (quiet_time_is_active()) { QuietTimeColor = GColorYellow; } else { QuietTimeColor = GColorRed; } GColor BGCOLOR = COLOR_FALLBACK(GColorDukeBlue, GColorBlack); BGColorHold = BGCOLOR; GColor TEXTCOLOR = COLOR_FALLBACK(GColorWhite, GColorWhite); TextColorHold = TEXTCOLOR; window = window_create(); window_set_background_color(window, BGCOLOR); window_stack_push(window, true /* Animated */); fontHelvNewLight20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELV_NEW_LIGHT_20)); fontRobotoCondensed20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_20)); fontRobotoCondensed21 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)); fontRobotoBoldSubset37 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_37)); fontRobotoBoldSubset49 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)); Layer *window_layer = window_get_root_layer(window); // Register callbacks app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); app_message_register_outbox_failed(outbox_failed_callback); app_message_register_outbox_sent(outbox_sent_callback); // Open AppMessage app_message_open(128, 128); //degrees text_degrees_layer = text_layer_create(GRect(30, 1, 60, 200)); text_layer_set_text_alignment(text_degrees_layer, GTextAlignmentCenter); text_layer_set_text(text_degrees_layer, degreesstr); text_layer_set_font(text_degrees_layer, fontRobotoCondensed20); text_layer_set_background_color(text_degrees_layer, BGCOLOR); text_layer_set_text_color(text_degrees_layer, TEXTCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_degrees_layer)); //degrees inside text_degrees_inside_layer = text_layer_create(GRect(85, 2, 55, 26)); text_layer_set_text_alignment(text_degrees_inside_layer, GTextAlignmentRight); text_layer_set_text(text_degrees_inside_layer, degreesstr); text_layer_set_font(text_degrees_inside_layer, fontRobotoCondensed20); text_layer_set_background_color(text_degrees_inside_layer, BGCOLOR); text_layer_set_text_color(text_degrees_inside_layer, TEXTCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_degrees_inside_layer)); // WA1OUI text_wa1oui_layer = text_layer_create(GRect(1,25, 144, 148)); text_layer_set_text_alignment(text_wa1oui_layer, GTextAlignmentCenter); text_layer_set_text(text_wa1oui_layer, "WA1OUI"); text_layer_set_font(text_wa1oui_layer, fontRobotoBoldSubset37); text_layer_set_text_color(text_wa1oui_layer, TEXTCOLOR); text_layer_set_background_color(text_wa1oui_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_wa1oui_layer)); // Dayname text_dayname_layer = text_layer_create(GRect(1, 65, 35, 168-65)); text_layer_set_text_alignment(text_dayname_layer, GTextAlignmentLeft); text_layer_set_font(text_dayname_layer, fontRobotoCondensed20); text_layer_set_text_color(text_dayname_layer, TEXTCOLOR); text_layer_set_background_color(text_dayname_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_dayname_layer)); // wind text_wind_layer = text_layer_create(GRect(37, 65, 60, 168-65)); text_layer_set_text_alignment(text_wind_layer, GTextAlignmentCenter); text_layer_set_font(text_wind_layer, fontRobotoCondensed20); text_layer_set_text_color(text_wind_layer, TEXTCOLOR); text_layer_set_background_color(text_wind_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_wind_layer)); // Rain text_rain_layer = text_layer_create(GRect(95, 65, 49, 168-65)); text_layer_set_text_alignment(text_rain_layer, GTextAlignmentRight); text_layer_set_font(text_rain_layer, fontRobotoCondensed21); text_layer_set_text_color(text_rain_layer, TEXTCOLOR); text_layer_set_background_color(text_rain_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_rain_layer)); // Date text_date_layer = text_layer_create(GRect(8, 88, 144-8, 168-88)); text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter); text_layer_set_font(text_date_layer, fontRobotoCondensed21); text_layer_set_text_color(text_date_layer, TEXTCOLOR); text_layer_set_background_color(text_date_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); // Time of Day text_time_layer = text_layer_create(GRect(7, 116, 144-7, 168-116)); text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter); text_layer_set_font(text_time_layer, fontRobotoBoldSubset49); text_layer_set_text_color(text_time_layer, TEXTCOLOR); text_layer_set_background_color(text_time_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); // Red Line GRect red_line_frame = GRect(10, 28, 124, 2); RedLineLayer = layer_create(red_line_frame); layer_set_update_proc(RedLineLayer, red_line_layer_update_callback); layer_add_child(window_layer, RedLineLayer); // Battery Line GRect line_frame = GRect(22, 118, 104, 6); LineLayer = layer_create(line_frame); layer_set_update_proc(LineLayer, line_layer_update_callback); layer_add_child(window_layer, LineLayer); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); //Bluetooth Logo Setup area GRect BTArea = GRect(1, 5, 20, 20); BTLayer1 = layer_create(BTArea); layer_add_child(window_layer, BTLayer1); layer_set_update_proc(BTLayer1, BTLine_update_callback); bluetooth_connection_service_subscribe(&handle_bluetooth); handle_bluetooth(bluetooth_connection_service_peek()); handle_battery(battery_state_service_peek()); //app focus service subscribe app_focus_service_subscribe(&handle_appfocus); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_tick(current_time, SECOND_UNIT); }
static void draw_temp(Layer *this_layer, GContext *ctx, int y) { GRect bounds = layer_get_bounds(this_layer); int16_t deg_per_pixel = 0; if (metric) deg_per_pixel = (45*bounds.size.w)/100; else deg_per_pixel = (35*bounds.size.w)/100; int16_t temp_conv = temp; if (!metric) temp_conv = 9*temp/5 + 320; // Round up if ((temp_conv % 10) >= 5) temp_conv += 5; temp_conv /= 10; int16_t deg; int16_t offset = 0-temp_conv*deg_per_pixel/10; int16_t tbase = temp_conv - temp_conv%10; for(deg = tbase-20; deg <= tbase+20; deg += 2) { int th = abs(deg%10); if (th > 1 && th < 9) { int16_t x = deg*deg_per_pixel/10+offset+bounds.size.w/2; if (x > 0 && x < bounds.size.w) graphics_draw_line(ctx, GPoint(x, y), GPoint(x, y+3)); } } for(deg = tbase-20; deg <= tbase+20; deg += 10) { int16_t x = deg*deg_per_pixel/10+offset; GRect frame = GRect(x, y-12, bounds.size.w, 18); static char s_buffer[4]; snprintf(s_buffer, 4, "%d", deg); graphics_draw_text(ctx, s_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), frame, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL ); } if (temp_fore_min != INVALID_TEMP) { int16_t temp_conv_min = temp_fore_min; int16_t temp_conv_max = temp_fore_max; if (!metric) { temp_conv_min = 9*temp_conv_min/5 + 320; temp_conv_max = 9*temp_conv_max/5 + 320; } if ((temp_conv_min % 10) >= 5) temp_conv_min += 5; if ((temp_conv_max % 10) >= 5) temp_conv_max += 5; temp_conv_min /= 10; temp_conv_max /= 10; int16_t tick_min = (temp_conv_min-temp_conv)*deg_per_pixel/10+bounds.size.w/2; int16_t tick_max = (temp_conv_max-temp_conv)*deg_per_pixel/10+bounds.size.w/2; APP_LOG(APP_LOG_LEVEL_INFO, "Temp: %d Ticks at %d and %d", temp_conv, (temp_conv_min-temp_conv), tick_min); graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorCeleste, GColorLightGray)); graphics_fill_rect(ctx, GRect(tick_min-4, y-10, 8, 5), 0, GCornerNone); graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorRed, GColorDarkGray)); graphics_fill_rect(ctx, GRect(tick_max-4, y-10, 8, 5), 0, GCornerNone); } }
static void draw_watchface(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); uint16_t width = bounds.size.w - (2 * PADDING); uint16_t max_height = bounds.size.h - (2 * PADDING); //set the colour graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorRed, GColorWhite)); //display the seconds graphics_fill_rect(ctx, GRect(((s_sec * width)/60) + PADDING, 84 - 10, 2, 19), 0 ,0); //display the hours //left hours------------------------------ int8_t cur_hours = s_hour % 12; if (cur_hours == 0) { cur_hours = 12; } int8_t left_hours = cur_hours; if (cur_hours > 6) { left_hours = 6; } GPathInfo HOURS_LEFT_PATH_INFO = { .num_points = 4, .points = (GPoint []) {{0,0},{(left_hours*width/12) + 2,0},{(left_hours*width/12) + 2,27},{0,27}} }; GPath *s_hours_path_left = gpath_create(&HOURS_LEFT_PATH_INFO); gpath_rotate_to(s_hours_path_left, DEG_TO_TRIGANGLE(-45)); gpath_move_to(s_hours_path_left, GPoint(3,32 + PADDING)); gpath_draw_filled(ctx, s_hours_path_left); //right hours------------------------------ int8_t right_hours = cur_hours; if (cur_hours < 6) { right_hours = 0; } else { right_hours = cur_hours - 6; } GPathInfo HOURS_RIGHT_PATH_INFO = { .num_points = 4, .points = (GPoint []) {{0,0},{(right_hours*width/12) + 2,0},{(right_hours*width/12) + 2,27},{0,27}} }; GPath *s_hours_path_right = gpath_create(&HOURS_RIGHT_PATH_INFO); gpath_rotate_to(s_hours_path_right, DEG_TO_TRIGANGLE(45)); gpath_move_to(s_hours_path_right, GPoint(width - 32 + 8, 1)); gpath_draw_filled(ctx, s_hours_path_right); //display the minutes //left minutes------------------------------ int8_t left_mins = s_min; if (s_min > 30) { left_mins = 30; } GPathInfo MINS_LEFT_PATH_INFO = { .num_points = 4, .points = (GPoint []) {{0,0},{(left_mins*width/60) + 1,0},{(left_mins*width/60) + 1, 27},{0,27}} }; GPath *s_mins_path_left = gpath_create(&MINS_LEFT_PATH_INFO); gpath_rotate_to(s_mins_path_left, DEG_TO_TRIGANGLE(45)); gpath_move_to(s_mins_path_left, GPoint(PADDING + 10, max_height - 32 - 11)); gpath_draw_filled(ctx, s_mins_path_left); //right minutes------------------------------ int8_t right_mins = s_min; if (s_min < 30) { right_mins = 0; } else { right_mins = s_min - 30; } GPathInfo MINS_RIGHT_PATH_INFO = { .num_points = 4, .points = (GPoint []) {{0,0},{(right_mins*width/60) + 1,0},{(right_mins*width/60) + 1, 27},{0,27}} }; GPath *s_mins_path_right = gpath_create(&MINS_RIGHT_PATH_INFO); gpath_rotate_to(s_mins_path_right, DEG_TO_TRIGANGLE(-45)); gpath_move_to(s_mins_path_right, GPoint(width - 32 - PADDING + 1, max_height)); gpath_draw_filled(ctx, s_mins_path_right); } static void set_background_color(int color) { GColor background_color = GColorFromHEX(color); window_set_background_color(window, background_color); } static void inbox_received_handler(DictionaryIterator *iter, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox received handler"); Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR); if (background_color_t) { int background_color = background_color_t->value->int32; if (background_color == 0) { //quick fix so that black colour persists background_color++; } persist_write_int(KEY_BACKGROUND_COLOR, background_color); set_background_color(background_color); APP_LOG(APP_LOG_LEVEL_DEBUG, "background color: %d", background_color); } } static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_layer = layer_create(layer_get_bounds(window_get_root_layer(window))); layer_add_child(window_get_root_layer(window), s_layer); layer_set_update_proc(s_layer, draw_watchface); uint16_t width = bounds.size.w - (2 * PADDING); uint16_t max_height = bounds.size.h - (2 * PADDING); //create the ternary seconds image s_ternary_seconds_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SECONDS_TERNARY_REFLECT); s_ternary_seconds_layer = bitmap_layer_create(GRect(PADDING, 0, width + 1, 168)); bitmap_layer_set_background_color(s_ternary_seconds_layer, GColorClear); bitmap_layer_set_bitmap(s_ternary_seconds_layer, s_ternary_seconds_bitmap); bitmap_layer_set_compositing_mode(s_ternary_seconds_layer, GCompOpSet); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_seconds_layer)); //create the left hours image s_unary_hours_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_6_SINGLE_BLOCKS); s_unary_hours_layer_left = rot_bitmap_layer_create(s_unary_hours_bitmap); rot_bitmap_layer_set_corner_clip_color(s_unary_hours_layer_left, GColorClear); rot_bitmap_set_compositing_mode(s_unary_hours_layer_left, GCompOpSet); rot_bitmap_layer_set_angle(s_unary_hours_layer_left, DEG_TO_TRIGANGLE(-45)); //position the frame GRect r = layer_get_frame((Layer *) s_unary_hours_layer_left); r.origin.x = 2; layer_set_frame((Layer *) s_unary_hours_layer_left, r); layer_add_child(window_get_root_layer(window), (Layer *) s_unary_hours_layer_left); //create the right hours image s_unary_hours_layer_right = rot_bitmap_layer_create(s_unary_hours_bitmap); rot_bitmap_layer_set_corner_clip_color(s_unary_hours_layer_right, GColorClear); rot_bitmap_set_compositing_mode(s_unary_hours_layer_right, GCompOpSet); rot_bitmap_layer_set_angle(s_unary_hours_layer_right, DEG_TO_TRIGANGLE(45)); //position the frame r = layer_get_frame((Layer *) s_unary_hours_layer_right); r.origin.x = width - 32 - PADDING; layer_set_frame((Layer *) s_unary_hours_layer_right, r); layer_add_child(window_get_root_layer(window), (Layer *) s_unary_hours_layer_right); //create the left minutes image s_ternary_minutes_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_30_TERNARY); s_ternary_minutes_layer_left = rot_bitmap_layer_create(s_ternary_minutes_bitmap); rot_bitmap_layer_set_corner_clip_color(s_ternary_minutes_layer_left, GColorClear); rot_bitmap_set_compositing_mode(s_ternary_minutes_layer_left, GCompOpSet); rot_bitmap_layer_set_angle(s_ternary_minutes_layer_left, DEG_TO_TRIGANGLE(45)); //position the frame r = layer_get_frame((Layer *) s_ternary_minutes_layer_left); r.origin.x = 2; r.origin.y = max_height - 32 - PADDING; layer_set_frame((Layer *) s_ternary_minutes_layer_left, r); layer_add_child(window_get_root_layer(window), (Layer *) s_ternary_minutes_layer_left); //create the right minutes image s_ternary_minutes_layer_right = rot_bitmap_layer_create(s_ternary_minutes_bitmap); rot_bitmap_layer_set_corner_clip_color(s_ternary_minutes_layer_right, GColorClear); rot_bitmap_set_compositing_mode(s_ternary_minutes_layer_right, GCompOpSet); rot_bitmap_layer_set_angle(s_ternary_minutes_layer_right, DEG_TO_TRIGANGLE(-45)); //position the frame r = layer_get_frame((Layer *) s_ternary_minutes_layer_right); r.origin.x = width - 32 - PADDING; r.origin.y = max_height - 32 - PADDING; layer_set_frame((Layer *) s_ternary_minutes_layer_right, r); layer_add_child(window_get_root_layer(window), (Layer *) s_ternary_minutes_layer_right); if (persist_read_int(KEY_BACKGROUND_COLOR)) { set_background_color(persist_read_int(KEY_BACKGROUND_COLOR)); } } static void window_unload(Window *window) { gbitmap_destroy(s_ternary_seconds_bitmap); bitmap_layer_destroy(s_ternary_seconds_layer); gbitmap_destroy(s_unary_hours_bitmap); rot_bitmap_layer_destroy(s_unary_hours_layer_left); rot_bitmap_layer_destroy(s_unary_hours_layer_right); gbitmap_destroy(s_ternary_minutes_bitmap); rot_bitmap_layer_destroy(s_ternary_minutes_layer_left); rot_bitmap_layer_destroy(s_ternary_minutes_layer_right); }