static void buildIconsDisplay(Window *window){ //create bluetooth icon gbitmap s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON); // create the bitmaplayer to display the bitmap s_bt_icon_layer = bitmap_layer_create(GRect(0, 0, 24, 24)); bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap); bitmap_layer_set_compositing_mode(s_bt_icon_layer, GCompOpSet); layer_add_child(s_root_layer, bitmap_layer_get_layer(s_bt_icon_layer)); //create bluetooth icon gbitmap s_weather_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_50DN); // create the bitmaplayer to display the bitmap s_weather_icon_layer = bitmap_layer_create(GRect(20, s_bounds.size.h - 50, 50, 50)); bitmap_layer_set_bitmap(s_weather_icon_layer, s_weather_icon_bitmap); bitmap_layer_set_compositing_mode(s_weather_icon_layer, GCompOpSet); layer_add_child(s_root_layer, bitmap_layer_get_layer(s_weather_icon_layer)); //create charge icon gbitmap s_charge_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CHARGE); GRect image_frame = GRect(s_bounds.size.w-24, 1, 24, 24); // create the bitmaplayer to display the bitmap s_charge_icon_layer = bitmap_layer_create(image_frame); bitmap_layer_set_bitmap(s_charge_icon_layer, s_charge_icon_bitmap); bitmap_layer_set_compositing_mode(s_charge_icon_layer, GCompOpSet); layer_add_child(s_root_layer, bitmap_layer_get_layer(s_charge_icon_layer)); }
// Initialise UI static void init(void) { srand(time(NULL)); inverter_timer = app_timer_register(INVERTER_TIMEOUT, inverter_timer_callback, 0); time_timer = app_timer_register(TIME_TIMEOUT, update_time, 0); window = window_create(); window_set_fullscreen(window, true); window_stack_push(window, false); // Assign resources s_res_tv_image = gbitmap_create_with_resource(RESOURCE_ID_TV_IMAGE); s_res_static_1_image = gbitmap_create_with_resource(RESOURCE_ID_STATIC_2_IMAGE); s_res_bitham_42_bold = fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD); s_res_gothic_14 = fonts_get_system_font(FONT_KEY_GOTHIC_14); // tv_bitmap tv_bitmap = bitmap_layer_create(GRect(0,0,144,168)); bitmap_layer_set_bitmap(tv_bitmap, s_res_tv_image); bitmap_layer_set_background_color(tv_bitmap, GColorClear); bitmap_layer_set_compositing_mode(tv_bitmap, GCompOpAssign); layer_add_child(window_get_root_layer(window), (Layer *) tv_bitmap); // static_1_bitmap static_1_bitmap = bitmap_layer_create(GRect(14, 42, 115, 87)); bitmap_layer_set_bitmap(static_1_bitmap, s_res_static_1_image); bitmap_layer_set_compositing_mode(static_1_bitmap, GCompOpOr); layer_add_child(window_get_root_layer(window), (Layer *)static_1_bitmap); // inverter_layer static_inverter_layer = inverter_layer_create(GRect(14, 42, 115, 0)); layer_add_child(window_get_root_layer(window), (Layer *)static_inverter_layer); layer_set_hidden(inverter_layer_get_layer(static_inverter_layer), false); // Screen On layer screen_on_layer = text_layer_create(GRect(14, 42, 115, 87)); text_layer_set_background_color(screen_on_layer, GColorWhite); layer_set_hidden(text_layer_get_layer(screen_on_layer), true); layer_add_child(window_get_root_layer(window), text_layer_get_layer(screen_on_layer)); // ch_layer ch_layer = text_layer_create(GRect(102, 46, 24, 14)); text_layer_set_background_color(ch_layer, GColorClear); text_layer_set_text(ch_layer, "Ch 3"); text_layer_set_font(ch_layer, s_res_gothic_14); layer_add_child(window_get_root_layer(window), text_layer_get_layer(ch_layer)); // time_layer clock_copy_time_string(buffer, 12); time_layer = text_layer_create(GRect(0, 56, 144, 42)); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_text(time_layer, buffer); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); text_layer_set_font(time_layer, s_res_bitham_42_bold); layer_set_hidden(text_layer_get_layer(time_layer), true); layer_add_child(window_get_root_layer(window), (Layer *)time_layer); accel_tap_service_subscribe(tap_handler); // Subcribe to the tap event service }
static void main_window_load(Window *window) { // Create bitmap s_example_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_NUM_1); s_bitmap_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_bitmap(s_bitmap_layer, s_example_bitmap); #ifdef PBL_PLATFORM_APLITE bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpAssign); #elif PBL_PLATFORM_BASALT bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet); #endif layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bitmap_layer)); // Create time TextLayer s_time_layer = text_layer_create(GRect(0, 10, 144, 50)); text_layer_set_background_color(s_time_layer, GColorBlack); text_layer_set_text_color(s_time_layer, GColorWhite); // Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SAN_FRANCISCO_42)); // Apply to time TextLayer text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); update_time(); }
static void main_window_load(Window *window) { int left = 0; left += LAYER_STATUS_LEFT_GAP; s_status_bt_layer = bitmap_layer_create(GRect(left, 0, LAYER_STATUS_BMP_WIDTH, LAYER_STATUS_HEIGHT)); bitmap_layer_set_alignment(s_status_bt_layer, GAlignRight); bitmap_layer_set_compositing_mode(s_status_bt_layer, GCompOpAssignInverted); layer_add_child(window_get_root_layer(window), (Layer *) s_status_bt_layer); left += LAYER_STATUS_BMP_WIDTH + LAYER_STATUS_GAP; s_status_battery_layer = bitmap_layer_create(GRect(left, 0, LAYER_STATUS_BMP_WIDTH, LAYER_STATUS_HEIGHT));\ bitmap_layer_set_alignment(s_status_battery_layer, GAlignLeft); bitmap_layer_set_compositing_mode(s_status_battery_layer, GCompOpAssignInverted); layer_add_child(window_get_root_layer(window), (Layer *) s_status_battery_layer); left += LAYER_STATUS_BMP_WIDTH; s_status_charge_layer = bitmap_layer_create(GRect(left, 0, LAYER_STATUS_BMP_WIDTH, LAYER_STATUS_HEIGHT));\ bitmap_layer_set_alignment(s_status_charge_layer, GAlignLeft); bitmap_layer_set_compositing_mode(s_status_charge_layer, GCompOpAssignInverted); layer_add_child(window_get_root_layer(window), (Layer *) s_status_charge_layer); left += LAYER_STATUS_BMP_WIDTH; s_status_text_layer = create_text_layer(window, GRect(left, 0, LAYER_STATUS_TEXT_WIDTH, LAYER_STATUS_HEIGHT)); text_layer_set_text_alignment(s_status_text_layer, GAlignRight); set_status_text(""); }
static void 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. GRect layer_frame_description = layer_get_frame(window_layer); layer_frame_description.origin.x = 0; layer_frame_description.origin.y = 0; // Add some background content to help demonstrate transparency. text_layer = text_layer_create(layer_frame_description); text_layer_set_text(text_layer, "pandamonium pandamon\n" "ium pandamonium panda\n" "monium pandamonium\n" "pandamonium pandamon\n" "ium pandamonium panda\n" "monium pandamonium\n" "pandamonium pandamon\n" "ium pandamonium panda\n" "monium pandamonium p\n" "andamonium pandamoni\n"); layer_add_child(window_layer, text_layer_get_layer(text_layer)); white_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PANDA_WHITE); black_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PANDA_BLACK); const GPoint center = grect_center_point(&bounds); GRect image_frame = (GRect) { .origin = center, .size = white_image->bounds.size }; image_frame.origin.x -= white_image->bounds.size.w/2; image_frame.origin.y -= white_image->bounds.size.h/2; // Use GCompOpOr to display the white portions of the image white_image_layer = bitmap_layer_create(image_frame); bitmap_layer_set_bitmap(white_image_layer, white_image); bitmap_layer_set_compositing_mode(white_image_layer, GCompOpOr); layer_add_child(window_layer, bitmap_layer_get_layer(white_image_layer)); // Use GCompOpClear to display the black portions of the image black_image_layer = bitmap_layer_create(image_frame); bitmap_layer_set_bitmap(black_image_layer, black_image); bitmap_layer_set_compositing_mode(black_image_layer, GCompOpClear); layer_add_child(window_layer, bitmap_layer_get_layer(black_image_layer)); } static void window_unload(Window *window) { bitmap_layer_destroy(white_image_layer); bitmap_layer_destroy(black_image_layer); text_layer_destroy(text_layer); gbitmap_destroy(white_image); gbitmap_destroy(black_image); }
static void set_button_graphic( Layer *window_layer, BitmapLayer *layer_white, BitmapLayer *layer_black, GBitmap *bmp_white, GBitmap *bmp_black ) { bitmap_layer_set_bitmap ( layer_white, bmp_white ); bitmap_layer_set_compositing_mode( layer_white, GCompOpOr ); bitmap_layer_set_bitmap ( layer_black, bmp_black ); bitmap_layer_set_compositing_mode( layer_black, GCompOpClear ); layer_add_child ( window_layer, bitmap_layer_get_layer(layer_white) ); layer_add_child ( window_layer, bitmap_layer_get_layer(layer_black) ); }
void show_tripwindow(void) { initialise_ui(); layer_set_update_proc(s_score_layer,score_layer_update); bitmap_layer_set_compositing_mode(s_hardbrakes_bitmaplayer,GCompOpSet); bitmap_layer_set_compositing_mode(s_hardaccs_bitmaplayer,GCompOpSet); bitmap_layer_set_compositing_mode(s_trend_bitmaplayer,GCompOpSet); // window_set_background_color(s_window,GColorChromeYellow); window_set_window_handlers(s_window, (WindowHandlers) { .unload = handle_window_unload, });
TransBitmapLayer * trans_bitmap_layer_create(GBitmap *black_image, GBitmap *white_image, GRect frame) { TransBitmapLayer *layer; layer = malloc(sizeof(TransBitmapLayer)); layer->black_layer = bitmap_layer_create(frame); layer->white_layer = bitmap_layer_create(frame); bitmap_layer_set_bitmap(layer->black_layer, black_image); bitmap_layer_set_bitmap(layer->white_layer, white_image); bitmap_layer_set_compositing_mode(layer->black_layer, GCompOpAnd); bitmap_layer_set_compositing_mode(layer->white_layer, GCompOpSet); return layer; }
static void window_load(Window *window) { window_set_background_color(window, GColorBlack); //Power bitmap power_bitmap = gbitmap_create_with_resource(RESOURCE_ID_POWER); //Phase phase_layer = layer_create(GRECT_PHASE_SHOWING); layer_set_update_proc(phase_layer, (LayerUpdateProc)phase_update_proc); layer_add_child(window_get_root_layer(window), phase_layer); //Time display under background time_bg_layer = layer_create(GRECT_TIME_BG_HIDDEN); time_layer = cl_init_text_layer(GRECT_TIME_BG_HIDDEN, GColorBlack, GColorClear, false, 0, FONT_KEY_GOTHIC_24_BOLD, GTextAlignmentCenter); layer_set_update_proc(time_bg_layer, (LayerUpdateProc)bg_update_proc); layer_add_child(window_get_root_layer(window), time_bg_layer); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); //Bluetooth bt_on_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BT_ON); bt_off_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BT_OFF); bt_layer = bitmap_layer_create(GRECT_BT_HIDDEN); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bt_layer)); //Battery battery_layer = layer_create(GRECT_BATTERY_HIDDEN); layer_set_update_proc(battery_layer, (LayerUpdateProc)battery_update_proc); layer_add_child(window_get_root_layer(window), battery_layer); //Background background_white_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BACKGROUND_WHITE); background_white_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_compositing_mode(background_white_layer, GCompOpOr); bitmap_layer_set_bitmap(background_white_layer, background_white_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(background_white_layer)); background_black_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BACKGROUND_BLACK); background_black_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_compositing_mode(background_black_layer, GCompOpAnd); bitmap_layer_set_bitmap(background_black_layer, background_black_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(background_black_layer)); //Date date_bg_layer = layer_create(GRECT_DATE_BG_HIDDEN); date_layer = cl_init_text_layer(GRECT_DATE_BG_HIDDEN, GColorBlack, GColorClear, false, 0, FONT_KEY_GOTHIC_24_BOLD, GTextAlignmentCenter); layer_set_update_proc(date_bg_layer, (LayerUpdateProc)bg_update_proc); layer_add_child(window_get_root_layer(window), date_bg_layer); layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); //Animate in cl_animate_layer(phase_layer, GRECT_PHASE_HIDDEN, GRECT_PHASE_SHOWING, 1000, 200); }
void handle_main_window_load(Window *window) { // Create GBitmap, then set to created BitmapLayer s_background_bitmap = gbitmap_create_with_resource(IMAGE_RESOURCE_IDS_BACKGROUNDS[4]); s_point_bitmap = gbitmap_create_with_resource(IMAGE_RESOURCE_IDS_HANDS[1]); s_background_layer = bitmap_layer_create(GRect(0, 12, 144, 144)); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); #if defined(USER_ROT_BITMAP) s_hour_point_layer = rot_bitmap_layer_create(s_point_bitmap); rot_bitmap_set_compositing_mode(s_hour_point_layer, GCompOpAnd); s_min_point_layer = rot_bitmap_layer_create(s_point_bitmap); rot_bitmap_set_compositing_mode(s_min_point_layer, GCompOpAnd); #else GRect rec= {{0, 0}, {16, 16}}; s_hour_point_layer = bitmap_layer_create(rec); bitmap_layer_set_bitmap(s_hour_point_layer, s_point_bitmap); bitmap_layer_set_compositing_mode(s_hour_point_layer, GCompOpAnd); s_min_point_layer = bitmap_layer_create(rec); bitmap_layer_set_bitmap(s_min_point_layer, s_point_bitmap); bitmap_layer_set_compositing_mode(s_min_point_layer, GCompOpAnd); #endif // Update the time now handle_update(); Layer * root_layer = window_get_root_layer(window); // Add it as a child layer to the Window's root layer layer_add_child(root_layer, bitmap_layer_get_layer(s_background_layer)); #if defined(USER_ROT_BITMAP) layer_add_child(root_layer, (Layer*)(s_hour_point_layer)); layer_add_child(root_layer, (Layer*)(s_min_point_layer)); #else layer_add_child(root_layer, bitmap_layer_get_layer(s_hour_point_layer)); layer_add_child(root_layer, bitmap_layer_get_layer(s_min_point_layer)); #endif add_invert(root_layer); // Register with TickTimerService #if defined(USE_TEST_SECONDS) tick_timer_service_subscribe(SECOND_UNIT, handle_tick); #else tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); #endif }
/** * Function intiailzes the main Window object * @param window Pointer to window to be intiailized */ static void main_window_load(Window *window) { s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND); s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); #ifdef PBL_BW bitmap_layer_set_compositing_mode(s_background_layer, GCompOpAssign); #elif PBL_COLOR bitmap_layer_set_compositing_mode(s_background_layer, GCompOpSet); #endif layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); welcome_window_build(window); }
static void main_window_load(Window *window) { // Get information about the Window Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); // Set background if(watch_info_get_model() != WATCH_INFO_MODEL_PEBBLE_ORIGINAL && watch_info_get_model() != WATCH_INFO_MODEL_PEBBLE_STEEL) { bg_grass = gbitmap_create_with_resource(RESOURCE_ID_BG_GRASS); background_image = bitmap_layer_create(bounds); bitmap_layer_set_bitmap(background_image, bg_grass); layer_add_child(window_layer, bitmap_layer_get_layer(background_image)); } // Create GBitmaps num0 = gbitmap_create_with_resource(RESOURCE_ID_NUM_0); num1left = gbitmap_create_with_resource(RESOURCE_ID_NUM_1_LEFT); num1right = gbitmap_create_with_resource(RESOURCE_ID_NUM_1_RIGHT); num2 = gbitmap_create_with_resource(RESOURCE_ID_NUM_2); num3 = gbitmap_create_with_resource(RESOURCE_ID_NUM_3); num4 = gbitmap_create_with_resource(RESOURCE_ID_NUM_4); num5 = gbitmap_create_with_resource(RESOURCE_ID_NUM_5); num6 = gbitmap_create_with_resource(RESOURCE_ID_NUM_6); num7 = gbitmap_create_with_resource(RESOURCE_ID_NUM_7); num8 = gbitmap_create_with_resource(RESOURCE_ID_NUM_8); num9 = gbitmap_create_with_resource(RESOURCE_ID_NUM_9); // Create BitmapLayers topleft_image = bitmap_layer_create(GRect(7, 5, 64, 76)); topright_image = bitmap_layer_create(GRect(71, 5, 64, 76)); bottomleft_image = bitmap_layer_create(GRect(7, 86, 64, 76)); bottomright_image = bitmap_layer_create(GRect(71, 86, 64, 76)); // Set transparency bitmap_layer_set_background_color(topleft_image, GColorClear); bitmap_layer_set_background_color(topright_image, GColorClear); bitmap_layer_set_background_color(bottomleft_image, GColorClear); bitmap_layer_set_background_color(bottomright_image, GColorClear); bitmap_layer_set_compositing_mode(topleft_image, GCompOpSet); bitmap_layer_set_compositing_mode(topright_image, GCompOpSet); bitmap_layer_set_compositing_mode(bottomleft_image, GCompOpSet); bitmap_layer_set_compositing_mode(bottomright_image, GCompOpSet); // Add BitmapLayers as child layers to the Window's root layer layer_add_child(window_layer, bitmap_layer_get_layer(topleft_image)); layer_add_child(window_layer, bitmap_layer_get_layer(topright_image)); layer_add_child(window_layer, bitmap_layer_get_layer(bottomleft_image)); layer_add_child(window_layer, bitmap_layer_get_layer(bottomright_image)); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BG_IMAGE); s_bitmap_layer = bitmap_layer_create(bounds); bitmap_layer_set_bitmap(s_bitmap_layer, s_bitmap); #ifdef PBL_PLATFORM_APLITE bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpAssign); #elif PBL_PLATFORM_BASALT bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet); #endif layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer)); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_bitmap = gbitmap_create_with_resource(RESOURCE_ID_US_FLAG_IMAGE); s_bitmap_layer = bitmap_layer_create(bounds); bitmap_layer_set_bitmap(s_bitmap_layer, s_bitmap); #if defined(PBL_BW) bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpAssign); #elif defined(PBL_COLOR) bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet); #endif layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer)); }
/*! * Initializes graphic elements and subscribes to accelerometer * * \param window the app's main window */ void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MAIN); GRect bounds = layer_get_frame(window_layer); image_layer = bitmap_layer_create(bounds); bitmap_layer_set_alignment(image_layer, GAlignCenter); note_layer = bitmap_layer_create(bounds); bitmap_layer_set_compositing_mode(note_layer, GCompOpAnd); bitmap_layer_set_alignment(note_layer, GAlignCenter); bitmap_layer_set_bitmap(note_layer, bitmap); bitmap_layer_set_bitmap(image_layer, bitmap); notes[NOTE_C] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_C); notes[NOTE_D] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_D); notes[NOTE_E] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_E); notes[NOTE_F] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_F); notes[NOTE_G] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_G); notes[NOTE_A] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_A); notes[NOTE_B] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_B); notes[NOTE_HI_C] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_HI_C); layer_add_child(window_layer, bitmap_layer_get_layer(image_layer)); /* layer_add_child(window_layer, bitmap_layer_get_layer(note_layer)); */ layer_insert_above_sibling(bitmap_layer_get_layer(note_layer), bitmap_layer_get_layer(image_layer)); accel_data_service_subscribe(0, accel_handler); accel_service_set_sampling_rate(ACCEL_SAMPLING_50HZ); }
ConnectionStatusComponent* connection_status_component_create(Layer *parent, int x, int y) { BitmapLayer *icon_layer = bitmap_layer_create(GRect(x, y, REASON_ICON_WIDTH, REASON_ICON_WIDTH)); // draw the icon background over the graph bitmap_layer_set_compositing_mode(icon_layer, get_element_data(parent)->black ? GCompOpAssignInverted : GCompOpAssign); layer_set_hidden(bitmap_layer_get_layer(icon_layer), true); layer_add_child(parent, bitmap_layer_get_layer(icon_layer)); FontChoice font = get_font(FONT_18_BOLD); TextLayer *staleness_text = text_layer_create(GRect( x + REASON_ICON_WIDTH + 1, y + (REASON_ICON_WIDTH - font.height) / 2 - font.padding_top, INITIAL_TEXT_SIZE, font.height + font.padding_top + font.padding_bottom )); text_layer_set_font(staleness_text, fonts_get_system_font(font.key)); text_layer_set_background_color(staleness_text, element_bg(parent)); text_layer_set_text_color(staleness_text, element_fg(parent)); text_layer_set_text_alignment(staleness_text, GTextAlignmentLeft); layer_set_hidden(text_layer_get_layer(staleness_text), true); layer_add_child(parent, text_layer_get_layer(staleness_text)); ConnectionStatusComponent *c = malloc(sizeof(ConnectionStatusComponent)); c->icon_layer = icon_layer; c->icon_bitmap = NULL; c->staleness_text = staleness_text; return c; }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect window_bounds = layer_get_bounds(window_layer); window_set_background_color(s_main_window, GColorMalachite); s_bitmap = gbitmap_create_with_resource(RESOURCE_ID_FACE); s_bitmap_layer = bitmap_layer_create(window_bounds); bitmap_layer_set_bitmap(s_bitmap_layer, s_bitmap); bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet); layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer)); action_bar = action_bar_layer_create(); action_bar_layer_add_to_window(action_bar, s_main_window); action_bar_layer_set_click_config_provider(action_bar, click_config_provider); action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_UP, menu_daily_up, true); action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_SELECT, menu_stats_select, true); action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_DOWN, menu_settings_down, true); s_output_layer = text_layer_create(GRect(5, 0, window_bounds.size.w - 5, window_bounds.size.h)); text_layer_set_font(s_output_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_background_color(s_output_layer, GColorClear); text_layer_set_text(s_output_layer, "Press a Button"); text_layer_set_text_alignment(s_output_layer, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft)); layer_add_child(window_layer, text_layer_get_layer(s_output_layer)); }
static void onWindowLoad(Window *window) { // 配置按键 window_set_click_config_provider(window, clickConfigProvider); // 窗口信息 Layer *layer = window_get_root_layer(window); bounds = layer_get_bounds(layer); // bitmap图层 GRect fromRect = GRect(0, 0, bounds.size.w, bounds.size.h); GRect toRect = GRect(0, bounds.size.h, bounds.size.w, bounds.size.h); bitmapLayer = bitmap_layer_create(fromRect); // bitmap对象 bitmap = gbitmap_create_with_resource(RESOURCE_ID_MY_LOGO); bitmap_layer_set_compositing_mode(bitmapLayer, GCompOpSet); bitmap_layer_set_bitmap(bitmapLayer, bitmap); // logo动画 PropertyAnimation *propAnim = property_animation_create_layer_frame((Layer *)bitmapLayer, &fromRect, &toRect); Animation *anim = property_animation_get_animation(propAnim); const int delay_ms = 1000; const int duration_ms = 3000; animation_set_curve(anim, AnimationCurveEaseOut); animation_set_delay(anim, delay_ms); animation_set_duration(anim, duration_ms); animation_schedule(anim); // 添加图层 layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bitmapLayer)); }
BatteryComponent* battery_component_create(Layer *parent, int16_t x, int16_t y, bool align_right) { battery_state_service_subscribe(battery_handler); BatteryComponent *c = malloc(sizeof(BatteryComponent)); c->icon_layer = NULL; c->icon_bitmap = NULL; c->text_layer = NULL; if (get_prefs()->battery_as_number) { FontChoice font = get_font(BATTERY_FONT); c->text_layer = add_text_layer( parent, GRect(x, y - font.padding_top + font.padding_bottom, BATTERY_TEXT_WIDTH, font.height + font.padding_top + font.padding_bottom), fonts_get_system_font(font.key), element_fg(parent), align_right ? GTextAlignmentRight : GTextAlignmentLeft ); } else { c->icon_layer = bitmap_layer_create(GRect(x, y + BATTERY_ICON_TOP_FUDGE, BATTERY_ICON_WIDTH, BATTERY_ICON_HEIGHT)); bitmap_layer_set_compositing_mode(c->icon_layer, element_comp_op(parent)); layer_add_child(parent, bitmap_layer_get_layer(c->icon_layer)); } // XXX s_component = c; battery_handler(battery_state_service_peek()); return c; }
static void main_window_load(Window *window) { window_set_background_color(window, GColorBlack); offscreen_layer = layer_create(GRect(0, 0, 180, 180)); layer_set_update_proc(offscreen_layer, offscreen_layer_update); sun_layer = layer_create(GRect(0, 0, 180, 180)); layer_set_update_proc(sun_layer, sun_layer_update); stars = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_STARS); night_layer = bitmap_layer_create(GRect(0, 0, 180, 180)); bitmap_layer_set_bitmap(night_layer, stars); bitmap_layer_set_compositing_mode(night_layer, GCompOpSet); sun = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SUN); moon = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MOON); ring_layer = layer_create(GRect(0, 0, 180, 180)); layer_set_update_proc(ring_layer, ring_layer_update); time_layer = text_layer_create(GRect(62, 130, 56, 25)); text_layer_set_background_color(time_layer, GColorOxfordBlue); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_text(time_layer, "00:00"); text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), offscreen_layer); layer_add_child(window_get_root_layer(window), sun_layer); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(night_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); layer_add_child(window_get_root_layer(window), ring_layer); }
void load_weather(Window *window) { s_weather_layer = text_layer_create(GRect(0,0,144,50)); //text_layer_set_text_color(s_weather_layer, GColorWhite); text_layer_set_text_color(s_weather_layer, default_color); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); s_weather_temp_min = text_layer_create(GRect(126,34,144,50)); text_layer_set_text_color(s_weather_temp_min, default_color); text_layer_set_background_color(s_weather_temp_min, GColorClear); text_layer_set_font(s_weather_temp_min, fonts_get_system_font(FONT_KEY_GOTHIC_14)); s_weather_temp_max = text_layer_create(GRect(126,23,144,50)); text_layer_set_text_color(s_weather_temp_max, default_color); text_layer_set_background_color(s_weather_temp_max, GColorClear); text_layer_set_font(s_weather_temp_max, fonts_get_system_font(FONT_KEY_GOTHIC_14)); s_weather_icon_layer = bitmap_layer_create(GRect(100, -8, 50, 50)); //bitmap_layer_set_background_color(s_weather_icon_layer, GColorWhite); bitmap_layer_set_compositing_mode(s_weather_icon_layer, GCompOpSet); s_weather_icon_draw_layer = layer_create(GRect(118, 1, 25, 25)); layer_set_update_proc(s_weather_icon_draw_layer, update_weather_cmd_img_proc); weather_display_refresh(); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_temp_max)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_temp_min)); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_weather_icon_layer)); layer_add_child(window_get_root_layer(window), s_weather_icon_draw_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)); }
static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) { switch (key) { case WEATHER_ICON_KEY: if (s_icon_bitmap) { gbitmap_destroy(s_icon_bitmap); } s_icon_bitmap = gbitmap_create_with_resource(WEATHER_ICONS[new_tuple->value->uint8]); #ifdef PBL_SDK_3 bitmap_layer_set_compositing_mode(s_icon_layer, GCompOpSet); #endif bitmap_layer_set_bitmap(s_icon_layer, s_icon_bitmap); break; case WEATHER_TEMPERATURE_KEY: // App Sync keeps new_tuple in s_sync_buffer, so we may use it directly text_layer_set_text(s_temperature_layer, new_tuple->value->cstring); break; case WEATHER_CITY_KEY: text_layer_set_text(s_city_layer, new_tuple->value->cstring); break; } }
static void main_window_load(Window *window) { // Get information about the Window Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); // Create the TextLayer with specific bounds s_time_layer = text_layer_create( GRect(PBL_IF_ROUND_ELSE(32, 28), PBL_IF_ROUND_ELSE(65, 60), bounds.size.w, 60)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_text(s_time_layer, "00:00"); text_layer_set_font(s_time_layer, fonts_get_system_font(PBL_IF_ROUND_ELSE(FONT_KEY_LECO_32_BOLD_NUMBERS, FONT_KEY_LECO_26_BOLD_NUMBERS_AM_PM))); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); // Add to Window s_bitmap = gbitmap_create_with_resource(PBL_IF_ROUND_ELSE(RESOURCE_ID_TORI, RESOURCE_ID_TORIS)); s_bitmap_layer = bitmap_layer_create(bounds); bitmap_layer_set_background_color(s_bitmap_layer, GColorTiffanyBlue); bitmap_layer_set_bitmap(s_bitmap_layer, s_bitmap); bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet); layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer)); // Add it as a child layer to the Window's root layer layer_add_child(window_layer, text_layer_get_layer(s_time_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_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)); }
void setup_bolt() { bolt = bitmap_layer_create(FRAME01); bitmap_layer_set_bitmap(bolt, bolt_image); bitmap_layer_set_compositing_mode(bolt, GCompOpAnd); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bolt)); layer_set_hidden(bitmap_layer_get_layer(bolt), true); }
static void window_load(Window *window) { Layer *root_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(root_layer); s_bitmap_layer = bitmap_layer_create(bounds); bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet); layer_add_child(root_layer, bitmap_layer_get_layer(s_bitmap_layer)); }
void setup_explosion() { explosion = bitmap_layer_create(LASTFRAME); bitmap_layer_set_bitmap(explosion, explosion_image); bitmap_layer_set_compositing_mode(explosion, GCompOpAnd); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(explosion)); layer_set_hidden(bitmap_layer_get_layer(explosion), true); }
void custom_main_window_load(Window *window) { Layer *window_layer=window_get_root_layer(window); #ifdef BG_IMAGE_GRECT GRect bounds=BG_IMAGE_GRECT; /* Hand crafted */ #else /* BG_IMAGE_GRECT */ GRect bounds=layer_get_bounds(window_layer); /* screen size, center image */ #endif /* BG_IMAGE_GRECT */ // Create GBitmap, then set to created BitmapLayer s_background_bitmap_main = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MAIN); s_background_bitmap_alt = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ALT); s_background_layer = bitmap_layer_create(bounds); #ifdef FAST_SWITCH /* show s_bg_image and then within 1 second show the next image */ if (s_bg_image == RESOURCE_ID_IMAGE_MAIN) #else /* not FAST_SWITCH */ /* ** set reverse image, TICK_HANDLER()/custom_tick_handler() is called ** almost immediately which will toggle the image */ if (s_bg_image != RESOURCE_ID_IMAGE_MAIN) #endif /* FAST_SWITCH/KEEP_IMAGE */ { bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap_main); } else { bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap_alt); } #ifdef PBL_COLOR bitmap_layer_set_compositing_mode(s_background_layer, GCompOpSet); #else /* PBL_BW MONO */ bitmap_layer_set_compositing_mode(s_background_layer, GCompOpAssign); #endif window_set_background_color(main_window, background_color); layer_add_child(window_layer, bitmap_layer_get_layer(s_background_layer)); /* End of custom code, call generic code */ main_window_load(window); }
void LoadMainBmpImage(Window *window, int id, int floorId) { int resourceId = id; Layer *window_layer = window_get_root_layer(window); #if DISABLE_MENU_BMPS return; #endif if(!window) { DEBUG_LOG("Skipping image load due to window not yet available."); return; } if(mainImageLoaded) { if(mainImageResourceLoaded == resourceId) { DEBUG_LOG("Resource %d already loaded.", resourceId); if(floorImageLoaded) layer_add_child(window_layer, bitmap_layer_get_layer(floorImage)); layer_add_child(window_layer, bitmap_layer_get_layer(mainImage)); return; // already loaded the correct one. } DEBUG_LOG("Unloading resourceId %d.", mainImageResourceLoaded); UnloadMainBmpImage(); } DEBUG_LOG("Loading resourceId %d.", resourceId); #if defined(PBL_COLOR) if(floorId >= 0) { floorImageBitmap = gbitmap_create_with_resource(floorId); floorImage = bitmap_layer_create(mainFrame); bitmap_layer_set_bitmap(floorImage, floorImageBitmap); bitmap_layer_set_alignment(floorImage, GAlignCenter); layer_add_child(window_layer, bitmap_layer_get_layer(floorImage)); floorImageLoaded = true; } #endif ProfileLogStart("LoadMainBmpImage"); mainImageBitmap = gbitmap_create_with_resource(resourceId); mainImage = bitmap_layer_create(mainFrame); bitmap_layer_set_bitmap(mainImage, mainImageBitmap); bitmap_layer_set_alignment(mainImage, GAlignCenter); #if defined(PBL_COLOR) bitmap_layer_set_compositing_mode(mainImage, GCompOpSet); #endif layer_add_child(window_layer, bitmap_layer_get_layer(mainImage)); mainImageLoaded = true; mainImageResourceLoaded = resourceId; ProfileLogStop("LoadMainBmpImage"); }