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)); }
/* * Battery icon callback handler (called via icon bar update now) */ static void battery_layer_update_callback(Layer *layer, GContext *ctx, int *running_horizontal) { #ifdef PBL_COLOR graphics_context_set_compositing_mode(ctx, GCompOpSet); #else graphics_context_set_compositing_mode(ctx, GCompOpAssign); #endif if (!ui.battery_plugged) { paint_icon(ctx, running_horizontal, 24, RESOURCE_ID_BATTERY_ICON, BMP_CACHE_BATTERY_ICON); graphics_context_set_stroke_color(ctx, BACKGROUND_COLOR); #ifdef PBL_COLOR GColor b_color = BATTERY_BAR_COLOR; if (ui.battery_level <= 20) { b_color = BATTERY_BAR_COLOR_CRITICAL; } else if (ui.battery_level <= 40) { b_color = BATTERY_BAR_COLOR_WARN; } graphics_context_set_fill_color(ctx, b_color); #else graphics_context_set_fill_color(ctx, BATTERY_BAR_COLOR); #endif graphics_fill_rect(ctx, GRect(*running_horizontal + 7, 4, ui.battery_level / 9, 4), 0, GCornerNone); } else { paint_icon(ctx, running_horizontal, 24, RESOURCE_ID_BATTERY_CHARGE, BMP_CACHE_BATTERY_CHARGE); } }
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 } }
/* * 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)); }
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); }
void rot_bitmap_layer_update_func (Layer* l,GContext* ctx) { ROT_BITMAP_GET; GPoint topOffset=getTopOffset (); setTopOffset(GPoint(0,0)); GRect rect=GRect(0,0,l->frame.size.w,l->frame.size.h); SDL_Surface* sur=createSurface(rotbitmap->bitmap->bounds.size.w,rotbitmap->bitmap->bounds.size.h); SDL_FillRect(sur,0,0); graphics_context_set_compositing_mode (ctx,GCompOpAssign); graphics_draw_bitmap_in_rect_to (ctx,rotbitmap->bitmap,rect,sur); double angle=(double)rotbitmap->rotation/TRIG_MAX_ANGLE*360.0; SDL_Surface* rotated=rotozoomSurface(sur,-angle,1.0,SMOOTHING_OFF); SDL_FreeSurface(sur); GPoint offset=getPivotRotationOffset(rotbitmap->bitmap->bounds.size,GSize(rotated->w,rotated->h),rotbitmap->src_ic,angle); rotbitmap->dest_ic.x=l->frame.size.w/2; //TODO: Verify this rotbitmap->dest_ic.y=l->frame.size.h/2; setTopOffset(topOffset); if (rotbitmap->corner_clip_color!=GColorClear) { graphics_context_set_fill_color(ctx,rotbitmap->corner_clip_color); graphics_fill_rect(ctx,GRect(0,0,l->frame.size.w,l->frame.size.h),0,0); } graphics_context_set_compositing_mode (ctx,rotbitmap->compositing_mode); graphics_draw_surface_in_rect (ctx,rotated,GRect(rotbitmap->dest_ic.x-offset.x,rotbitmap->dest_ic.y-offset.y,rotated->w,rotated->h)); SDL_FreeSurface(rotated); }
/* * Bluetooth icon callback handler */ void bluetooth_layer_update_callback(Layer *layer, GContext *ctx) { if (bluetooth_ok) { graphics_context_set_compositing_mode(ctx, GCompOpAssign); } else { graphics_context_set_compositing_mode(ctx, GCompOpClear); } graphics_draw_bitmap_in_rect(ctx, icon_bluetooth, GRect(0, 0, 9, 12)); }
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 } }
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 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)); }
void update_time_display() { static char timeText[] = "00:00"; char *timeFormat; PblTm currentTime; GContext* ctx = app_get_current_graphics_context(); #ifdef INVERT_COLORS graphics_context_set_compositing_mode(ctx, GCompOpAssignInverted); #endif if (clock_is_24h_style()) { timeFormat = "%R"; } else { timeFormat = "%I:%M"; } get_time(¤tTime); string_format_time(timeText, sizeof(timeText), timeFormat, ¤tTime); // Kludge to handle lack of non-padded hour format string // for twelve hour clock. if (!clock_is_24h_style() && (timeText[0] == '0')) { memmove(timeText, &timeText[1], sizeof(timeText) - 1); } text_layer_set_text(&timeLayer, timeText); }
// 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 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)); }
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); }
// 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); }
/* * 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 }
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 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 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)); } } }
static void DrawStepsBars(Layer *layer, GContext *ctx) { graphics_context_set_compositing_mode(ctx, GCompOpSet); int MaxStepHis = GetMaxStepHistory(); float BestSteps = 1; for(int index = MaxStepHis-1; index >= 0; --index) { int thisHis = GetStepHistory(index); if(thisHis > BestSteps) BestSteps = thisHis; } graphics_context_set_fill_color(ctx, GColorFromRGB(255,255,0)); //APP_LOG(APP_LOG_LEVEL_DEBUG, "StepUpdate3"); for(int index = 0; index < MaxStepHis; ++index) { float thisHis = (float)GetStepHistory(index); int zSize = (thisHis / BestSteps) * 18; if(zSize <= 0) zSize = 1; graphics_fill_rect(ctx, GRect(index * 3, 18 - zSize, 2, zSize), 0, GCornerNone); } }
static void items_draw_strikethrough_on_item(GContext* ctx, Layer* cell_layer, TodoListItem* item) { graphics_context_set_compositing_mode(ctx, GCompOpClear); graphics_context_set_stroke_color(ctx, GColorBlack); graphics_context_set_fill_color(ctx, GColorBlack); GRect cell_bounds = cell_layer->bounds; static const int menu_cell_margin = 5; GSize text_cell_size = cell_bounds.size; text_cell_size.w -= 2 * menu_cell_margin; GRect text_cell_rect; text_cell_rect.origin = GPointZero; text_cell_rect.size = text_cell_size; GSize max_used_size = graphics_text_layout_get_max_used_size(ctx, item->text, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), text_cell_rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); GRect strike_through; strike_through.origin = cell_bounds.origin; strike_through.origin.x += menu_cell_margin; strike_through.origin.y += cell_bounds.size.h / 2; strike_through.size = (GSize) { max_used_size.w, 2 }; // Stretch the strikethrough to be slightly wider than the text static const int pixel_nudge = 2; strike_through.origin.x -= pixel_nudge; strike_through.size.w += 2 * pixel_nudge; graphics_fill_rect(ctx, strike_through, 0, GCornerNone); }
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { char* text; GBitmap* icon; int16_t index = cell_index->row; if (index == 0) { text = "Call History"; icon = callHistoryIcon; } else if (index == 1) { text = "All contacts"; icon = contactsIcon; } else { text = groupNames[index - 2]; icon = contactGroupIcon; } graphics_context_set_compositing_mode(ctx, PNG_COMPOSITING_MODE); menu_cell_basic_draw(ctx, cell_layer, text, NULL, icon); }
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)); } } }
static void updateFast(Layer *layer, GContext *ctx) { update_state(); graphics_context_set_compositing_mode(ctx, GCompOpAssign); graphics_draw_bitmap_in_rect(ctx, s_bmap_bg, GRect(0,0,144, 168)); graphics_context_set_compositing_mode(ctx, GCompOpAssign); sprite_draw( RESOURCE_ID_IMAGE_ROCKET, layer,ctx ); if( s_enableParticles ) { graphics_context_set_stroke_color(ctx,GColorWhite); // ugh, fixme. update_particles(layer,ctx); } }
static void update_proc(Layer* layer, GContext* ctx) { graphics_context_set_compositing_mode(ctx, GCompOpAssign); GRect rect = gbitmap_get_bounds(s_bitmap_battery); // draw battery mark GBitmap* bmp = s_charge_state.is_charging ? s_bitmap_battery_charging : s_bitmap_battery; graphics_draw_bitmap_in_rect(ctx, bmp, rect); // get number int num = s_charge_state.charge_percent / 10; GPoint p = { .x = rect.size.w + MARGIN, .y = ((rect.size.h - TN_HEIGHT) >> 1) + 1 }; if (num < 10) { graphics_draw_tiny_number(ctx, num, p.x, p.y); } else { graphics_draw_tiny_letter(ctx, 'F', p.x, p.y); } } void watch_battery_layer_create() { if (!s_bitmap_battery) { s_bitmap_battery = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WATCH_BATTERY); s_bitmap_battery_charging = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_WATCH_BATTERY_CHARGING); } if (!s_layer) { GRect rect = gbitmap_get_bounds(s_bitmap_battery); rect.size.w += MARGIN + TN_WIDTH; rect.origin.x = SX - SPACING_X - 1 - rect.size.w; rect.origin.y = SY + CH * WN + SPACING_Y; s_layer = layer_create(rect); layer_set_update_proc(s_layer, update_proc); } } void watch_battery_layer_destroy() { if (s_bitmap_battery) { gbitmap_destroy(s_bitmap_battery_charging); s_bitmap_battery_charging = NULL; gbitmap_destroy(s_bitmap_battery); s_bitmap_battery = NULL; } if (s_layer) { layer_destroy(s_layer); s_layer = NULL; } } Layer* watch_battery_layer_get_layer() { return s_layer; } void watch_battery_layer_update(BatteryChargeState state) { s_charge_state = state; }
static void IconUpdateProc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GRect bitmap_bounds = gbitmap_get_bounds(s_icon_bitmap); graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, s_icon_bitmap, (GRect) { .origin = bounds.origin, .size = bitmap_bounds.size });
/* * 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 rotbmp_layer_update_func (Layer* me,GContext* ctx) { GPoint topOffset=getTopOffset (); setTopOffset(GPoint(0,0)); GRect rect=GRect(0,0,me->frame.size.w,me->frame.size.h); RotBitmapLayer* bitmapLayer=(RotBitmapLayer*)me; SDL_Surface* bitmap=createSurface(bitmapLayer->bitmap->bounds.size.w,bitmapLayer->bitmap->bounds.size.h); SDL_FillRect(bitmap,0,0); graphics_context_set_compositing_mode (ctx,GCompOpAssign); graphics_draw_bitmap_in_rect_to (ctx,bitmapLayer->bitmap,rect,bitmap); double angle=(double)bitmapLayer->rotation/TRIG_MAX_ANGLE*360.0; SDL_Surface* rotated=rotozoomSurface(bitmap,-angle,1.0,SMOOTHING_OFF); SDL_FreeSurface(bitmap); GPoint offset=getPivotRotationOffset(bitmapLayer->bitmap->bounds.size,GSize(rotated->w,rotated->h),bitmapLayer->src_ic,angle); setTopOffset(topOffset); graphics_context_set_compositing_mode (ctx,bitmapLayer->compositing_mode); graphics_draw_surface_in_rect (ctx,rotated,GRect(bitmapLayer->dest_ic.x-offset.x,bitmapLayer->dest_ic.y-offset.y,rotated->w,rotated->h)); SDL_FreeSurface(rotated); }
void bitmap_layer_update_func (Layer* l,GContext* ctx) { BITMAP_GET; GRect rect=GRect(0,0,l->frame.size.w,l->frame.size.h); graphics_context_set_fill_color(ctx,bitmap->background_color); graphics_fill_rect (ctx,rect,0,0); rect.origin=l->frame.origin; grect_align (&rect,&l->frame,bitmap->alignment,l->clips); rect.origin.x-=l->frame.origin.x; rect.origin.y-=l->frame.origin.y; graphics_context_set_compositing_mode (ctx,bitmap->compositing_mode); graphics_draw_bitmap_in_rect (ctx,bitmap->bitmap,rect); }