static void main_window_load(Window *window){ Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); GRect weather_bounds = GRect(0,PBL_IF_ROUND_ELSE(115,105), bounds.size.w, 50); s_status_bar = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(18,5), bounds.size.w, 50)); s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(43,35), bounds.size.w, 50)); //Load custom minimal font s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_REGULAR_DOS_48)); s_font_small = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_REGULAR_DOS_12)); s_weather_bitmap = gbitmap_create_with_resource(getImageId(temperature)); s_weather_icon = bitmap_layer_create(weather_bounds); window_set_background_color(s_main_window, GColorVividCerulean); //Set time text layer attributes 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, s_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); //Set status bar layer attributes text_layer_set_background_color(s_status_bar, GColorClear); text_layer_set_text_color(s_status_bar, GColorWhite); //text_layer_set_text(s_status_bar, "Battery status"); text_layer_set_font(s_status_bar, s_font_small); text_layer_set_text_alignment(s_status_bar, GTextAlignmentCenter); bitmap_layer_set_alignment(s_weather_icon, GAlignCenter); bitmap_layer_set_background_color(s_weather_icon, GColorClear); bitmap_layer_set_compositing_mode(s_weather_icon, GCompOpSet); layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); layer_add_child(window_layer, text_layer_get_layer(s_status_bar)); bitmap_layer_set_bitmap(s_weather_icon, s_weather_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_weather_icon)); battery_handler(battery_state_service_peek()); }
/* Initialize the application. */ void handle_init(AppContextRef ctx) { PblTm tm; PebbleTickEvent t; ResHandle res_d; ResHandle res_h; ResHandle res_m; window_init(&window, "Roboto"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); res_d = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21); res_h = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49); res_m = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_THIN_SUBSET_49); font_date = fonts_load_custom_font(res_d); font_hour = fonts_load_custom_font(res_h); font_minute = fonts_load_custom_font(res_m); time_layer_init(&time_layer, window.layer.frame); time_layer_set_text_color(&time_layer, GColorWhite); time_layer_set_background_color(&time_layer, GColorClear); time_layer_set_fonts(&time_layer, font_hour, font_minute); layer_set_frame(&time_layer.layer, TIME_FRAME); layer_add_child(&window.layer, &time_layer.layer); text_layer_init(&date_layer, window.layer.frame); text_layer_set_text_color(&date_layer, GColorWhite); text_layer_set_background_color(&date_layer, GColorClear); text_layer_set_font(&date_layer, font_date); text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); layer_set_frame(&date_layer.layer, DATE_FRAME); layer_add_child(&window.layer, &date_layer.layer); // Add weather layer weather_layer_init(&weather_layer, GPoint(0, 95)); //0, 100 layer_add_child(&window.layer, &weather_layer.layer); http_register_callbacks((HTTPCallbacks){.failure=failed,.success=success,.reconnect=reconnect,.location=location}, (void*)ctx);
static void day_text_layer_create(Window *window){ s_day_layer = text_layer_create(GRect(5,150,50,18)); text_layer_setup(window, s_day_layer); // Create GFont s_status_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SQUARE_16)); // Apply to TextLayer text_layer_set_font(s_day_layer, s_status_font); text_layer_set_text_alignment(s_day_layer, GTextAlignmentLeft); }
void set_date_layer() { // Create Layer date_layer = text_layer_create(GRect(0, dateY, 144, 28)); //(x,y,w,h) (x,y,144*168) // Set the text, font, and text alignment text_layer_set_text(date_layer, ""); text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TREK_24))); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); }
void set_fonts() { s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_IMAGINE_36)); s_text_time_font = fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT); s_task_font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD); s_text_time_bold_font = fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD); s_weather_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); s_day_of_month_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); s_travel_header_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); s_travel_row_font = fonts_get_system_font(FONT_KEY_GOTHIC_24); }
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); bg_image=gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG); background_layer=bitmap_layer_create(bounds); bitmap_layer_set_bitmap(background_layer, bg_image); layer_add_child(window_layer, bitmap_layer_get_layer(background_layer)); // Create canvas layer s_canvas_layer = layer_create(bounds); // Assign the custom drawing procedure layer_set_update_proc(s_canvas_layer, canvas_update_proc); // Add to Window layer_add_child(window_get_root_layer(window), s_canvas_layer); // Create the TextLayer with specific bounds s_time_layer = text_layer_create( GRect(bounds.size.w/2, 2*bounds.size.h/3, bounds.size.w/2, bounds.size.h/2)); // 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, "0"); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); // Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_AW_18)); // Create the TextLayer with specific bounds // s_minute_layer = text_layer_create( // GRect(0, 2*bounds.size.h/10, 3*bounds.size.w/4, bounds.size.h/3)); // Improve the layout to be more like a watchface // text_layer_set_background_color(s_minute_layer, GColorClear); // text_layer_set_text_color(s_minute_layer, GColorWhite); // text_layer_set_text(s_minute_layer, "0"); // Apply to TextLayer text_layer_set_font(s_time_layer, s_time_font); //text_layer_set_font(s_minute_layer, s_time_font); // Add it as a child layer to the Window's root layer layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); // Create the TextLayer with specific bounds }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Brown Watch"); window_stack_push(&window, true /* Animated */); resource_init_current_app(&APP_RESOURCES); #if DISPLAY_DATE_SHORT bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_BOX, &background_image_container); #else bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); #endif layer_add_child(&window.layer, &background_image_container.layer.layer); #if DISPLAY_DATE_SHORT || DISPLAY_DATE_LONG date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OPENSANS_REGULAR_14)); text_layer_init(&date_layer, GRect(27, 110, 90, 30)); text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); text_layer_set_text_color(&date_layer, GColorWhite); text_layer_set_background_color(&date_layer, GColorClear); text_layer_set_font(&date_layer, date_font); layer_add_child(&window.layer, &date_layer.layer); draw_date(); #endif layer_init(&hour_display_layer, window.layer.frame); hour_display_layer.update_proc = &hour_display_layer_update_callback; layer_add_child(&window.layer, &hour_display_layer); gpath_init(&hour_hand_outline_path, &HOUR_HAND_OUTLINE_PATH_POINTS); gpath_move_to(&hour_hand_outline_path, grect_center_point(&hour_display_layer.frame)); gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS); gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame)); layer_init(&minute_display_layer, window.layer.frame); minute_display_layer.update_proc = &minute_display_layer_update_callback; layer_add_child(&window.layer, &minute_display_layer); gpath_init(&minute_hand_outline_path, &MINUTE_HAND_OUTLINE_PATH_POINTS); gpath_move_to(&minute_hand_outline_path, grect_center_point(&minute_display_layer.frame)); gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS); gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame)); layer_init(¢er_display_layer, window.layer.frame); center_display_layer.update_proc = ¢er_display_layer_update_callback; layer_add_child(&window.layer, ¢er_display_layer); #if DISPLAY_SECONDS layer_init(&second_display_layer, window.layer.frame); second_display_layer.update_proc = &second_display_layer_update_callback; layer_add_child(&window.layer, &second_display_layer); #endif }
static TextLayer* text_layer_create_for_departure_layer(GRect frame, GTextAlignment text_alignment) { TextLayer* layer = text_layer_create(frame); text_layer_set_background_color(layer, GColorClear); text_layer_set_font(layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_UBUNTU_9))); //text_layer_set_overflow_mode(layer, GTextOverflowModeTrailingEllipsis); text_layer_set_text_alignment(layer, text_alignment); text_layer_set_text_color(layer, GColorWhite); return layer; }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Storm"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); layer_init(&month_display_layer, window.layer.frame); month_display_layer.update_proc = &month_display_layer_update_callback; layer_add_child(&window.layer, &month_display_layer); layer_init(&day_display_layer, window.layer.frame); day_display_layer.update_proc = &day_display_layer_update_callback; layer_add_child(&window.layer, &day_display_layer); layer_init(&hour_display_layer, window.layer.frame); hour_display_layer.update_proc = &hour_display_layer_update_callback; layer_add_child(&window.layer, &hour_display_layer); layer_init(&minute_display_layer, window.layer.frame); minute_display_layer.update_proc = &minute_display_layer_update_callback; layer_add_child(&window.layer, &minute_display_layer); text_layer_init(&date_text_layer, GRect(82,168/2-12,62,24)); text_layer_set_text_color(&date_text_layer, GColorWhite); text_layer_set_background_color(&date_text_layer, GColorClear); text_layer_set_text_alignment(&date_text_layer, GTextAlignmentCenter); text_layer_set_font(&date_text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTOCONDENSED_LIGHT_18))); layer_add_child(&window.layer, &date_text_layer.layer); text_layer_init(&time_text_layer, GRect(0,168/2-13,62,26)); text_layer_set_text_color(&time_text_layer, GColorWhite); text_layer_set_background_color(&time_text_layer, GColorClear); text_layer_set_text_alignment(&time_text_layer, GTextAlignmentCenter); text_layer_set_font(&time_text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTOCONDENSED_BOLD_20))); layer_add_child(&window.layer, &time_text_layer.layer); update_text(); }
void simply_ui_set_style(SimplyUi *self, int style_index) { if (self->ui_layer.custom_body_font) { fonts_unload_custom_font(self->ui_layer.custom_body_font); self->ui_layer.custom_body_font = NULL; } self->ui_layer.style = &STYLES[style_index]; if (self->ui_layer.style->custom_body_font_id) { self->ui_layer.custom_body_font = fonts_load_custom_font( resource_get_handle(self->ui_layer.style->custom_body_font_id)); } mark_dirty(self); }
void init() { main_window = window_create(); custom_font_24 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CUSTOM_24)); battery_state_service_subscribe(battery_state_changed_handler); tick_timer_service_subscribe(MINUTE_UNIT | DAY_UNIT, time_changed_handler); window_set_window_handlers(main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload });
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Trekkie"); window_stack_push(&window, true /* Animated */); resource_init_current_app(&APP_RESOURCES); bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image); layer_add_child(&window.layer, &background_image.layer.layer); // Date Layer text_layer_init(&text_date_layer, window.layer.frame); text_layer_set_text_color(&text_date_layer, GColorWhite); text_layer_set_background_color(&text_date_layer, GColorClear); layer_set_frame(&text_date_layer.layer, GRect(78, 5, 144-78, 168-5)); text_layer_set_font(&text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LCARS_BOLD_17))); layer_add_child(&window.layer, &text_date_layer.layer); // Time Layer text_layer_init(&text_time_layer, window.layer.frame); text_layer_set_text_color(&text_time_layer, GColorWhite); text_layer_set_background_color(&text_time_layer, GColorClear); layer_set_frame(&text_time_layer.layer, GRect(40, 48, 144-40, 168-48)); text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LCARS_60))); layer_add_child(&window.layer, &text_time_layer.layer); // AMPM Layer text_layer_init(&text_ampm_layer, window.layer.frame); text_layer_set_text_color(&text_ampm_layer, GColorWhite); text_layer_set_background_color(&text_ampm_layer, GColorClear); layer_set_frame(&text_ampm_layer.layer, GRect(40, 105, 144-40, 168-105)); text_layer_set_font(&text_ampm_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LCARS_BOLD_17))); layer_add_child(&window.layer, &text_ampm_layer.layer); // No blank screen on init. PblTm tick_time; get_time(&tick_time); update_display(&tick_time); }
void handle_init() { window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); // week text_week_layer = text_layer_create(GRect(96, 8, 144-96, 168-8)); text_layer_set_text_color(text_week_layer, GColorWhite); text_layer_set_background_color(text_week_layer, GColorClear); text_layer_set_font(text_week_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SANSATION_REGULAR_18))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_week_layer)); // daynumber text_daynum_layer = text_layer_create(GRect(100, 24, 144-100, 168-24)); text_layer_set_text_color(text_daynum_layer, GColorWhite); text_layer_set_background_color(text_daynum_layer, GColorClear); text_layer_set_font(text_daynum_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SANSATION_REGULAR_18))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_daynum_layer)); // weekday text_day_layer = text_layer_create(GRect(8, 8, 144-8, 168-8)); text_layer_set_text_color(text_day_layer, GColorWhite); text_layer_set_background_color(text_day_layer, GColorClear); text_layer_set_font(text_day_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SANSATION_REGULAR_18))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_day_layer)); // day/month text_date_layer = text_layer_create(GRect(8, 24, 144-8, 168-24)); text_layer_set_text_color(text_date_layer, GColorWhite); text_layer_set_background_color(text_date_layer, GColorClear); text_layer_set_font(text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SANSATION_REGULAR_18))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_date_layer)); // time text_time_layer = text_layer_create(GRect(6, 53, 144-6, 168-53)); text_layer_set_text_color(text_time_layer, GColorWhite); text_layer_set_background_color(text_time_layer, GColorClear); text_layer_set_font(text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CONTINUUM_BOLD_48))); // text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SANSATION_BOLD_47))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_time_layer)); // year text_year_layer = text_layer_create(GRect(10, 140, 144-20, 168-140)); text_layer_set_text_alignment(text_year_layer, GTextAlignmentCenter); text_layer_set_text_color(text_year_layer, GColorWhite); text_layer_set_background_color(text_year_layer, GColorClear); text_layer_set_font(text_year_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SANSATION_REGULAR_18))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_year_layer)); // line line_layer = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(line_layer, line_layer_update_callback); layer_add_child(window_get_root_layer(window), line_layer); tick_timer_service_subscribe(MINUTE_UNIT, update_display); // Avoid blank display on launch time_t t = time(NULL); update_display(localtime(&t), MINUTE_UNIT); }
static void main_window_load(Window *window) { // Create GBitmap, then set to created BitmapLayer 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); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); // Create time TextLayer s_time_layer = text_layer_create(GRect(5, 52, 139, 50)); //s_time_layer = text_layer_create(GRect(0, 55, 144, 50)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); //text_layer_set_text(s_time_layer, "00:00"); // Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_48)); // Apply to TextLayer text_layer_set_font(s_time_layer, s_time_font); // Improve the layout to be more like a watchface //text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); 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)); // Create temperature Layer s_weather_layer = text_layer_create(GRect(0, 130, 144, 25)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, GColorWhite); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter); text_layer_set_text(s_weather_layer, "Loading..."); // Create second custom font, apply it and add to Window s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20)); text_layer_set_font(s_weather_layer, s_weather_font); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); }
void topbar_layer_init(Window* window) { int16_t w = SCREEN_W - MENU_WIDTH; s_data.topbar_layer.layer = layer_create(GRect(0,0,w,SCREEN_H)); layer_add_child(window_get_root_layer(window), s_data.topbar_layer.layer); // time (centered in top bar) s_data.topbar_layer.time_layer = text_layer_create(GRect(0,0,w,TOPBAR_HEIGHT)); set_layer_attr_full(s_data.topbar_layer.time_layer, s_data.time, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_16)), GTextAlignmentCenter, GColorWhite, GColorBlack, window_get_root_layer(window)); // bluetooth icon s_data.topbar_layer.bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH); s_data.topbar_layer.bluetooth_layer = bitmap_layer_create(gbitmap_get_bounds(s_data.topbar_layer.bluetooth_image)); bitmap_layer_set_bitmap(s_data.topbar_layer.bluetooth_layer, s_data.topbar_layer.bluetooth_image); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_data.topbar_layer.bluetooth_layer)); layer_set_hidden(bitmap_layer_get_layer(s_data.topbar_layer.bluetooth_layer), !bluetooth_connection_service_peek()); // accuracy (1/3, right) s_data.topbar_layer.accuracy_layer = text_layer_create(GRect(w-18,0,18,TOPBAR_HEIGHT)); set_layer_attr_full(s_data.topbar_layer.accuracy_layer, s_data.accuracy, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_16)), GTextAlignmentRight, GColorWhite, GColorBlack, window_get_root_layer(window)); }
static void set_text_to_window() { //Time TextLayer clock_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_arcade_24)); s_time_layer = text_layer_create(GRect(0, 30, 144, 44)); 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, clock_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); // Create current date TextLayer date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_dos_18)); // Create current date TextLayer month_layer = text_layer_create(GRect(0, 55, 144, 18)); text_layer_set_background_color(month_layer, GColorClear); text_layer_set_text_color(month_layer, GColorWhite); text_layer_set_text(month_layer, "SEPTEMBER 00"); text_layer_set_font(month_layer, date_font); text_layer_set_text_alignment(month_layer, GTextAlignmentCenter); // Create current date TextLayer batt_txt_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_lcd_10)); batt_txt_layer = text_layer_create(GRect(10, 152, 20, 14)); text_layer_set_background_color(batt_txt_layer, GColorClear); text_layer_set_text_color(batt_txt_layer, GColorRed); text_layer_set_text(batt_txt_layer, "100"); text_layer_set_font(batt_txt_layer, batt_txt_font); text_layer_set_text_alignment(batt_txt_layer, GTextAlignmentRight); // Create current date TextLayer pct_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_lcd_12)); pct_layer = text_layer_create(GRect(19, 150, 20, 14)); text_layer_set_background_color(pct_layer, GColorClear); text_layer_set_text_color(pct_layer, GColorYellow); text_layer_set_text(pct_layer, "%"); text_layer_set_font(pct_layer, pct_font); text_layer_set_text_alignment(pct_layer, GTextAlignmentRight); }
// Initialize the application void handle_init() { struct tm* tick_time; ResHandle res_d; ResHandle res_h; window_init(&window, "Futura"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); res_d = resource_get_handle(RESOURCE_ID_FUTURA_18); // Date font res_h = resource_get_handle(RESOURCE_ID_FUTURA_CONDENSED_53); // Time font font_date = fonts_load_custom_font(res_d); font_hour = fonts_load_custom_font(res_h); font_minute = fonts_load_custom_font(res_h); time_layer_init(&time_layer, window.layer.frame); time_layer_set_text_color(&time_layer, GColorWhite); time_layer_set_background_color(&time_layer, GColorClear); time_layer_set_fonts(&time_layer, font_hour, font_minute); layer_set_frame(&time_layer.layer, TIME_FRAME); layer_add_child(&window.layer, &time_layer.layer); text_layer_init(&date_layer, window.layer.frame); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_background_color(&date_layer, GColorClear); text_layer_set_font(&date_layer, font_date); text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); layer_set_frame(&date_layer.layer, DATE_FRAME); layer_add_child(&window.layer, &date_layer.layer); // Add weather layer weather_layer_init(&weather_layer, GPoint(0, 90)); layer_add_child(&window.layer, &weather_layer.layer); http_register_callbacks((HTTPCallbacks){.failure=failed,.success=success,.reconnect=reconnect,.location=location}, NULL);
void init() { // load fonts font1 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ASAKIM_BOLD_38)); font2 = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD); // create main window element and assign to pointer s_main_window = window_create(); // set handlers to manage the elements inside the window window_set_window_handlers(s_main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload });
void handle_init(void) { window = window_create(); window_stack_push(window, true); window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); // Set up AppMessage to receive timezone offset app_message_register_inbox_received(in_received_handler); app_message_open(64, 64); dolce_vita_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GEOSANS_LIGHT_26)); // Current Time text_time_layer = text_layer_create(GRect(0, 114, 144, 43)); text_layer_set_text_color(text_time_layer, GColorWhite); text_layer_set_background_color(text_time_layer, GColorClear); text_layer_set_font(text_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_MEDIUM_NUMBERS)); text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); // Apple Logo logo_image = gbitmap_create_with_resource(RESOURCE_ID_WWDC14); logo_image_layer = bitmap_layer_create(GRect(0, 0, 144, 60)); bitmap_layer_set_bitmap(logo_image_layer, logo_image); layer_add_child(window_layer, bitmap_layer_get_layer(logo_image_layer)); // WWDC14 Text text_image = gbitmap_create_with_resource(RESOURCE_ID_WWDC14TEXT); text_image_layer = bitmap_layer_create(GRect(0, 60, 144, 30)); bitmap_layer_set_bitmap(text_image_layer, text_image); layer_add_child(window_layer, bitmap_layer_get_layer(text_image_layer)); // Countdown text_countdown_layer = text_layer_create(GRect(0, 88, 144, 33)); text_layer_set_text_color(text_countdown_layer, GColorWhite); text_layer_set_background_color(text_countdown_layer, GColorBlack); text_layer_set_font(text_countdown_layer, dolce_vita_font); text_layer_set_text_alignment(text_countdown_layer, GTextAlignmentCenter); text_layer_set_background_color(text_countdown_layer, GColorClear); layer_add_child(window_layer, text_layer_get_layer(text_countdown_layer)); tim_cook_image = gbitmap_create_with_resource(RESOURCE_ID_TIMCOOK); tim_cook_image_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_bitmap(tim_cook_image_layer, tim_cook_image); layer_add_child(window_layer, bitmap_layer_get_layer(tim_cook_image_layer)); layer_set_hidden(bitmap_layer_get_layer(tim_cook_image_layer), true); tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick); accel_tap_service_subscribe(&acceleration_tap_handler); }
static void main_window_load(Window *window) { //Create Gfont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_48)); //Create GBitmap. This must be done before creating the textlayer //As main_window_load draws things front to back 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); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); //Create time textlayer s_time_layer = text_layer_create(GRect(5, 52, 139, 50)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_text(s_time_layer, "00:00"); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); //Create date textlayer s_date_layer = text_layer_create(GRect(5, 20, 144, 50)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_text(s_date_layer, "0101"); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); //Create temperature layer s_weather_layer = text_layer_create(GRect(0, 130, 144, 25)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, GColorWhite); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter); text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text(s_weather_layer, "Loading..."); //Create battery meter layer s_battery_layer = layer_create(GRect(14, 54, 115, 2)); layer_set_update_proc(s_battery_layer, battery_update_proc); //Create bluetooth icon s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON); s_bt_icon_layer = bitmap_layer_create(GRect(59, 12, 30, 30)); bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap); //Add layers to window layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); layer_add_child(window_get_root_layer(window), s_battery_layer); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bt_icon_layer)); }
static void main_window_load(Window *window) { //Create GBitmap, then set to created BitmapLayer 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); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); // Create time TextLayer s_time_layer = text_layer_create(GRect(5, 52, 139, 50)); 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"); //Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_BATMAN_22)); //Apply to 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)); // Create temperature Layer s_weather_layer = text_layer_create(GRect(0, 130, 144, 25)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, GColorBlack); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter); text_layer_set_text(s_weather_layer, "Loading..."); // Create second custom font, apply it and add to Window s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_BATMAN_18)); text_layer_set_font(s_weather_layer, s_weather_font); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); // Make sure the time is displayed from the start update_time(); }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "SimplicITA"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); text_layer_init(&text_day_layer, window.layer.frame); text_layer_set_text_color(&text_day_layer, GColorWhite); text_layer_set_background_color(&text_day_layer, GColorClear); layer_set_frame(&text_day_layer.layer, GRect(8, 40, 144-8, 168-40)); text_layer_set_font(&text_day_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21))); layer_add_child(&window.layer, &text_day_layer.layer); text_layer_init(&text_month_layer, window.layer.frame); text_layer_set_text_color(&text_month_layer, GColorWhite); text_layer_set_background_color(&text_month_layer, GColorClear); layer_set_frame(&text_month_layer.layer, GRect(8, 68, 144-8, 168-68)); text_layer_set_font(&text_month_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21))); layer_add_child(&window.layer, &text_month_layer.layer); text_layer_init(&text_time_layer, window.layer.frame); text_layer_set_text_color(&text_time_layer, GColorWhite); text_layer_set_background_color(&text_time_layer, GColorClear); layer_set_frame(&text_time_layer.layer, GRect(7, 92, 144-7, 168-92)); text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49))); layer_add_child(&window.layer, &text_time_layer.layer); layer_init(&line_layer, window.layer.frame); line_layer.update_proc = &line_layer_update_callback; layer_add_child(&window.layer, &line_layer); PblTm t; get_time(&t); update_time(&t); }
void window_load(Window *window){ //setup text layer for time text_layer = text_layer_create(GRect(0, 120, 132, 168)); text_layer_set_background_color(text_layer, GColorClear); text_layer_set_text_color(text_layer, GColorBlack); text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); text_layer_set_font(text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_POKEMON_GB_24))); layer_add_child(window_get_root_layer(window), (Layer*) text_layer); //Setup Battery Layer batt_layer = text_layer_create(GRect(5, 5, 144, 30)); text_layer_set_font(batt_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_POKEMON_GB_8))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(batt_layer)); //Get info, copy to long-lived buffer and display BatteryChargeState state = battery_state_service_peek(); static char buffer[] = "HP: 100/100"; snprintf(buffer, sizeof("HP: 100/100"), "HP: %d/100", state.charge_percent); text_layer_set_text(batt_layer, buffer); //Subscribe to AccelerometerService (uncomment one to choose) //accel_tap_service_subscribe(accel_tap_handler); accel_data_service_subscribe(1, accel_raw_handler); //Setup Accel Layer accel_layer = text_layer_create(GRect(5, 15, 144, 30)); text_layer_set_font(accel_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_POKEMON_GB_8))); text_layer_set_text(accel_layer, "Accel tap: N/A"); layer_add_child(window_get_root_layer(window), text_layer_get_layer(accel_layer)); //Get a time structure so that the face doesn't start blank struct tm *t; time_t temp; temp = time(NULL); t = localtime(&temp); //Manually call the tick handler when the window is loading tick_handler(t, MINUTE_UNIT); }
static void init() { window = window_create(); window_set_background_color(window, GColorBlack); window_stack_push(window, true); font_on = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ON_20)); font_off = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OFF_20)); for (unsigned i = 0 ; i < WORD_COUNT ; i++) { word_layer_init(i); } // Flag the ones that are always on word_mark(LAYER_IT, 1); word_mark(LAYER_IS, 1); // Create a graphics layer for the entire background minute_layer = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(minute_layer, minute_layer_update); layer_add_child(window_get_root_layer(window), minute_layer); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); }
static void main_window_load(Window *window){ time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_23)); time_layer = text_layer_create(GRect(5, 52, 139, 50)); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_text_color(time_layer, GColorBlack); text_layer_set_text(time_layer, "00:00"); text_layer_set_font(time_layer, time_font); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); update_time(); }
static void m_window_load(Window *window){ s_background_layer=bitmap_layer_create(GRect(0,0,144,168)); s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_RED_BLUE_PNG); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); layer_add_child(window_get_root_layer(window),bitmap_layer_get_layer(s_background_layer)); s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_DOS_VGA_48)); s_time_layer = text_layer_create(GRect(5,52,139,50)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_text(s_time_layer, "00:00"); text_layer_set_font(s_time_layer,s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); s_weather_font=fonts_load_custom_font(resource_get_handle(RESOURCE_ID_DOS_VGA_20)); s_weather_layer = text_layer_create(GRect(0,130,144,25)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, GColorWhite); text_layer_set_text(s_weather_layer, "Loading..."); text_layer_set_font(s_weather_layer,s_weather_font); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); update_time(); }
static void window_load(Window *window) { hour = text_layer_create(GRect(0, 0, 72, 72)); text_layer_set_background_color(hour, GColorClear); text_layer_set_text_color(hour, GColorBlack); text_layer_set_text_alignment(hour,GTextAlignmentRight); layer_add_child(window_get_root_layer(window), (Layer*) hour); text_layer_set_text(hour, "12"); GFont bold = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_COND_BOLD_60)); text_layer_set_font(hour, bold); minute = text_layer_create(GRect(72, 12, 58, 58)); text_layer_set_background_color(minute, GColorClear); text_layer_set_text_color(minute, GColorBlack); layer_add_child(window_get_root_layer(window), (Layer*) minute); text_layer_set_text(minute, "25"); GFont light = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_COND_LIGHT_48)); text_layer_set_font(minute, light); }
static void handle_init( AppContextRef ctx ) { (void) ctx; get_time(&now); window_init(&window, "Main"); window_stack_push(&window, true); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); // If you change the number of timezones, you need to update the ttf resources and these names to the new font size // The resource identifier for the fonts are defined here. e.g. "FONT_ARIAL_12" if ( NUM_TIMEZONES == 4 ) { font_thin = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_12)); font_thick = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_BLACK_20)); } else { font_thin = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_16)); font_thick = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_BLACK_30)); } for (int i = 0 ; i < NUM_TIMEZONES ; i++) { timezone_t * const tz = &timezones[i]; layer_init( &tz->layer, GRect(0, i * LAYER_HEIGHT, PEBBLE_SCREEN_WIDTH, LAYER_HEIGHT) ); tz->layer.update_proc = timezone_layer_update; layer_add_child(&window.layer, &tz->layer); layer_mark_dirty(&tz->layer); } }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "BMO"); window_stack_push(&window, true /* Animated */); resource_init_current_app(&APP_RESOURCES); bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image); layer_add_child(&window.layer, &background_image.layer.layer); // Date Layer text_layer_init(&text_date_layer, window.layer.frame); text_layer_set_text_color(&text_date_layer, GColorBlack); text_layer_set_background_color(&text_date_layer, GColorClear); layer_set_frame(&text_date_layer.layer, GRect(0, 88, 144, 168-88)); text_layer_set_text_alignment(&text_date_layer, GTextAlignmentCenter); text_layer_set_font(&text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_12))); layer_add_child(&window.layer, &text_date_layer.layer); // Time Layer GRect time_rect; text_layer_init(&text_time_layer, window.layer.frame); text_layer_set_text_color(&text_time_layer, GColorBlack); text_layer_set_background_color(&text_time_layer, GColorClear); layer_set_frame(&text_time_layer.layer, GRect(0, 54, 144, 168-54)); text_layer_set_text_alignment(&text_time_layer, GTextAlignmentCenter); text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_29))); layer_add_child(&window.layer, &text_time_layer.layer); // No blank screen on init. PblTm tick_time; get_time(&tick_time); update_display(&tick_time); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); //ACTION: Create GBitmap, then set to created BitmapLayer clock_bitmap = gbitmap_create_with_resource(RESOURCE_ID_bg_image); clock_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_bitmap(clock_layer, clock_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(clock_layer)); //Time TextLayer s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_mermaid_10)); date_layer = text_layer_create(GRect(50, 97, 45, 10)); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_text(date_layer, "Wed 00"); text_layer_set_font(date_layer, s_date_font); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); //Time TextLayer s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_mermaid_18)); time_layer = text_layer_create(GRect(43, 73, 58, 19)); text_layer_set_background_color(time_layer, GColorBlack); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_text(time_layer, "00:00"); text_layer_set_font(time_layer, s_time_font); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); s_hands_layer = layer_create(bounds); layer_set_update_proc(s_hands_layer, hands_update_proc); layer_add_child(window_layer, s_hands_layer); }