void action_bar_update_handler (Layer* me,GContext* ctx) { ActionBarLayer* bar=(ActionBarLayer*)me; GCompOp compOp; //TODO: implement corner_mask in graphics_fill_rect graphics_context_set_fill_color (ctx,bar->background_color); graphics_fill_rect (ctx,GRect(0,0,me->frame.size.w+3,me->frame.size.h),3,0); if (bar->icons[0]!=0) { if (bar->is_highlighted&(1<<0)) compOp=GCompOpAssignInverted; else compOp=GCompOpAssign; graphics_context_set_compositing_mode(ctx,compOp); graphics_draw_bitmap_in_rect (ctx,bar->icons[0],GRect(11-bar->icons[0]->bounds.size.w/2,20+11-bar->icons[0]->bounds.size.h,bar->icons[0]->bounds.size.w,bar->icons[0]->bounds.size.h)); } if (bar->icons[1]!=0) { if (bar->is_highlighted&(1<<1)) compOp=GCompOpAssignInverted; else compOp=GCompOpAssign; graphics_context_set_compositing_mode(ctx,compOp); graphics_draw_bitmap_in_rect (ctx,bar->icons[1],GRect(11-bar->icons[1]->bounds.size.w/2,me->frame.size.h/2-bar->icons[1]->bounds.size.h/2,bar->icons[1]->bounds.size.w,bar->icons[1]->bounds.size.h)); } if (bar->icons[2]!=0) { if (bar->is_highlighted&(1<<2)) compOp=GCompOpAssignInverted; else compOp=GCompOpAssign; graphics_context_set_compositing_mode(ctx,compOp); graphics_draw_bitmap_in_rect (ctx,bar->icons[2],GRect(11-bar->icons[2]->bounds.size.w/2,me->frame.size.h-20-11-bar->icons[2]->bounds.size.h,bar->icons[2]->bounds.size.w,bar->icons[2]->bounds.size.h)); } }
// Draws the frame and optionally fills the background of the current date window. void draw_date_window_background(GContext *ctx, unsigned int fg_draw_mode, unsigned int bg_draw_mode, bool opaque_layer) { if (opaque_layer || bg_draw_mode != fg_draw_mode) { if (date_window_mask.bitmap == NULL) { date_window_mask = rle_bwd_create(RESOURCE_ID_DATE_WINDOW_MASK); if (date_window_mask.bitmap == NULL) { trigger_memory_panic(__LINE__); return; } } graphics_context_set_compositing_mode(ctx, draw_mode_table[bg_draw_mode].paint_mask); graphics_draw_bitmap_in_rect(ctx, date_window_mask.bitmap, date_window_box); } if (date_window.bitmap == NULL) { date_window = rle_bwd_create(RESOURCE_ID_DATE_WINDOW); if (date_window.bitmap == NULL) { bwd_destroy(&date_window_mask); trigger_memory_panic(__LINE__); return; } } graphics_context_set_compositing_mode(ctx, draw_mode_table[fg_draw_mode].paint_fg); graphics_draw_bitmap_in_rect(ctx, date_window.bitmap, date_window_box); }
static void paint_weather_icon(WeatherIcon *aIcon, GContext *aCtx, GRect r, GPoint aCenter, int32_t aRadius, bool aZoomedIn) { // background #ifdef PBL_COLOR graphics_context_set_fill_color(aCtx, GColorVividCerulean); graphics_fill_circle(aCtx, aCenter, aRadius); #else fill_dithered_circle(aCtx, aCenter, aRadius, PATTERN_50); #endif #ifndef PBL_COLOR GBitmap* mask = weather_icon_get_mask(aIcon); graphics_context_set_compositing_mode(aCtx, GCompOpClear); for (int dx = -1; dx <= +1; ++dx) { for (int dy = -1; dy <= +1; ++dy) { graphics_draw_bitmap_in_rect(aCtx, mask, GRect( dx + 1 + (r.size.w - WEATHER_ICON_SIZE) / 2, dy + (r.size.h - WEATHER_ICON_SIZE) / 2, WEATHER_ICON_SIZE, WEATHER_ICON_SIZE)); } } #endif GBitmap* weather = weather_icon_get_weather(aIcon); graphics_context_set_compositing_mode(aCtx, GCompOpSet); graphics_draw_bitmap_in_rect(aCtx, weather, GRect( 1 + (r.size.w - WEATHER_ICON_SIZE) / 2, (r.size.h - WEATHER_ICON_SIZE) / 2, WEATHER_ICON_SIZE, WEATHER_ICON_SIZE)); }
void chrono_dial_layer_update_callback(Layer *me, GContext *ctx) { // app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "chrono_dial_layer"); if (config.chrono_dial != CDM_off) { if (chrono_dial_white.bitmap == NULL) { load_chrono_dial(); if (chrono_dial_white.bitmap == NULL) { trigger_memory_panic(__LINE__); return; } } GRect destination = layer_get_bounds(me); destination.origin.x = 0; destination.origin.y = 0; #ifdef PBL_PLATFORM_APLITE graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode].paint_fg); graphics_draw_bitmap_in_rect(ctx, chrono_dial_black.bitmap, destination); graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode].paint_bg); graphics_draw_bitmap_in_rect(ctx, chrono_dial_white.bitmap, destination); #else // PBL_PLATFORM_APLITE graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, chrono_dial_white.bitmap, destination); #endif // PBL_PLATFORM_APLITE } }
void draw_chrono_dial(GContext *ctx) { // app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "draw_chrono_dial"); if (config.chrono_dial != CDM_off) { #ifdef PBL_PLATFORM_APLITE BitmapWithData chrono_dial_black; if (chrono_dial_shows_tenths) { chrono_dial_black = rle_bwd_create(RESOURCE_ID_CHRONO_DIAL_TENTHS_BLACK); } else { chrono_dial_black = rle_bwd_create(RESOURCE_ID_CHRONO_DIAL_HOURS_BLACK); } if (chrono_dial_black.bitmap == NULL) { bwd_destroy(&chrono_dial_black); trigger_memory_panic(__LINE__); } #endif // PBL_PLATFORM_APLITE // In Basalt, we only load the "white" image. if (chrono_dial_white.bitmap == NULL) { if (chrono_dial_shows_tenths) { chrono_dial_white = rle_bwd_create(RESOURCE_ID_CHRONO_DIAL_TENTHS_WHITE); } else { chrono_dial_white = rle_bwd_create(RESOURCE_ID_CHRONO_DIAL_HOURS_WHITE); } if (chrono_dial_white.bitmap == NULL) { trigger_memory_panic(__LINE__); return; } // We apply the color scheme as needed. remap_colors_clock(&chrono_dial_white); } int x = chrono_tenth_hand_def.place_x - chrono_dial_size.w / 2; int y = chrono_tenth_hand_def.place_y - chrono_dial_size.h / 2; GRect destination = GRect(x, y, chrono_dial_size.w, chrono_dial_size.h); #ifdef PBL_PLATFORM_APLITE graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode ^ APLITE_INVERT].paint_fg); graphics_draw_bitmap_in_rect(ctx, chrono_dial_black.bitmap, destination); graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode ^ APLITE_INVERT].paint_bg); graphics_draw_bitmap_in_rect(ctx, chrono_dial_white.bitmap, destination); #else // PBL_PLATFORM_APLITE graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, chrono_dial_white.bitmap, destination); #endif // PBL_PLATFORM_APLITE if (!keep_assets) { bwd_destroy(&chrono_dial_white); } #ifdef PBL_PLATFORM_APLITE bwd_destroy(&chrono_dial_black); #endif // PBL_PLATFORM_APLITE } }
/* * Battery icon callback handler */ void battery_layer_update_callback(Layer *layer, GContext *ctx) { graphics_context_set_compositing_mode(ctx, GCompOpAssign); if (!battery_plugged && ((battery_level<=20) || (battery_level>=90))) { graphics_draw_bitmap_in_rect(ctx, icon_battery, GRect(0, 0, 24, 12)); graphics_context_set_stroke_color(ctx, GColorBlack); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, GRect(7, 4, (uint8_t)((battery_level / 100.0) * 11.0), 4), 0, GCornerNone); } else if (battery_plugged) { graphics_draw_bitmap_in_rect(ctx, icon_battery_charge, GRect(0, 0, 24, 12)); } }
void timer_draw_row(Timer* timer, GContext* ctx) { char* time_left = malloc(12); timer_time_str(timer->current_time, settings()->timers_hours, time_left, 12); graphics_context_set_text_color(ctx, GColorBlack); graphics_context_set_fill_color(ctx, GColorBlack); graphics_draw_text(ctx, time_left, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), GRect(33, -3, PEBBLE_WIDTH - 33, 28), GTextOverflowModeFill, GTextAlignmentLeft, NULL); GBitmap* bmp_icon = NULL; GBitmap* bmp_direction = NULL; switch (timer->status) { case TIMER_STATUS_STOPPED: bmp_icon = bitmaps_get_sub_bitmap(RESOURCE_ID_ICONS_16, ICON_RECT_STOP); break; case TIMER_STATUS_RUNNING: bmp_icon = bitmaps_get_sub_bitmap(RESOURCE_ID_ICONS_16, ICON_RECT_PLAY); break; case TIMER_STATUS_PAUSED: bmp_icon = bitmaps_get_sub_bitmap(RESOURCE_ID_ICONS_16, ICON_RECT_PAUSE); break; case TIMER_STATUS_DONE: bmp_icon = bitmaps_get_sub_bitmap(RESOURCE_ID_ICONS_16, ICON_RECT_DONE); break; } if (bmp_icon) { graphics_draw_bitmap_in_rect(ctx, bmp_icon, GRect(8, 8, 16, 16)); } switch (timer->type) { case TIMER_TYPE_TIMER: bmp_direction = bitmaps_get_sub_bitmap(RESOURCE_ID_ICONS_16, ICON_RECT_TIMER); break; case TIMER_TYPE_STOPWATCH: bmp_direction = bitmaps_get_sub_bitmap(RESOURCE_ID_ICONS_16, ICON_RECT_STOPWATCH); break; } if (bmp_direction) { graphics_draw_bitmap_in_rect(ctx, bmp_direction, GRect(PEBBLE_WIDTH - 8 - 8, 9, 8, 16)); } if (timer->type == TIMER_TYPE_TIMER) { uint8_t width = (144 * timer->current_time) / timer->length; graphics_fill_rect(ctx, GRect(0, 31, width, 2), 0, GCornerNone); } free(time_left); }
/* * Status icon callback handler */ void status_layer_update_callback(Layer *layer, GContext *ctx) { graphics_context_set_compositing_mode(ctx, GCompOpAssign); if (status_display == STATUS_REQUEST) { graphics_draw_bitmap_in_rect(ctx, &icon_status_1.bmp, GRect(0, 0, 38, 9)); } else if (status_display == STATUS_REPLY) { graphics_draw_bitmap_in_rect(ctx, &icon_status_2.bmp, GRect(0, 0, 38, 9)); } else if (status_display == STATUS_ALERT_SET) { graphics_draw_bitmap_in_rect(ctx, &icon_status_3.bmp, GRect(0, 0, 38, 9)); } }
static void bluetooth_layer_update_callback(Layer *layer, GContext *ctx) { bool connected = bluetooth_connection_service_peek(); // Draw bluetooth icon graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, s_bluetooth_image, gbitmap_get_bounds(s_bluetooth_image)); // Draw cross if not connected if (!connected) { graphics_draw_bitmap_in_rect(ctx, s_cross_image, gbitmap_get_bounds(s_cross_image)); } }
static void layer_update_callback(Layer *me, GContext* ctx) { if(isAnimating){ graphics_draw_bitmap_in_rect(ctx, tmp_image, displayBounds); } else { graphics_draw_bitmap_in_rect(ctx, from_image, displayBounds); } if(isAnimating){ timer = app_timer_register(50 /* milliseconds */, timer_callback, NULL); } }
static void update_proc(Layer* layer, GContext* ctx) { graphics_context_set_compositing_mode(ctx, GCompOpAssign); // draw bluetooth mark GRect rect = gbitmap_get_bounds(s_bitmap_bluetooth); graphics_draw_bitmap_in_rect(ctx, s_bitmap_bluetooth, rect); // draw yes/no GBitmap* bmp = s_bt_on ? s_bitmap_yes : s_bitmap_no; GRect rect_yn = gbitmap_get_bounds(bmp); rect_yn.origin.x = rect.origin.x + rect.size.w + MARGIN; rect_yn.origin.y = rect.origin.y + ((rect.size.h - rect_yn.size.h) >> 1); graphics_draw_bitmap_in_rect(ctx, bmp, rect_yn); }
/* * Battery icon callback handler */ void battery_layer_update_callback(Layer *layer, GContext *ctx) { graphics_context_set_compositing_mode(ctx, GCompOpAssign); if (battery_status.state == 1 && battery_status.level > 0 && battery_status.level <= 100) { graphics_draw_bitmap_in_rect(ctx, &icon_battery.bmp, GRect(0, 0, 24, 12)); graphics_context_set_stroke_color(ctx, GColorBlack); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_rect(ctx, GRect(7, 4, (uint8_t)((battery_status.level / 100.0) * 11.0), 4), 0, GCornerNone); } else if (battery_status.state == 2 || battery_status.state == 3) { graphics_draw_bitmap_in_rect(ctx, &icon_battery_charge.bmp, GRect(0, 0, 24, 12)); } }
void menu_cell_draw_other(GContext* ctx, const Layer *cell_layer, const char *title, GBitmap ** icon) { GRect bounds = layer_get_frame(cell_layer); #ifndef PBL_SDK_3 graphics_context_set_text_color(ctx, GColorBlack); #endif graphics_draw_text(ctx, title, FONT_GOTHIC_24_BOLD, GRect(MENU_ICON_SPACE, -4, bounds.size.w-MENU_ICON_SPACE, 4+18), GTextOverflowModeFill, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft), NULL); #ifdef PBL_ROUND uint8_t text_width=graphics_text_layout_get_content_size(title, FONT_GOTHIC_24_BOLD, GRect(MENU_ICON_SPACE, -4, bounds.size.w-MENU_ICON_SPACE, 4+18), GTextOverflowModeFill, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft)).w; if (icon) graphics_draw_bitmap_in_rect(ctx, icon[PBL_IF_SDK_3_ELSE(menu_cell_layer_is_highlighted(cell_layer), 0)], GRect((bounds.size.w-text_width)/2-16-6,(bounds.size.h-16)/2, 16, 16)); #else if (icon) graphics_draw_bitmap_in_rect(ctx, icon[PBL_IF_SDK_3_ELSE(menu_cell_layer_is_highlighted(cell_layer), 0)], GRect(6,(bounds.size.h-16)/2, 16, 16)); #endif }
// Draws a date window with the current lunar phase. void draw_lunar_window(Layer *me, GContext *ctx, DateWindowMode dwm, bool invert, bool opaque_layer) { // The draw_mode is the color to draw the frame of the date window. unsigned int draw_mode = invert ^ config.draw_mode; // The moon_draw_mode is the color to draw the moon within the date window. unsigned int moon_draw_mode = draw_mode; if (config.lunar_background) { // If the user specified an always-black background, that means moon_draw_mode is always 1. moon_draw_mode = 1; } draw_date_window_background(ctx, draw_mode, moon_draw_mode, opaque_layer); if (moon_bitmap.bitmap == NULL) { assert(current_placement.lunar_phase <= 7); if (moon_draw_mode == 0) { moon_bitmap = rle_bwd_create(RESOURCE_ID_MOON_BLACK_0 + current_placement.lunar_phase); } else { moon_bitmap = rle_bwd_create(RESOURCE_ID_MOON_WHITE_0 + current_placement.lunar_phase); } if (moon_bitmap.bitmap == NULL) { trigger_memory_panic(__LINE__); return; } if (config.lunar_direction) { // Draw the moon phases animating from left-to-right, as seen in // the southern hemisphere. (This really means drawing the moon // upside-down, as it would be seen by someone facing north.) flip_bitmap_x(moon_bitmap.bitmap, NULL); flip_bitmap_y(moon_bitmap.bitmap, NULL); } } // Draw the moon in the fg color. This will be black-on-white if // moon_draw_mode = 0, or white-on-black if moon_draw_mode = 1. // Since we have selected the particular moon resource above based // on draw_mode, we will always draw the moon in the correct color, // so that it looks like the moon. (Drawing the moon in the // inverted color would look weird.) graphics_context_set_compositing_mode(ctx, draw_mode_table[moon_draw_mode].paint_black); if (config.lunar_direction) { graphics_draw_bitmap_in_rect(ctx, moon_bitmap.bitmap, date_window_box_offset); } else { graphics_draw_bitmap_in_rect(ctx, moon_bitmap.bitmap, date_window_box); } }
static void prv_hands_layer_update_proc(Layer *layer, GContext *ctx) { const SprinklesConfiguration *configuration = sprinkles_configuration_get_configuration(); const GRect layer_bounds = layer_get_bounds(layer); const GPoint center = grect_center_point(&layer_bounds); // Minutes const int32_t minutes_angle = s_app_data->current_minutes * TRIG_MAX_ANGLE / 60; const int32_t minutes_hand_length = layer_bounds.size.w * 4 / 9; prv_draw_major_hands(ctx, ¢er, minutes_hand_length, minutes_angle, configuration->minute_hand_color); // Hours int32_t hours_angle = ((s_app_data->current_hours * TRIG_MAX_ANGLE) + minutes_angle) / 12; const int32_t hours_hand_length = layer_bounds.size.w * 32 / 100; prv_draw_major_hands(ctx, ¢er, hours_hand_length, hours_angle, configuration->hour_hand_color); // Seconds (if enabled in the configuration) if (configuration->seconds_hand_enabled) { prv_draw_seconds_hand(ctx, &layer_bounds, ¢er); } // Draw the dot in the center of the watchface const int16_t center_circle_radius = 5; graphics_context_set_fill_color(ctx, configuration->center_dot_color); graphics_fill_circle(ctx, center, center_circle_radius); // Draw the donut const int32_t donut_angle = prv_get_donut_angle(); const GRect donut_rect = prv_get_donut_rect(&layer_bounds, donut_angle); graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, s_app_data->donut_bitmap, donut_rect); }
static void layer_update_callback2(Layer *layer, GContext* ctx) { // We make sure the dimensions of the GRect to draw into // are equal to the size of the bitmap--otherwise the image // will automatically tile. Which might be what *you* want. GSize image_size = gbitmap_get_bounds(s_image2).size; graphics_draw_bitmap_in_rect(ctx, s_image2, GRect(22, 142, 31, 20)); }
/* * Bluetooth icon callback handler */ void bt_layer_update_callback(Layer *layer, GContext *ctx) { if (bt_ok) graphics_context_set_compositing_mode(ctx, GCompOpAssign); else graphics_context_set_compositing_mode(ctx, GCompOpClear); graphics_draw_bitmap_in_rect(ctx, icon_bt, GRect(0, 0, 9, 12)); }
static void draw_row_callback(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *context) { if(cell_index->row == CHECKBOX_WINDOW_NUM_ROWS) { // Submit item menu_cell_basic_draw(ctx, cell_layer, "Submit", NULL, NULL); } else { // Choice item static char s_buff[16]; snprintf(s_buff, sizeof(s_buff), "Choice %d", (int)cell_index->row); menu_cell_basic_draw(ctx, cell_layer, s_buff, NULL, NULL); // Selected? GBitmap *ptr = tick_black_bitmap; if(menu_cell_layer_is_highlighted(cell_layer)) { graphics_context_set_stroke_color(ctx, GColorWhite); ptr = tick_white_bitmap; } GRect bounds = layer_get_bounds(cell_layer); GRect bitmap_bounds = gbitmap_get_bounds(ptr); // Draw checkbox GRect r = GRect( bounds.size.w - (2 * CHECKBOX_WINDOW_BOX_SIZE), (bounds.size.h / 2) - (CHECKBOX_WINDOW_BOX_SIZE / 2), CHECKBOX_WINDOW_BOX_SIZE, CHECKBOX_WINDOW_BOX_SIZE); graphics_draw_rect(ctx, r); if(s_selections[cell_index->row]) { graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, ptr, GRect(r.origin.x, r.origin.y - 3, bitmap_bounds.size.w, bitmap_bounds.size.h)); } } }
/* * This is the menu item draw callback where you specify what each item should look like */ static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { #ifdef PBL_COLOR graphics_context_set_compositing_mode(ctx, GCompOpSet); #endif // Pick up names from the array except for the one instance where we fiddle with it int16_t index = cell_index->row + menu_slide; const char *subtitle = menu_def[index].subtitle; const char *title = menu_def[index].title; GBitmap *icon = menu_def[index].state == NULL ? NULL : menu_icons[*(menu_def[index].state)]; if ((menu_def[index].feature & FEATURE_WAKEUP) == FEATURE_WAKEUP && auto_reset_state == 1 && original_auto_reset_state == 1) { snprintf(menu_text, sizeof(menu_text), MENU_AUTO_RESET_DES_ON, twenty_four_to_twelve(get_config_data()->autohr), get_config_data()->automin, am_pm_text(get_config_data()->autohr)); subtitle = menu_text; } else if ((menu_def[index].feature & FEATURE_SMART_ALARM) == FEATURE_SMART_ALARM) { copy_alarm_time_range_into_field(menu_text, sizeof(menu_text)); subtitle = menu_text; } #ifndef PBL_ROUND menu_cell_basic_draw(ctx, cell_layer, title, subtitle, icon); #else menu_cell_basic_draw(ctx, cell_layer, title, subtitle, NULL); if (icon != NULL && menu_layer_get_selected_index(menu_layer).row == cell_index->row) { graphics_draw_bitmap_in_rect(ctx, icon, GRect(10, 7, 24, 28)); } #endif }
void menu_cell_basic_draw_multiline_with_extra_title(GContext* ctx, const Layer *cell_layer, char *title, char *right_title, char *subtitle, GBitmap *icon) { GRect bounds = layer_get_frame(cell_layer); graphics_context_set_text_color (ctx, GColorBlack); // Line 1 if (icon != NULL) { graphics_draw_bitmap_in_rect(ctx, icon, GRect(2, 2, 20, 20)); } graphics_draw_text(ctx, title, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(26, -5, bounds.size.w - 5, 26), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, right_title, fonts_get_system_font(FONT_KEY_GOTHIC_24), GRect(bounds.size.w/2, 16, bounds.size.w/2 - 5, 26), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); // Line 2 graphics_draw_text(ctx, subtitle, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(5, 21, bounds.size.w-10, 40), 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); }
// This is a layer update callback where compositing will take place static void layer_update_callback(Layer *layer, GContext* ctx) { GRect bounds = layer_get_frame(layer); // Display the name of the current compositing operation graphics_context_set_text_color(ctx, GColorBlack); graphics_draw_text(ctx, gcompops[current_gcompop].name, fonts_get_system_font(FONT_KEY_GOTHIC_18), bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); // Draw the large circle the image will composite with graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, GPoint(bounds.size.w/2, bounds.size.h+110), 180); // Use the image size to help center the image GRect destination = image->bounds; // Center horizontally using the window frame size destination.origin.x = (bounds.size.w-destination.size.w)/2; destination.origin.y = 50; // Set the current compositing operation // This will only cause bitmaps to composite graphics_context_set_compositing_mode(ctx, gcompops[current_gcompop].op); // Draw the bitmap; it will use current compositing operation set graphics_draw_bitmap_in_rect(ctx, image, destination); }
static void background_layer_update(Layer* layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GBitmap *bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_1); graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, bitmap, bounds); gbitmap_destroy(bitmap); }
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { bool hasNumberType = strlen(getNumber(cell_index->row)) > 0; graphics_context_set_text_color(ctx, GColorBlack); graphics_draw_text(ctx, getName(cell_index->row), fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(35, 0, SCREEN_WIDTH - 30, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, getDate(cell_index->row), fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(35, 20, SCREEN_WIDTH - 30, 15), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); if (hasNumberType) graphics_draw_text(ctx, getNumber(cell_index->row), fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD), GRect(35, 35, SCREEN_WIDTH - 30, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); GBitmap* image; switch (getType(cell_index->row)) { case 1: image = incomingCall; break; case 2: image = outgoingCall; break; default: image = missedCall; break; } graphics_context_set_compositing_mode(ctx, PNG_COMPOSITING_MODE); graphics_draw_bitmap_in_rect(ctx, image, GRect(3, hasNumberType ? 14 : 5, 28, 28)); }
static void draw_row_callback(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *context) { static char title[16]; int i = (int)cell_index->row; if (i == SETTINGS_CHECKBOX_NUM_ROWS) { menu_cell_basic_draw(ctx, cell_layer, SETTINGS_CHECKBOX_SUBMIT_HINT, NULL, NULL); } else { snprintf(title, sizeof(title), "%s", MenuItem[i]); menu_cell_basic_draw(ctx, cell_layer, title, NULL, NULL); // Selected? GBitmap *ptr = s_tick_black_bitmap; if(menu_cell_layer_is_highlighted(cell_layer)) { graphics_context_set_stroke_color(ctx, GColorWhite); ptr = s_tick_white_bitmap; } GRect bounds = layer_get_bounds(cell_layer); GRect bitmap_bounds = gbitmap_get_bounds(ptr); // Draw checkbox GRect r = GRect( bounds.size.w - (2 * SETTINGS_CHECKBOX_BOX_SIZE), (bounds.size.h / 2) - (SETTINGS_CHECKBOX_BOX_SIZE / 2), SETTINGS_CHECKBOX_BOX_SIZE, SETTINGS_CHECKBOX_BOX_SIZE); graphics_draw_rect(ctx, r); if(MenuSelection[cell_index->row]) { graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, ptr, GRect(r.origin.x, r.origin.y - 3, bitmap_bounds.size.w, bitmap_bounds.size.h)); } } }
void clock_face_layer_update_callback(Layer *me, GContext *ctx) { // app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "clock_face_layer"); if (memory_panic_count > 5) { // In case we're in extreme memory panic mode--too little // available memory to even keep the clock face resident--we do // nothing in this function. return; } // Load the clock face from the resource file if we haven't already. if (clock_face.bitmap == NULL) { clock_face = rle_bwd_create(clock_face_table[config.face_index]); if (clock_face.bitmap == NULL) { trigger_memory_panic(__LINE__); return; } } // Draw the clock face into the layer. GRect destination = layer_get_bounds(me); destination.origin.x = 0; destination.origin.y = 0; graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode].paint_assign); graphics_draw_bitmap_in_rect(ctx, clock_face.bitmap, destination); }
static void ring_layer_update(Layer *layer, GContext *ctx) { if (data_loaded) { const GRect entire_screen = GRect(0, 0, 180, 180); draw_circle(ctx, entire_screen, GColorWhite, 20, 360); graphics_context_set_stroke_color(ctx, GColorOxfordBlue); graphics_context_set_stroke_width(ctx, 10); const GRect time_orbit = GRect(10, 10, 160, 160); int degree_icon = degreeify(hour, minute); int degree_rise = degreeify(hour_rise, minute_rise); int degree_set = degreeify(hour_set, minute_set); GBitmap *icon = degree_icon >= degree_set && degree_icon <= degree_rise ? moon : sun; const GRect icon_space = grect_centered_from_polar( time_orbit, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(degree_icon), GSize(18, 18) ); graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, icon, icon_space); } }
static void windshield_proc(Layer *layer, GContext *ctx) { // fill it first graphics_context_set_fill_color(ctx, jeep_color); gpath_draw_filled(ctx,s_windshield_path); // now stroke it graphics_context_set_stroke_width(ctx, 1); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_draw_outline(ctx, s_windshield_path); // glass graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(4, 4, 136, 50), 3, GCornersAll); graphics_context_set_fill_color(ctx, background_color); graphics_fill_rect(ctx, GRect(5, 5, 134, 48), 3, GCornersAll); // forest // graphics_context_set_compositing_mode(ctx, GCompOpSet); // graphics_draw_bitmap_in_rect(ctx, s_forest_image, GRect( 6, 6, 132, 46)); // logo graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, s_logo_image, GRect( 14, 6, 117, 46)); }
// Draw configure on phone dialog void drawing_config(GContext *ctx, GSize window_size, GBitmap *bmp) { // set drawing colors graphics_context_set_fill_color(ctx, COLOR_PAUSED_FORE); #ifdef PBL_COLOR graphics_context_set_text_color(ctx, GColorBlack); #else graphics_context_set_text_color(ctx, GColorWhite); #endif // draw background graphics_fill_rect(ctx, GRect(0, 0, window_size.w, window_size.h), 1, GCornerNone); // draw image GRect bmp_size = gbitmap_get_bounds(bmp); #ifdef PBL_COLOR graphics_context_set_compositing_mode(ctx, GCompOpSet); #endif graphics_draw_bitmap_in_rect(ctx, bmp, GRect((window_size.w - bmp_size.size.w) / 2, (window_size.h - bmp_size.size.h) / 2 - 5, bmp_size.size.w, bmp_size.size.h)); // draw title graphics_draw_text(ctx, "7 Minute+", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(0, 7, window_size.w, 28), GTextOverflowModeFill, GTextAlignmentCenter, NULL); // draw footer graphics_draw_text(ctx, "Set up in the Pebble app", fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(10, 120, window_size.w - 20, 48), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); }
void bars_update_callback(Layer *me, GContext* ctx) { (void)me; (void)ctx; for (int i=0; i<=5; i++) { GRect destination = layer_get_frame(&bar_off.layer.layer); destination.origin.x = 0; destination.origin.y = 115 - i*23; if (i <= power && on) { graphics_draw_bitmap_in_rect(ctx, &bar_on.bmp, destination); } else { graphics_draw_bitmap_in_rect(ctx, &bar_off.bmp, destination); } } }