static void layer_update_callback(Layer *me, GContext* ctx) { // preparations GRect bounds = layer_get_bounds(me); uint16_t width = bounds.size.w; uint16_t height = bounds.size.h; uint16_t stride = (bounds.size.w + 31) / 32 * 32; uint16_t max = (height - 1) * stride + width; uint16_t shake = stride - width; uint16_t shake_stride = shake * stride; // handle shake if (do_shake) { do_shake = false; light_enable_interaction(); for (uint16_t i = 0, j = rand(); i < NUM_FLAKES; i++, j+=31) { for (uint16_t k = 0; k < 2; k++, j+=31) { uint16_t next = flakes[i] + j % (max * 2) - max; if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) { flakes[i] = next; break; } } } last_time = 0; } // update time text time_t t = time(NULL); if (t / UPDATE_S > last_time) { last_time = t / UPDATE_S; char time_text[6]; clock_copy_time_string(time_text, sizeof(time_text)); graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, bounds, 0, GCornerNone); GRect rect = (GRect) {{0, 60}, {width, 50}}; GFont font = fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD); graphics_draw_text(ctx, time_text, font, rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); graphics_context_set_stroke_color(ctx, GColorWhite); for (uint16_t i = 0, j = rand(); i < NUM_FLAKES; i++) { if (get_pixel(ctx, flakes[i]) == GColorBlack) { graphics_draw_pixel(ctx, GPoint(flakes[i] % stride, flakes[i] / stride)); } else { for (uint16_t k = 0; k < 8; k++, j++) { uint16_t next = flakes[i] + (j % 9 / 3 - 1) * shake_stride + (j % 3 - 1) * shake; if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) { flakes[i] = next; graphics_draw_pixel(ctx, GPoint(flakes[i] % stride, flakes[i] / stride)); break; } } } } } // apply physics AccelData accel = {.x = 0, .y = 0, .z = 0}; accel_service_peek(&accel); uint16_t absx = accel.x < 0 ? -accel.x : accel.x; uint16_t absy = accel.y < 0 ? -accel.y : accel.y; uint16_t span = (absx + absy + 10) * SPEED; for (uint16_t i = 0, j = rand(), k = rand(), l = rand(); i < span; i++, j++, k++, l++) { uint16_t index = j % NUM_FLAKES; uint16_t next = flakes[index]; int16_t sideway = k % 3 == 0 ? l % 5 - 2 : 0; int16_t accx = accel.x + accel.y * sideway; int16_t accy = accel.y - accel.x * sideway; absx = accx < 0 ? -accx : accx; absy = accy < 0 ? -accy : accy; if (absx > absy || k % absy < absx) { if (accx > 0) { next++; } else { next--; } } if (absy > absx || l % absx < absy) { if (accy > 0) { next -= stride; } else { next += stride; } } if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) { graphics_context_set_stroke_color(ctx, GColorBlack); graphics_draw_pixel(ctx, GPoint(flakes[index] % stride, flakes[index] / stride)); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_pixel(ctx, GPoint(next % stride, next / stride)); flakes[index] = next; } } if (!timer) timer = app_timer_register(UPDATE_MS, timer_callback, NULL); } static void handle_accel(AccelData *accel_data, uint32_t num_samples) { // or else I will crash } static void accel_tap_handler(AccelAxisType axis, int32_t direction) { do_shake = true; } static void root_update_callback(Layer *me, GContext* ctx) { // hack to prevent screen cleaning } static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); layer_set_update_proc(window_layer, root_update_callback); GRect bounds = layer_get_bounds(window_layer); layer = layer_create(bounds); layer_set_update_proc(layer, layer_update_callback); layer_add_child(window_layer, layer); uint16_t width = bounds.size.w; uint16_t height = bounds.size.h; uint16_t stride = (bounds.size.w + 31) / 32 * 32; for (uint16_t i = 0; i < NUM_FLAKES; i++) { flakes[i] = rand() % height * stride + rand() % width; } }
static void bg_update_proc(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); graphics_context_set_fill_color(ctx, GColorWhite); }
static void line_layer_update_callback2(Layer *layer, GContext* ctx) { graphics_context_set_fill_color(ctx, GColorVividCerulean); //sets color of top block graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); }
static void update_proc(Layer *layer, GContext *ctx) { const GRect bounds = layer_get_bounds(layer); graphics_context_set_fill_color(ctx, bottom_color); graphics_fill_rect(ctx, bounds, 0, GCornerNone); };
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; }
void progress_update_callback(Layer *me, GContext* ctx) { (void)me; graphics_context_set_stroke_color(ctx, GColorWhite); //Progress bars PblTm t; get_time(&t); //% of date //Year float year; int year_percent; year = t.tm_yday; year = ((double)100/366)*year; //Percent of year //Month float month; int month_percent; int isLeapYear = (t.tm_year%4 == 0)?1:0; int daysInMonth = (t.tm_mon + 1 == 2) ? (28 + isLeapYear) : 31 - ((t.tm_mon) % 7 % 2); month = t.tm_mday; month = ((double)100/daysInMonth)*month; //Percent of month //Week float week; int week_percent; week = t.tm_wday; week = week*24 + t.tm_hour; week = ((double)100/(7*24))*week; //Percent of Week //Day float day; int day_percent; day = t.tm_hour; day = day*60 + t.tm_min; day = ((double)100/(24*60))*day; //Percent of year //% of progress bar //Year year = ((double)134/100)*year; //Percent of bar based on % of year year_percent = (int)year; graphics_context_set_fill_color(app_get_current_graphics_context(), GColorWhite); graphics_fill_rect(app_get_current_graphics_context(), GRect(5, 25, year_percent, 5), 0, GCornerNone); //Month month = ((double)134/100)*month; //Percent of bar based on % of month month_percent = (int)month; graphics_context_set_fill_color(app_get_current_graphics_context(), GColorWhite); graphics_fill_rect(app_get_current_graphics_context(), GRect(5, 56, month_percent, 5), 0, GCornerNone); //Week week = ((double)134/100)*week; //Percent of bar based on % of year week_percent = (int)week; graphics_context_set_fill_color(app_get_current_graphics_context(), GColorWhite); graphics_fill_rect(app_get_current_graphics_context(), GRect(5, 87, week_percent, 5), 0, GCornerNone); //Day day = ((double)134/100)*day; //Percent of bar based on % of year day_percent = (int)day; graphics_context_set_fill_color(app_get_current_graphics_context(), GColorWhite); graphics_fill_rect(app_get_current_graphics_context(), GRect(5, 118, day_percent, 5), 0, GCornerNone); }
void seven_segment_15_clear(GContext* ctx, GPoint pos){ graphics_fill_rect(ctx, GRect(0+pos.x,0+pos.y,10,15), 0, 0); }
static void pad_update_proc(Layer *this_layer, GContext *ctx) { //Background graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, layer_get_bounds(s_pad_layer), 0, GCornerNone); pos += (spd*.7); //Paddle bounds if(pos <= 0) { pos = 0; } else if(pos >= 105) { pos = 105; } //Paddle graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, GRect(10, pos , 7, 45), 0, GCornerNone); //Ball bounce off right if(bpos.x >= 130) { bspd.x = bspd.x * -1; score += 1; //Score static char sco[32]; snprintf(sco, sizeof(sco), "Score %i", score); text_layer_set_text(s_scr, sco); } //Ball bounce off top or bot if(bpos.y <= 5 || bpos.y >= 140) { bspd.y = bspd.y * -1; } //Change in speed if(bpos.x >= 16 && bpos.x < 20) { if(abs(bpos.y + 5 - (pos+23)) < 23) { if(abs(bpos.y - pos - 11) <12) { if(bspd.y < 10) { bspd.y += 1; } else { bspd.y = 10; } } else if(abs(bpos.y - pos + 11) < 12) { if(bspd.y > -10) { bspd.y -= 1; } else { bspd.y = -10; } } bspd.x *= -1; } if(bpos.x <= 5) { bspd.x = bspd.x * -1; bpos.x += bspd.x; layer_mark_dirty(s_pad_layer); score -= 1; static char sco[32]; snprintf(sco, sizeof(sco), "Score %i", score); text_layer_set_text(s_scr, sco); } } /* if(bpos.x < 5) //Suppose to vibrate { vibes_short_pulse(); }*/ //Change in HighScore bpos.x += bspd.x; bpos.y += bspd.y; //The ball graphics_fill_rect(ctx, GRect(bpos.x, bpos.y, 10, 10), 0, GCornerNone); }
static void updateLayer(Layer *layer, GContext *ctx) { int m; GPoint p; int32_t a, cosa, sina; GRect rect; graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_fill_color(ctx, GColorWhite); for (m=0; m<60; m++) { a = (m*TRIG_MAX_ANGLE/60 + 3*TRIG_MAX_ANGLE/4)%TRIG_MAX_ANGLE; cosa = cos_lookup(a); sina = sin_lookup(a); p.x = center.x + R_MIN * cosa / TRIG_MAX_RATIO; p.y = center.y + R_MIN * sina / TRIG_MAX_RATIO; if (!(m%15)) { switch (m) { case 0: break; case 15: p.x -= 5; p.y -= 2; rect.origin = p; rect.size.w = 11; rect.size.h = 5; graphics_fill_rect(ctx, rect, 0, GCornerNone); break; case 30: p.x -= 2; p.y -= 5; rect.origin = p; rect.size.w = 5; rect.size.h = 11; graphics_fill_rect(ctx, rect, 0, GCornerNone); break; case 45: p.x -= 6; p.y -= 2; rect.origin = p; rect.size.w = 11; rect.size.h = 5; graphics_fill_rect(ctx, rect, 0, GCornerNone); break; } } else if (!(m%5)) { p.x -= 2; p.y -= 2; rect.origin = p; rect.size.w = rect.size.h = 5; graphics_fill_rect(ctx, rect, 0, GCornerNone); } else { p.x -= 1; p.y -= 1; rect.origin = p; rect.size.w = rect.size.h = 3; graphics_fill_rect(ctx, rect, 0, GCornerNone); } } }
/*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); }
void goal_image_layer_update_callback(Layer *me, GContext* ctx) { //draw the goal achievement percentage graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, GRect(2, 2, ((goal_percent/100.0)*28.0), 4), 0, GCornerNone); }
void battery_layer_update_callback(Layer *me, GContext* ctx) { //draw the remaining battery percentage graphics_context_set_stroke_color(ctx, GColorBlack); graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(2, 2, ((batteryPercent/100.0)*11.0), 5), 0, GCornerNone); }
static void bg_update_proc(Layer* me, GContext* ctx) { graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, me->bounds, 0, GCornerNone); }
static void prv_draw_menu_row(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *menu) { char time_buf[17]; char minutes_buf[6]; char zone_buf[7]; TrainStop stop; TrainTime *time = &s_times[cell_index->row]; stop_get(time->stop, &stop); snprintf(zone_buf, sizeof(zone_buf), "Zone %d", stop.zone); train_time_format_minutes(time->time, sizeof(minutes_buf), minutes_buf); int16_t time_diff = time->time - s_times[s_index].time; if(time_diff > 0) { snprintf(time_buf, sizeof(time_buf), "%s (%d min)", minutes_buf, time_diff); } else { strncpy(time_buf, minutes_buf, sizeof(time_buf)); } menu_hack_set_colours(ctx, menu, cell_index); graphics_fill_rect(ctx, layer_get_bounds(cell_layer), 0, GCornerNone); graphics_draw_text(ctx, stop.name, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(13, -7, 131, 29), GTextOverflowModeFill, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, zone_buf, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(14, 16, 129, 20), GTextOverflowModeFill, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, time_buf, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(14, 16, 129, 20), GTextOverflowModeFill, GTextAlignmentRight, NULL); // Draw in map thing in the left margin. const bool is_start = (cell_index->row == 0); const bool is_end = (cell_index->row == s_time_count - 1); graphics_context_set_fill_color(ctx, COLOUR_ROUTE_FILLED); graphics_context_set_stroke_color(ctx, COLOUR_ROUTE_OUTLINE); if(time->sequence < s_sequence) { // Empty section because the train has already gone past here. int16_t top = -1; int16_t bottom = 41; // Avoid drawing past either end. if(is_start) { top = 20; } else if(is_end) { bottom = 20; } graphics_context_set_fill_color(ctx, COLOUR_ROUTE_EMPTY); graphics_fill_rect(ctx, GRect(3, top, 7, bottom - top), 0, GCornerNone); graphics_draw_rect(ctx, GRect(3, top, 7, bottom - top)); graphics_fill_circle(ctx, GPoint(6, 20), 6); // Fill white and draw black outline to avoid intersecting tracks. graphics_draw_circle(ctx, GPoint(6, 20), 6); } else if(time->sequence > s_sequence) { // Filled section; we haven't gone here yet. GRect rect = GRect(3, -1, 7, 41); // Avoid drawing past either end. if(is_end) { rect.size.h = 21; } else if(is_start) { rect.size.h = 21; rect.origin.y = 20; } graphics_fill_rect(ctx, rect, 0, GCornerNone); graphics_fill_circle(ctx, GPoint(6, 20), 6); } else { // Half-filled; we're here, and heading in one direction. // Which direction we fill depends on which direction we're going in. if(!is_start) { if(s_trip.direction == TrainDirectionSouthbound) { graphics_context_set_fill_color(ctx, COLOUR_ROUTE_EMPTY); } else { graphics_context_set_fill_color(ctx, COLOUR_ROUTE_FILLED); } graphics_fill_rect(ctx, GRect(3, -1, 7, 21), 0, GCornerNone); graphics_draw_rect(ctx, GRect(3, -1, 7, 21)); } if(!is_end) { if(s_trip.direction == TrainDirectionSouthbound) { graphics_context_set_fill_color(ctx, COLOUR_ROUTE_FILLED); } else { graphics_context_set_fill_color(ctx, COLOUR_ROUTE_EMPTY); } graphics_fill_rect(ctx, GRect(3, 20, 7, 21), 0, GCornerNone); graphics_draw_rect(ctx, GRect(3, -1, 7, 21)); } graphics_context_set_fill_color(ctx, COLOUR_ROUTE_FILLED); graphics_fill_circle(ctx, GPoint(6, 20), 6); graphics_draw_circle(ctx, GPoint(6, 20), 6); } }
void DateWidget_draw(GContext* ctx, int yPosition) { graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor); // compensate for extra space that appears on the top of the date widget yPosition -= (globalSettings.useLargeFonts) ? 10 : 7; // first draw the day name graphics_draw_text(ctx, currentDayName, currentSidebarFont, GRect(-5 + SidebarWidgets_xOffset, yPosition, 40, 20), GTextOverflowModeFill, GTextAlignmentCenter, NULL); // next, draw the date background // (an image in normal mode, a rectangle in large font mode) if(!globalSettings.useLargeFonts) { if(dateImage) { gdraw_command_image_recolor(dateImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor); gdraw_command_image_draw(ctx, dateImage, GPoint(3 + SidebarWidgets_xOffset, yPosition + 23)); } } else { graphics_context_set_fill_color(ctx, globalSettings.iconStrokeColor); graphics_fill_rect(ctx, GRect(2 + SidebarWidgets_xOffset, yPosition + 30, 26, 22), 2, GCornersAll); graphics_context_set_fill_color(ctx, globalSettings.iconFillColor); graphics_fill_rect(ctx, GRect(4 + SidebarWidgets_xOffset, yPosition + 32, 22, 18), 0, GCornersAll); } // next, draw the date number graphics_context_set_text_color(ctx, globalSettings.iconStrokeColor); int yOffset = 0; yOffset = globalSettings.useLargeFonts ? 24 : 26; graphics_draw_text(ctx, currentDayNum, currentSidebarFont, GRect(0 + SidebarWidgets_xOffset, yPosition + yOffset, 30, 20), GTextOverflowModeFill, GTextAlignmentCenter, NULL); // switch back to normal color for the rest graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor); // don't draw the month if we're in compact mode if(!SidebarWidgets_useCompactMode) { yOffset = globalSettings.useLargeFonts ? 48 : 47; graphics_draw_text(ctx, currentMonth, currentSidebarFont, GRect(0 + SidebarWidgets_xOffset, yPosition + yOffset, 30, 20), GTextOverflowModeFill, GTextAlignmentCenter, NULL); } }
// -------------------------------------------------------- // 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 // TODO: bug in clockwise hour setting if(left_handed) { leftTime = 12 - t.tm_hour; gpath_rotate_to(&s_data.hour_arrow, (TRIG_MAX_ANGLE * (((leftTime % 12) * 6) - (t.tm_min / 10))) / (12 * 6)); } else { leftTime = t.tm_hour; gpath_rotate_to(&s_data.hour_arrow, (TRIG_MAX_ANGLE * (((leftTime % 12) * 6) + (t.tm_min / 10))) / (12 * 6)); } // gpath_rotate_to(&s_data.hour_arrow, (TRIG_MAX_ANGLE * (((t.tm_hour % 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()
void WeatherForecast_draw(GContext* ctx, int yPosition) { graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor); if(Weather_forecastWeatherIcon) { gdraw_command_image_recolor(Weather_forecastWeatherIcon, globalSettings.iconFillColor, globalSettings.iconStrokeColor); gdraw_command_image_draw(ctx, Weather_forecastWeatherIcon, GPoint(3 + SidebarWidgets_xOffset, yPosition)); } // draw weather data only if it has been set if(Weather_weatherForecast.highTemp != INT32_MIN) { int highTemp = Weather_weatherForecast.highTemp; int lowTemp = Weather_weatherForecast.lowTemp; if(!globalSettings.useMetric) { highTemp = roundf(highTemp * 1.8f + 32); lowTemp = roundf(lowTemp * 1.8f + 32); } char tempString[8]; graphics_context_set_fill_color(ctx, globalSettings.sidebarTextColor); // in large font mode, omit the degree symbol and move the text if(!globalSettings.useLargeFonts) { snprintf(tempString, sizeof(tempString), " %d°", highTemp); graphics_draw_text(ctx, tempString, currentSidebarFont, GRect(-5 + SidebarWidgets_xOffset, yPosition + 24, 38, 20), GTextOverflowModeFill, GTextAlignmentCenter, NULL); graphics_fill_rect(ctx, GRect(3 + SidebarWidgets_xOffset, 8 + yPosition + 37, 24, 1), 0, GCornerNone); snprintf(tempString, sizeof(tempString), " %d°", lowTemp); graphics_draw_text(ctx, tempString, currentSidebarFont, GRect(-5 + SidebarWidgets_xOffset, yPosition + 42, 38, 20), GTextOverflowModeFill, GTextAlignmentCenter, NULL); } else { snprintf(tempString, sizeof(tempString), "%d", highTemp); graphics_draw_text(ctx, tempString, currentSidebarFont, GRect(0 + SidebarWidgets_xOffset, yPosition + 20, 30, 20), GTextOverflowModeFill, GTextAlignmentCenter, NULL); graphics_fill_rect(ctx, GRect(3 + SidebarWidgets_xOffset, 8 + yPosition + 38, 24, 1), 0, GCornerNone); snprintf(tempString, sizeof(tempString), "%d", lowTemp); graphics_draw_text(ctx, tempString, currentSidebarFont, GRect(0 + SidebarWidgets_xOffset, yPosition + 39, 30, 20), GTextOverflowModeFill, GTextAlignmentCenter, NULL); } } else { // if the weather data isn't set, draw a loading indication graphics_draw_text(ctx, "...", currentSidebarFont, GRect(-5 + SidebarWidgets_xOffset, yPosition, 38, 20), GTextOverflowModeFill, GTextAlignmentCenter, NULL); } }
void line_layer_update_callback(Layer *layer, GContext* ctx) { graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); }
static void bt_update_proc(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, data_get_color(AppKeyBackgroundColor)); graphics_fill_rect(ctx, layer_get_bounds(layer), 0 , GCornerNone); }
void seven_segment_41_clear(GContext* ctx, GPoint pos){ graphics_fill_rect(ctx, GRect(0+pos.x,0+pos.y,26,41), 0, 0); }
void graphics_draw_weather(GContext* ctx, weather* forecast, char** text) { for (int i = 0; i < 5; i++) { weather current = forecast[i]; // weather next = null; // if (i < 5) { // next = forecast[i+1]; // } if (current == clear) { graphics_context_set_fill_color(ctx, GColorCyan); } else if (current == cloudy) { graphics_context_set_fill_color(ctx, GColorVividCerulean); } else if (current == rainy || current == tstorm) { graphics_context_set_fill_color(ctx, GColorVeryLightBlue); } graphics_context_set_fill_color(ctx, GColorVividCerulean); graphics_fill_rect(ctx, GRect(i*29, 85+y_off2, 29, 168), 0, GCornerNone); if (i<=2) { graphics_context_set_fill_color(ctx, GColorDukeBlue); } else { graphics_context_set_fill_color(ctx, GColorYellow); } graphics_fill_rect(ctx, GRect(i*29, 85+y_off2-3, 29, 4), 0, GCornerNone); } graphics_context_set_fill_color(ctx, GColorVividCerulean); graphics_fill_rect(ctx, GRect(0, 85+y_off2-5, 2, 9), 0, GCornerNone); graphics_fill_rect(ctx, GRect(144-2, 85+y_off2-5, 2, 9), 0, GCornerNone); graphics_fill_rect(ctx, GRect(0, 85+y_off2-5, 144, 2), 0, GCornerNone); graphics_context_set_stroke_color(ctx, GColorDukeBlue); graphics_draw_rect(ctx, GRect(2,85+y_off2-3,140,4)); for (int i = 0; i < 5; i++) { weather current = forecast[i]; weather next = null; if (i < 5) { next = forecast[i+1]; } if (current == cloudy) { graphics_draw_cloud(ctx, i, 0, GColorWhite, next); } else if (current == rainy || current == tstorm) { graphics_draw_cloud(ctx, i, 0, GColorDarkGray, next); } else if (current == part_cloudy) { graphics_draw_part_cloudy(ctx, i, 0, next); } } for (int i = 0; i < 5; i++) { weather current = forecast[i]; weather next = null; if (i < 5) { next = forecast[i+1]; } if (current == cloudy) { graphics_draw_cloud(ctx, i, 1, GColorWhite, next); } else if (current == rainy) { graphics_draw_cloud(ctx, i, 1, GColorDarkGray, next); graphics_draw_rain(ctx, i); } else if (current == tstorm) { graphics_draw_cloud(ctx, i, 1, GColorDarkGray, next); graphics_draw_lightning(ctx,i); } else if (current == part_cloudy) { graphics_draw_part_cloudy(ctx, i, 1, next); } } for (int i = 0; i < 5; i++) { graphics_draw_wtext(ctx, i, text[i*2], text[i*2 + 1]); } }
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 timezone_layer_update( Layer * const me, GContext * ctx ) { const timezone_t * const tz = container_of(me, timezone_t, layer); const int orig_hour = now.tm_hour; const int orig_min = now.tm_min; now.tm_min += (tz->offset - gmt_offset) % 60; if (now.tm_min > 60) { now.tm_hour++; now.tm_min -= 60; } else if (now.tm_min < 0) { now.tm_hour--; now.tm_min += 60; } now.tm_hour += (tz->offset - gmt_offset) / 60; if (now.tm_hour > 24) now.tm_hour -= 24; if (now.tm_hour < 0) now.tm_hour += 24; char buf[32]; string_format_time( buf, sizeof(buf), "%H:%M", &now ); //Swaps the background/foreground colors for night and day. Day=6 and later. Night=18 and later. const int night_time = (now.tm_hour > 17 || now.tm_hour < 6); now.tm_hour = orig_hour; now.tm_min = orig_min; const int w = me->bounds.size.w; const int h = me->bounds.size.h; // it is night there, draw in black video graphics_context_set_fill_color(ctx, night_time ? GColorBlack : GColorWhite); graphics_context_set_text_color(ctx, !night_time ? GColorBlack : GColorWhite); graphics_fill_rect(ctx, GRect(0, 0, w, h), 0, 0); graphics_text_draw(ctx, tz->name, font_thin, GRect(0, 0, w, h/3), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL ); graphics_text_draw(ctx, buf, font_thick, GRect(0, h/3, w, 2*h/3), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL ); }
void battery_line_layer_update_callback(Layer *BatteryLineLayer, GContext* ctx) { graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, layer_get_bounds(BatteryLineLayer), 3, GCornersAll); if (batterycharging == 1) { #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, GColorBlue); #else graphics_context_set_fill_color(ctx, GColorBlack); #endif graphics_fill_rect(ctx, GRect(2, 1, 100, 4), 3, GCornersAll); } else if (batterychargepct > 20) { #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, GColorGreen); #else graphics_context_set_fill_color(ctx, GColorBlack); #endif graphics_fill_rect(ctx, GRect(2, 1, batterychargepct, 4), 3, GCornersAll); } else { #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, GColorRed); #else graphics_context_set_fill_color(ctx, GColorBlack); #endif graphics_fill_rect(ctx, GRect(2, 1, batterychargepct, 4),3, GCornersAll); } //Battery % Markers #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, GColorBlack); #else if(batterycharging == 1) { graphics_context_set_fill_color(ctx, GColorBlack); } else { graphics_context_set_fill_color(ctx, GColorWhite); } #endif graphics_fill_rect(ctx, GRect(89, 1, 3, 4), 3, GCornerNone); graphics_fill_rect(ctx, GRect(79, 1, 3, 4), 3, GCornerNone); graphics_fill_rect(ctx, GRect(69, 1, 3, 4), 3, GCornerNone); graphics_fill_rect(ctx, GRect(59, 1, 3, 4), 3, GCornerNone); graphics_fill_rect(ctx, GRect(49, 1, 3, 4), 3, GCornerNone); graphics_fill_rect(ctx, GRect(39, 1, 3, 4), 3, GCornerNone); graphics_fill_rect(ctx, GRect(29, 1, 3, 4), 3, GCornerNone); graphics_fill_rect(ctx, GRect(19, 1, 3, 4), 3, GCornerNone); graphics_fill_rect(ctx, GRect(9, 1, 3, 4), 3, GCornerNone); }
static void lyr_background_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, GRect(bounds.size.w - 21,2, 21,bounds.size.h - 4), 4, GCornersLeft); }
static void line_layer_update_callback(Layer *layer, GContext* ctx) { graphics_context_set_fill_color(ctx, GColorIndigo); //sets color of background block graphics_fill_rect(ctx, layer_get_bounds(layer), 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); }
static void line_layer_update_callback3Red(Layer *layer, GContext* ctx) { graphics_context_set_fill_color(ctx, GColorRed); //sets color of bottom left block graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); }
//BT Logo Callback; void BTLine_update_callback(Layer *BTLayer1, GContext* BT1ctx) { GPoint BTLinePointStart; GPoint BTLinePointEnd; graphics_context_set_stroke_color(BT1ctx, TextColorHold); if (BTConnected == 0) { #ifdef PBL_COLOR graphics_context_set_stroke_color(BT1ctx, GColorRed); graphics_context_set_fill_color(BT1ctx, GColorWhite); graphics_fill_rect(BT1ctx, layer_get_bounds(BTLayer1), 0, GCornerNone); #else graphics_context_set_stroke_color(BT1ctx, GColorBlack); graphics_context_set_fill_color(BT1ctx, GColorWhite); graphics_fill_rect(BT1ctx, layer_get_bounds(BTLayer1), 0, GCornerNone); #endif // "X"" Line 1 BTLinePointStart.x = 1; BTLinePointStart.y = 1; BTLinePointEnd.x = 20; BTLinePointEnd.y = 20; graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd); // "X"" Line 2 BTLinePointStart.x = 1; BTLinePointStart.y = 20; BTLinePointEnd.x = 20; BTLinePointEnd.y = 1; graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd); } else { //Line 1 BTLinePointStart.x = 10; BTLinePointStart.y = 1; BTLinePointEnd.x = 10; BTLinePointEnd.y = 20; graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd); //Line 2 BTLinePointStart.x = 10; BTLinePointStart.y = 1; BTLinePointEnd.x = 16; BTLinePointEnd.y = 5; graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd); //Line 3 BTLinePointStart.x = 4; BTLinePointStart.y = 5; BTLinePointEnd.x = 16; BTLinePointEnd.y = 16; graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd); //Line 4 BTLinePointStart.x = 4; BTLinePointStart.y = 16; BTLinePointEnd.x = 16; BTLinePointEnd.y = 5; graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd); //Line 5 BTLinePointStart.x = 10; BTLinePointStart.y = 20; BTLinePointEnd.x = 16; BTLinePointEnd.y = 16; graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd); } }