GRect buttons_get_sprite_layer_bounds(Buttons *buttons) { int x = buttons->hunger_button->button_pos.x; int y = buttons->hunger_button->button_pos.y + gbitmap_get_bounds(buttons->hunger_button->bitmap).size.h; int width = PEBBLE_WIDTH; int height = PEBBLE_HEIGHT - y + gbitmap_get_bounds(buttons->settings_button->bitmap).size.h; return GRect(x, y, width, height); }
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 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 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); }
// 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); }
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 window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_CONFIRM); GRect bitmap_bounds = gbitmap_get_bounds(s_icon_bitmap); s_header_layer = text_layer_create(GRect(10, 5, 124, bounds.size.h - (10 + bitmap_bounds.size.h + 15))); text_layer_set_text(s_header_layer, RESULTS_WINDOW_HEADER); text_layer_set_background_color(s_header_layer, GColorClear); text_layer_set_text_alignment(s_header_layer, GTextAlignmentCenter); text_layer_set_font(s_header_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK)); layer_add_child(window_layer, text_layer_get_layer(s_header_layer)); s_icon_layer = bitmap_layer_create(GRect((bounds.size.w / 2) - (bitmap_bounds.size.w / 2), 45, bitmap_bounds.size.w, bitmap_bounds.size.h)); bitmap_layer_set_bitmap(s_icon_layer, s_icon_bitmap); bitmap_layer_set_compositing_mode(s_icon_layer, GCompOpSet); layer_add_child(window_layer, bitmap_layer_get_layer(s_icon_layer)); s_label_layer = text_layer_create(GRect(10, 30 + bitmap_bounds.size.h + 5, 124, bounds.size.h - (10 + bitmap_bounds.size.h + 15))); set_results_speed(0); text_layer_set_background_color(s_label_layer, GColorClear); text_layer_set_text_alignment(s_label_layer, GTextAlignmentCenter); text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(window_layer, text_layer_get_layer(s_label_layer)); }
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)); }
void graphics_darken(GBitmap *bitmap) { static int count = 0; count = (count + 1) % 4; uint16_t row_size_bytes = gbitmap_get_bytes_per_row(bitmap); uint8_t *imagebuffer = gbitmap_get_data(bitmap); GRect bounds = gbitmap_get_bounds(bitmap); for (int y = bounds.origin.y; y < bounds.origin.y + bounds.size.h; y++) { for (int x = bounds.origin.x; x < bounds.origin.x + bounds.size.w; x++) { if ((x + y) % 4 == count) { uint8_t *line = imagebuffer + (row_size_bytes * y); GColor pixel = (GColor)line[x]; if (pixel.a > 0) { pixel.a--; } else if (pixel.g >= pixel.r && pixel.g > 0) { pixel.g--; } else if (pixel.r >= pixel.b && pixel.r > 0) { pixel.r--; } else if (pixel.b > 0) { pixel.b--; } line[x] = pixel.argb; } } } }
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 load_digit_image_into_slot(int slot_number, int digit_value) { /* * Loads the digit image from the application's resources and * displays it on-screen in the correct location. * * Each slot is a quarter of the screen. */ if ((slot_number < 0) || (slot_number >= TOTAL_IMAGE_SLOTS)) { return; } if ((digit_value < 0) || (digit_value > 9)) { return; } if (s_image_slot_state[slot_number] != EMPTY_SLOT) { return; } s_image_slot_state[slot_number] = digit_value; s_images[slot_number] = gbitmap_create_with_resource(IMAGE_RESOURCE_IDS[digit_value]); #ifdef PBL_PLATFORM_BASALT GRect bounds = gbitmap_get_bounds(s_images[slot_number]); #else GRect bounds = s_images[slot_number]->bounds; #endif BitmapLayer *bitmap_layer = bitmap_layer_create(GRect((slot_number % 2) * 72, (slot_number / 2) * 84, bounds.size.w, bounds.size.h)); s_image_layers[slot_number] = bitmap_layer; bitmap_layer_set_bitmap(bitmap_layer, s_images[slot_number]); Layer *window_layer = window_get_root_layer(s_main_window); layer_add_child(window_layer, bitmap_layer_get_layer(bitmap_layer)); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_CONFIG_REQUIRED); GRect bitmap_bounds = gbitmap_get_bounds(s_icon_bitmap); s_icon_layer = bitmap_layer_create(GRect( (bounds.size.w - bitmap_bounds.size.w) / 2, ((bounds.size.h - bitmap_bounds.size.h) / 2) - 10, bitmap_bounds.size.w, bitmap_bounds.size.h) ); bitmap_layer_set_bitmap(s_icon_layer, s_icon_bitmap); bitmap_layer_set_compositing_mode(s_icon_layer, GCompOpSet); layer_add_child(window_layer, bitmap_layer_get_layer(s_icon_layer)); s_title_layer = text_layer_create(GRect(0, 5, bounds.size.w, 60)); text_layer_set_text(s_title_layer, DIALOG_CONFIG_WINDOW_APP_NAME); text_layer_set_text_color(s_title_layer, GColorWhite); text_layer_set_background_color(s_title_layer, GColorClear); text_layer_set_text_alignment(s_title_layer, GTextAlignmentCenter); text_layer_set_font(s_title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(window_layer, text_layer_get_layer(s_title_layer)); s_body_layer = text_layer_create(GRect(5, 120, bounds.size.w - 10, 60)); text_layer_set_text(s_body_layer, DIALOG_CONFIG_WINDOW_MESSAGE); text_layer_set_text_color(s_body_layer, GColorWhite); text_layer_set_background_color(s_body_layer, GColorClear); text_layer_set_font(s_body_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(s_body_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_body_layer)); }
//Funktionen MainWindow static void draw_background(Layer *layer, GContext *ctx) { // Get a tm structure time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); int hour = tick_time->tm_hour; int i_corr = 0; if (hour > 12){ hour = hour -12; } if ((hour == 3) || (hour == 9)) { i_corr = 0; } // Get image center GRect img_bounds = gbitmap_get_bounds(s_background_bitmap); GPoint src_ic = grect_center_point(&img_bounds); // Get context center GRect ctx_bounds = layer_get_bounds(layer); GPoint ctx_ic = grect_center_point(&ctx_bounds); // Angle of rotation int angle = ((hour * TRIG_MAX_ANGLE) / 12) + i_corr ; // Draw! graphics_draw_rotated_bitmap(ctx, s_background_bitmap, src_ic, angle, ctx_ic); }
void set_bitmap_pixel_color(GBitmap *bitmap, GBitmapFormat bitmap_format, int y, int x, GColor color) { GRect bounds = gbitmap_get_bounds(bitmap); if (y < 0 || y >= bounds.size.h) { //APP_LOG(APP_LOG_LEVEL_WARNING, "Setting offscreen pixel at (%u, %u) to %x", x, y, color.argb); return; } GBitmapDataRowInfo row = gbitmap_get_data_row_info(bitmap, y); if ((x >= row.min_x) && (x <= row.max_x)) { switch(bitmap_format) { case GBitmapFormat1Bit : row.data[x / 8] ^= (-(gcolor_equal(color, GColorWhite)? 1 : 0) ^ row.data[x / 8]) & (1 << (x % 8)); break; case GBitmapFormat1BitPalette : //TODO break; case GBitmapFormat2BitPalette : //TODO break; case GBitmapFormat4BitPalette : //TODO break; case GBitmapFormat8BitCircular : case GBitmapFormat8Bit : row.data[x] = color.argb; } } }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND); s_background_layer = bitmap_layer_create(layer_get_frame(window_layer)); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_background_layer)); s_meter_bar_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_METER_BAR); #ifdef PBL_PLATFORM_BASALT GRect bitmap_bounds = gbitmap_get_bounds(s_meter_bar_bitmap); #else GRect bitmap_bounds = s_meter_bar_bitmap->bounds; #endif GRect frame = GRect(17, 43, bitmap_bounds.size.w, bitmap_bounds.size.h); s_meter_bar_layer = bitmap_layer_create(frame); bitmap_layer_set_bitmap(s_meter_bar_layer, s_meter_bar_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_meter_bar_layer)); if (!clock_is_24h_style()) { s_time_format_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_24_HOUR_MODE); #ifdef PBL_PLATFORM_BASALT bitmap_bounds = gbitmap_get_bounds(s_time_format_bitmap); #else bitmap_bounds = s_time_format_bitmap->bounds; #endif GRect frame = GRect(17, 68, bitmap_bounds.size.w, bitmap_bounds.size.h); s_time_format_layer = bitmap_layer_create(frame); bitmap_layer_set_bitmap(s_time_format_layer, s_time_format_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_time_format_layer)); } // Create time and date layers GRect dummy_frame = GRect(0, 0, 0, 0); s_day_name_layer = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(s_day_name_layer)); for (int i = 0; i < TOTAL_TIME_DIGITS; ++i) { s_time_digits_layers[i] = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(s_time_digits_layers[i])); } for (int i = 0; i < TOTAL_DATE_DIGITS; ++i) { s_date_digits_layers[i] = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(s_date_digits_layers[i])); } }
void graphics_draw_pixel_color(GBitmap *bitmap, GPoint point, GColor color) { uint16_t row_size_bytes = gbitmap_get_bytes_per_row(bitmap); uint8_t *imagebuffer = gbitmap_get_data(bitmap); GRect bounds = gbitmap_get_bounds(bitmap); if (grect_contains_point(&bounds, &point)) { uint8_t *line = imagebuffer + (row_size_bytes * point.y); line[point.x] = color.argb; } }
static GRect prv_get_donut_rect(const GRect *layer_bounds, int32_t donut_angle) { const GRect donut_orbit_rect = prv_get_donut_orbit_rect(layer_bounds); GRect donut_rect = grect_centered_from_polar(donut_orbit_rect, GOvalScaleModeFitCircle, donut_angle, gbitmap_get_bounds(s_app_data->donut_bitmap).size); donut_rect.origin.y = (int16_t)prv_interpolate_int64_linear(0, donut_rect.origin.y, s_app_data->intro_animation_progress); return donut_rect; }
static void layer_update_callback(Layer *layer, GContext* ctx) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Layer update callback"); GSize image_size = gbitmap_get_bounds(s_image).size; GRect frame = layer_get_frame(s_image_layer); APP_LOG(APP_LOG_LEVEL_DEBUG, "Size of image: %d %d", image_size.w, image_size.h); graphics_draw_bitmap_in_rect(ctx, s_image, GRect(10, 10, image_size.w, image_size.h)); }
static void layer_update_callback(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. #ifdef PBL_PLATFORM_BASALT GSize image_size = gbitmap_get_bounds(s_image).size; #else GSize image_size = s_image->bounds.size; #endif graphics_draw_bitmap_in_rect(ctx, s_image, GRect(0, 0, image_size.w, image_size.h)); #ifdef PBL_PLATFORM_BASALT image_size = gbitmap_get_bounds(s_bitmap_batterie).size; #else image_size = s_bitmap_batterie->bounds.size; #endif graphics_draw_bitmap_in_rect(ctx, s_bitmap_batterie, GRect(12, 111, image_size.w, image_size.h)); }
void bluetooth_layer_create() { if (!s_bitmap_bluetooth) { s_bitmap_bluetooth = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH_MARK); s_bitmap_yes_no = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_YES_NO); GRect rect = gbitmap_get_bounds(s_bitmap_yes_no); rect.size.w >>= 1; s_bitmap_yes = gbitmap_create_as_sub_bitmap(s_bitmap_yes_no, rect); rect.origin.x += rect.size.w; s_bitmap_no = gbitmap_create_as_sub_bitmap(s_bitmap_yes_no, rect); }
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 });
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); s_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ICONO_PRINCIPAL); GRect bitmap_bounds = gbitmap_get_bounds(s_icon_bitmap); s_fondo_layer = bitmap_layer_create(GRect(0, 0, 144, 40)); bitmap_layer_set_background_color(s_fondo_layer, COLOR_CABECERA); layer_add_child(window_layer, bitmap_layer_get_layer(s_fondo_layer)); s_scroll_layer = scroll_layer_create(GRect(10, 10 + bitmap_bounds.size.h + 5, 124, 168 - (10 + bitmap_bounds.size.h + 10))); scroll_layer_set_click_config_onto_window(s_scroll_layer, window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(0, 0, 120, 2000); s_label_layer = text_layer_create(max_text_bounds); text_layer_set_text(s_label_layer, i_lineas); text_layer_set_text_color(s_label_layer, COLOR_TEXTO_CUERPO); text_layer_set_background_color(s_label_layer, GColorClear); if (i_total_lineas> 3) text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); else text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28)); //layer_add_child(window_layer, text_layer_get_layer(s_label_layer)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(s_label_layer); text_layer_set_size(s_label_layer, max_size); scroll_layer_set_content_size(s_scroll_layer, GSize(bounds.size.w, max_size.h + 4)); scroll_layer_set_shadow_hidden(s_scroll_layer, true); scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_label_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); // CAPA DE LA PARADA s_titulo_layer = text_layer_create(GRect(38, 0 , 101, 40)); text_layer_set_text(s_titulo_layer, string_parada); text_layer_set_background_color(s_titulo_layer, GColorClear ); text_layer_set_text_color(s_titulo_layer, COLOR_TEXTO_CABECERA ); text_layer_set_text_alignment(s_titulo_layer, GTextAlignmentCenter); text_layer_set_font(s_titulo_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); layer_add_child(window_layer, text_layer_get_layer(s_titulo_layer)); // FIN DE CAPA DE LA PARADA // CAPA DEL ICONO DEL BUS s_icon_layer = bitmap_layer_create(GRect(5, 5, bitmap_bounds.size.w, bitmap_bounds.size.h)); bitmap_layer_set_bitmap(s_icon_layer, s_icon_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_icon_layer)); // FIN DE LA CAPA }
GPoint buttons_get_pet_layer_start_point(Buttons* buttons) { //graphics_draw_bitmap_in_rect(ctx, pet->sprite_one, GRect(pet->position.x, pet->position.y, gbitmap_get_bounds(pet->sprite_one).size.w, gbitmap_get_bounds(pet->sprite_one).size.h)); int point_x = buttons->hunger_button->button_pos.x; int point_y = buttons->hunger_button->button_pos.y + gbitmap_get_bounds(buttons->hunger_button->bitmap).size.h; // APP_LOG(APP_LOG_LEVEL_DEBUG, "Hunger button: %d,%d", buttons->hunger_button->button_pos.x, buttons->hunger_button->button_pos.y); return GPoint(point_x, point_y); }
static void window_load(Window *window) { SprinklesAppData *data = window_get_user_data(window); Layer *root_layer = window_get_root_layer(window); const GRect root_layer_bounds = layer_get_bounds(root_layer); data->homer_bitmap = gbitmap_create_with_resource(RESOURCE_ID_HOMER); GRect homer_bitmap_layer_frame = root_layer_bounds; homer_bitmap_layer_frame.size = gbitmap_get_bounds(data->homer_bitmap).size; grect_align(&homer_bitmap_layer_frame, &root_layer_bounds, GAlignBottom, true /* clip */); data->homer_layer = bitmap_layer_create(homer_bitmap_layer_frame); bitmap_layer_set_bitmap(data->homer_layer, data->homer_bitmap); bitmap_layer_set_compositing_mode(data->homer_layer, GCompOpSet); layer_add_child(root_layer, bitmap_layer_get_layer(data->homer_layer)); const int16_t date_layer_width = PBL_IF_RECT_ELSE(41, 58); const int16_t date_layer_height = 17; GRect date_layer_frame = (GRect) { .size = GSize(date_layer_width, date_layer_height) }; grect_align(&date_layer_frame, &root_layer_bounds, GAlignRight, true /* clip */); data->date_layer = layer_create(date_layer_frame); layer_set_update_proc(data->date_layer, prv_date_layer_update_proc); layer_add_child(root_layer, data->date_layer); data->homer_eyes_layer = layer_create(homer_bitmap_layer_frame); layer_set_update_proc(data->homer_eyes_layer, prv_homer_eyes_layer_update_proc); layer_add_child(root_layer, data->homer_eyes_layer); data->donut_bitmap = gbitmap_create_with_resource(RESOURCE_ID_DONUT); data->hands_layer = layer_create(root_layer_bounds); layer_set_update_proc(data->hands_layer, prv_hands_layer_update_proc); layer_add_child(root_layer, data->hands_layer); const time_t current_time = time(NULL); struct tm *current_time_tm = localtime(¤t_time); prv_tick_timer_service_handler(current_time_tm, SECOND_UNIT); } static void window_unload(Window *window) { SprinklesAppData *data = window_get_user_data(window); layer_destroy(data->hands_layer); layer_destroy(data->homer_eyes_layer); layer_destroy(data->date_layer); gbitmap_destroy(data->donut_bitmap); bitmap_layer_destroy(data->homer_layer); gbitmap_destroy(data->homer_bitmap); window_destroy(window); }
/** * Flood fill algorithm : http://en.wikipedia.org/wiki/Flood_fill * TO BE IMPROVED to reduce memory consumption */ static void floodFill(GBitmap* bitmap, uint8_t* pixels, int bytes_per_row, GPoint start, GPoint offset, GColor8 fill_color){ uint8_t* img_pixels = gbitmap_get_data(bitmap); GRect bounds_bmp = gbitmap_get_bounds(bitmap); int16_t w_bmp = bounds_bmp.size.w; uint32_t max_size = 1000; GPoint *queue = malloc(sizeof(GPoint) * max_size); uint32_t size = 0; int32_t x = start.x - offset.x; int32_t y = start.y - offset.y; queue[size++] = (GPoint){x, y}; int32_t w,e; while(size > 0) { size--; x = queue[size].x; y = queue[size].y; w = e = x; while(!get_pixel_(pixels, bytes_per_row, e, y)) e++; while(w>=0 && !get_pixel_(pixels, bytes_per_row, w, y)) w--; // Increase the size of the queue if needed if(size > (max_size - 2*(e-w))){ max_size += 1000; GPoint *tmp_queue = malloc(sizeof(GPoint) * max_size); memcpy(tmp_queue, queue, sizeof(GPoint) * size); free(queue); queue = tmp_queue; } for(x=w+1; x<e; x++) { // change the color of the pixel in the final image if(grect_contains_point(&bounds_bmp,&((GPoint){x + offset.x, y + offset.y}))) img_pixels[x + offset.x + w_bmp * (y + offset.y)] = fill_color.argb; set_pixel_(pixels, bytes_per_row, x, y); if(!get_pixel_(pixels, bytes_per_row, x, y+1)){ queue[size++] = (GPoint){x, y+1}; } if(!get_pixel_(pixels, bytes_per_row, x, y-1)){ queue[size++] = (GPoint){x, y-1}; } } } free(queue); }
static void charge_layer_update_callback(Layer *layer, GContext *ctx) { BatteryChargeState batChargeState = battery_state_service_peek(); GColor charge_color = GColorClear; // Select color for battery charge if (batChargeState.charge_percent >= 60) { charge_color = GColorGreen; } else if (batChargeState.charge_percent >= 25) { charge_color = GColorChromeYellow; } else { charge_color = GColorRed; } // Fill the battery frame graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, s_bat_frame_path_ptr); // Draw battery charge graphics_context_set_fill_color(ctx, charge_color); int h = (100 - batChargeState.charge_percent) / 5 + 1; graphics_fill_rect(ctx, GRect(3, h, 8, 21 - h), 0, GCornerNone); // Clear overwritten part (outside of battery) graphics_context_set_stroke_color(ctx, GColorClear); graphics_draw_pixel(ctx, GPoint(3, 1)); graphics_draw_pixel(ctx, GPoint(10, 1)); // Stroke the battery frame graphics_context_set_stroke_color(ctx, (conf.fiboDisplay == FiboDispZoomed) ? s_legibleColor : gcolor_legible_over(conf.backgroundColor)); gpath_draw_outline(ctx, s_bat_frame_path_ptr); graphics_context_set_compositing_mode(ctx, GCompOpSet); if (batChargeState.is_charging) { // Draw charging icon graphics_draw_bitmap_in_rect(ctx, s_charging_image, gbitmap_get_bounds(s_charging_image)); } else if (batChargeState.is_plugged) { // Draw plugged icon graphics_draw_bitmap_in_rect(ctx, s_plugged_image, gbitmap_get_bounds(s_plugged_image)); } }
static void bitmap_make_semi_transparent(GBitmap *bitmap) { GRect bounds = gbitmap_get_bounds(bitmap); for (int y = bounds.origin.y; y < bounds.origin.y + bounds.size.h; y++) { GBitmapDataRowInfo row_info = gbitmap_get_data_row_info(bitmap, y); for (int x = row_info.min_x; x < row_info.max_x; x++) { GColor *pixel = (GColor*)&row_info.data[x]; if (pixel->a == 0x3) { //pixel->a = ((x%2 + y%2) % 2) ? 0x2 : 0x1; pixel->a = 0x2; } } } }
void draw_line_antialias_(GBitmap* img, int16_t x1, int16_t y1, int16_t x2, int16_t y2, GColor8 color) { uint8_t* img_pixels = gbitmap_get_data(img); int16_t w = gbitmap_get_bounds(img).size.w; int16_t h = gbitmap_get_bounds(img).size.h; fixed dx = int_to_fixed(abs_(x1 - x2)); fixed dy = int_to_fixed(abs_(y1 - y2)); bool steep = dy > dx; if(steep){ swap_(x1, y1); swap_(x2, y2); } if(x1 > x2){ swap_(x1, x2); swap_(y1, y2); } dx = x2 - x1; dy = y2 - y1; fixed intery; int x; for(x=x1; x <= x2; x++) { intery = int_to_fixed(y1) + (int_to_fixed(x - x1) * dy / dx); if(x>=0){ if(steep){ _plot(img_pixels, w, h, ipart_(intery) , x, color, rfpart_(intery)); _plot(img_pixels, w, h, ipart_(intery) + 1, x, color, fpart_(intery)); } else { _plot(img_pixels, w, h, x, ipart_(intery) , color, rfpart_(intery)); _plot(img_pixels, w, h, x, ipart_(intery) + 1, color, fpart_(intery)); } } } }
static void bt_update_proc(Layer *layer, GContext *ctx) { // if(!data_get_boolean_setting(DataKeyBTIndicator)) { // return; // } // Draw it white graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, s_bt_bitmap, gbitmap_get_bounds(s_bt_bitmap)); // Swap to FG color // GBitmap *fb = graphics_capture_frame_buffer(ctx); // universal_fb_swap_colors(fb, layer_get_frame(layer), GColorWhite, data_get_foreground_color()); // graphics_release_frame_buffer(ctx, fb); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); //********************************************************************************* GRect bounds = layer_get_bounds(window_layer); // We do this to account for the offset due to the status bar // at the top of the app window. GPoint center = grect_center_point(&bounds); GSize image_size = gbitmap_get_bounds(back_icon).size; //GRect image_frame = GRect(center.x-8, center.y-10, image_size.w, image_size.h); //image_frame.origin.x -= image_size.w / 2; //image_frame.origin.y -= image_size.h / 2; GRect image_frame = GRect(center.x-14, center.y-10, image_size.w, image_size.h); image_frame.origin.x -= image_size.w / 2; image_frame.origin.y -= image_size.h / 2; // Use GCompOpClear to display the black portions of the image s_black_layer = bitmap_layer_create(image_frame); bitmap_layer_set_bitmap(s_black_layer, back_icon); bitmap_layer_set_compositing_mode(s_black_layer, GCompOpSet); layer_add_child(window_layer, bitmap_layer_get_layer(s_black_layer)); //************************************************************************************************** // Create ActionBar // Initialize the action bar: s_action_bar_layer = action_bar_layer_create(); // Associate the action bar with the window: action_bar_layer_add_to_window(s_action_bar_layer, window); // Set the click config provider: action_bar_layer_set_click_config_provider(s_action_bar_layer, config_provider); // Set the icons: // The loading the icons is omitted for brevity... See HeapBitmap. action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_UP, my_icon_location); action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_DOWN, my_icon_stop); // Create output TextLayer s_output_layer = text_layer_create(GRect(5, 135, 105, 25)); //text_layer_set_font(s_output_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text(s_output_layer, " Save pos"); text_layer_set_text_color(s_output_layer,GColorWhite); text_layer_set_background_color(s_output_layer,GColorBlack); text_layer_set_overflow_mode(s_output_layer, GTextOverflowModeWordWrap); layer_add_child(window_layer, text_layer_get_layer(s_output_layer)); }