void handle_init( void ) { // Create the window, add it to the stack, and get its boundaries. window = window_create(); window_stack_push( window, true ); GRect window_bounds = layer_get_bounds( window_get_root_layer(window) ); // Init the background image layer. background_image = gbitmap_create_with_resource( RESOURCE_ID_IMAGE_BACKGROUND ); background_layer = bitmap_layer_create( window_bounds ); bitmap_layer_set_bitmap( background_layer, background_image ); layer_add_child( window_get_root_layer(window), bitmap_layer_get_layer(background_layer) ); // Init the text layer used to show the time. time_layer = text_layer_create( GRect( 54, 1, 144, 168 ) ); text_layer_set_text_color( time_layer, GColorBlack ); text_layer_set_background_color( time_layer, GColorClear ); text_layer_set_font( time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CHICAGO_13)) ); layer_add_child( window_get_root_layer(window), text_layer_get_layer(time_layer) ); // Init the text layer used to show the date. date_layer = text_layer_create( GRect( 9, 86, 144, 168 ) ); text_layer_set_text_color( date_layer, GColorBlack ); text_layer_set_background_color( date_layer, GColorClear ); text_layer_set_font( date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GENEVA_12)) ); layer_add_child( window_get_root_layer(window), text_layer_get_layer(date_layer) ); // Avoid a blank screen on watch start. time_t t = time( NULL ); struct tm *tick_time = localtime( &t ); update_display( tick_time ); // Request an update signal every second. tick_timer_service_subscribe( SECOND_UNIT, handle_tick ); }
int main(void) { window = window_create(); window_stack_push(window, true); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); //Load in logo image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_LOGO); //Draw the logo image_layer = bitmap_layer_create(bounds); bitmap_layer_set_bitmap(image_layer, image); bitmap_layer_set_alignment(image_layer, GAlignCenter); layer_add_child(window_layer, bitmap_layer_get_layer(image_layer)); //Start main loop app_event_loop(); //Unload the logo gbitmap_destroy(image); //Destroy the graphics layer bitmap_layer_destroy(image_layer); window_destroy(window); }
// init state on app open static void init_stroke_datas(Window *window) { for(int i = 0; i < 4; i++) { StrokeData *stroke_data = &s_stroke_datas[i]; stroke_data->count = 0; stroke_data->bitmap = gbitmap_create_with_resource(RESOURCE_IDS[i + 3]); switch(i) { case 0: stroke_data->text = "Backstroke"; stroke_data->count = persist_read_int(BACKSTROKE_LENGTH_COUNT); break; case 1: stroke_data->text = "Breaststroke"; stroke_data->count = persist_read_int(BREASTSTROKE_LENGTH_COUNT); break; case 2: stroke_data->text = "Butterfly"; stroke_data->count = persist_read_int(BUTTERFLY_LENGTH_COUNT); break; case 3: stroke_data->text = "Freestyle"; stroke_data->count = persist_read_int(FREESTYLE_LENGTH_COUNT); break; } } }
static void main_window_load(Window *window) { // Get info about the window Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); // Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CALIG_48)); // Create GBitmap s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND); // Create BitmapLayer to display image s_background_layer = bitmap_layer_create(bounds); // Set the bitmap onto the layer and add to the window bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_background_layer)); // Create the textLayer with specific bounds s_time_layer = text_layer_create( GRect(0, PBL_IF_ROUND_ELSE(58, 52), bounds.size.w, 50)); // 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, GColorBlack); text_layer_set_text(s_time_layer, "00:00"); text_layer_set_font(s_time_layer, s_time_font); //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_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); deco_layer = layer_create(GRect(0, 0, 144, 8)); layer_set_update_proc(deco_layer, deco_layer_onupdate); arrow_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ARROW_24); image_layer = bitmap_layer_create(GRect(12, 20, 24, 24)); bitmap_layer_set_bitmap(image_layer, arrow_image); text_layer = text_layer_create(GRect(16, 113, 128, 24)); text_layer_set_background_color(text_layer, METRO_APP_BACK_COLOR); text_layer_set_text_color(text_layer, METRO_APP_TEXT_COLOR); text_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OSWALD_LIGHT_18)); text_layer_set_font(text_layer, text_font); time_layer = text_layer_create(GRect(16, 58, 128, 48)); text_layer_set_background_color(time_layer, METRO_APP_BACK_COLOR); text_layer_set_text_color(time_layer, METRO_APP_TEXT_COLOR); time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OSWALD_REGULAR_48)); text_layer_set_font(time_layer, time_font); layer_add_child(window_layer, deco_layer); layer_add_child(window_layer, bitmap_layer_get_layer(image_layer)); layer_add_child(window_layer, text_layer_get_layer(text_layer)); layer_add_child(window_layer, text_layer_get_layer(time_layer)); }
static void set_container_image(GBitmap **bmp_image, BitmapLayer *bmp_layer, const int resource_id, GPoint origin) { GBitmap *old_image = *bmp_image; *bmp_image = gbitmap_create_with_resource(resource_id); GRect frame = (GRect) { .origin = origin, .size = (*bmp_image)->bounds.size }; bitmap_layer_set_bitmap(bmp_layer, *bmp_image); layer_set_frame(bitmap_layer_get_layer(bmp_layer), frame); gbitmap_destroy(old_image); } static void update_hours(struct tm *tick_time) { if(appStarted && hourlyvibe) { //vibe! vibes_short_pulse(); } } static void update_minutes(struct tm *tick_time) { set_container_image(&time_digits_images[2], time_digits_layers[2], BIG_DIGIT_IMAGE_RESOURCE_IDS[tick_time->tm_min/10], GPoint(6, 6)); set_container_image(&time_digits_images[3], time_digits_layers[3], BIG_DIGIT_IMAGE_RESOURCE_IDS[tick_time->tm_min%10], GPoint(75, 6)); }
void replywindow_load(Window *reply_window) { // Creating texts. Pebble screen is 144x168 pixels // "Busy" text busy_text = text_layer_create(GRect(5, 2, 144, 168)); text_layer_set_background_color(busy_text, GColorClear); text_layer_set_text_color(busy_text, GColorBlack); text_layer_set_font(busy_text, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(window_get_root_layer(reply_window), text_layer_get_layer(busy_text)); text_layer_set_text(busy_text, "1. Busy"); // "Will call back" text callback_text = text_layer_create(GRect(5, 56, 144, 168)); text_layer_set_background_color(callback_text, GColorClear); text_layer_set_text_color(callback_text, GColorBlack); text_layer_set_font(callback_text, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(window_get_root_layer(reply_window), text_layer_get_layer(callback_text)); text_layer_set_text(callback_text, "2. Will call back"); // "lol" text lol_text = text_layer_create(GRect(5, 115, 144, 168)); text_layer_set_background_color(lol_text, GColorClear); text_layer_set_text_color(lol_text, GColorBlack); text_layer_set_font(lol_text, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(window_get_root_layer(reply_window), text_layer_get_layer(lol_text)); text_layer_set_text(lol_text, "3. lol"); //Load bitmaps into GBitmap structures replyoptions_bitmap = gbitmap_create_with_resource(RESOURCE_ID_REPLYOPTIONS); // Create BitmapLayers to show GBitmaps and add to Window. "Option" image is 21 x 146 pixels replyoptions_layer = bitmap_layer_create(GRect(123, 4, 21, 146)); bitmap_layer_set_bitmap(replyoptions_layer, replyoptions_bitmap); layer_add_child(window_get_root_layer(reply_window), bitmap_layer_get_layer(replyoptions_layer)); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); // Background image s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BACKGROUND); s_background_layer = bitmap_layer_create(layer_get_bounds(window_layer)); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_background_layer)); // Month and day s_date_layer = text_layer_create(GRect(0, 96, 144, 168-95)); #ifdef PBL_COLOR text_layer_set_text_color(s_date_layer, GColorDarkCandyAppleRed); #else text_layer_set_text_color(s_date_layer, GColorBlack); #endif text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_date_layer)); // The time s_time_layer = text_layer_create(GRect(0, 66, 144, 168-66)); #ifdef PBL_COLOR text_layer_set_text_color(s_time_layer, GColorDarkCandyAppleRed); #else text_layer_set_text_color(s_time_layer, GColorBlack); #endif text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_time_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_PIRATES); 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, 50, 139, 58)); 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_LEFTY_48)); //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)); // Make sure the time is displayed from the start update_time(); }
void colourswap() { if (mask.bitmap_background != NULL) { gbitmap_destroy(mask.bitmap_background); mask.bitmap_background = NULL; } switch (colour) { case 0: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),true); break; case 1: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),false); mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK7); break; case 2: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),false); mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK); break; case 3: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),false); mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK2); break; case 4: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),false); mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK6); break; case 5: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),false); mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK5); break; case 6: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),false); mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK4); break; case 7: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),false); mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK1); break; case 8: layer_set_hidden(effect_layer_get_layer(effect_layer_mask),false); mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK3); break; } if (mask.bitmap_background != NULL) { effect_layer_add_effect(effect_layer_mask, effect_mask, &mask); layer_mark_dirty(effect_layer_get_layer(effect_layer_mask)); } }
void Update_Connection(bool Connected){ if (Settings.Vibe_BT) vibes_long_pulse(); gbitmap_destroy(s_res_bt_picture); s_res_bt_picture = gbitmap_create_with_resource(BT_Icons[Connected]); bitmap_layer_set_bitmap(BT_Layer, s_res_bt_picture); }
void passcode_draw(GContext* ctx, char *passcode, int *timer, const int type) { graphics_context_set_text_color(ctx, GColorBlack); if (!s_down || !s_up || !s_center) { s_down = gbitmap_create_with_resource(RESOURCE_ID_DOWN); s_up = gbitmap_create_with_resource(RESOURCE_ID_UP); s_center = gbitmap_create_with_resource(RESOURCE_ID_CENTER); } int i, x; for (i = 0; i < (int)strlen(passcode); i++) { x = 26*i + 10; switch(passcode[i] - 48) { case 1: graphics_draw_bitmap_in_rect(ctx, s_up, (GRect) {.origin = {x, 65}, .size = {20, 20}}); break; case 2: graphics_draw_bitmap_in_rect(ctx, s_center, (GRect) {.origin = {x, 65}, .size = {20, 20}});
// Setup the action bar on the side of the app static void action_bar_init(){ s_play_icon = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PLAY); s_pause_icon = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PAUSE); s_refresh_icon = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_REFRESH); s_share_icon = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SHARE); if(timer.paused) s_select_button_icon = s_play_icon; else s_select_button_icon = s_pause_icon; action_bar_layer_set_icon(action_bar, BUTTON_ID_UP, s_refresh_icon); action_bar_layer_set_icon(action_bar, BUTTON_ID_SELECT, s_select_button_icon); if(bluetooth_connection_service_peek()){ action_bar_layer_set_icon(action_bar, BUTTON_ID_DOWN, s_share_icon); } bluetooth_connection_service_subscribe(bluetooth_connection_handler); }
//! Create window data and layers in here, as well as any variable prepping //! @param window A pointer to the window the load was called by static void prv_window_load_handler(Window *window) { // window properties Layer *root = window_get_root_layer(window); GRect bounds = layer_get_bounds(root); WindowData *data = (WindowData*)malloc(sizeof(WindowData)); // check return if (data) { // set window properties window_set_user_data(window, data); window_set_click_config_provider_with_context(window, prv_click_config_provider, data); // create drawing layer and store pointer to window data in it data->draw_layer = layer_create_with_data(bounds, sizeof(StickFigure*)); WindowData **layer_data = (WindowData**)layer_get_data(data->draw_layer); (*layer_data) = data; layer_set_update_proc(data->draw_layer, prv_layer_update_proc_handler); layer_add_child(root, data->draw_layer); // create the stick figure data->stick_figure = stick_figure_create(); stick_figure_snap_pose(data->stick_figure, PoseWaitingForStart, prv_get_epoch_ms()); // create the button data->button = drawing_button_create(); // set some window data properties data->start_epoch = 0; // load image resources data->config_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CONFIG); data->grid_1_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_GRID_1); data->grid_2_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_GRID_2); // open app message communication with the phone app_message_set_context(data); app_message_register_inbox_received(prv_inbox_recived); app_message_open(APP_MESSAGE_INBOX_SIZE_MINIMUM, APP_MESSAGE_OUTBOX_SIZE_MINIMUM); // start first refresh data->app_timer = app_timer_register(REFRESH_RATE_MS_PER_FRAME, prv_app_timer_callback, data); return; } // error handling window_stack_remove(window, false); APP_LOG(APP_LOG_LEVEL_ERROR, "Error: Failed to allocate memory for WindowData."); }
void window_load( Window *window ) { // Initialize the action bar: actionBar = action_bar_layer_create(); // Associate the action bar with the window: action_bar_layer_add_to_window( actionBar, window ); // Set the click config provider: action_bar_layer_set_click_config_provider( actionBar, click_config_provider ); // Set the icons: bitmapRing = gbitmap_create_with_resource( RESOURCE_ID_IMAGE_RING_ICON ); bitmapSilence = gbitmap_create_with_resource( RESOURCE_ID_IMAGE_SILENCE_ICON ); // Set the icons: action_bar_layer_set_icon( actionBar, BUTTON_ID_UP, bitmapRing ); action_bar_layer_set_icon( actionBar, BUTTON_ID_DOWN, bitmapSilence ); }
static void render_image(uint8_t image_index, GContext* ctx) { if (icon_bitmap) { gbitmap_destroy(icon_bitmap); } icon_bitmap = gbitmap_create_with_resource(STATUS_RESOURCES[image_index]); GRect bounds = icon_bitmap->bounds; bitmap_layer_set_bitmap(icon_layer, icon_bitmap); }
void win_viera_init(void) { logo_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_VIERA); window = window_create(); window_set_window_handlers(window, (WindowHandlers) { .load = window_load, .unload = window_unload, });
static void set_container_image(GBitmap **bmp_image, BitmapLayer *bmp_layer, const int resource_id){ GBitmap *old_image = *bmp_image; *bmp_image = gbitmap_create_with_resource(resource_id); bitmap_layer_set_bitmap(bmp_layer, *bmp_image); gbitmap_destroy(old_image); }
static GBitmap *create_bitmap_with_id(SimplyImage *image, void *data) { const uint32_t id = (uint32_t)(uintptr_t) data; GBitmap *bitmap = gbitmap_create_with_resource(id); if (bitmap) { image->id = id; } return bitmap; }
static void bt_handler(bool connected) { if (s_bluetooth) gbitmap_destroy(s_bluetooth); s_bluetooth = gbitmap_create_with_resource(connected ? RESOURCE_ID_PHONE_BLANK : RESOURCE_ID_PHONE_X); bitmap_layer_set_bitmap(s_bluetooth_layer, s_bluetooth); layer_mark_dirty(bitmap_layer_get_layer(s_bluetooth_layer)); }
void set_bluetooth_layer() { bluetooth_layer = bitmap_layer_create(GRect (62, 5, 20, 10)); //(x,y,w,h) (x,y,144*168) off_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH_OFF); bitmap_layer_set_bitmap(bluetooth_layer, on_image); //layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bluetooth_layer)); }
void load_icon_into_layer(int value, Layer* layer) { if ((int) layer == (int) conn_layer) { if (conn_image != NULL) { gbitmap_destroy(conn_image); } conn_image = gbitmap_create_with_resource(CONN_RESOURCE_IDS[value]); bitmap_layer_set_bitmap(conn_layer, conn_image); layer_mark_dirty(bitmap_layer_get_layer(conn_layer)); } else if ((int) layer == (int) battery_layer) { if (battery_image != NULL) { gbitmap_destroy(battery_image); } battery_image = gbitmap_create_with_resource(BATT_RESOURCE_IDS[value]); bitmap_layer_set_bitmap(battery_layer, battery_image); layer_mark_dirty(bitmap_layer_get_layer(battery_layer)); } }
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); }
static void init(void) { reward = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_REWARD); star = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_STAR); load_text(KEY_BALANCE, false); load_text(KEY_REWARDS, false); load_text(KEY_STARS, false); load_text(KEY_STATUS, false); window = window_create(); window_set_fullscreen(window, true); window_set_background_color(window, GColorBlack); window_set_click_config_provider(window, click_config_provider); window_set_window_handlers(window, (WindowHandlers) { .load = window_load, .unload = window_unload, });
void splash_window_load(Window *window) { splash_bitmap = gbitmap_create_with_resource(RESOURCE_ID_SPLASH); splash_bitmap_layer = bitmap_layer_create(GRect(5, 5, 130, 130)); bitmap_layer_set_bitmap(splash_bitmap_layer, splash_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(splash_bitmap_layer)); app_timer_register(SPLASH_SEC * 1000,(AppTimerCallback) after_splash_window, NULL); }
// Init function to handle the creation of layers, // event subscribing, etc void handle_init(void) { // window init window = window_create(); window_stack_push(window, true); window_set_background_color(window, GColorWhite); // display layer Layer *window_layer = window_get_root_layer(window); // background leafs = gbitmap_create_with_resource(RESOURCE_ID_BKNG); leafs_layer = bitmap_layer_create(GRect(0, 0, WATCH_WIDTH, WATCH_HEIGHT)); bitmap_layer_set_bitmap(leafs_layer, leafs); layer_add_child(window_layer, bitmap_layer_get_layer(leafs_layer)); GFont prox_reg = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PROXIMA_REGULAR_16)); GFont prox_bold = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PROXIMA_BOLD_30)); // time init text_time_layer = text_layer_create(GRect(55, 100,(WATCH_WIDTH - 55), 50)); text_layer_set_font(text_time_layer, prox_bold); text_layer_set_background_color(text_time_layer, GColorClear); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); // date init text_date_layer = text_layer_create(GRect(55, 130, (WATCH_WIDTH - 55), 20)); text_layer_set_font(text_date_layer, prox_reg); text_layer_set_background_color(text_date_layer, GColorClear); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); // score init text_score_layer = text_layer_create(GRect(55, 15, (WATCH_WIDTH - 55), 20)); text_layer_set_font(text_score_layer, prox_reg); text_layer_set_text_color(text_score_layer, GColorWhite); text_layer_set_background_color(text_score_layer, GColorClear); layer_add_child(window_layer, text_layer_get_layer(text_score_layer)); //update_display(tick_time); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); // AppSync stuff const int inbound_size = 64; const int outbound_size = 64; app_message_open(inbound_size, outbound_size); Tuplet initial_values[] = { TupletCString(0, "0-0") }; app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL); send_cmd(); // setting up timer to send cmds for updates timer = app_timer_register(10000, timer_callback, NULL); }
static void load_bitmaps() { big_light = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BIG_LIGHT); big_medium = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BIG_MEDIUM); big_dark = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BIG_DARK); small_light = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SMALL_LIGHT); small_medium = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SMALL_MEDIUM); small_dark = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SMALL_DARK); circle_light = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CIRCLE_LIGHT); circle_dark = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CIRCLE_DARK); }
void menu_load(Window *menu) { int num_menu_items = 0; main_menu_items[num_menu_items++] = (SimpleMenuItem) { .title = "Ask", .callback = search_select_callback, }; main_menu_items[num_menu_items++] = (SimpleMenuItem) { .title = "Answers", //.callback = //callback to what you want this item to do when clicked }; main_menu_items[num_menu_items++] = (SimpleMenuItem) { .title = "Questions", //.callback = //callback to what you want this item to do when clicked }; main_menu_items[num_menu_items++] = (SimpleMenuItem) { .title = "Help", .callback = help_select_callback, }; main_menu_sections[0] = (SimpleMenuSection) { .num_items = MENU_NUM_ITEMS, .items = main_menu_items }; GRect bounds = layer_get_bounds(window_get_root_layer(menu)); main_menu_layer = simple_menu_layer_create(bounds, menu, main_menu_sections, MENU_NUM_SECTIONS, NULL); layer_add_child(window_get_root_layer(menu), simple_menu_layer_get_layer(main_menu_layer)); } void menu_unload(Window *menu) { text_layer_destroy(menu_text); text_layer_destroy(select_text); } void title_load(Window *title) { title_bitmap = gbitmap_create_with_resource(RESOURCE_ID_REDDIT_TITLE_IMAGE); title_layer = bitmap_layer_create(GRect(0, 0, 144, 180)); bitmap_layer_set_bitmap(title_layer, title_bitmap); layer_add_child(window_get_root_layer(title), bitmap_layer_get_layer(title_layer)); } void title_unload(Window *title) { bitmap_layer_destroy(title_layer); } void title_click_handler(ClickRecognizerRef recognizer, void *context) { window_stack_push(menu, true); }
void Weather_init() { // if possible, load weather data from persistent storage printf("starting weather!"); if (persist_exists(WEATHERINFO_PERSIST_KEY)) { printf("current key exists!"); WeatherInfo w; persist_read_data(WEATHERINFO_PERSIST_KEY, &w, sizeof(WeatherInfo)); Weather_weatherInfo = w; #ifdef PBL_COLOR Weather_currentWeatherIcon = gdraw_command_image_create_with_resource(w.currentIconResourceID); #else Weather_currentWeatherIcon = gbitmap_create_with_resource(w.currentIconResourceID); #endif } else { printf("current key does not exist!"); // otherwise, use null data Weather_currentWeatherIcon = NULL; Weather_weatherInfo.currentTemp = INT32_MIN; } if (persist_exists(WEATHERFORECAST_PERSIST_KEY)) { printf("forecast key exists!"); WeatherForecastInfo w; persist_read_data(WEATHERFORECAST_PERSIST_KEY, &w, sizeof(WeatherForecastInfo)); Weather_weatherForecast = w; #ifdef PBL_COLOR Weather_forecastWeatherIcon = gdraw_command_image_create_with_resource(w.forecastIconResourceID); #else Weather_forecastWeatherIcon = gbitmap_create_with_resource(w.forecastIconResourceID); #endif } else { printf("forecast key does not exist!"); Weather_forecastWeatherIcon = NULL; Weather_weatherForecast.highTemp = INT32_MIN; Weather_weatherForecast.lowTemp = INT32_MIN; } }
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])); } }