void line_layer_update_callback(Layer *me, GContext* ctx) { (void)me; graphics_context_set_stroke_color(ctx, GColorWhite); //graphics_draw_line(ctx, GPoint(8, 68), GPoint(131, 68)); //graphics_draw_line(ctx, GPoint(8, 67), GPoint(131, 67)); graphics_draw_line(ctx, GPoint(8, 97), GPoint(131, 97)); graphics_draw_line(ctx, GPoint(8, 98), GPoint(131, 98)); }
static void gui_layer_bg_update(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, c_bg); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); int width = layer_get_frame(layer).size.w; int height = layer_get_frame(layer).size.h; graphics_context_set_stroke_color(ctx, PBL_IF_COLOR_ELSE(GColorLightGray, GColorBlack)); graphics_context_set_stroke_width(ctx, 1); graphics_draw_line(ctx, GPoint(PADDING_X, height/2-10), GPoint(width-PADDING_X, height/2-10)); graphics_draw_line(ctx, GPoint(PADDING_X, height/2+10), GPoint(width-PADDING_X, height/2+10)); }
static void draw_bg(Layer *layer, GContext *ctx) { if (!playing) { return; } // Right pane. graphics_context_set_stroke_color(ctx, blueish); graphics_context_set_fill_color(ctx, blueish); GRect right_pane = GRect(80, 0, 64, 160); graphics_fill_rect(ctx, right_pane, 0, GCornerNone); graphics_draw_rect(ctx, right_pane); // Bottom pane. GRect bottom_pane = GRect(0, 160, 144, 8); graphics_fill_rect(ctx, bottom_pane, 0, GCornerNone); // Next block. graphics_context_set_stroke_color(ctx, GColorBlack); graphics_context_set_fill_color(ctx, col_map[nextBlockType]); int sPosX = 108 + next_block_offset(nextBlockType); int sPosY = 24; for (int i=0; i<4; i++) { GRect bl = GRect(sPosX+(nextBlock[i].x*8), sPosY+(nextBlock[i].y*8), 8, 8); graphics_fill_rect(ctx, bl, 0, GCornerNone); graphics_draw_rect(ctx, bl); } // Left pane BG. graphics_context_set_fill_color(ctx, GColorBlack); GRect left_pane = GRect(0, 0, 80, 160); graphics_fill_rect(ctx, left_pane, 0, GCornerNone); // Grid colors from leftover blocks. for (int i=0; i<10; i++) { for (int j=0; j<20; j++) { if (grid_col[i][j] != 255) { graphics_context_set_fill_color(ctx, col_map[grid_col[i][j]]); GRect brick = GRect(i*8, j*8, 8, 8); graphics_fill_rect(ctx, brick, 0, GCornerNone); } } } // Left pane grid. graphics_context_set_stroke_color(ctx, purple); for (int i=0; i<10; i++) { graphics_draw_line(ctx, GPoint(i*8, 0), GPoint(i*8, 160)); } for (int i=0; i<20; i++) { graphics_draw_line(ctx, GPoint(0, i*8), GPoint(80, i*8)); } }
// Draw a thick line on the graphics context static void prv_drawing_thick_line(GContext *ctx, GPoint p0, GPoint p1) { #ifdef PBL_SDK_3 graphics_context_set_stroke_width(ctx, 4); graphics_draw_line(ctx, p0, p1); #else for (int8_t x = -2; x <= 2; x++) { for (int8_t y = -2; y <= 2; y++) { if (abs(x) + abs(y) <= 2) { graphics_draw_line(ctx, GPoint(p0.x + x, p0.y + y), GPoint(p1.x + x, p1.y + y)); } } } #endif }
void line_layer_update_callback(Layer *me, GContext* ctx) { (void)me; graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_line(ctx, GPoint(6, 79), GPoint(52, 79)); graphics_draw_line(ctx, GPoint(6, 80), GPoint(52, 80)); graphics_draw_line(ctx, GPoint(92, 79), GPoint(144-6, 79)); graphics_draw_line(ctx, GPoint(92, 80), GPoint(144-6, 80)); //graphics_draw_line(ctx, GPoint(6, 79), GPoint(144-6, 79)); //raphics_draw_line(ctx, GPoint(6, 80), GPoint(144-6, 80)); }
static void draw_background_and_borders(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); if (get_element_data(layer)->black) { graphics_context_set_fill_color(ctx, element_bg(layer)); graphics_fill_rect(ctx, GRect(0, 0, bounds.size.w, bounds.size.h), 0, GCornerNone); } graphics_context_set_stroke_color(ctx, element_fg(layer)); if (get_element_data(layer)->bottom) { graphics_draw_line(ctx, GPoint(0, bounds.size.h - 1), GPoint(bounds.size.w - 1, bounds.size.h - 1)); } if (get_element_data(layer)->right) { graphics_draw_line(ctx, GPoint(bounds.size.w - 1, 0), GPoint(bounds.size.w - 1, bounds.size.h - 1)); } }
static void draw_minutes(Layer *this_layer, GContext *ctx, int y) { GRect bounds = layer_get_bounds(this_layer); int16_t min_per_pixel = (10*bounds.size.w)/100; int16_t min; int16_t offset = 0-ctick_time->tm_min*min_per_pixel/10; // APP_LOG(APP_LOG_LEVEL_INFO, "t: %d m: %d o: %d from: %d to %d", tick_time->tm_min, min_per_pixel, offset, // (-60)*min_per_pixel/10+offset, // (120)*min_per_pixel/10+offset); for(min = -60; min <= 100; min += 5) { int16_t x = min*min_per_pixel/10+offset+bounds.size.w/2; if (x > 0 && x < bounds.size.w) graphics_draw_line(ctx, GPoint(x, y+6), GPoint(x, y+9)); } for(min = -60; min <= 100; min += 15) { int16_t x = min*min_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+15)); } for(min = -60; min <= 120; min += 15) { int16_t x = min*min_per_pixel/10+offset; GRect frame = GRect(x, y+15, bounds.size.w, 24); static char s_buffer[3]; int16_t value = min; value %= 60; if(value < 0) value = 60+value; snprintf(s_buffer, 3, "%d", value); graphics_draw_text(ctx, s_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), frame, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL ); } }
static void draw_header_callback(GContext *ctx, const Layer *cell_layer, uint16_t section_index, void *callback_context) { GRect bounds = layer_get_bounds(cell_layer); graphics_context_set_text_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorLightGray, GColorBlack)); int lowerY = bounds.origin.y + bounds.size.h - 1; graphics_draw_line(ctx, GPoint(0, bounds.origin.y), GPoint(bounds.size.w, bounds.origin.y)); graphics_draw_line(ctx, GPoint(0, lowerY), GPoint(bounds.size.w, lowerY)); graphics_draw_text(ctx, stationName, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(0, -2, bounds.size.w, 18), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); }
static void maze_layer_update_callback(Layer *layer, GContext *ctx) { for(int i = 0; i < mazeWidth; i++){ for(int j = 0; j < mazeHeight; j++){ int currentPos = getPOS(j, i, mazeWidth); if(maze[currentPos].r == 1) { graphics_draw_line(ctx, GPoint(corridorSize*(i + 1), corridorSize*j), GPoint(corridorSize*(i + 1), corridorSize*(j + 1))); } if(maze[currentPos].b == 1) { graphics_draw_line(ctx, GPoint(corridorSize*i, corridorSize*(j + 1)), GPoint(corridorSize*(i + 1), corridorSize*(j + 1))); } } } graphics_draw_circle(ctx, GPoint((mazeWidth-1)*corridorSize+corridorSize/2, (mazeHeight-1)*corridorSize+corridorSize/2), corridorSize/2-1); }
// 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); }
void graphics_draw_horizontal_dotted_line(GContext *ctx, uint8_t start_x, uint8_t end_x, uint8_t y_coord, uint8_t dash_length, uint8_t distance_between) { for(uint8_t i = start_x; i < end_x; i=i + (dash_length + distance_between)) { GPoint start_dash = GPoint(i, y_coord); GPoint end_dash = GPoint(i + dash_length, y_coord); graphics_draw_line(ctx, start_dash, end_dash); } }
static void update_scale(Layer *layer, GContext *context) { GRect bounds = layer_get_bounds(layer); GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2); graphics_context_set_stroke_color(context, GColorWhite); GPoint start; GPoint end; for( int i = 0; i < 12; ++i) { int32_t current_angle = TRIG_MAX_ANGLE * i / 12; // create an oval shape indicator start point start.x = (sin_lookup(current_angle) * 65 / TRIG_MAX_RATIO) + center.x; start.y = (-cos_lookup(current_angle) * 75 / TRIG_MAX_RATIO) + center.y; end.x = (sin_lookup(current_angle) * 100 / TRIG_MAX_RATIO) + center.x; end.y = (-cos_lookup(current_angle) * 100 / TRIG_MAX_RATIO) + center.y; if (i % 3 == 0) { // reached a quarter, draw bigger indicator graphics_context_set_stroke_width(context, 6); } else { graphics_context_set_stroke_width(context, 3); } graphics_draw_line(context, start, end); } }
void second_display_layer_update_callback(Layer *me, GContext* ctx) { (void)me; PblTm t; get_time(&t); int32_t second_angle = t.tm_sec * (0xffff/60); int32_t counter_second_angle = t.tm_sec * (0xffff/60); if(t.tm_sec<30) { counter_second_angle += 0xffff/2; } else { counter_second_angle -= 0xffff/2; } int second_hand_length = 60; int counter_second_hand_length = 15; graphics_context_set_fill_color(ctx, GColorWhite); GPoint center = grect_center_point(&me->frame); GPoint counter_second = GPoint(center.x + counter_second_hand_length * sin_lookup(counter_second_angle)/0xffff, center.y + (-counter_second_hand_length) * cos_lookup(counter_second_angle)/0xffff); GPoint second = GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff, center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff); graphics_draw_line(ctx, counter_second, second); }
/* * Progress line */ EXTFN void progress_layer_update_callback(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, BACKGROUND_COLOR); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); graphics_context_set_fill_color(ctx, BAR_CHART_MARKS); graphics_context_set_stroke_color(ctx, BAR_CHART_MARKS); graphics_context_set_stroke_width(ctx, 2); for (uint8_t i = 0; i <= 120; i += 12) { graphics_draw_pixel(ctx, GPoint(i, 8)); graphics_draw_pixel(ctx, GPoint(i, 7)); } for (uint8_t i = 0; i <= get_internal_data()->highest_entry; i++) { if (!get_internal_data()->ignore[i]) { uint16_t height = get_internal_data()->points[i] / 500; uint8_t i2 = i * 2; #ifdef PBL_COLOR graphics_context_set_stroke_color(ctx, bar_color(height)); #endif graphics_draw_line(ctx, GPoint(i2, 8 - height), GPoint(i2, 8)); } } }
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { GRect bounds = layer_get_bounds(cell_layer); if (data_nb_stop_times > 0) { int r = cell_index->row; GRect frame_line = GRect(0, 0, 26, TIMES_CELL_HEIGHT); GRect frame_destination = GRect(30, 0, bounds.size.w - 55, TIMES_CELL_HEIGHT); GRect frame_time = GRect(bounds.size.w - 25, 0, 25, TIMES_CELL_HEIGHT); graphics_draw_text(ctx, data_stop_times[r].line, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), frame_line, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); graphics_draw_line(ctx, GPoint(27, 0), GPoint(27, TIMES_CELL_HEIGHT)); graphics_draw_text(ctx, data_stop_times[r].direction, fonts_get_system_font(FONT_KEY_GOTHIC_18), frame_destination, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, data_stop_times[r].time, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), frame_time, GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); } else if (data_nb_stop_times == -1) { graphics_draw_text(ctx, "Loading...", fonts_get_system_font(FONT_KEY_GOTHIC_18), bounds, GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); } else if (data_nb_stop_times == -2) { graphics_draw_text(ctx, "No bus.", fonts_get_system_font(FONT_KEY_GOTHIC_18), bounds, GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); } }
static void updateLayer(Layer *layer, GContext *ctx) { int angle; int cos, sin; GPoint a; static GRect r = { { 0, 0}, { 144, 168 } }; angle = TRIG_MAX_ANGLE * (60*(now.tm_hour%12) + now.tm_min) / 720; cos = cos_lookup(angle); sin = sin_lookup(angle); center.x = 72 - 72*sin/TRIG_MAX_RATIO; center.y = 84 + 72*cos/TRIG_MAX_RATIO; r.origin.x = center.x - bgBitmap->bounds.size.w/2; r.origin.y = center.y - bgBitmap->bounds.size.h/2; r.size = bgBitmap->bounds.size; graphics_draw_bitmap_in_rect(ctx, bgBitmap, r); a.x = 72 + 72*sin/TRIG_MAX_RATIO; a.y = 84 - 72*cos/TRIG_MAX_RATIO; graphics_context_set_stroke_color(ctx, GColorBlack); graphics_draw_thick_line(ctx, a, center, 5); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_line(ctx, a, center); }
static void sun_layer_update(Layer *layer, GContext *ctx) { if (data_loaded) { const GRect entire_screen = GRect(0, 0, 180, 180); const GRect sun_outline_rect = GRect(70, 70, 40, 40); const GRect sun_rect = GRect(72, 72, 36, 36); draw_circle(ctx, entire_screen, GColorVividCerulean, 90, 360); graphics_context_set_stroke_color(ctx, GColorChromeYellow); graphics_context_set_stroke_width(ctx, 2); int i; for (i = 0; i < 360; i += 12) { const GPoint in = gpoint_from_polar( sun_outline_rect, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(i) ); const GPoint out = gpoint_from_polar( entire_screen, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(i) ); graphics_draw_line(ctx, out, in); } draw_circle(ctx, sun_outline_rect, GColorWindsorTan, 20, 360); draw_circle(ctx, sun_rect, GColorOrange, 18, 360); } }
void second_display_layer_update_callback(Layer *me, GContext* ctx) { (void) me; time_t now = time(NULL); struct tm *t = localtime(&now); int32_t second_angle = t->tm_sec * (0xffff / 60); int second_hand_length = 70; GPoint center = grect_center_point(&GRECT_FULL_WINDOW); GPoint second = GPoint(center.x, center.y - second_hand_length); if (init_anim < ANIM_SECONDS) { second = GPoint(center.x, center.y - 70); } else if (init_anim == ANIM_SECONDS) { second_angle_anim += 0xffff / 60; if (second_angle_anim >= second_angle) { init_anim = ANIM_DONE; second = GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff, center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff); } else { second = GPoint(center.x + second_hand_length * sin_lookup(second_angle_anim)/0xffff, center.y + (-second_hand_length) * cos_lookup(second_angle_anim)/0xffff); } } else { second = GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff, center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff); } graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_line(ctx, center, second); }
void line_layer_update_callback(Layer *me, GContext* ctx) { (void)me; graphics_context_set_stroke_color(ctx, COLOR_LINES); graphics_draw_line(ctx, GPoint(PAGE_OFFSET_X + PAGE_W / 2, PAGE_DATA_TOP_H + 2), GPoint(PAGE_OFFSET_X + PAGE_W / 2, PAGE_H - 2)); graphics_context_set_fill_color(ctx, bg_color_data_main); graphics_fill_rect(ctx, GRect(0, PAGE_DATA_TOP_DATA_H, SCREEN_W, PAGE_DATA_MAIN_H), 0, GCornerNone); #ifndef PBL_SDK_2 graphics_context_set_fill_color(ctx, COLOR_LINES_DATA_MAIN); graphics_fill_rect(ctx, GRect(0, PAGE_DATA_TOP_DATA_H, SCREEN_W, 2), 0, GCornerNone); graphics_fill_rect(ctx, GRect(0, PAGE_DATA_BOTTOM_DATA_H, SCREEN_W, 2), 0, GCornerNone); #endif #ifdef ENABLE_NAVIGATION nav_draw_compass(ctx, NAVIGATION_COMPASS_CENTER, NAVIGATION_COMPASS_RECT, false); #endif if (s_data.data_subpage == SUBPAGE_UNDEF) { return; } #define GRECT_GRAPH GRect(PBL_IF_ROUND_ELSE(19, 1), 1, SCREEN_W - 2*PBL_IF_ROUND_ELSE(19, 1), PBL_IF_ROUND_ELSE(25,34)) #ifdef ENABLE_DEMO GraphData heartrates; int16_t points[GRAPH_NB_POINTS] = {135,145,150,148,150,155,162,170,180,185,182,175,170,160,155,163,165,155,162,164}; memcpy(heartrates.points, points, sizeof(int16_t)*GRAPH_NB_POINTS); GraphRange colors_heartrates[3] = { {.min = 140, .color = PBL_IF_COLOR_ELSE(GColorDarkGreen, GColorBlack)}, {.min = 150, .color = PBL_IF_COLOR_ELSE(GColorWindsorTan, GColorBlack)}, {.min = 170, .color = PBL_IF_COLOR_ELSE(GColorDarkCandyAppleRed, GColorBlack)}
static void progress_bar_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); int width = (int)(float)(((float)s_progress / 100.0F) * bounds.size.w); graphics_context_set_stroke_color(ctx, GColorWhite); graphics_draw_line(ctx, GPointZero, GPoint(width, 0)); }
static 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; get_time(&t); int32_t second_angle = TRIG_MAX_ANGLE * t.tm_sec / 60; 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; // 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); gpath_rotate_to(&s_data.minute_arrow, TRIG_MAX_ANGLE * t.tm_min / 60); gpath_draw_filled(ctx, &s_data.minute_arrow); gpath_draw_outline(ctx, &s_data.minute_arrow); 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); }
static void hour_line_update_proc(Layer *layer, GContext *ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); int32_t hour_angle = time_to_hour_angle(t); APP_LOG(APP_LOG_LEVEL_DEBUG, "Hour update at %d", (int) hour_angle); graphics_draw_line(ctx, center_point, calculate_angled_point(hour_angle, HOUR_RADIUS)); // TODO }
static void minute_line_update_proc(Layer *layer, GContext *ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); int32_t minute_angle = time_to_minute_angle(t); APP_LOG(APP_LOG_LEVEL_DEBUG, "Minute update at %d", (int) minute_angle); graphics_draw_line(ctx, center_point, calculate_angled_point(minute_angle, MINUTE_RADIUS)); // TODO }
static void hands_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); const GPoint center = grect_center_point(&bounds); const int16_t secondHandLength = bounds.size.w / 2; GPoint secondHand; time_t now = time(NULL); struct tm *t = localtime(&now); int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60; 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; // 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); gpath_rotate_to(minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60); gpath_draw_filled(ctx, minute_arrow); gpath_draw_outline(ctx, minute_arrow); gpath_rotate_to(hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6)); gpath_draw_filled(ctx, hour_arrow); gpath_draw_outline(ctx, 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); }
// This is called whenever the `boardLayer` layer needs to be redrawn. void boardLayer_update_callback(Layer *me, GContext* ctx) { graphics_context_set_stroke_color(ctx, COLOR_FOREGROUND); // Draw playing board grid // TODO: Change this to allow for a nicely centred circle in each square. // Vertical lines graphics_draw_line(ctx, GPoint(54, 19), GPoint(54, 123)); graphics_draw_line(ctx, GPoint(89, 19), GPoint(89, 123)); // Horizontal lines graphics_draw_line(ctx, GPoint(19, 54), GPoint(123, 54)); graphics_draw_line(ctx, GPoint(19, 89), GPoint(123, 89)); }
// callback function for rendering the background layer static void background_update_callback(Layer *me, GContext* ctx) { graphics_context_set_fill_color(ctx, COLOR_FOREGROUND); graphics_fill_rect(ctx, GRect(2,8,68,68), 4, GCornersAll); graphics_fill_rect(ctx, GRect(74,8,68,68), 4, GCornersAll); graphics_fill_rect(ctx, GRect(2,92,140,32), 4, GCornersAll); graphics_fill_rect(ctx, GRect(dateFormats[dateStyle].yx,128,68,32), 4, GCornersAll); graphics_fill_rect(ctx, GRect(dateFormats[dateStyle].mx,128,32,32), 4, GCornersAll); graphics_fill_rect(ctx, GRect(dateFormats[dateStyle].dx,128,32,32), 4, GCornersAll); graphics_context_set_stroke_color(ctx, COLOR_BACKGROUND); graphics_draw_line(ctx, GPoint(2,41), GPoint(142,41)); graphics_draw_line(ctx, GPoint(2,108), GPoint(142,108)); graphics_draw_line(ctx, GPoint(2,144), GPoint(142,144)); }
/* * Draw a bar for a particular 10 minute slice */ static void draw_bar_sector(GContext *ctx, GColor color, uint8_t position, int32_t stroke_width) { int32_t x = x_from_position(position); graphics_context_set_stroke_width(ctx, stroke_width); graphics_context_set_stroke_color(ctx, color); graphics_draw_line(ctx, GPoint(x, 0), GPoint(x, bar_height-7)); }
void sechand_update_proc(Layer *me, GContext *ctx) // The second-hand is drawn as a simple line, rather than using image // rotation. { // The second-hand has a "counterbalance", so we actually start // the other side of the center. static GPoint endpoint1, endpoint2; graphics_context_set_stroke_color(ctx, GColorWhite); // We could probably precalc these calculations, but screw it. The // length of the second-hand is the same as the radius of the // watchface, which is the same as watchface_center.x (as that's half // the width a.k.a. diameter) int32_t a = TRIG_MAX_ANGLE * pebble_time.tm_sec / 60; int16_t dy = (int16_t)(-cos_lookup(a) * (int32_t)watchface_center.x / TRIG_MAX_RATIO); int16_t dx = (int16_t)(sin_lookup(a) * (int32_t)watchface_center.x / TRIG_MAX_RATIO); // Draw a line _across_ the center to the edge of the face. endpoint1.x = watchface_center.x + dx; endpoint1.y = watchface_center.y + dy; endpoint2.x = watchface_center.x - dx/3; endpoint2.y = watchface_center.y - dy/3; graphics_draw_line(ctx, endpoint1, endpoint2); }
static void hands_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); const int16_t hourHandLength = bounds.size.w / 2 +20; const int16_t minuteHandLength = hourHandLength - 30; GPoint minuteHand; center.y +=20; time_t now = time(NULL); struct tm *t = localtime(&now); for (int i=0;i<12;i++) { int16_t minute_angle = TRIG_MAX_ANGLE * (((59-t->tm_min)+i*5)%60) / 60; minuteHand.y = (int16_t)(-cos_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.y; minuteHand.x = (int16_t)(sin_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.x; GRect frame = layer_get_frame(text_layer_get_layer(num_layer[i])); frame.origin.x = minuteHand.x-frame.size.w/2; frame.origin.y = minuteHand.y-frame.size.h/2; layer_set_frame(text_layer_get_layer(num_layer[i]),frame); layer_set_hidden(text_layer_get_layer(num_layer[i]),false); int16_t hour_angle = (TRIG_MAX_ANGLE * (((24-t->tm_hour+i) % 12) * 6) + ((TRIG_MAX_ANGLE * (60-t->tm_min)) / 10)) / (12 * 6); minuteHand.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.y; minuteHand.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.x; frame = layer_get_frame(text_layer_get_layer(hour_layer[i])); frame.origin.x = minuteHand.x-frame.size.w/2; frame.origin.y = minuteHand.y-frame.size.h/2; layer_set_frame(text_layer_get_layer(hour_layer[i]),frame); layer_set_hidden(text_layer_get_layer(hour_layer[i]),false); } // draw minute line if(getDrawline()) { if(getInvert()) graphics_context_set_stroke_color(ctx,GColorWhite); else graphics_context_set_stroke_color(ctx,GColorBlack); graphics_draw_line(ctx,GPoint(144/2,0),GPoint(144/2,167)); } // draw background transbitmap_draw_in_rect(background_bitmap, ctx, bounds); // draw date if(draw_date) { graphics_context_set_fill_color(ctx,GColorBlack); graphics_fill_circle(ctx,GPoint(120,120),16); layer_set_hidden(text_layer_get_layer(date_layer),false); } else layer_set_hidden(text_layer_get_layer(date_layer),true); }
void draw_wall(pixbuf_t *pixbuf){ //138 = brown, 14 = grey, 120=dark grey graphics_draw_rectangle(pixbuf, (280), (11), (360), (468), 14); int i, j, k; //Lines slow down the game speed by a fair bit. for (i = 0; i < 45; i++){ graphics_draw_line(pixbuf,280, 20+i*10, 360, 20+i*10, 138); if (i%2 == 0){ for (j = 0; j < 3; j++) graphics_draw_line(pixbuf, 300+j*20, 10+i*10, 300+j*20, 20+i*10, 120); } else{ for (j = 0; j < 4; j++) graphics_draw_line(pixbuf,290+j*20, 10+i*10, 290+j*20, 20+i*10, 120); } } }