void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Modern Watch"); window_stack_push(&window, true /* Animated */); resource_init_current_app(&APP_RESOURCES); #if DISPLAY_DATE_ANALOG bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_DATEBOX, &background_image_container); #elif INVERTED bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_INVERTED, &background_image_container); #else bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); #endif layer_add_child(&window.layer, &background_image_container.layer.layer); #if DISPLAY_DATE_ANALOG date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ORBITRON_MEDIUM_12)); text_layer_init(&date_layer, GRect(116, 77, 20, 20)); #else date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIGITALDREAM_NARROW_12)); text_layer_init(&date_layer, GRect(27, 110, 90, 30)); #endif #if DISPLAY_DATE_ANALOG text_layer_set_text_color(&date_layer, GColorBlack); #elif INVERTED text_layer_set_text_color(&date_layer, GColorBlack); #else text_layer_set_text_color(&date_layer, GColorWhite); #endif text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); text_layer_set_background_color(&date_layer, GColorClear); text_layer_set_font(&date_layer, date_font); layer_add_child(&window.layer, &date_layer.layer); draw_date(); layer_init(&hour_display_layer, window.layer.frame); hour_display_layer.update_proc = &hour_display_layer_update_callback; layer_add_child(&window.layer, &hour_display_layer); gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS); gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame)); layer_init(&minute_display_layer, window.layer.frame); minute_display_layer.update_proc = &minute_display_layer_update_callback; layer_add_child(&window.layer, &minute_display_layer); gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS); gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame)); layer_init(¢er_display_layer, window.layer.frame); center_display_layer.update_proc = ¢er_display_layer_update_callback; layer_add_child(&window.layer, ¢er_display_layer); #if DISPLAY_SECONDS layer_init(&second_display_layer, window.layer.frame); second_display_layer.update_proc = &second_display_layer_update_callback; layer_add_child(&window.layer, &second_display_layer); #endif }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Plain Watch"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); layer_init(&hour_display_layer, window.layer.frame); hour_display_layer.update_proc = &hour_display_layer_update_callback; layer_add_child(&window.layer, &hour_display_layer); gpath_init(&hour_hand_outline_path, &HOUR_HAND_OUTLINE_PATH_POINTS); gpath_move_to(&hour_hand_outline_path, grect_center_point(&hour_display_layer.frame)); gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS); gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame)); layer_init(&minute_display_layer, window.layer.frame); minute_display_layer.update_proc = &minute_display_layer_update_callback; layer_add_child(&window.layer, &minute_display_layer); gpath_init(&minute_hand_outline_path, &MINUTE_HAND_OUTLINE_PATH_POINTS); gpath_move_to(&minute_hand_outline_path, grect_center_point(&minute_display_layer.frame)); gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS); gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame)); }
static void main_window_load(Window *window) { //get root layer of window Layer *window_layer = window_get_root_layer(window); //get window dimensions GRect bounds = layer_get_bounds(window_layer); //add drawing layers s_clock_layer_outer = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2))); layer_set_update_proc(s_clock_layer_outer, draw_clock_layer_outer); layer_add_child(window_layer, s_clock_layer_outer); s_clock_layer_center = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2))); layer_set_update_proc(s_clock_layer_center, draw_clock_layer_center); layer_add_child(window_layer, s_clock_layer_center); s_clock_layer_inner = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2))); layer_set_update_proc(s_clock_layer_inner, draw_clock_layer_inner); layer_add_child(window_layer, s_clock_layer_inner); //init text time layer GSize max_size = graphics_text_layout_get_content_size( "00:00", fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(0, 0, bounds.size.w, bounds.size.h), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter ); s_text_time = text_layer_create(GRect( (bounds.size.w / 2) - (max_size.w / 2), (bounds.size.h / 2) - (max_size.h / 2), max_size.w, max_size.h) ); text_layer_set_background_color(s_text_time, GColorClear); text_layer_set_text_color(s_text_time, GColorBlack); text_layer_set_font(s_text_time, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_text_time, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_text_time)); toggle_text_time(); //init inverter layer s_layer_invert = inverter_layer_create(GRect(0, 0, bounds.size.w, bounds.size.h)); layer_add_child(window_layer, inverter_layer_get_layer(s_layer_invert)); invert_face(); //store clock layer bounds s_clock_bounds = layer_get_bounds(s_clock_layer_outer); s_clock_center = grect_center_point(&s_clock_bounds); //init hand paths s_hand_path_outer = gpath_create(&OUTER_HAND_POINTS); gpath_move_to(s_hand_path_outer, s_clock_center); s_hand_path_center = gpath_create(&CENTER_HAND_POINTS); gpath_move_to(s_hand_path_center, s_clock_center); s_hand_path_inner = gpath_create(&INNER_HAND_POINTS); gpath_move_to(s_hand_path_inner, s_clock_center); }
static void init(void) { window = window_create(); window_set_background_color(window, GColorBlack); window_stack_push(window, true); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); // Init the layer for the minute display minute_display_layer = layer_create(bounds); layer_set_update_proc(minute_display_layer, minute_display_layer_update_callback); layer_add_child(window_layer, minute_display_layer); // Init the minute segment path minute_segment_path = gpath_create(&MINUTE_SEGMENT_PATH_POINTS); gpath_move_to(minute_segment_path, grect_center_point(&bounds)); // Init the layer for the hour display hour_display_layer = layer_create(bounds); layer_set_update_proc(hour_display_layer, hour_display_layer_update_callback); layer_add_child(window_layer, hour_display_layer); // Init the hour segment path hour_segment_path = gpath_create(&HOUR_SEGMENT_PATH_POINTS); gpath_move_to(hour_segment_path, grect_center_point(&bounds)); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Watchface"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); PblTm t; get_time(&t); setPhase(daysSinceNewMoon(t.tm_year+1900,t.tm_yday,t.tm_hour)); curHour=t.tm_hour; curMin=t.tm_min; curSec=t.tm_sec; if(showDetailedMoonGraphic){ resource_init_current_app(&LUNARCLOCK_IMAGE_RESOURCES); bmp_init_container(RESOURCE_ID_IMAGE_MOON, &moonimage_container); layer_add_child(&window.layer, &moonimage_container.layer.layer); }else{ layer_init(&moon_layer, window.layer.frame); moon_layer.update_proc = &moon_layer_update_callback; layer_add_child(&window.layer, &moon_layer); } layer_init(&shadow_layer, window.layer.frame); shadow_layer.update_proc = &shadow_layer_update_callback; layer_add_child(&window.layer, &shadow_layer); layer_init(&phase_layer, window.layer.frame); phase_layer.update_proc = &phase_layer_update_callback; layer_add_child(&window.layer, &phase_layer); if(showHours){ layer_init(&hour_layer, window.layer.frame); hour_layer.update_proc = &hour_layer_update_callback; layer_add_child(&window.layer, &hour_layer); gpath_init(&hour_hand, &hour_hand_info); gpath_move_to(&hour_hand, GPoint(centerx, centery)); } if(showMinutes){ layer_init(&minute_layer, window.layer.frame); minute_layer.update_proc = &minute_layer_update_callback; layer_add_child(&window.layer, &minute_layer); gpath_init(&minute_hand, &minute_hand_info); gpath_move_to(&minute_hand, GPoint(centerx, centery)); } if(showSeconds){ layer_init(&second_layer, window.layer.frame); second_layer.update_proc = &second_layer_update_callback; layer_add_child(&window.layer, &second_layer); } layer_init(&top_layer, window.layer.frame); top_layer.update_proc = &top_layer_update_callback; layer_add_child(&window.layer, &top_layer); }
static void handle_init(AppContextRef app_ctx) { window_init(&s_data.window, "Simple Analog Watch"); s_data.day_buffer[0] = '\0'; s_data.num_buffer[0] = '\0'; // init hand paths gpath_init(&s_data.minute_arrow, &MINUTE_HAND_POINTS); gpath_init(&s_data.hour_arrow, &HOUR_HAND_POINTS); const GPoint center = grect_center_point(&s_data.window.layer.bounds); gpath_move_to(&s_data.minute_arrow, center); gpath_move_to(&s_data.hour_arrow, center); // init clock face paths for (int i = 0; i < NUM_CLOCK_TICKS; ++i) { gpath_init(&s_data.tick_paths[i], &ANALOG_BG_POINTS[i]); } // init layers layer_init(&s_data.simple_bg_layer, s_data.window.layer.frame); s_data.simple_bg_layer.update_proc = &bg_update_proc; layer_add_child(&s_data.window.layer, &s_data.simple_bg_layer); // init date layer -> a plain parent layer to create a date update proc layer_init(&s_data.date_layer, s_data.window.layer.frame); s_data.date_layer.update_proc = &date_update_proc; layer_add_child(&s_data.window.layer, &s_data.date_layer); // init day text_layer_init(&s_data.day_label, GRect(46, 114, 27, 20)); text_layer_set_text(&s_data.day_label, s_data.day_buffer); text_layer_set_background_color(&s_data.day_label, GColorBlack); text_layer_set_text_color(&s_data.day_label, GColorWhite); GFont norm18 = fonts_get_system_font(FONT_KEY_GOTHIC_18); text_layer_set_font(&s_data.day_label, norm18); layer_add_child(&s_data.date_layer, &s_data.day_label.layer); // init num text_layer_init(&s_data.num_label, GRect(73, 114, 18, 20)); text_layer_set_text(&s_data.num_label, s_data.num_buffer); text_layer_set_background_color(&s_data.num_label, GColorBlack); text_layer_set_text_color(&s_data.num_label, GColorWhite); GFont bold18 = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); text_layer_set_font(&s_data.num_label, bold18); layer_add_child(&s_data.date_layer, &s_data.num_label.layer); // init hands layer_init(&s_data.hands_layer, s_data.simple_bg_layer.frame); s_data.hands_layer.update_proc = &hands_update_proc; layer_add_child(&s_data.window.layer, &s_data.hands_layer); // Push the window onto the stack const bool animated = true; window_stack_push(&s_data.window, animated); }
void handle_init(void) { window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); fontRobotoCondensed19 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_19)); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); triangle_overlay_layer = layer_create(bounds); layer_set_update_proc(triangle_overlay_layer, triangle_display_layer_update_callback); layer_add_child(window_layer, triangle_overlay_layer); triangle_overlay_path = gpath_create(&TRIANGLE_OVERLAY_POINTS); gpath_move_to(triangle_overlay_path, grect_center_point(&bounds)); // init hand paths minute_arrow_path = gpath_create(&MINUTE_HAND_POINTS); gpath_move_to(minute_arrow_path, grect_center_point(&bounds)); hour_arrow_path = gpath_create(&HOUR_HAND_POINTS); gpath_move_to(hour_arrow_path, grect_center_point(&bounds)); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); s_hands_layer = layer_create(bounds); layer_set_update_proc(s_hands_layer, hands_update_proc); layer_add_child(window_layer, s_hands_layer); // Battery Line Basalt #ifdef PBL_PLATFORM_BASALT GRect line_frame = GRect(22, 160, 104, 6); LineLayer = layer_create(line_frame); layer_set_update_proc(LineLayer, line_layer_update_callback); layer_add_child(window_layer, LineLayer); #else //Chalk GRect line_round_frame = GRect(1, 1, 180, 180); RoundBatteryLayer = layer_create(line_round_frame); layer_set_update_proc(RoundBatteryLayer, RoundBatteryLayer_update_callback); layer_add_child(window_layer,RoundBatteryLayer); #endif //Service subscribes: battery_state_service_subscribe(&handle_battery); handle_battery(battery_state_service_peek()); bluetooth_connection_service_subscribe(&handle_bluetooth); handle_bluetooth(bluetooth_connection_service_peek()); app_focus_service_subscribe(&handle_appfocus); }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Brown Watch"); window_stack_push(&window, true /* Animated */); resource_init_current_app(&APP_RESOURCES); #if DISPLAY_DATE_SHORT bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_BOX, &background_image_container); #else bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); #endif layer_add_child(&window.layer, &background_image_container.layer.layer); #if DISPLAY_DATE_SHORT || DISPLAY_DATE_LONG date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OPENSANS_REGULAR_14)); text_layer_init(&date_layer, GRect(27, 110, 90, 30)); text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); text_layer_set_text_color(&date_layer, GColorWhite); text_layer_set_background_color(&date_layer, GColorClear); text_layer_set_font(&date_layer, date_font); layer_add_child(&window.layer, &date_layer.layer); draw_date(); #endif layer_init(&hour_display_layer, window.layer.frame); hour_display_layer.update_proc = &hour_display_layer_update_callback; layer_add_child(&window.layer, &hour_display_layer); gpath_init(&hour_hand_outline_path, &HOUR_HAND_OUTLINE_PATH_POINTS); gpath_move_to(&hour_hand_outline_path, grect_center_point(&hour_display_layer.frame)); gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS); gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame)); layer_init(&minute_display_layer, window.layer.frame); minute_display_layer.update_proc = &minute_display_layer_update_callback; layer_add_child(&window.layer, &minute_display_layer); gpath_init(&minute_hand_outline_path, &MINUTE_HAND_OUTLINE_PATH_POINTS); gpath_move_to(&minute_hand_outline_path, grect_center_point(&minute_display_layer.frame)); gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS); gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame)); layer_init(¢er_display_layer, window.layer.frame); center_display_layer.update_proc = ¢er_display_layer_update_callback; layer_add_child(&window.layer, ¢er_display_layer); #if DISPLAY_SECONDS layer_init(&second_display_layer, window.layer.frame); second_display_layer.update_proc = &second_display_layer_update_callback; layer_add_child(&window.layer, &second_display_layer); #endif }
void tick_handler(struct tm *tick_time, TimeUnits units_changed){ //update digital clock strftime(buffer, sizeof("00:00"), "%H:%M", tick_time); strftime(date_buffer, sizeof("00"), "%d", tick_time); text_layer_set_text(text_layer, buffer); text_layer_set_text(date_layer, date_buffer); //update analog clock gpath_rotate_to(hour_path, (TRIG_MAX_ANGLE/360)*(((tick_time->tm_hour)*30)+((tick_time->tm_min)*0.5))); gpath_move_to(hour_path, (GPoint){72, 84}); gpath_rotate_to(minute_path, (TRIG_MAX_ANGLE/360)*((tick_time->tm_min)*6)); gpath_move_to(minute_path, (GPoint){72, 84}); }
/* Window handler */ static void main_window_load(Window *window) { // Get information about the Window Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); GPoint center = grect_center_point(&bounds); // init hand paths s_minute_arrow = gpath_create(&MINUTE_HAND_POINTS); s_hour_arrow = gpath_create(&HOUR_HAND_POINTS); gpath_move_to(s_minute_arrow, center); gpath_move_to(s_hour_arrow, center); // background all black s_bg_layer = layer_create(bounds); layer_set_update_proc(s_bg_layer, bg_update_proc); layer_add_child(window_layer, s_bg_layer); s_draw_layer = layer_create(bounds); layer_set_update_proc(s_draw_layer, hands_update_proc); s_time_layer = text_layer_create(PBL_IF_ROUND_ELSE( GRect(63, center.y / 2 - 15, 56, 20), GRect(46, center.y / 2 - 15, 56, 20))); text_layer_set_background_color(s_time_layer, GColorBlack); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_layer, s_draw_layer); layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); // register timetick handler tick_timer_service_subscribe(SECOND_UNIT, tick_handler); //s_app_timer = app_timer_register(TIMER_INTERVALL,app_timer_handler,window); Layer *batteryLayer = init_battery_watcher(GRect(PBL_IF_ROUND_ELSE(30,1), PBL_IF_ROUND_ELSE(19,5), 35, 20)); if (batteryLayer != NULL) { layer_add_child(window_layer, batteryLayer); } Layer *btLayer = init_bluetooth_layer(GRect(120, 5, 24,24)); if (btLayer != NULL) { layer_add_child(window_layer, btLayer); } }
void startup_animation_init() { update_angles(); hour_delta = GPoint( DOTS_RADIUS * sin_lookup(hour_angle) / ONE, -DOTS_RADIUS * cos_lookup(hour_angle) / ONE); gpath_move_to(hour_path, GPoint(CENTER_X + hour_delta.x, CENTER_Y + hour_delta.y)); min_delta = GPoint( DOTS_RADIUS * sin_lookup(min_angle) / ONE, -DOTS_RADIUS * cos_lookup(min_angle) / ONE); gpath_move_to(min_path, GPoint(CENTER_X + min_delta.x, CENTER_Y + min_delta.y)); sec_delta = GPoint( DOTS_RADIUS * sin_lookup(sec_angle) / ONE, -DOTS_RADIUS * cos_lookup(sec_angle) / ONE); gpath_move_to(sec_path, GPoint(CENTER_X + sec_delta.x, CENTER_Y + sec_delta.y)); }
void initLayerPathAndCenter(Layer *layer, GPath *path, const GPathInfo *pathInfo, const void *updateProc) { layer_init(layer, GRect(0, 0, 70, 70)); layer->update_proc = updateProc; layer_add_child(&window.layer, layer); gpath_init(path, pathInfo); gpath_move_to(path, grect_center_point(&layer->frame)); }
static void update_triangle_proc(Layer *layer, GContext *ctx) { if(!s_spinning) { return; } // Move int32_t move_x = (int32_t)(sin_lookup(angle) * (RADIUS - 4) / TRIG_MAX_RATIO); int32_t move_y = (int32_t)(-cos_lookup(angle) * (RADIUS - 4) / TRIG_MAX_RATIO); gpath_move_to(s_spin_arrow_path, GPoint(s_spin_circle_center.x - move_x, s_spin_circle_center.y + move_y)); if(TESTING){ APP_LOG(APP_LOG_LEVEL_DEBUG, "move_x: %d", (int)move_x); APP_LOG(APP_LOG_LEVEL_DEBUG, "move_y: %d", (int)move_y); APP_LOG(APP_LOG_LEVEL_DEBUG, "angle: %d", (int)TRIGANGLE_TO_DEG(angle)); } // Rotate gpath_rotate_to(s_spin_triangle_path, -angle); gpath_rotate_to(s_spin_arrow_path, -angle); // Fill the path: graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, s_spin_triangle_path); graphics_context_set_fill_color(ctx, GColorWhite); gpath_draw_filled(ctx, s_spin_arrow_path); }
// Draws a given hand on the face, using the vector structures. void draw_vector_hand(struct VectorHandTable *hand, int hand_index, int num_steps, int place_x, int place_y, GContext *ctx) { GPoint center = { place_x, place_y }; int32_t angle = TRIG_MAX_ANGLE * hand_index / num_steps; int gi; for (gi = 0; gi < hand->num_groups; ++gi) { struct VectorHandGroup *group = &hand->group[gi]; GPath path; gpath_init(&path, &group->path_info); gpath_rotate_to(&path, angle); gpath_move_to(&path, center); if (group->fill != GColorClear) { graphics_context_set_fill_color(ctx, group->fill); gpath_draw_filled(ctx, &path); } if (group->outline != GColorClear) { graphics_context_set_stroke_color(ctx, group->outline); gpath_draw_outline(ctx, &path); } } }
void paths_create() { for (int i = 0; i < NUM_WEDGES; i++) { if (s_paths[i]) { gpath_destroy(s_paths[i]); } GPathInfo path_info = (GPathInfo) { .num_points = 3, .points = s_points[i] }; s_paths[i] = gpath_create(&path_info); gpath_move_to(s_paths[i], s_center); } } void paths_destroy() { for (int i = 0; i < NUM_WEDGES; i++) { gpath_destroy(s_paths[i]); } } Layer* forecast_create(GRect window_bounds) { s_center = grect_center_point(&window_bounds); init_points(); paths_create(); s_canvas_layer = layer_create(window_bounds); //layer_add_child(s_canvas_layer, textlayer_create()); layer_set_update_proc(s_canvas_layer, draw_forecast); static Layer* icons_layer; icons_layer = forecast_icons_create(window_bounds); layer_add_child(s_canvas_layer, icons_layer); return s_canvas_layer; }
// Draw the lizard by calling from the layer redraw proc void draw_lizard(GContext* ctx) { GPath *lizard_path = gpath_create(&lizard_points); GPath *bug_path = gpath_create(&bug_points); //gpath_rotate_to(lizard_path, TRIG_MAX_ANGLE / 360 * 20); gpath_move_to(lizard_path, GPoint(10, 0)); graphics_context_set_fill_color(ctx, GColorGreen); gpath_draw_filled(ctx, lizard_path); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_draw_outline(ctx, lizard_path); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, bug_path); GPoint center = { .x = 41, .y = 59 }; graphics_fill_circle(ctx, center, 3); graphics_draw_circle(ctx, center, 8); graphics_draw_line(ctx, GPoint(6, 73), GPoint(16, 72)); graphics_context_set_text_color(ctx, GColorRed); graphics_draw_text(ctx, "Lizzy", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(0,120,144,140), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); } // Only need to draw the lizard static void drawing_layer_update_callback(Layer *me, GContext *ctx) { draw_lizard(ctx); }
/** * Redraw handler for the minute layer * Draws the minute dial */ static void minute_layer_draw(Layer *layer, GContext *ctx) { // rotate the black quadrant that we use to mask the white circle gpath_rotate_to(minute_path, (TRIG_MAX_ANGLE * minutes / 60)); gpath_move_to(minute_path, GPoint(144/2,168/2)); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, minute_path); // draw the other overlays if(minutes < 45){ // hide the last quadrant (45-60) graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(0,0,144/2,168/2), 0, 0); } if(minutes < 30) { // hide third quadrant (30-45) graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(0,168/2,144/2,168/2), 0, 0); } if(minutes <= 15) { // hide second quadrant (15-30) graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(144/2,168/2,144/2,168/2), 0, 0); } }
Layer * create_direction_layer(GRect bounds) { Layer *layer = layer_create_with_data(GRect(0, 20, bounds.size.w, 30), sizeof(Arrow)); layer_set_update_proc(layer, redraw_direction_arrow); arrow_path = gpath_create(&ARROW_PATH_INFO); GRect layer_bounds = layer_get_bounds(layer); gpath_move_to(arrow_path, grect_center_point(&layer_bounds)); return layer; }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_minute_display_layer = layer_create(bounds); layer_set_update_proc(s_minute_display_layer, minute_display_update_proc); layer_add_child(window_layer, s_minute_display_layer); s_minute_segment_path = gpath_create(&MINUTE_SEGMENT_PATH_POINTS); gpath_move_to(s_minute_segment_path, grect_center_point(&bounds)); s_hour_display_layer = layer_create(bounds); layer_set_update_proc(s_hour_display_layer, hour_display_update_proc); layer_add_child(window_layer, s_hour_display_layer); s_hour_segment_path = gpath_create(&HOUR_SEGMENT_PATH_POINTS); gpath_move_to(s_hour_segment_path, grect_center_point(&bounds)); }
void startup_animation_update(Animation *animation, const AnimationProgress progress) { dots_radius = DOTS_RADIUS * progress / ANIMATION_NORMALIZED_MAX; AnimationProgress reverse = ANIMATION_NORMALIZED_MAX - progress; hour_pos = GPoint( CENTER_X + hour_delta.x * reverse / ANIMATION_NORMALIZED_MAX, CENTER_Y + hour_delta.y * reverse / ANIMATION_NORMALIZED_MAX); gpath_move_to(hour_path, hour_pos); min_pos = GPoint( CENTER_X + min_delta.x * reverse / ANIMATION_NORMALIZED_MAX, CENTER_Y + min_delta.y * reverse / ANIMATION_NORMALIZED_MAX); gpath_move_to(min_path, min_pos); sec_pos = GPoint( CENTER_X + sec_delta.x * reverse / ANIMATION_NORMALIZED_MAX, CENTER_Y + sec_delta.y * reverse / ANIMATION_NORMALIZED_MAX); gpath_move_to(sec_path, sec_pos); layer_mark_dirty(background_layer); layer_mark_dirty(hands_layer); }
void graphics_sun_layer_update_callback(Layer *me, GContext* ctx) { (void)me; gpath_init(&sun_path, &sun_path_info); gpath_move_to(&sun_path, grect_center_point(&graphics_sun_layer.frame)); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, &sun_path); }
ClockLayer* clock_layer_create(const GRect frame) { ClockLayer *clock_layer = layer_create(frame); layer_set_update_proc(clock_layer,clock_layer_update); //Create coordinate paths s_large_ticks = gpath_create(&LARGE_TICKS); s_small_ticks = gpath_create(&SMALL_TICKS); s_hour_hand = gpath_create(&HOUR_HAND); s_minute_hand = gpath_create(&MINUTE_HAND); // Center the coordinate paths GPoint center = grect_center_point(&frame); gpath_move_to(s_large_ticks, center); gpath_move_to(s_small_ticks, center); gpath_move_to(s_hour_hand, center); gpath_move_to(s_minute_hand, center); return clock_layer; }
static void draw_shape(GContext* ctx, int shape, int32_t angle, bool hour) { if (shape < 3) { graphics_draw_circle(ctx, center_point, hour ? HOUR_RADIUS : MINUTE_RADIUS); } else { GPathInfo* path_info = (hour ? HOUR_SHAPES : MINUTE_SHAPES) + shape - 3; GPath* path = gpath_create(path_info); gpath_rotate_to(path, angle); gpath_move_to(path, center_point); gpath_draw_outline(ctx, path); } }
static void bg_update_proc(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, s_backColor); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); graphics_context_set_fill_color(ctx, s_textColor); for (int i = 0; i < NUM_CLOCK_TICKS; ++i) { const int x_offset = PBL_IF_ROUND_ELSE(18, 0); const int y_offset = PBL_IF_ROUND_ELSE(6, 0); gpath_move_to(s_tick_paths[i], GPoint(x_offset, y_offset)); gpath_draw_filled(ctx, s_tick_paths[i]); } }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); s_path_layer = layer_create(bounds); layer_set_update_proc(s_path_layer, path_layer_update_callback); layer_add_child(window_layer, s_path_layer); // Move all paths to the center of the screen for (int i = 0; i < NUM_PATHS; i++) { gpath_move_to(s_path_array[i], GPoint(bounds.size.w/2, bounds.size.h/2)); } }
void analog_init(Window* window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); const GPoint center = grect_center_point(&bounds); analog_layer = layer_create(bounds); layer_set_update_proc(analog_layer, analog_update_proc); layer_add_child(window_layer, analog_layer); minute_arrow = gpath_create(&MINUTE_HAND_POINTS); minute_fill = gpath_create(&MINUTE_FILL_POINTS); hour_arrow = gpath_create(&HOUR_HAND_POINTS); hour_fill = gpath_create(&HOUR_FILL_POINTS); peg_fill = gpath_create(&PEG_POINTS); gpath_move_to(minute_arrow, center); gpath_move_to(minute_fill, center); gpath_move_to(hour_arrow, center); gpath_move_to(hour_fill, center); gpath_move_to(peg_fill, center); tick_init(window); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); //arrow /*directionArrow = gbitmap_create_with_resource(RESOURCE_ID_COMPASS_BACKGROUND; arrow = bitmap_layer_create(GRect(0,0,144,138)); bitmap_layer_set_bitmap(arrow,directionArrow); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(arrow)); */ GRect bounds = layer_get_frame(window_layer); s_bitmap_layer = bitmap_layer_create(bounds); s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_COMPASS_BACKGROUND); bitmap_layer_set_bitmap(s_bitmap_layer, s_background_bitmap); bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpAnd); layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer)); // Create the layer in which we will draw the compass needles s_path_layer = layer_create(bounds); // Define the draw callback to use for this layer layer_set_update_proc(s_path_layer, path_layer_update_callback); layer_add_child(window_layer, s_path_layer); s_needle_north = gpath_create(&NEEDLE_NORTH_POINTS); GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2); gpath_move_to(s_needle_north, center); //distance distance = text_layer_create(GRect(0, 0, 144, 30)); //text_layer_set_text(distance, "Distance is x m"); static char s_heading_buf[16]; snprintf(s_heading_buf, sizeof(s_heading_buf), "%i",(int)bering); text_layer_set_text(distance, s_heading_buf); text_layer_set_text_alignment(distance, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(distance)); //est time timeTo = text_layer_create(GRect(0, 144, 144, 30)); text_layer_set_text(timeTo, "It will take x min"); text_layer_set_text_alignment(timeTo, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(timeTo)); }
static void glyph_layer_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GPoint center = GPoint(bounds.size.w / 2 - 50, 0); for(int i=0; i < ui.glyph_paths_num; i++) { gpath_move_to(ui.glyph_path[i], center); #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, FG_COLOR); graphics_context_set_stroke_color(ctx, FG_COLOR); #endif gpath_draw_filled(ctx, ui.glyph_path[i]); } }
void handle_init(AppContextRef ctx) { window_init(&window, "Sector watch"); window_stack_push(&window, true); window_set_background_color(&window, GColorBlack); // Init the layer for the minute display layer_init(&minute_display_layer, window.layer.frame); minute_display_layer.update_proc = &minute_display_layer_update_callback; layer_add_child(&window.layer, &minute_display_layer); // Init the minute segment path gpath_init(&minute_segment_path, &MINUTE_SEGMENT_PATH_POINTS); gpath_move_to(&minute_segment_path, grect_center_point(&minute_display_layer.frame)); // Init the five-minute segment path gpath_init(&minute5_segment_path, &MINUTE5_SEGMENT_PATH_POINTS); gpath_move_to(&minute5_segment_path, grect_center_point(&minute_display_layer.frame)); // Init the minute marker path gpath_init(&minute_marker_path, &MINUTE_MARKER_PATH_POINTS); gpath_move_to(&minute_marker_path, grect_center_point(&minute_display_layer.frame)); // Init the layer for the hour display layer_init(&hour_display_layer, window.layer.frame); hour_display_layer.update_proc = &hour_display_layer_update_callback; layer_add_child(&window.layer, &hour_display_layer); // Init the hour segment path gpath_init(&hour_segment_path, &HOUR_SEGMENT_PATH_POINTS); gpath_move_to(&hour_segment_path, grect_center_point(&hour_display_layer.frame)); }
void bearing_layer_update_callback(Layer *me, GContext *ctx) { int x, y; x = (XINI + (s_gpsdata.xpos * SCREEN_W / (map_scale/10))) % MAP_VSIZE_X; y = (YINI - (s_gpsdata.ypos * SCREEN_W / (map_scale/10))) % MAP_VSIZE_Y; gpath_move_to(bearing_gpath, GPoint(x + pathFrame.origin.x, y + pathFrame.origin.y)); gpath_rotate_to(bearing_gpath, (TRIG_MAX_ANGLE / 360) * s_gpsdata.bearing); // Fill the path: //graphics_context_set_fill_color(ctx, GColorBlack); //gpath_draw_filled(ctx, &bearing_gpath); // Stroke the path: graphics_context_set_stroke_color(ctx, GColorBlack); gpath_draw_outline(ctx, bearing_gpath); }