static void update_backgroundImage(int weatherId, bool isDay){ gbitmap_destroy(background_bitmap); /* 0 = clear 1 = cloud 2 = partly 3 = foggy 4 = rain 5 = thunder */ // Assemble full string and display text_layer_set_text(temp_layer, temperature_buffer); if( weatherId == 0 ) { if(isDay){ background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SUNNY); } else { background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MOON); } } else if( weatherId == 1 ) { background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CLOUD); } else if( weatherId == 2 ) { if(isDay){ background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PARTLY); } else { background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CLOUD_MOON); } } else if( weatherId == 3 ) { background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_FOGGY); } else if( weatherId == 4 ) { background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_RAINY); } else if( weatherId == 5 ) { background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_THUNDER); } else { if(isDay){ background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SUNNY); } else { background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MOON); } } bitmap_layer_set_bitmap(background_layer, background_bitmap); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); // Create sequence // s_sequence = gbitmap_sequence_create_with_resource(RESOURCE_ID_SLOTH_ANIMATE); // Create blank GBitmap using APNG frame size // GSize frame_size = gbitmap_sequence_get_bitmap_size(s_sequence); // s_bitmap = gbitmap_create_blank(frame_size, GBitmapFormat8Bit); s_bitmap = gbitmap_create_with_resource(RESOURCE_ID_SLOTH_OKAY); s_bitmap_layer = bitmap_layer_create(GRect(5, 5, 130, 112)); bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet); bitmap_layer_set_bitmap(s_bitmap_layer, s_bitmap); s_label_layer = make_text_layer(85, 100, FONT_KEY_GOTHIC_24_BOLD); s_value_layer = make_text_layer(0, 110, FONT_KEY_ROBOTO_BOLD_SUBSET_49 ); layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer)); layer_add_child(window_layer, text_layer_get_layer(s_value_layer)); layer_add_child(window_layer, text_layer_get_layer(s_label_layer)); }
/* Handle bluetooth events */ void handle_bluetooth( bool connected ) { if ( bluetooth_image != NULL ) { gbitmap_destroy( bluetooth_image ); } if ( connected ) { bluetooth_image = gbitmap_create_with_resource( RESOURCE_ID_IMAGE_BLUETOOTH ); } else { bluetooth_image = gbitmap_create_with_resource( RESOURCE_ID_IMAGE_NO_BLUETOOTH ); if ( prev_bt_status != connected && bluetoothvibe_status) { vibes_short_pulse(); } } prev_bt_status = connected; bitmap_layer_set_bitmap( bluetooth_layer, bluetooth_image ); }
static void load_bitmap(unsigned short image_number, BitmapLayer** layer, GBitmap** bitmap, GColor color, int x, int y) { unload_bitmap(layer, bitmap); *bitmap = gbitmap_create_with_resource(IMAGE_RESOURCE_IDS[image_number]); replace_gbitmap_color(GColorBlack, color, *bitmap, NULL); #ifdef PBL_PLATFORM_BASALT GRect bounds = gbitmap_get_bounds(*bitmap); #else GRect bounds = *bitmap->bounds; #endif *layer = bitmap_layer_create(GRect(x,y, bounds.size.w, bounds.size.h)); bitmap_layer_set_bitmap(*layer, *bitmap); bitmap_layer_set_compositing_mode(*layer, GCompOpSet); layer_add_child(window_layer, bitmap_layer_get_layer(*layer)); }
//accelerometer handler, this code will loop constantly when the program launches at the rate specified by accel_service_set_sampling_rate() //function during the initialization phase. static void data_handler(AccelData *data, uint32_t num_samples) { double z_val = data[0].z; //if the watch is tipped past ~90 deg advance the animation frame by one if(z_val > 0 && animation_frame < 11){ ++animation_frame; } //if the watch is not being tipped past ~90 deg, move one frame back else if(z_val < 0 && animation_frame > 1) { --animation_frame; } //big ol' switch statement to animate this mess. //note that if the animation reaches the last frame, //the animation_frame counter is set to 5 before breaking out of the code block //this is so that the animation will continue to run, but will start over about half-way //through the loop to avoid the animation running backwards from an unnatural point in the series //(e.g. the barf flying back into the cat's mouth, yeesh) //it will also allow the animation to keep running from that point so as to crack your friends up. switch (animation_frame){ case 1: bitmap_layer_set_bitmap(image_layer, seasick_the_cat_bmp_01); break; case 2: bitmap_layer_set_bitmap(image_layer, seasick_the_cat_bmp_02); break; case 3: bitmap_layer_set_bitmap(image_layer, seasick_the_cat_bmp_03); break; case 4: bitmap_layer_set_bitmap(image_layer, seasick_the_cat_bmp_04); break; case 5: bitmap_layer_set_bitmap(image_layer, seasick_the_cat_bmp_05); break; case 6: bitmap_layer_set_bitmap(image_layer, seasick_the_cat_bmp_06); break; case 7: //bitmap_layer_set_bitmap(image_layer, seasick_the_cat_bmp_06); animation_frame = 1; break; } }
static void cb_in_received_handler(DictionaryIterator *iter, void *context) { // Get the bitmap Tuple *size_tuple = dict_find(iter, KEY_SIZE); if (size_tuple){ if (data_image) { free(data_image); data_image = NULL; } data_size = size_tuple->value->uint32; data_image = malloc(data_size); } Tuple *image_tuple = dict_find(iter, KEY_IMAGE); Tuple *index_tuple = dict_find(iter, KEY_INDEX); if (index_tuple && image_tuple) { int32_t index = index_tuple->value->int32; APP_LOG(APP_LOG_LEVEL_DEBUG, "image received index=%ld size=%d", index, image_tuple->length); memcpy(data_image + index, &image_tuple->value->uint8, image_tuple->length); if (image_tuple->length < CHUNK_SIZE){ if (image){ gbitmap_destroy(image); image = NULL; } #ifdef PBL_COLOR image = gbitmap_create_from_png_data(data_image, data_size); #else image = gbitmap_create_with_data(data_image); #endif bitmap_layer_set_bitmap(image_layer, image); text_layer_set_text(webcam_status_text_layer, ""); layer_mark_dirty(bitmap_layer_get_layer(image_layer)); } } Tuple *message_tuple = dict_find(iter, KEY_MESSAGE); if (message_tuple){ text_layer_set_text(webcam_status_text_layer, message_tuple->value->cstring); } }
// Window Handlers static void main_window_load(Window *window) { // background s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BACKGROUND_IMAGE); 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)); // date text layer s_date_layer = text_layer_create(GRect(0, 10, 144, 40)); text_layer_set_background_color(s_date_layer, GColorBlack); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); // time text layer 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); // weather layer s_weather_layer = text_layer_create(GRect(0, 120, 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..."); // improve the view s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PERFECT_DOS_VGA_48)); s_standard_font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); improve_text_layer(s_time_layer, s_time_font); improve_text_layer(s_date_layer, s_standard_font); improve_text_layer(s_weather_layer, s_standard_font); // add our text layers 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_time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); // displays time upon load update_time(); update_date(); }
void init(void) { // Init the global stuff window = window_create(); window_stack_push(window, true); Layer *window_layer = window_get_root_layer(window); GRect window_bounds = layer_get_bounds(window_layer); last_hour = -1; last_minute = -1; // Get local values and set them as a defaults seconds = persist_read_int(setting_seconds); background = persist_read_int(setting_background); info = persist_read_int(setting_info); digital = persist_read_int(setting_digital); // Load settings Tuplet tuples[] = { TupletInteger(setting_seconds, seconds), TupletInteger(setting_background, background), TupletInteger(setting_info, info), TupletInteger(setting_digital, digital) }; app_message_open(160, 160); app_sync_init(&app, buffer, sizeof(buffer), tuples, ARRAY_LENGTH(tuples), tuple_changed_callback, app_error_callback, NULL); // Init background background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND); background_simple_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND_SIMPLE); background_layer = bitmap_layer_create(window_bounds); bitmap_layer_set_bitmap(background_layer, (background == background_simple) ? background_simple_bitmap : background_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(background_layer)); // Init info info_container = layer_create(window_bounds); layer_add_child(window_layer, info_container); info_layer = layer_create(window_bounds); bluetooth_layer = text_layer_create((GRect) { .origin = { 0, 0 }, .size = { 44, 18 } });
static void main_window_load(Window *window) { //Initialize the backgrounds we can select s_dog_bg = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_DOG); s_cat_bg = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_CAT); s_bird_bg = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_BIRD); // Create time TextLayer s_time_layer = text_layer_create(GRect(0, 0, 144, 32)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); // Improve the layout to be more like a watchface s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MULI_24)); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); //Check for saved background option char facebg[20]; persist_read_string(KEY_BG, facebg, sizeof(facebg)); if(strcmp(facebg,"dog") == 0){ s_bg_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_DOG); }else if(strcmp(facebg,"cat") == 0){ s_bg_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_CAT); }else if(strcmp(facebg,"bird") == 0){ s_bg_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_BIRD); } //Declare a bitmap layer //static BitmapLayer *s_bitmap_layer; //Create bitmap layer and set it to show the GBitmap s_bitmap_layer = bitmap_layer_create(GRect(0,0,144,168)); bitmap_layer_set_bitmap(s_bitmap_layer,s_bg_bitmap); //Add the bitmaplayer as a child layer to the window: layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bitmap_layer)); // Add text layer 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)); }
void draw_timer_callback(void *data) { int direction = rand()%5; while (((direction == 0) && (last_direction == 0)) || ( ((direction == 2) || (direction == 5)) &&(facing == 1)&&(last_direction!= 0)) || ( ((direction == 3) || (direction == 4)) &&(facing == 0)&&(last_direction!= 0))) { direction = rand()%4; } if (direction == 0) { // up y = y-(6*pixel_multiplier); if (facing == 0) { selected_gbit = gbfly_lu; } else { selected_gbit = gbfly_ru; } } else if (direction == 1) { // down y=y+(3*pixel_multiplier); if (facing == 0) { selected_gbit = gbfly_ld; } else { selected_gbit = gbfly_rd; } } else if ((direction == 2)||(direction == 5)) { // left x=x-(3*pixel_multiplier); selected_gbit = gbfly_ld; facing = 0; } else if ((direction == 3)||(direction == 4)) { // right x=x+(3*pixel_multiplier); facing = 1; selected_gbit = gbfly_rd; } bitmap_layer_set_bitmap(draw_layer, selected_gbit); layer_set_bounds(bitmap_layer_get_layer(draw_layer), GRect(x, y, 144-x, 112-y)); last_direction = direction; if (is_window_loaded == 1) { drawtimer = app_timer_register(100, draw_timer_callback, NULL); } }
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()); }
//Window load static void main_window_load(Window *window) { //Bitmap and Bitmap layer 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(s_main_window), bitmap_layer_get_layer(s_background_layer)); //Time layer 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"); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_48)); 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)); layer_add_child(window_get_root_layer(s_main_window), text_layer_get_layer(s_time_layer)); }
static void main_window_load(Window *window){ Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); // s_image_layer = layer_create(bounds); s_image_layer = bitmap_layer_create(bounds); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_image_layer)); s_happy = gbitmap_create_with_resource(RESOURCE_ID_HAPPY); s_neutral = gbitmap_create_with_resource(RESOURCE_ID_NEUTRAL); s_sad = gbitmap_create_with_resource(RESOURCE_ID_SAD); /** s_output_layer = text_layer_create(GRect(5, 0, window_bounds.size.w - 10, window_bounds.size.h)); text_layer_set_font(s_output_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text(s_output_layer, "move"); text_layer_set_overflow_mode(s_output_layer, GTextOverflowModeWordWrap); layer_add_child(window_layer, text_layer_get_layer(s_output_layer)); */ bitmap_layer_set_bitmap(s_image_layer,s_happy); }
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_AILEYA); GRect bitmap_bounds = gbitmap_get_bounds(s_icon_bitmap); s_icon_layer = bitmap_layer_create(GRect(0, 0, 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_tick_bitmap = gbitmap_create_with_resource(RESOURCE_ID_MENU_1); s_cross_bitmap = gbitmap_create_with_resource(RESOURCE_ID_MENU_2); s_action_bar_layer = action_bar_layer_create(); action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_UP, s_tick_bitmap); action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_DOWN, s_cross_bitmap); action_bar_layer_add_to_window(s_action_bar_layer, window); }
/* Update the text layer for the battery status */ void qtp_update_battery_status(bool mark_dirty) { BatteryChargeState charge_state = battery_state_service_peek(); static char battery_text[] = "100%"; snprintf(battery_text, sizeof(battery_text), "%d%%", charge_state.charge_percent); if (charge_state.charge_percent >= 85) { qtp_battery_image = qtp_battery_images[2]; } else if (charge_state.charge_percent <= 30) { qtp_battery_image = qtp_battery_images[0]; } else { qtp_battery_image = qtp_battery_images[1]; } bitmap_layer_set_bitmap(qtp_battery_image_layer, qtp_battery_image); text_layer_set_text(qtp_battery_text_layer, battery_text); if (mark_dirty) { layer_mark_dirty(text_layer_get_layer(qtp_battery_text_layer)); layer_mark_dirty(bitmap_layer_get_layer(qtp_battery_image_layer)); } }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); //Bitmap Layyer + GBitmap s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ROBOSTANGS_LOGO); s_background_layer = bitmap_layer_create(bounds); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); bitmap_layer_set_alignment(s_background_layer, GAlignTop); layer_add_child(window_layer, bitmap_layer_get_layer(s_background_layer)); //Time layer s_time_layer = text_layer_create(GRect(0, 125, bounds.size.w, 50)); s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BANK_GOTHIC_30)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, PBL_IF_BW_ELSE(GColorWhite, GColorChromeYellow)); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); }
void LoadFaces(Window *ParentWindow) { QuestionFaceBitmap = gbitmap_create_with_resource(QUESTIONFACE); for(int FaceIdx = 0; FaceIdx < C_MAX; ++FaceIdx) { FacesBitmaps[FaceIdx] = gbitmap_create_with_resource(Faces[FaceIdx]); FacesGreyBitmaps[FaceIdx] = gbitmap_create_with_resource(FacesGrey[FaceIdx]); } // Create GBitmap, then set to created BitmapLayer FacesLayer = layer_create(GRect(FACESTARTX, FACESTARTY, (FACESIZEX * 2) + FACEGAP, (FACESIZEY * 4) + (FACEGAP * 3))); //Parent to background bitmap_layer_set_bitmap(BackgroundLayer, BackgroundBitmap); layer_add_child(bitmap_layer_get_layer(BackgroundLayer), FacesLayer); //Set update func layer_set_update_proc(FacesLayer, DrawFaces); }
static void init(void) { // Create window window = window_create(); window_stack_push(window, true); // Load images bg_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG); pony_black_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PONY_BLACK); pony_white_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PONY_WHITE); hour_black_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HOUR_BLACK); hour_white_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HOUR_WHITE); minute_black_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MINUTE_BLACK); minute_white_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MINUTE_WHITE); // Create bg layer bg_layer = bitmap_layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); bitmap_layer_set_bitmap(bg_layer, bg_image); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bg_layer)); // Create minute_layer minute_layer = trans_rot_bitmap_layer_create(minute_black_image, minute_white_image); trans_rot_bitmap_layer_set_frame(minute_layer, GRect(-39, -27, 221, 221)); trans_rot_bitmap_layer_add_child(bitmap_layer_get_layer(bg_layer), minute_layer); // Create pony layer pony_layer = trans_bitmap_layer_create(pony_black_image, pony_white_image, GRect(PONY_X, PONY_Y, PONY_WIDTH, SCREEN_WIDTH)); //trans_rot_bitmap_layer_set_frame(pony_layer, GRect(-39, -27, 221, 221)); trans_bitmap_layer_add_child(bitmap_layer_get_layer(bg_layer), pony_layer); // Create hour layer hour_layer = trans_rot_bitmap_layer_create(hour_black_image, hour_white_image); trans_rot_bitmap_layer_set_frame(hour_layer, GRect(-39, -27, 221, 221)); trans_rot_bitmap_layer_add_child(bitmap_layer_get_layer(bg_layer), hour_layer); time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_tick(current_time, MINUTE_UNIT); // Subscribe minute handler tick_timer_service_subscribe(MINUTE_UNIT, &handle_tick); }
static void tuple_changed_callback(const uint32_t key, const Tuple* tuple_new, const Tuple* tuple_old, void* context) { int value = tuple_new->value->uint8; switch (key) { case setting_seconds: seconds = value; persist_write_int(setting_seconds, seconds); if (seconds == seconds_on) enable_seconds(); else disable_seconds(); break; case setting_background: background = value; persist_write_int(setting_background, background); bitmap_layer_set_bitmap(background_layer, (background == background_simple) ? background_simple_bitmap : background_bitmap); layer_mark_dirty((Layer*) background_layer); break; case setting_info: info = value; persist_write_int(setting_info, info); if (info == info_on) enable_info(); else disable_info(); break; case setting_digital: digital = value; persist_write_int(setting_digital, digital); if (digital == digital_off) disable_digital(); else enable_digital(); break; } update_now(); }
static void main_window_load(Window *window) { time_t now = time(NULL); struct tm *tick_time = localtime(&now); block_o_bitmap = gbitmap_create_with_resource(RESOURCE_ID_block_o_background); #if defined(PBL_RECT) block_o_layer = bitmap_layer_create(GRect(0,0,144,168)); #elif defined(PBL_ROUND) block_o_layer = bitmap_layer_create(GRect(18,6,144,168)); #endif bitmap_layer_set_bitmap(block_o_layer, block_o_bitmap); #if defined(PBL_BW) bitmap_layer_set_compositing_mode(block_o_layer, GCompOpAssign); #elif defined(PBL_COLOR) bitmap_layer_set_compositing_mode(block_o_layer, GCompOpSet); #endif layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(block_o_layer)); display_time(tick_time); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); }
void load_digit_image_into_slot(int slot_number, int digit_value, bool reversed) { if ((slot_number < 0) || (slot_number >= TOTAL_IMAGE_SLOTS)) { return; } if ((digit_value < 0) || (digit_value > 9)) { return; } if(bitmaps[slot_number]){ return; } if(reversed){ bitmaps[slot_number] = gbitmap_create_with_resource(IMAGE_RESOURCE_REVERSE_IDS[digit_value]); }else{ bitmaps[slot_number] = gbitmap_create_with_resource(IMAGE_RESOURCE_IDS[digit_value]); } bitmap_layer_set_bitmap(image_containers[slot_number],bitmaps[slot_number]); }
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]); 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 battery_callback(BatteryChargeState state) { snprintf(battery_level_text, 8, "%d%%", state.charge_percent); if (state.is_charging == true) { bitmap_layer_set_bitmap(battery_icon_layer, battery_loading_bitmap); } else if (state.charge_percent >= 90) { bitmap_layer_set_bitmap(battery_icon_layer, battery_5_bitmap); } else if (state.charge_percent >= 70) { bitmap_layer_set_bitmap(battery_icon_layer, battery_4_bitmap); } else if (state.charge_percent >= 50) { bitmap_layer_set_bitmap(battery_icon_layer, battery_3_bitmap); } else if (state.charge_percent >= 30) { bitmap_layer_set_bitmap(battery_icon_layer, battery_2_bitmap); } else if (state.charge_percent >= 10) { bitmap_layer_set_bitmap(battery_icon_layer, battery_1_bitmap); } else { bitmap_layer_set_bitmap(battery_icon_layer, battery_0_bitmap); } text_layer_set_text(battery_text_layer, battery_level_text); }
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); GRect bounds = layer_get_bounds(window_layer); display_layer = layer_create(bounds); background_image_layer = bitmap_layer_create(bounds); bitmap_layer_set_bitmap(background_image_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND)); layer_add_child(window_layer, bitmap_layer_get_layer(background_image_layer)); layer_set_update_proc(display_layer, display_layer_update_callback); layer_add_child(window_layer, display_layer); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); layer_mark_dirty(display_layer); }
static void psLoad(Window *window) { //APP_LOG(APP_LOG_LEVEL_DEBUG, "Enter psLoad()"); //psRestorePersistentData(); // Chronometer time that elapsed while window was not open. time_t timeSinceClosed = 0; if (chronoRunSelect == RUN_START) { timeSinceClosed = time(NULL) - chronoCloseTm; } chronoElapsed += timeSinceClosed; Layer * psWindowLayer = window_get_root_layer(psWindow); window_set_background_color(psWindow, GColorBlack); psChronoLayer = text_layer_create(GRect(0, 0, 144, 32)); text_layer_set_text_alignment(psChronoLayer, GTextAlignmentCenter); text_layer_set_font(psChronoLayer, fonts_get_system_font(FONT_KEY_GOTHIC_28)); text_layer_set_background_color(psChronoLayer, GColorWhite); text_layer_set_text_color(psChronoLayer, GColorBlack); displayChrono(); layer_add_child(psWindowLayer, text_layer_get_layer(psChronoLayer)); psSplitsLayer = text_layer_create(GRect(0, 34, 144, 134)); text_layer_set_text_alignment(psSplitsLayer, GTextAlignmentCenter); text_layer_set_font(psSplitsLayer, fonts_get_system_font(FONT_KEY_GOTHIC_28)); text_layer_set_background_color(psSplitsLayer, GColorWhite); text_layer_set_text_color(psSplitsLayer, GColorBlack); psGenerateSplits(); psDisplaySelectedSplits(); layer_add_child(psWindowLayer, text_layer_get_layer(psSplitsLayer)); ssIconLayer = bitmap_layer_create(GRect(130, 67, 14, 30)); bitmap_layer_set_bitmap(ssIconLayer, startStopIcon); layer_add_child(psWindowLayer, bitmap_layer_get_layer(ssIconLayer)); window_set_click_config_provider(psWindow, (ClickConfigProvider) ps_click_config_provider); // Start keeping track of chrono elapsed. tick_timer_service_subscribe(SECOND_UNIT, ps_handle_second_tick); }
// prepare all layers and window static void main_window_load(Window *window) { // logo s_logo_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_LOGO); s_logo_layer = bitmap_layer_create(GRect(3, 3, 144, 66)); bitmap_layer_set_bitmap(s_logo_layer, s_logo_bitmap); // VIAcode text s_text_layer = text_layer_create(GRect(0, 66, 144, 120)); text_layer_set_background_color(s_text_layer, GColorWhite); text_layer_set_text_color(s_text_layer, GColorBlack); text_layer_set_text(s_text_layer, "VIAcode"); // time s_time_layer = text_layer_create(GRect(0, 115, 144, 168)); text_layer_set_background_color(s_time_layer, GColorWhite); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_text(s_time_layer, "00:00"); // font and aligment 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); text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK)); text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter); // add layers to window layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_text_layer)); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_logo_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); // invert colors if needed if (invertColors) { // screen size 144x168 s_invert_layer = inverter_layer_create(GRect(0, 0, 144, 168)); layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(s_invert_layer)); } // show time update_time(); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); app_message_open(inbox_size, outbox_size); compass_service_subscribe(compass_heading_handler); // 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. s_text_layer = text_layer_create(layer_frame_description); text_layer_set_text(s_text_layer, "Point towards\nthe device"); layer_add_child(window_layer, text_layer_get_layer(s_text_layer)); s_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_POINT); GPoint center = grect_center_point(&bounds); GSize image_size = gbitmap_get_bounds(s_bitmap).size; GRect image_frame = GRect(center.x, center.y, image_size.w, image_size.h); image_frame.origin.x -= image_size.w / 2; image_frame.origin.y -= image_size.h / 2 - 30; // Use GCompOpOr to display the white portions of the image s_layer = bitmap_layer_create(image_frame); bitmap_layer_set_bitmap(s_layer, s_bitmap); bitmap_layer_set_compositing_mode(s_layer, GCompOpSet); text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter); layer_add_child(window_layer, bitmap_layer_get_layer(s_layer)); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); //get the boundary of the root window layer GRect bounds = layer_get_bounds(window_layer); //create the bitmap layer and make it the same size as the window so that it takes up the whole screen image_layer = bitmap_layer_create(bounds); //load up frames of animation into the bitmap objects we established at the top of the code //TODO: remember to come back and swap these PNGs out for non-transparent resources, so to //simplify the resource id needed to instantiate them. seasick_the_cat_bmp_01 = gbitmap_create_with_resource(RESOURCE_ID_STK_0); seasick_the_cat_bmp_02 = gbitmap_create_with_resource(RESOURCE_ID_STK_1); seasick_the_cat_bmp_03 = gbitmap_create_with_resource(RESOURCE_ID_STK_2); //set the initial frame that we want to appear on the screen when the app loads up bitmap_layer_set_bitmap(image_layer, seasick_the_cat_bmp_01); //add the configured image layer to the window layer. layer_add_child(window_layer, bitmap_layer_get_layer(image_layer)); animation_timer = app_timer_register(100, apptimer_handler, NULL); }
static void main_window_load(Window *window) { // Create Gbitmap, then set to created BitmpaLayer 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(0, 55, 144, 50)); //s_time_layer = text_layer_create(GRect(5, 52, 139, 50)); s_time_layer = text_layer_create(GRect(40, 100, 144, 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"); s_date_layer = text_layer_create(GRect(30, 130, 144, 50)); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_background_color(s_date_layer, GColorClear); // 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)); // Create GFont //http://yolkfolk.com/site/page.php?id=94 //http://yolkfolk.com/media/downloads/fuddle.ttf (by Ingolemo) s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FUDDLE_12)); // Apply to TextLayer text_layer_set_font(s_time_layer, s_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_font(s_date_layer, s_font); text_layer_set_text_alignment(s_date_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)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); // Make sure the time is displayed from the start update_time(); }
void connection_status_component_refresh(ConnectionStatusComponent *c) { ConnectionIssue issue = connection_issue(); if (issue.reason == CONNECTION_ISSUE_NONE) { layer_set_hidden(bitmap_layer_get_layer(c->icon_layer), true); layer_set_hidden(text_layer_get_layer(c->staleness_text), true); } else { layer_set_hidden(bitmap_layer_get_layer(c->icon_layer), false); if (c->icon_bitmap != NULL) { gbitmap_destroy(c->icon_bitmap); } c->icon_bitmap = gbitmap_create_with_resource(CONN_ISSUE_ICONS[issue.reason]); bitmap_layer_set_bitmap(c->icon_layer, c->icon_bitmap); layer_set_hidden(text_layer_get_layer(c->staleness_text), false); text_layer_set_text(c->staleness_text, staleness_text(issue.staleness)); // XXX: need this on Basalt, but not on Aplite or emulator resize_text_frame(c, INITIAL_TEXT_SIZE); layer_mark_dirty(text_layer_get_layer(c->staleness_text)); app_timer_register(100, trim_text_frame, c); } }