void hour_layer_update_callback(Layer *me, GContext* ctx) { (void)me; gpath_rotate_to(&hour_hand, (TRIG_MAX_ANGLE / 360) * (curHour * 30 + curMin / 2)); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, &hour_hand); gpath_draw_outline(ctx, &hour_hand); }
void minute_layer_update_callback(Layer *me, GContext* ctx) { (void)me; gpath_rotate_to(&minute_hand, (TRIG_MAX_ANGLE / 360) * curMin * 6); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, &minute_hand); gpath_draw_outline(ctx, &minute_hand); }
void hands_layer_update_callback(Layer *layer, GContext* ctx) { #if SCREENSHOT now->tm_hour = 10; now->tm_min = 9; now->tm_sec = 36; #endif GPoint center = GPoint(CENTER_X, CENTER_Y); // hours and minutes int32_t hour_angle = THREESIXTY * (now->tm_hour * 5 + now->tm_min / 12) / 60; int32_t min_angle = THREESIXTY * now->tm_min / 60; gpath_rotate_to(hour_path, hour_angle); gpath_rotate_to(min_path, min_angle); graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_draw_filled(ctx, hour_path); gpath_draw_outline(ctx, hour_path); graphics_draw_circle(ctx, center, DOTS_SIZE+4); gpath_draw_filled(ctx, min_path); gpath_draw_outline(ctx, min_path); graphics_fill_circle(ctx, center, DOTS_SIZE+3); // seconds if (!hide_seconds) { int32_t sec_angle = THREESIXTY * now->tm_sec / 60; GPoint sec_pos = GPoint( CENTER_X + SEC_RADIUS * sin_lookup(sec_angle) / ONE, CENTER_Y - SEC_RADIUS * cos_lookup(sec_angle) / ONE); graphics_context_set_fill_color(ctx, GColorBlack); gpath_rotate_to(sec_path, sec_angle); gpath_draw_filled(ctx, sec_path); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_compositing_mode(ctx, GCompOpAssignInverted); graphics_draw_line(ctx, center, sec_pos); } // center dot graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, center, DOTS_SIZE); }
static void hands_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); int16_t second_hand_length = bounds.size.w / 2; time_t now = time(NULL); struct tm *t = localtime(&now); int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60; GPoint second_hand = { .x = (int16_t)(sin_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.x, .y = (int16_t)(-cos_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.y, }; // second hand graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_line(ctx, second_hand, center); // minute/hour hand graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60); gpath_draw_filled(ctx, s_minute_arrow); gpath_draw_outline(ctx, s_minute_arrow); gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6)); gpath_draw_filled(ctx, s_hour_arrow); gpath_draw_outline(ctx, s_hour_arrow); // dot in the middle graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone); } static void date_update_proc(Layer *layer, GContext *ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); strftime(s_num_buffer, sizeof(s_num_buffer), "%d", t); text_layer_set_text(s_num_label, s_num_buffer); }
static void path_layer_update_callback(Layer *me, GContext *ctx) { (void)me; if (outline_mode) { // draw outline uses the stroke color graphics_context_set_stroke_color(ctx, GColorWhite); gpath_draw_outline(ctx, current_path); } else { // draw filled uses the fill color graphics_context_set_fill_color(ctx, GColorWhite); gpath_draw_filled(ctx, current_path); } }
static void background_update(Layer *layer, GContext *ctx) { #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, GColorMidnightGreen); graphics_fill_rect(ctx, GRect(5,130,5,15), 0, GCornersAll); graphics_fill_rect(ctx, GRect(5,110,5,15), 0, GCornersAll); graphics_fill_rect(ctx, GRect(5,90,5,15), 0, GCornersAll); graphics_fill_rect(ctx, GRect(5,70,5,15), 0, GCornersAll); graphics_fill_rect(ctx, GRect(5,50,5,15), 0, GCornersAll); graphics_fill_rect(ctx, GRect(5,29,5,15), 0, GCornersAll); gpath_draw_filled(ctx, level1); gpath_draw_filled(ctx, level2); gpath_draw_filled(ctx, level3); gpath_draw_filled(ctx, level4); gpath_draw_filled(ctx, level5); gpath_draw_filled(ctx, level6); #else graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_rect(ctx, GRect(5,130,5,15)); graphics_draw_rect(ctx, GRect(5,110,5,15)); graphics_draw_rect(ctx, GRect(5,90,5,15)); graphics_draw_rect(ctx, GRect(5,70,5,15)); graphics_draw_rect(ctx, GRect(5,50,5,15)); graphics_draw_rect(ctx, GRect(5,29,5,15)); gpath_draw_outline(ctx, level1); gpath_draw_outline(ctx, level2); gpath_draw_outline(ctx, level3); gpath_draw_outline(ctx, level4); gpath_draw_outline(ctx, level5); gpath_draw_outline(ctx, level6); #endif }
static void draw_ticks(Layer *layer, GContext *ctx) { graphics_context_set_antialiased(ctx, true); graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorBlack); graphics_context_set_stroke_width(ctx, 5); gpath_draw_outline(ctx, tick_path_1); gpath_draw_filled(ctx, tick_path_1); gpath_draw_outline(ctx, tick_path_3); gpath_draw_filled(ctx, tick_path_3); gpath_draw_outline(ctx, tick_path_5); gpath_draw_filled(ctx, tick_path_5); gpath_draw_outline(ctx, tick_path_7); gpath_draw_filled(ctx, tick_path_7); gpath_draw_outline(ctx, tick_path_9); gpath_draw_filled(ctx, tick_path_9); gpath_draw_outline(ctx, tick_path_11); gpath_draw_filled(ctx, tick_path_11); draw_hour(2); draw_hour(4); draw_hour(6); draw_hour(8); draw_hour(10); draw_hour(12); }
static void hands_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); time_t now = time(NULL); struct tm *t = localtime(&now); // minute/hour hand graphics_context_set_fill_color(ctx, GColorBrass); graphics_context_set_stroke_color(ctx, GColorWhite); gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6)); gpath_draw_filled(ctx, s_hour_arrow); gpath_draw_outline(ctx, s_hour_arrow); gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60); gpath_draw_filled(ctx, s_minute_arrow); gpath_draw_outline(ctx, s_minute_arrow); // dot in the middle graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone); }
static void platform_update_proc(Layer *layer, GContext *ctx) { // Could change this later for platform movement OR could make a new func with gpath_move_to() GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, GColorWhite); gpath_draw_filled(ctx, platform_path); gpath_draw_outline(ctx, platform_path); }
static void hexagon_update_proc( Layer *layer, GContext *context ){ struct _hexagon_layer_data *layer_data = hexagon_get_layer_data(layer); graphics_context_set_fill_color(context, layer_data->color); gpath_draw_filled(context, layer_data->path); if( layer_data->border_path ){ graphics_context_set_stroke_color(context, layer_data->border_color); graphics_context_set_stroke_width(context,(uint8_t)layer_data->border_width); gpath_draw_outline(context, layer_data->border_path); } }
void battery_layer_update_callback(Layer *layer, GContext* ctx) { BatteryChargeState battery = battery_state_service_peek(); graphics_context_set_stroke_color(ctx, FG_COLOR); gpath_draw_outline(ctx, battery_path); int width = battery.charge_percent * 10 / 100; #ifdef PBL_BW graphics_context_set_fill_color(ctx, FG_COLOR); #else graphics_context_set_fill_color(ctx, battery.is_plugged ? (width < 3 ? GColorRed : GColorGreen) : FG_COLOR); #endif graphics_fill_rect(ctx, GRect(9, 2, width, 5), 0, GCornerNone); if (battery.is_plugged) gpath_draw_outline_open(ctx, charge_path); }
void hands_layer_update_callback(Layer *layer, GContext* ctx) { #if SCREENSHOT now->tm_hour = 10; now->tm_min = 9; now->tm_sec = 36; #endif update_angles(); // hours and minutes gpath_rotate_to(hour_path, hour_angle); gpath_rotate_to(min_path, min_angle); graphics_context_set_fill_color(ctx, FG_COLOR); graphics_context_set_stroke_color(ctx, BG_COLOR); gpath_draw_filled(ctx, hour_path); gpath_draw_outline(ctx, hour_path); graphics_fill_circle(ctx, hour_pos, DOTS_SIZE+3); gpath_draw_filled(ctx, min_path); gpath_draw_outline(ctx, min_path); graphics_fill_circle(ctx, min_pos, DOTS_SIZE+3); // seconds if (!hide_seconds) { GPoint sec_end = GPoint( sec_pos.x + SEC_RADIUS * sin_lookup(sec_angle) / ONE, sec_pos.y - SEC_RADIUS * cos_lookup(sec_angle) / ONE); graphics_context_set_fill_color(ctx, BG_COLOR); gpath_rotate_to(sec_path, sec_angle); gpath_draw_filled(ctx, sec_path); graphics_context_set_stroke_color(ctx, FG_COLOR); graphics_context_set_compositing_mode(ctx, GCompOpAssignInverted); graphics_draw_line(ctx, sec_pos, sec_end); } // center dot graphics_context_set_fill_color(ctx, BG_COLOR); graphics_fill_circle(ctx, min_pos, DOTS_SIZE); }
void minute_display_layer_update_callback(Layer *me, GContext* ctx) { (void)me; PblTm t; get_time(&t); unsigned int angle = t.tm_min * 6 + t.tm_sec / 10; gpath_rotate_to(&minute_hand_path, (TRIG_MAX_ANGLE / 360) * angle); graphics_context_set_fill_color(ctx, GColorWhite); gpath_draw_filled(ctx, &minute_hand_path); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_draw_outline(ctx, &minute_hand_path); }
static void draw_battery(Layer* layer, GContext* ctx) { BatteryChargeState state = battery_state_service_peek(); GColor color; if (state.is_charging) { color = GColorGreen; } else if (state.charge_percent <= 15) { color = GColorRed; } else { color = GColorWhite; } graphics_context_set_stroke_color(ctx, color); graphics_context_set_fill_color(ctx, color); gpath_draw_outline(ctx, s_battery_path); short lvl = state.charge_percent/10; graphics_fill_rect(ctx, GRect(0, 0, lvl, 7), 0, GCornerNone); }
static void bg_update_proc(struct Layer *layer, GContext *ctx){ GRect bounds = layer_get_bounds(layer); graphics_draw_bitmap_in_rect(ctx, s_bitmap, gbitmap_get_bounds(s_bitmap)); gpath_rotate_to(s_arrow_path, DEG_TO_TRIGANGLE(s_mood_level * 180 / 100)); // Fill the path: graphics_context_set_fill_color(ctx, GColorRed); gpath_draw_filled(ctx, s_arrow_path); // Stroke the path: graphics_context_set_stroke_width(ctx, 3); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_draw_outline(ctx, s_arrow_path); graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, (GPoint){PBL_IF_ROUND_ELSE(100,89), bounds.size.h/2}, 32); graphics_fill_rect(ctx, (GRect){.origin={PBL_IF_ROUND_ELSE(100,89),bounds.size.h/2-32},.size={64,65}}, 0, 0);
// This is the layer update callback which is called on render updates static void path_layer_update_callback(Layer *layer, GContext *ctx) { // You can rotate the path before rendering gpath_rotate_to(s_current_path, (TRIG_MAX_ANGLE / 360) * s_path_angle); // There are two ways you can draw a GPath: outline or filled // In this example, only one or the other is drawn, but you can draw // multiple instances of the same path filled or outline. if (s_outline_mode) { // draw outline uses the stroke color graphics_context_set_stroke_color(ctx, GColorWhite); gpath_draw_outline(ctx, s_current_path); } else { // draw filled uses the fill color graphics_context_set_fill_color(ctx, GColorWhite); gpath_draw_filled(ctx, s_current_path); } }
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); }
void minute_display_layer_update_callback(Layer *me, GContext* ctx) { (void)me; PblTm t; get_time(&t); unsigned int angle = t.tm_min * 6 + t.tm_sec / 10; if(init_anim < ANIM_MINUTES) { angle = 0; } else if(init_anim==ANIM_MINUTES) { minute_angle_anim += 6; if(minute_angle_anim >= angle) { #if DISPLAY_SECONDS init_anim = ANIM_SECONDS; #else init_anim = ANIM_DONE; #endif } else { angle = minute_angle_anim; } } gpath_rotate_to(&minute_hand_path, (TRIG_MAX_ANGLE / 360) * angle); #if INVERTED graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, GColorWhite); #else graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorBlack); #endif gpath_draw_filled(ctx, &minute_hand_path); gpath_draw_outline(ctx, &minute_hand_path); }
// Draws a given hand on the face, using the vector structures. void draw_vector_hand(struct HandCache *hand_cache, struct HandDef *hand_def, int hand_index, GContext *ctx) { struct VectorHand *vector_hand = hand_def->vector_hand; int gi; if (hand_cache->vector_hand_index != hand_index) { // Force a new path. for (gi = 0; gi < vector_hand->num_groups; ++gi) { if (hand_cache->path[gi] != NULL) { gpath_destroy(hand_cache->path[gi]); hand_cache->path[gi] = NULL; } } hand_cache->vector_hand_index = hand_index; } GPoint center = { hand_def->place_x, hand_def->place_y }; int32_t angle = TRIG_MAX_ANGLE * hand_index / hand_def->num_steps; assert(vector_hand->num_groups <= HAND_CACHE_MAX_GROUPS); for (gi = 0; gi < vector_hand->num_groups; ++gi) { struct VectorHandGroup *group = &vector_hand->group[gi]; if (hand_cache->path[gi] == NULL) { hand_cache->path[gi] = gpath_create(&group->path_info); if (hand_cache->path[gi] == NULL) { trigger_memory_panic(__LINE__); return; } gpath_rotate_to(hand_cache->path[gi], angle); gpath_move_to(hand_cache->path[gi], center); } if (group->fill != 0) { graphics_context_set_fill_color(ctx, draw_mode_table[config.draw_mode].colors[group->fill]); gpath_draw_filled(ctx, hand_cache->path[gi]); } if (group->outline != 0) { graphics_context_set_stroke_color(ctx, draw_mode_table[config.draw_mode].colors[group->outline]); gpath_draw_outline(ctx, hand_cache->path[gi]); } } }
void hour_display_layer_update_callback(Layer *me, GContext* ctx) { (void)me; PblTm t; get_time(&t); unsigned int angle = t.tm_hour * 30 + t.tm_min / 2; if(init_anim < ANIM_HOURS) { angle = 0; } else if(init_anim==ANIM_HOURS) { if(hour_angle_anim==0&&t.tm_hour>=12) { hour_angle_anim = 360; } hour_angle_anim += 6; if(hour_angle_anim >= angle) { init_anim = ANIM_MINUTES; } else { angle = hour_angle_anim; } } gpath_rotate_to(&hour_hand_path, (TRIG_MAX_ANGLE / 360) * angle); #if INVERTED graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, GColorWhite); #else graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorBlack); #endif gpath_draw_filled(ctx, &hour_hand_path); gpath_draw_outline(ctx, &hour_hand_path); }
static void charge_layer_update_callback(Layer *layer, GContext *ctx) { BatteryChargeState batChargeState = battery_state_service_peek(); GColor charge_color = GColorClear; // Select color for battery charge if (batChargeState.charge_percent >= 60) { charge_color = GColorGreen; } else if (batChargeState.charge_percent >= 25) { charge_color = GColorChromeYellow; } else { charge_color = GColorRed; } // Fill the battery frame graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, s_bat_frame_path_ptr); // Draw battery charge graphics_context_set_fill_color(ctx, charge_color); int h = (100 - batChargeState.charge_percent) / 5 + 1; graphics_fill_rect(ctx, GRect(3, h, 8, 21 - h), 0, GCornerNone); // Clear overwritten part (outside of battery) graphics_context_set_stroke_color(ctx, GColorClear); graphics_draw_pixel(ctx, GPoint(3, 1)); graphics_draw_pixel(ctx, GPoint(10, 1)); // Stroke the battery frame graphics_context_set_stroke_color(ctx, (conf.fiboDisplay == FiboDispZoomed) ? s_legibleColor : gcolor_legible_over(conf.backgroundColor)); gpath_draw_outline(ctx, s_bat_frame_path_ptr); graphics_context_set_compositing_mode(ctx, GCompOpSet); if (batChargeState.is_charging) { // Draw charging icon graphics_draw_bitmap_in_rect(ctx, s_charging_image, gbitmap_get_bounds(s_charging_image)); } else if (batChargeState.is_plugged) { // Draw plugged icon graphics_draw_bitmap_in_rect(ctx, s_plugged_image, gbitmap_get_bounds(s_plugged_image)); } }
static void display_layer_update(Layer *layer, GContext *ctx) { time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); // Second angle = TRIG_MAX_ANGLE * (tick_time->tm_sec / 60.0); path_info.points[0].x = centre.x + (sin_lookup(angle) * radius / TRIG_MAX_RATIO); path_info.points[0].y = centre.y - (cos_lookup(angle) * radius / TRIG_MAX_RATIO); // Minute angle = TRIG_MAX_ANGLE * (((tick_time->tm_min * 60) + tick_time->tm_sec) / 3600.0); path_info.points[1].x = centre.x + (sin_lookup(angle) * radius / TRIG_MAX_RATIO); path_info.points[1].y = centre.y - (cos_lookup(angle) * radius / TRIG_MAX_RATIO); // Hour angle = TRIG_MAX_ANGLE * ((((tick_time->tm_hour % 12) * 60) + tick_time->tm_min) / 720.0); path_info.points[2].x = centre.x + (sin_lookup(angle) * radius / TRIG_MAX_RATIO); path_info.points[2].y = centre.y - (cos_lookup(angle) * radius / TRIG_MAX_RATIO); // Do some drawing graphics_context_set_stroke_color(ctx, GColorBlack); graphics_context_set_fill_color(ctx, GColorBlack); // Draw the poly path = gpath_create(&path_info); if(tick_time->tm_sec == tick_time->tm_min || tick_time->tm_sec == tick_time->tm_hour * 5) { // Make it easier to see gpath_draw_outline(ctx, path); } else { gpath_draw_filled(ctx, path); } gpath_destroy(path); // Draw some dots graphics_fill_circle(ctx, path_info.points[0], 1); graphics_fill_circle(ctx, path_info.points[1], 2); graphics_fill_circle(ctx, path_info.points[2], 3); }
// -------------------------------------------------------- // hands_update_proc() // // callback handler supplied to system during init // -------------------------------------------------------- void hands_update_proc(Layer* me, GContext* ctx) { const GPoint center = grect_center_point(&me->bounds); const int16_t secondHandLength = me->bounds.size.w / 2; GPoint secondHand; PblTm t; int leftTime; get_time(&t); // ------------------------------------------------ // Remove this section to eliminate second hand // ------------------------------------------------ if(second_hand) { // Added for Left Handed Operation if(left_handed) { leftTime = 60 - t.tm_sec; } else { leftTime = t.tm_sec; } // calculate new angle // int32_t second_angle = TRIG_MAX_ANGLE * t.tm_sec / 60; // uncomment for right-handed operation int32_t second_angle = TRIG_MAX_ANGLE * leftTime / 60; // uncomment for left-handed operation secondHand.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.y; secondHand.x = (int16_t)(sin_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.x; // draw second hand graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_line(ctx, secondHand, center); } // minute/hour hand graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorBlack); // Added for Left Handed Operation if(left_handed) { leftTime = 60 - t.tm_min; } else { leftTime = t.tm_min; } // gpath_rotate_to(&s_data.minute_arrow, TRIG_MAX_ANGLE * t.tm_min / 60); gpath_rotate_to(&s_data.minute_arrow, TRIG_MAX_ANGLE * leftTime / 60); gpath_draw_filled(ctx, &s_data.minute_arrow); gpath_draw_outline(ctx, &s_data.minute_arrow); // Added for Left Handed Operation if(left_handed) { leftTime = 12 - t.tm_hour; } else { leftTime = t.tm_hour; } // gpath_rotate_to(&s_data.hour_arrow, (TRIG_MAX_ANGLE * (((t.tm_hour % 12) * 6) + (t.tm_min / 10))) / (12 * 6)); gpath_rotate_to(&s_data.hour_arrow, (TRIG_MAX_ANGLE * (((leftTime % 12) * 6) - (t.tm_min / 10))) / (12 * 6)); gpath_draw_filled(ctx, &s_data.hour_arrow); gpath_draw_outline(ctx, &s_data.hour_arrow); // dot in the middle graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(me->bounds.size.w / 2-1, me->bounds.size.h / 2-1, 3, 3), 0, GCornerNone); } // hands_update_proc()
static void bluetooth_update_proc(Layer *layer, GContext *ctx) { graphics_context_set_stroke_color(ctx, bluetooth_connection_service_peek() ? GColorWhite : GColorBlack); gpath_draw_outline(ctx, bluez); }
void draw_custom_weather_gpath(GContext *ctx, int CUSTOM_PATH_ID, GPoint origin, struct CONFIG_TYPE *config) { int path_num = 0; const struct GPathInfo *path; switch (CUSTOM_PATH_ID) { case CLOUDY_DAY: path_num = CLOUDY_DAY_PATH_COUNT; path = CLOUDY_DAY_PATHS; break; case HEAVY_RAIN: path_num = HEAVY_RAIN_PATH_COUNT; path = HEAVY_RAIN_PATHS; break; case HEAVY_SNOW: path_num = HEAVY_SNOW_PATH_COUNT; path = HEAVY_SNOW_PATHS; break; case LIGHT_RAIN: path_num = LIGHT_RAIN_PATH_COUNT; path = LIGHT_RAIN_PATHS; break; case LIGHT_SNOW: path_num = LIGHT_SNOW_PATH_COUNT; path = LIGHT_SNOW_PATHS; break; case PARTLY_CLOUDY: path_num = PARTLY_CLOUDY_PATH_COUNT; path = PARTLY_CLOUDY_PATHS; break; case RAINING_AND_SNOWING: path_num = RAINING_AND_SNOWING_PATH_COUNT; path = RAINING_AND_SNOWING_PATHS; break; case TIMELINE_SUN: path_num = TIMELINE_SUN_PATH_COUNT; path = TIMELINE_SUN_PATHS; break; case TIMELINE_WEATHER: path_num = TIMELINE_WEATHER_PATH_COUNT; path = TIMELINE_WEATHER_PATHS; break; default: path_num = TIMELINE_WEATHER_PATH_COUNT; path = TIMELINE_WEATHER_PATHS; break; } // Draw GPath for (int i = 0; i < path_num; i++) { s_my_path_ptr = gpath_create(&path[i]); gpath_move_to(s_my_path_ptr, origin); // Fill the path: graphics_context_set_fill_color(ctx, config->WEATHER_COLOR_FILL); gpath_draw_filled(ctx, s_my_path_ptr); // Stroke the path: graphics_context_set_stroke_color(ctx, config->WEATHER_COLOR_STROKE); graphics_context_set_stroke_width(ctx, 1); gpath_draw_outline(ctx, s_my_path_ptr); // Release gpath_destroy(s_my_path_ptr); //APP_LOG(APP_LOG_LEVEL_DEBUG, "Heap Available: %d", heap_bytes_free()); } }
//----------------------------------------------------------------------------------------------------------------------- static void face_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds), clock_center = GPoint(200, 200); //Draw Mask #if defined(PBL_RECT) if (CfgData.circle) graphics_draw_bitmap_in_rect(ctx, bmp_mask, bounds); #endif graphics_context_set_stroke_color(ctx, CfgData.circle || CfgData.inv ? GColorBlack : GColorWhite); graphics_context_set_text_color(ctx, CfgData.circle || CfgData.inv ? GColorBlack : GColorWhite); graphics_context_set_fill_color(ctx, CfgData.circle || CfgData.inv ? GColorBlack : GColorWhite); //TRIG_MAX_ANGLE * t->tm_sec / 60 int32_t angle = (TRIG_MAX_ANGLE * (((aktHH % 12) * 60) + (aktMM / 1))) / (12 * 60), sinl = sin_lookup(angle), cosl = cos_lookup(angle); int16_t radV = 144, radD = 175, radT = 135; GPoint sub_center, ptLin, ptDot; sub_center.x = (int16_t)(sinl * (int32_t)radV / TRIG_MAX_RATIO) + clock_center.x; sub_center.y = (int16_t)(-cosl * (int32_t)radV / TRIG_MAX_RATIO) + clock_center.y; GRect sub_rect = { .origin = GPoint(sub_center.x - bounds.size.w / 2, sub_center.y - bounds.size.h / 2), .size = bounds.size }; for (int32_t i = 1; i<=72; i++) { int32_t angleC = TRIG_MAX_ANGLE * i / 72, sinC = sin_lookup(angleC), cosC = cos_lookup(angleC); ptLin.x = (int16_t)(sinC * (int32_t)(radD) / TRIG_MAX_RATIO) + clock_center.x - sub_rect.origin.x; ptLin.y = (int16_t)(-cosC * (int32_t)(radD) / TRIG_MAX_RATIO) + clock_center.y - sub_rect.origin.y; if (ptLin.x > -40 && ptLin.x < bounds.size.w+40 && ptLin.y > -40 && ptLin.y < bounds.size.h+40) { if ((i % 6) == 0) { gpath_move_to(hour_path, ptLin); gpath_rotate_to(hour_path, angleC); gpath_draw_filled(ctx, hour_path); int16_t nHrPnt = i/6; if (clock_is_24h_style()) if ((aktHH > 9 && aktHH < 21 && nHrPnt > 0 && nHrPnt < 6) || (((aktHH > 15 && aktHH <= 23) || (aktHH >= 0 && aktHH < 3)) && nHrPnt >= 6 && nHrPnt <= 12)) nHrPnt += 12; snprintf(hhBuffer, sizeof(hhBuffer), "%d", nHrPnt); GSize txtSize = graphics_text_layout_get_content_size(hhBuffer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD), bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter); ptDot.x = (int16_t)(sinC * (int32_t)radT / TRIG_MAX_RATIO) + clock_center.x - sub_rect.origin.x; ptDot.y = (int16_t)(-cosC * (int32_t)radT / TRIG_MAX_RATIO) + clock_center.y - sub_rect.origin.y; graphics_draw_text(ctx, hhBuffer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD), GRect(ptDot.x-txtSize.w/2, ptDot.y-txtSize.h/2, txtSize.w, txtSize.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); } else if ((i % 3) == 0) { gpath_move_to(mins_path, ptLin); gpath_rotate_to(mins_path, angleC); gpath_draw_filled(ctx, mins_path); } else { gpath_move_to(secs_path, ptLin); gpath_rotate_to(secs_path, angleC); gpath_draw_filled(ctx, secs_path); } } } //Draw Hand Path ptLin.x = (int16_t)(sinl * (int32_t)(radV+111) / TRIG_MAX_RATIO) + clock_center.x - sub_rect.origin.x; ptLin.y = (int16_t)(-cosl * (int32_t)(radV+111) / TRIG_MAX_RATIO) + clock_center.y - sub_rect.origin.y; #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, GColorOrange); #else graphics_context_set_fill_color(ctx, CfgData.circle || CfgData.inv ? GColorBlack : GColorWhite); #endif gpath_move_to(hand_path, ptLin); gpath_rotate_to(hand_path, angle); gpath_draw_filled(ctx, hand_path); //Only if no Mask... if (!CfgData.circle) { graphics_context_set_stroke_color(ctx, CfgData.inv ? GColorWhite : GColorBlack); gpath_draw_outline(ctx, hand_path); } //Draw Separator Lines graphics_context_set_stroke_color(ctx, CfgData.inv ? GColorBlack : GColorWhite); #if defined(PBL_RECT) if (CfgData.sep && !CfgData.circle) graphics_draw_line(ctx, GPoint(10, bounds.size.h-1), GPoint(bounds.size.w-10, bounds.size.h-1)); #elif defined(PBL_ROUND) //Radio & Battery graphics_context_set_fill_color(ctx, CfgData.inv ? GColorWhite : GColorBlack); if (CfgData.smart) { graphics_fill_radial(ctx, GRect(-20, center.y-20, 40, 40), GOvalScaleModeFitCircle, 20, DEG_TO_TRIGANGLE(5), DEG_TO_TRIGANGLE(175)); graphics_fill_radial(ctx, GRect(bounds.size.w-20, center.y-20, 40, 40), GOvalScaleModeFitCircle, 20, DEG_TO_TRIGANGLE(185), DEG_TO_TRIGANGLE(355)); if (CfgData.sep) { graphics_draw_arc(ctx, GRect(-20, center.y-20, 40, 40), GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(5), DEG_TO_TRIGANGLE(175)); graphics_draw_arc(ctx, GRect(bounds.size.w-20, center.y-20, 40, 40), GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(190), DEG_TO_TRIGANGLE(350)); } } //DateTime if (!CfgData.fsm) { graphics_fill_radial(ctx, GRect(center.x-100, bounds.size.h-n_bottom_margin-5, 200, 200), GOvalScaleModeFitCircle, n_bottom_margin+5, DEG_TO_TRIGANGLE(275), DEG_TO_TRIGANGLE(445)); graphics_draw_text(ctx, ddmmyyyyBuffer, digitS, GRect(0, bounds.size.h-n_bottom_margin-5, bounds.size.w, n_bottom_margin), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); if (CfgData.sep) graphics_draw_arc(ctx, GRect(center.x-100, bounds.size.h-n_bottom_margin-5, 200, 200), GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(275), DEG_TO_TRIGANGLE(445)); } #endif } //----------------------------------------------------------------------------------------------------------------------- static void handle_tick(struct tm *tick_time, TimeUnits units_changed) { if (b_initialized) { aktHH = tick_time->tm_hour; aktMM = tick_time->tm_min; layer_mark_dirty(face_layer); } #if defined(PBL_RECT) strftime(ddmmyyyyBuffer, sizeof(ddmmyyyyBuffer), //true ? "%a %d.%b" : CfgData.datefmt == 1 ? "%d-%m-%Y" : CfgData.datefmt == 2 ? "%d/%m/%Y" : CfgData.datefmt == 3 ? "%m/%d/%Y" : CfgData.datefmt == 4 ? "%Y-%m-%d" : CfgData.datefmt == 5 ? "%d.%m.%y" : CfgData.datefmt == 6 ? "%d-%m-%y" : CfgData.datefmt == 7 ? "%d/%m/%y" : CfgData.datefmt == 8 ? "%m/%d/%y" : CfgData.datefmt == 9 ? "%y-%m-%d" : CfgData.datefmt == 10 ? "%a %d.%m." : CfgData.datefmt == 11 ? "%a %d.%b" : "%d.%m.%Y", tick_time); #elif defined(PBL_ROUND) strftime(ddmmyyyyBuffer, sizeof(ddmmyyyyBuffer), //true ? "%a %d." : CfgData.datefmt == 1 ? "%d-%m" : CfgData.datefmt == 2 ? "%d/%m" : CfgData.datefmt == 3 ? "%m/%d" : CfgData.datefmt == 4 ? "%m-%d" : CfgData.datefmt == 5 ? "%d.%m" : CfgData.datefmt == 6 ? "%d-%m" : CfgData.datefmt == 7 ? "%d/%m" : CfgData.datefmt == 8 ? "%m/%d" : CfgData.datefmt == 9 ? "%m-%d" : CfgData.datefmt == 10 ? "%a %d." : CfgData.datefmt == 11 ? "%a %d." : "%d.%m", tick_time); #endif /* snprintf(ddmmyyyyBuffer, sizeof(ddmmyyyyBuffer), CfgData.datefmt == 1 ? "%d-%d-%d" : CfgData.datefmt == 2 ? "%d/%d/%d" : CfgData.datefmt == 3 ? "%d/%d/%d" : CfgData.datefmt == 4 ? "%d-%d-%d" : "%d.%d.%d", 88, 88, 8888); */ //strcpy(ddmmyyyyBuffer, "00000"); text_layer_set_text(date_layer, ddmmyyyyBuffer); //Hourly vibrate if (CfgData.vibr && tick_time->tm_min == 0) vibes_enqueue_custom_pattern(vibe_pat_hr); } //----------------------------------------------------------------------------------------------------------------------- static void timerCallback(void *data) { if ((int)data == TIMER_ANIM_FACE && !b_initialized) { time_t temp = time(NULL); struct tm *t = localtime(&temp); if ((aktHH % 12) != (t->tm_hour % 12) || aktMM != t->tm_min) { int16_t nStep = (aktHH % 12) != (t->tm_hour % 12) ? 5 : 1; if ((t->tm_hour % 12) < 6) { //Initial Value? Set correct initial if (aktHH == 0 && aktMM == 0) { aktHH = t->tm_hour >= 12 ? 12 : 0; aktMM = 0; } if (aktMM < 60-nStep) aktMM += nStep; else { aktMM = 0; aktHH++; } } else { //Initial Value? Set correct initial if (aktHH == 0 && aktMM == 0) { aktHH = t->tm_hour > 12 ? 23 : 11; aktMM = 60; } if (aktMM > nStep) aktMM -= nStep; else { aktMM = 60; aktHH--; } //Little workaround if time is close to the 12 o'clock if ((aktHH % 12) == (t->tm_hour % 12) && aktMM < t->tm_min) aktMM = t->tm_min; } layer_mark_dirty(face_layer); timer_face = app_timer_register(TIMER_ANIM_FACE_MS, timerCallback, (void*)TIMER_ANIM_FACE); } else b_initialized = true; } else if ((int)data == TIMER_ANIM_BATT && b_charging) { int nImage = 10 - (aktBattAnim / 10); bitmap_layer_set_bitmap(battery_layer, NULL); gbitmap_destroy(bmp_batt); bmp_batt = gbitmap_create_as_sub_bitmap(batteryAll, GRect(10*nImage, 0, 10, 20)); bitmap_layer_set_bitmap(battery_layer, bmp_batt); aktBattAnim += 10; if (aktBattAnim > 100) aktBattAnim = aktBatt; timer_batt = app_timer_register(TIMER_ANIM_BATT_MS, timerCallback, (void*)TIMER_ANIM_BATT); } } //----------------------------------------------------------------------------------------------------------------------- void battery_state_service_handler(BatteryChargeState charge_state) { int nImage = 0; aktBatt = charge_state.charge_percent; if (charge_state.is_charging) { if (!b_charging) { nImage = 10; b_charging = true; aktBattAnim = aktBatt; timer_batt = app_timer_register(TIMER_ANIM_BATT_MS, timerCallback, (void*)TIMER_ANIM_BATT); } } else { nImage = 10 - (aktBatt / 10); b_charging = false; } bmp_batt = gbitmap_create_as_sub_bitmap(batteryAll, GRect(10*nImage, 0, 10, 20)); bitmap_layer_set_bitmap(battery_layer, bmp_batt); }
static void hands_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); int16_t second_hand_length = bounds.size.w / 2; time_t now = time(NULL); struct tm *t = localtime(&now); // minute/hour hand graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorWhite); gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60); gpath_move_to(s_minute_arrow, GPoint(s_center.x,s_center.y+50)); gpath_draw_filled(ctx, s_minute_arrow); gpath_draw_outline(ctx, s_minute_arrow); graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorWhite); gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6)); gpath_draw_filled(ctx, s_hour_arrow); gpath_draw_outline(ctx, s_hour_arrow); // dot in the middle mHandCircle.x = 60*sin_lookup(TRIG_MAX_ANGLE * t->tm_min / 60)/TRIG_MAX_RATIO + s_center.x; mHandCircle.y = -60*cos_lookup(TRIG_MAX_ANGLE * t->tm_min / 60)/TRIG_MAX_RATIO + s_center.y; hHandCircle.x = 30*sin_lookup(TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10)) / (12 * 6))/TRIG_MAX_RATIO + s_center.x; hHandCircle.y = -30*cos_lookup(TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10)) / (12 * 6))/TRIG_MAX_RATIO + s_center.y; graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, GPoint(s_center.x,s_center.y-50), 22); graphics_context_set_fill_color(ctx, GColorRed); graphics_fill_circle(ctx, GPoint(s_center.x,s_center.y-50), 20); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, GPoint(s_center.x,s_center.y), 22); graphics_context_set_fill_color(ctx, GColorYellow); graphics_fill_circle(ctx, GPoint(s_center.x,s_center.y), 20); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, GPoint(s_center.x,s_center.y+50), 22); graphics_context_set_fill_color(ctx, GColorGreen); graphics_fill_circle(ctx, GPoint(s_center.x,s_center.y+50), 20); text_layer_destroy(m_num_label); text_layer_destroy(h_num_label); text_layer_destroy(d_num_label); m_num_label = text_layer_create(GRect(s_center.x-19, s_center.y+50-17, 40, 40)); text_layer_set_background_color(m_num_label, GColorClear); text_layer_set_text_color(m_num_label, GColorBlack); text_layer_set_font(m_num_label, fonts_get_system_font(FONT_KEY_LECO_26_BOLD_NUMBERS_AM_PM)); text_layer_set_text_alignment(m_num_label,GTextAlignmentCenter); strftime(m_num_buffer, sizeof(m_num_buffer), "%M", t); text_layer_set_text(m_num_label, m_num_buffer); layer_add_child(layer, text_layer_get_layer(m_num_label)); h_num_label = text_layer_create(GRect(s_center.x-19, s_center.y-17, 40, 40)); text_layer_set_background_color(h_num_label, GColorClear); text_layer_set_text_color(h_num_label, GColorBlack); text_layer_set_font(h_num_label, fonts_get_system_font(FONT_KEY_LECO_26_BOLD_NUMBERS_AM_PM)); text_layer_set_text_alignment(h_num_label,GTextAlignmentCenter); strftime(h_num_buffer, sizeof(h_num_buffer), "%H", t); text_layer_set_text(h_num_label, h_num_buffer); layer_add_child(layer, text_layer_get_layer(h_num_label)); d_num_label = text_layer_create(GRect(s_center.x-19, s_center.y-50-17, 40, 40)); text_layer_set_background_color(d_num_label, GColorClear); text_layer_set_text_color(d_num_label, GColorBlack); text_layer_set_font(d_num_label, fonts_get_system_font(FONT_KEY_LECO_26_BOLD_NUMBERS_AM_PM)); text_layer_set_text_alignment(d_num_label,GTextAlignmentCenter); strftime(d_num_buffer, sizeof(d_num_buffer), "%d", t); text_layer_set_text(d_num_label, d_num_buffer); layer_add_child(layer, text_layer_get_layer(d_num_label)); /* graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, GPoint(s_center.x,s_center.y), 20);*/ }
static void clock_layer_update(ClockLayer *clock_layer, GContext *ctx) { GRect bounds = layer_get_bounds(clock_layer); GPoint center = grect_center_point(&bounds); // Get the current time time_t now = time(NULL); struct tm *t = localtime(&now); const int hand_stroke_width = 2; graphics_context_set_stroke_color(ctx, GColorBlack); graphics_context_set_stroke_width(ctx, hand_stroke_width); int hour_angle = (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6); int minute_angle = TRIG_MAX_ANGLE * t->tm_min / 60; hand_update_radius(hour_angle, bounds, 2, &HOUR_HAND); hand_update_radius(minute_angle, bounds, 1, &MINUTE_HAND); // Draw hour hand gpath_rotate_to(s_hour_hand, hour_angle); gpath_draw_outline(ctx, s_hour_hand); // Draw minute hand gpath_rotate_to(s_minute_hand, minute_angle); gpath_draw_outline(ctx, s_minute_hand); const int hand_fill_width = 6; graphics_context_set_stroke_width(ctx, hand_fill_width); GPoint minute_hand_fill = gpoint_from_polar(GRect((bounds.size.w / 2) - 8, (bounds.size.h / 2) - 8, 17, 17), GOvalScaleModeFitCircle, TRIG_MAX_ANGLE * t->tm_min / 60); graphics_draw_line(ctx, center, minute_hand_fill); GPoint hour_hand_fill = gpoint_from_polar(GRect((bounds.size.w / 2) - 8, (bounds.size.h / 2) - 8, 17, 17), GOvalScaleModeFitCircle, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6)); graphics_draw_line(ctx, center, hour_hand_fill); // Draw large ticks for (int c = 0; c < 4; c++) { #if defined(PBL_BW) graphics_context_set_stroke_color(ctx, GColorBlack); #elif defined(PBL_COLOR) graphics_context_set_stroke_color(ctx, GColorBlack); #endif gpath_rotate_to(s_large_ticks, ((TRIG_MAX_ANGLE/4) * c ) + (TRIG_MAX_ANGLE/2)); gpath_draw_outline(ctx, s_large_ticks); } // Draw small ticks for (int c = 1; c < 12; c++) { #if defined(PBL_BW) graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, GColorBlack); #elif defined(PBL_COLOR) graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, GColorBlack); #endif if((c != 3) || (c != 6) || (c != 6)) { gpath_rotate_to(s_small_ticks, ((TRIG_MAX_ANGLE/12) * c ) + (TRIG_MAX_ANGLE/2)); gpath_draw_outline(ctx, s_small_ticks); } } // graphics_fill_radial(ctx, GRect((bounds.size.w / 2) - 3, (bounds.size.h / 2) - 3, 5, 5), GOvalScaleModeFitCircle, 5, 0, TRIG_MAX_ANGLE); }
/*Update Drawing Handler*/ static void hands_update_proc(Layer *layer, GContext *ctx) { graphics_context_set_antialiased(ctx, true); int16_t scale = _12HScaleFactor*60; if ( clock_is_24h_style() ) { scale = _24HScaleFactor*60; } GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); GPoint secondHand; GPoint hourHand1, hourHand2; time_t now = time(NULL); struct tm* t = localtime(&now); int16_t ms = time_ms(NULL, NULL); const int16_t second_hand_length = PBL_IF_ROUND_ELSE((bounds.size.w / 2) - 19, (bounds.size.w / 2) - 2); const int16_t hour_tick_length = PBL_IF_ROUND_ELSE((bounds.size.w / 2) - 28, bounds.size.w / 2); //const int16_t hour_hand_length = PBL_IF_ROUND_ELSE((bounds.size.w / 2) - 60, bounds.size.w / 2); calculate_pointer_end((t->tm_sec*100)+ms/10, second_hand_length, ¢er, &secondHand, 60*100, 0); // minute/hour hand graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60); gpath_draw_filled(ctx, s_minute_arrow); gpath_draw_outline(ctx, s_minute_arrow); //graphics_draw_line(ctx, minuteHand, center); graphics_context_set_stroke_color(ctx, GColorWhite); //gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6)); gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (t->tm_hour*60+t->tm_min ))/ scale); gpath_draw_filled(ctx, s_hour_arrow); gpath_draw_outline(ctx, s_hour_arrow); // draw hour lines int hours = clock_is_24h_style() ? _24HScaleFactor : _12HScaleFactor; for (int h = 0; h < hours; h++) { calculate_pointer_end(h, hour_tick_length, ¢er, &hourHand1, hours, 0); if (h % 3 == 0) { calculate_pointer_end(h, hour_tick_length-11, ¢er, &hourHand2, hours, 0); } else { calculate_pointer_end(h, hour_tick_length-7, ¢er, &hourHand2, hours, 0); } graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_line(ctx, hourHand1, hourHand2); } // draw second ticks for (int i = 0; i < t->tm_sec; i++) { calculate_pointer_end(i, second_hand_length, ¢er, &secondHand, 60, 0); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, GRect(secondHand.x, secondHand.y, 3, 3), 0, GCornerNone); } // dot in the middle graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone); }
static void draw_astro(Layer *layer, GContext *ctx) { if (astro_initialized) { // draw dawn & dusk lines (background) GRect bounds = layer_get_bounds(layer); const GPoint center = grect_center_point(&bounds); GPathInfo horizon_info = { .num_points = 5, .points = (GPoint []) {{bounds.origin.x, center.y - (bounds.size.w * sin_lookup(sunrise_angle) / (2 * cos_lookup(sunrise_angle)))}, {center.x, center.y}, {bounds.size.w, center.y - (bounds.size.w * sin_lookup(sunset_angle) / (2 * cos_lookup(sunset_angle)))}, {bounds.size.w, bounds.size.h}, {bounds.origin.x, bounds.size.h} } }; GPath *horizon = NULL; horizon = gpath_create(&horizon_info); graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_draw_filled(ctx, horizon); gpath_draw_outline(ctx, horizon); // draw sun and moon rays graphics_draw_ray(ctx, layer, center, sun_angle, SUN_THICKNESS, SUN_STROKE, SUN_FILL); graphics_draw_ray(ctx, layer, center, moon_angle, MOON_THICKNESS, MOON_STROKE, MOON_FILL); // draw planets GPath *venus = NULL; GPath *mars = NULL; graphics_context_set_fill_color(ctx, GColorWhite); graphics_context_set_stroke_color(ctx, GColorBlack); venus = gpath_create(&VENUS_PATH_INFO); gpath_move_to(venus, GPoint(center.x + VENUS_RADIUS * cos_lookup(venus_angle) / TRIG_MAX_RATIO, center.y + VENUS_RADIUS * sin_lookup(venus_angle) / TRIG_MAX_RATIO)); gpath_draw_filled(ctx, venus); gpath_draw_outline(ctx, venus); mars = gpath_create(&VENUS_PATH_INFO); gpath_move_to(mars, GPoint(center.x + MARS_RADIUS * cos_lookup(mars_angle) / TRIG_MAX_RATIO, center.y + MARS_RADIUS * sin_lookup(mars_angle) / TRIG_MAX_RATIO)); gpath_rotate_to(mars, TRIG_MAX_ANGLE / 2); gpath_draw_filled(ctx, mars); gpath_draw_outline(ctx, mars); GRect jupiter = GRect(center.x + JUPITER_RADIUS * cos_lookup(jupiter_angle) / TRIG_MAX_RATIO, center.y + JUPITER_RADIUS * sin_lookup(jupiter_angle) / TRIG_MAX_RATIO, JUPITER_SIZE * 2, JUPITER_SIZE * 2); graphics_fill_rect(ctx, jupiter, 0, 0); graphics_draw_rect(ctx, jupiter); } } static void draw_time(Layer *layer, GContext *ctx) { // draw the time in an analog clock at the center GRect bounds = layer_get_bounds(layer); const GPoint center = grect_center_point(&bounds); time_t now = time(NULL); struct tm *t = localtime(&now); int secondMarkers = t->tm_sec / 2; int i; graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, center, HMS_RADIUS); graphics_context_set_fill_color(ctx, GColorBlack); // draw the seconds if (secondMarkers % 30 != 0) { if (secondMarkers <= 15) { for (i=1; i<=secondMarkers; i++) { int angle = i * 4; GPoint marker = GPoint(center.x + SECOND_RADIUS * sin_lookup(angle * angle_180 / 30) / TRIG_MAX_RATIO, center.y - SECOND_RADIUS * cos_lookup(angle * angle_180 / 30) / TRIG_MAX_RATIO); graphics_fill_circle(ctx, marker, SECOND_THICKNESS); } } else { for (i=(secondMarkers % 15 + 1); i<=15; i++) { int angle = i * 4; GPoint marker = GPoint(center.x + SECOND_RADIUS * sin_lookup(angle * angle_180 / 30) / TRIG_MAX_RATIO, center.y - SECOND_RADIUS * cos_lookup(angle * angle_180 / 30) / TRIG_MAX_RATIO); graphics_fill_circle(ctx, marker, SECOND_THICKNESS); } } } // draw hour hand graphics_draw_arc_cw(ctx, center, HOUR_RADIUS, HOUR_THICKNESS, -angle_90, ((t->tm_hour * angle_180 / 6) - angle_90), GColorBlack); // draw minute hand graphics_draw_arc_cw(ctx, center, MINUTE_RADIUS, MINUTE_THICKNESS, -angle_90, ((t->tm_min * angle_180 / 30) - angle_90), GColorBlack); }