static bool update_sliding_row(SlidingTextData *data, SlidingRow *row) { (void) data; GRect frame = layer_get_frame(text_layer_get_layer(row->label)); bool something_changed = true; switch (row->state) { case PREPARE_TO_MOVE: frame.origin.x = row->still_pos; row->delay_count++; if (row->delay_count > row->movement_delay) { row->state = MOVING_OUT; row->delay_count = 0; } break; case MOVING_IN: { int speed = abs(frame.origin.x - row->still_pos) / 3 + 1; frame.origin.x -= speed; if (frame.origin.x <= row->still_pos) { frame.origin.x = row->still_pos; row->state = IN_FRAME; } } break; case MOVING_OUT: { int speed = abs(frame.origin.x - row->still_pos) / 3 + 1; frame.origin.x -= speed; if (frame.origin.x <= row->left_pos) { frame.origin.x = row->right_pos; row->state = MOVING_IN; text_layer_set_text(row->label, row->next_string); row->next_string = NULL; } } break; case IN_FRAME: default: something_changed = false; break; } if (something_changed) { layer_set_frame(text_layer_get_layer(row->label), frame); } return something_changed; }
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); #ifdef PBL_PLATFORM_BASALT GRect bitmap_bounds = gbitmap_get_bounds((*bmp_image)); #else GRect bitmap_bounds = (*bmp_image)->bounds; #endif GRect frame = GRect(origin.x, origin.y, bitmap_bounds.size.w, bitmap_bounds.size.h); bitmap_layer_set_bitmap(bmp_layer, *bmp_image); layer_set_frame(bitmap_layer_get_layer(bmp_layer), frame); if (old_image != NULL) { gbitmap_destroy(old_image); } }
// Handle the start-up of the app void handle_init(AppContextRef app_ctx) { // Create our app's base window window_init(&window, "Peanut Butter Jelly Time"); window_stack_push(&window, true); window_set_background_color(&window, GColorBlack); GFont font_date; resource_init_current_app(&APP_RESOURCES); font_date = fonts_get_system_font(FONT_KEY_GOTHIC_14); // Set up a layer for the static watch face background bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); layer_add_child(&window.layer, &background_image_container.layer.layer); // Set up a layer for the hour hand rotbmp_pair_init_container(RESOURCE_ID_IMAGE_HOUR_HAND_WHITE, RESOURCE_ID_IMAGE_HOUR_HAND_BLACK, &hour_hand_image_container); rotbmp_pair_layer_set_src_ic(&hour_hand_image_container.layer, GPoint(33, 40)); layer_add_child(&window.layer, &hour_hand_image_container.layer.layer); // Set up a layer for the minute hand rotbmp_pair_init_container(RESOURCE_ID_IMAGE_MINUTE_HAND_WHITE, RESOURCE_ID_IMAGE_MINUTE_HAND_BLACK, &minute_hand_image_container); rotbmp_pair_layer_set_src_ic(&minute_hand_image_container.layer, GPoint(16, 60)); layer_add_child(&window.layer, &minute_hand_image_container.layer.layer); // Set up a layer for the date 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(8, 152, 144-8, 168-92)); text_layer_set_font(&text_date_layer, font_date); text_layer_set_text_alignment(&text_date_layer,GTextAlignmentCenter); layer_add_child(&window.layer, &text_date_layer.layer); PblTm t; get_time(&t); update_watch(&t); last_wday = -1; }
void set_container_image(RotBmpPairContainer *bmp_container, const int resource_id_white, const int resource_id_black, GPoint origin, int digit, int position) { layer_remove_from_parent(&bmp_container->layer.layer); rotbmp_pair_deinit_container(bmp_container); rotbmp_pair_init_container(resource_id_white, resource_id_black, bmp_container); GRect frame = layer_get_frame(&bmp_container->layer.layer); frame.origin.x = origin.x - 13; frame.origin.y = origin.y; if (position == 2 && digit == 1) { frame.origin.x -= 16; } layer_set_frame(&bmp_container->layer.layer, frame); layer_add_child(&window.layer, &bmp_container->layer.layer); }
static void initialise_ui(void) { s_window = window_create(); window_set_background_color(s_window, GColorBlack); IF_A(window_set_fullscreen(s_window, true)); s_res_img_standby = gbitmap_create_with_resource(RESOURCE_ID_IMG_STANDBY); s_res_img_settings = gbitmap_create_with_resource(RESOURCE_ID_IMG_SETTINGS); s_res_roboto_bold_subset_49 = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49); s_res_gothic_18_bold = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); // action_layer action_layer = action_bar_layer_create(); action_bar_layer_add_to_window(action_layer, s_window); action_bar_layer_set_background_color(action_layer, GColorWhite); action_bar_layer_set_icon(action_layer, BUTTON_ID_UP, s_res_img_standby); action_bar_layer_set_icon(action_layer, BUTTON_ID_DOWN, s_res_img_settings); layer_set_frame(action_bar_layer_get_layer(action_layer), GRect(124, 0, 20, 168)); IF_B(layer_set_bounds(action_bar_layer_get_layer(action_layer), GRect(-5, 0, 30, 168))); layer_add_child(window_get_root_layer(s_window), (Layer *)action_layer); // clockbg_layer clockbg_layer = text_layer_create(GRect(0, 60, 144, 50)); text_layer_set_background_color(clockbg_layer, GColorBlack); text_layer_set_text_color(clockbg_layer, GColorClear); text_layer_set_text(clockbg_layer, " "); layer_add_child(window_get_root_layer(s_window), (Layer *)clockbg_layer); // clock_layer clock_layer = text_layer_create(GRect(0, 52, 144, 65)); text_layer_set_background_color(clock_layer, GColorClear); text_layer_set_text_color(clock_layer, GColorWhite); text_layer_set_text(clock_layer, "23:55"); text_layer_set_text_alignment(clock_layer, GTextAlignmentCenter); text_layer_set_font(clock_layer, s_res_roboto_bold_subset_49); layer_add_child(window_get_root_layer(s_window), (Layer *)clock_layer); // onoff_layer onoff_layer = text_layer_create(GRect(2, 2, 119, 56)); layer_set_update_proc(text_layer_get_layer(onoff_layer), draw_onoff); layer_add_child(window_get_root_layer(s_window), (Layer *)onoff_layer); // info_layer info_layer = text_layer_create(GRect(2, 110, 119, 56)); layer_set_update_proc(text_layer_get_layer(info_layer), draw_info); layer_add_child(window_get_root_layer(s_window), (Layer *)info_layer); }
// init app and setup void handle_init(AppContextRef ctx) { (void)ctx; // init main window and app wide resources window_init(&main_window, "Lively"); window_stack_push(&main_window, true); window_set_background_color(&main_window, GColorClear); resource_init_current_app(&APP_RESOURCES); // custom fonts avenir_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_AVENIR_NEXT_COND_42)); silkscreen_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SILKSCREEN_8)); // background image layer_init(&background_layer, GRect(0, 0, SCREEN_WIDWTH, SCREEN_HEIGHT)); bmp_init_container(RESOURCE_ID_EDWARD_AND_KATE, &background_image); layer_add_child(&main_window.layer, &background_image.layer.layer); layer_set_frame(&background_image.layer.layer, GRect(0, 0, SCREEN_WIDWTH, SCREEN_HEIGHT)); // date text text_layer_init(&date_text_layer, GRect(99, 100, 45, 8)); text_layer_set_font(&date_text_layer, silkscreen_font); text_layer_set_text_alignment(&date_text_layer, GTextAlignmentRight); text_layer_set_text_color(&date_text_layer, GColorWhite); text_layer_set_background_color(&date_text_layer, /*GColorClear*/ GColorBlack); layer_add_child(&main_window.layer, &date_text_layer.layer); // init time text text_layer_init(&time_text_layer, GRect(22, 108, 120, 42)); text_layer_set_font(&time_text_layer, avenir_font); text_layer_set_text_alignment(&time_text_layer, GTextAlignmentRight); text_layer_set_text_color(&time_text_layer, GColorWhite); text_layer_set_background_color(&time_text_layer, GColorBlack); layer_add_child(&main_window.layer, &time_text_layer.layer); // update initial time PblTm current_time; get_time(¤t_time); update_time(ctx, ¤t_time); // button bindings window_set_click_config_provider(&main_window, (ClickConfigProvider) config_provider); }
static void inbox_received_callback(DictionaryIterator *iterator, void *context) { Tuple *tuple = dict_find(iterator, 0); if (!tuple) { APP_LOG(APP_LOG_LEVEL_ERROR, "The tuple was missing!"); return; } s_speaking_enabled = true; APP_LOG(APP_LOG_LEVEL_INFO, "Got message: %s", tuple->value->cstring); snprintf(s_defn_buffer, sizeof(s_defn_buffer), "%s", tuple->value->cstring); //where the word and def show up GSize size = graphics_text_layout_get_content_size(s_defn_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(0, 0, 134, 1000), GTextOverflowModeWordWrap, GTextAlignmentCenter); layer_set_frame((Layer *)s_def_layer, GRect(5, 40, 134, size.h)); scroll_layer_set_content_size(s_scroll_layer, GSize(144, 50 + size.h)); text_layer_set_text(s_word_layer, s_last_text_buffer); text_layer_set_text(s_def_layer, s_defn_buffer); window_stack_push(s_def_window, true); }
static void toggleSeconds(bool hidden) { layer_set_hidden(bitmap_layer_get_layer(time_digits_layers[5]), hidden); layer_set_hidden(bitmap_layer_get_layer(time_digits_layers[6]), hidden); layer_set_hidden(bitmap_layer_get_layer(time_digits_layers[7]), hidden); layer_set_hidden(bitmap_layer_get_layer(zulu_time_digits_layers[5]), hidden); layer_set_hidden(bitmap_layer_get_layer(zulu_time_digits_layers[6]), hidden); layer_set_hidden(bitmap_layer_get_layer(zulu_time_digits_layers[7]), hidden); if (hidden) { // seconds aren't visible if (mTimeLayerShifted) { // 12hr clock, single digit layer_set_frame(time_layer, GRect(9, 0, 144, 168)); } else { layer_set_frame(time_layer, GRect(16, 0, 144, 168)); } if (mZuluLayerShifted) { // 12hr clock, single digit layer_set_frame(zulu_time_layer, GRect(9, 0, 144, 168)); } else { layer_set_frame(zulu_time_layer, GRect(16, 0, 144, 168)); } } else { // seconds are visible if (mTimeLayerShifted) { // 12hr clock, single digit layer_set_frame(time_layer, GRect(-7, 0, 144, 168)); } else { layer_set_frame(time_layer, GRect(0, 0, 144, 168)); } if (mZuluLayerShifted) { // 12hr clock, single digit layer_set_frame(zulu_time_layer, GRect(-7, 0, 144, 168)); } else { layer_set_frame(zulu_time_layer, GRect(0, 0, 144, 168)); } } }
static void initialise_ui(void) { Layer *root_layer = NULL; GRect bounds; s_window = window_create_fullscreen(&root_layer, &bounds); s_res_img_standby = gbitmap_create_with_resource(RESOURCE_ID_IMG_STANDBY); s_res_img_settings = gbitmap_create_with_resource(RESOURCE_ID_IMG_SETTINGS); s_res_roboto_bold_subset_49 = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49); s_res_gothic_18_bold = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); // action_layer action_layer = action_bar_layer_create(); action_bar_layer_add_to_window(action_layer, s_window); action_bar_layer_set_background_color(action_layer, GColorWhite); action_bar_layer_set_icon(action_layer, BUTTON_ID_UP, s_res_img_standby); action_bar_layer_set_icon(action_layer, BUTTON_ID_DOWN, s_res_img_settings); #ifdef PBL_RECT layer_set_frame(action_bar_layer_get_layer(action_layer), GRect(bounds.size.w-20, 0, 20, bounds.size.h)); IF_3(layer_set_bounds(action_bar_layer_get_layer(action_layer), GRect(-6, 0, 31, bounds.size.h))); // Put Action Bar underneath other layers on rectangular Pebbles layer_add_child(root_layer, action_bar_layer_get_layer(action_layer)); #endif // clock_layer clock_layer = layer_create_with_proc(root_layer, draw_clock, GRect(0 - PBL_IF_RECT_ELSE(0, ACTION_BAR_WIDTH/2), (bounds.size.h/2)-32-PBL_IF_ROUND_ELSE(2, 0), bounds.size.w, 65)); // onoff_layer onoff_layer = layer_create_with_proc(root_layer, draw_onoff, PBL_IF_RECT_ELSE(GRect(2, (bounds.size.h/2)-82, 119, 56), GRect(-10, (bounds.size.h/2)-82, bounds.size.w+11, 56))); // info_layer info_layer = layer_create_with_proc(root_layer, draw_info, PBL_IF_RECT_ELSE(GRect(2, (bounds.size.h/2)+26, 119, 56), GRect(-10, (bounds.size.h/2)+24, bounds.size.w+11, 56))); #ifdef PBL_ROUND // Put Action Bar on top for Pebble Round layer_add_child(root_layer, (Layer *)action_layer); #endif }
// -------------------------------------------------------- // page_start_tick() // (called from TempusFugit tick handler) // -------------------------------------------------------- void page_start_tick(int tick_count) { if(tick_count < (NUMBER_OF_IMAGES - 1)) { // Increment tick_count & Animate Logo layer_remove_from_parent(&page_start_logo_data.image_container[tick_count].layer.layer); page_start_logo_data.current_logo = page_start_logo_data.current_logo+1; layer_set_frame(&page_start_logo_data.image_container[page_start_logo_data.current_logo].layer.layer, GRect(24,2,100,115)); layer_add_child(&tf_start_window.layer, &page_start_logo_data.image_container[page_start_logo_data.current_logo].layer.layer); } else if (tick_count == NUMBER_OF_IMAGES){ // Show "Tempus" field layer_add_child(&tf_start_window.layer, &tempus_layer.layer); } else if (tick_count == (NUMBER_OF_IMAGES+1)){ // Show "Fugit" field layer_add_child(&tf_start_window.layer, &fugit_layer.layer); } else if (tick_count == (NUMBER_OF_IMAGES+2)){ // Show version field layer_add_child(&tf_start_window.layer, &version_layer.layer); } } // page_start_tick(int tick_count)
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "FSU Spear"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&RESOURCES); bmp_init_container(RESOURCE_ID_IMAGE_FSU_SPEAR, &image_container); layer_add_child(&window.layer, &image_container.layer.layer); text_layer_init(&text_time_layer, window.layer.frame); text_layer_set_text_color(&text_time_layer, GColorWhite); text_layer_set_text_alignment(&text_time_layer, GTextAlignmentCenter); 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_AVENIR_44)) /*fonts_get_system_font(FONT_KEY_GOTHAM_30_BLACK)*/); layer_set_frame(&text_time_layer.layer, GRect(0,116,144,68)); layer_add_child(&window.layer, &text_time_layer.layer); }
static void prv_draw_cell_backgrounds(Layer *layer, GContext *ctx) { SelectionLayerData *data = layer_get_data(layer); // Loop over each cell and draw the background rectangles for (int i = 0, current_x_offset = 0; i < data->num_cells; i++) { if (data->cell_widths[i] == 0) { continue; } int y_offset = 0; if (data->selected_cell_idx == i && data->bump_is_upwards) { y_offset = -prv_get_pixels_for_bump_settle(data->bump_settle_anim_progress); } int height = layer_get_bounds(layer).size.h; if (data->selected_cell_idx == i) { height += prv_get_pixels_for_bump_settle(data->bump_settle_anim_progress); } const GRect rect = GRect(current_x_offset, y_offset, data->cell_widths[i], height); #ifdef PBL_SDK_3 GColor bg_color = data->inactive_background_color; if (data->selected_cell_idx == i && !data->slide_amin_progress) { bg_color = data->active_background_color; } graphics_context_set_fill_color(ctx, bg_color); graphics_fill_rect(ctx, rect, 1, GCornerNone); #elif PBL_SDK_2 graphics_context_set_stroke_color(ctx, GColorBlack); graphics_draw_rect(ctx, rect); if (data->selected_cell_idx == i && !data->slide_amin_progress){ layer_set_frame(inverter_layer_get_layer(data->inverter), rect); } #endif current_x_offset += data->cell_widths[i] + data->cell_padding; } }
static void prv_draw_slider_slide(Layer *layer, GContext *ctx) { SelectionLayerData *data = layer_get_data(layer); int starting_x_offset = 0; for (int i = 0; i < data->num_cells; i++) { if (data->selected_cell_idx == i) { break; } starting_x_offset += data->cell_widths[i] + data->cell_padding; } int next_cell_width = data->cell_widths[data->selected_cell_idx + 1]; if (!data->slide_is_forward) { next_cell_width = data->cell_widths[data->selected_cell_idx - 1]; } int slide_distance = next_cell_width + data->cell_padding; int current_slide_distance = (slide_distance * data->slide_amin_progress) / 100; if (!data->slide_is_forward) { current_slide_distance = -current_slide_distance; } int current_x_offset = starting_x_offset + current_slide_distance; int cur_cell_width = data->cell_widths[data->selected_cell_idx]; int total_cell_width_change = next_cell_width - cur_cell_width + data->cell_padding; int current_cell_width_change = (total_cell_width_change * (int) data->slide_amin_progress) / 100; int current_cell_width = cur_cell_width + current_cell_width_change; if (!data->slide_is_forward) { current_x_offset -= current_cell_width_change; } GRect rect = GRect(current_x_offset, 0, current_cell_width, layer_get_bounds(layer).size.h); #ifdef PBL_COLOR graphics_context_set_fill_color(ctx, data->active_background_color); graphics_fill_rect(ctx, rect, 1, GCornerNone); #else layer_set_frame(inverter_layer_get_layer(data->inverter), rect); #endif }
static Layer* selection_layer_init(SelectionLayerData *selection_layer_, GRect frame, int num_cells) { Layer *layer = layer_create_with_data(frame, sizeof(SelectionLayerData)); SelectionLayerData *selection_layer_data = layer_get_data(layer); if (num_cells > MAX_SELECTION_LAYER_CELLS) { num_cells = MAX_SELECTION_LAYER_CELLS; } // Set layer defaults *selection_layer_data = (SelectionLayerData) { #ifdef PBL_COLOR .active_background_color = DEFAULT_ACTIVE_COLOR, .inactive_background_color = DEFAULT_INACTIVE_COLOR, #else .inverter = inverter_layer_create(GRect(0, 0, 0, frame.size.h)), #endif .num_cells = num_cells, .cell_padding = DEFAULT_CELL_PADDING, .selected_cell_idx = DEFAULT_SELECTED_INDEX, .font = fonts_get_system_font(DEFAULT_FONT), .is_active = true, }; for (int i = 0; i < num_cells; i++) { selection_layer_data->cell_widths[i] = 0; } layer_set_frame(layer, frame); layer_set_clips(layer, false); layer_set_update_proc(layer, (LayerUpdateProc)prv_draw_selection_layer); #ifndef PBL_COLOR layer_add_child(layer, inverter_layer_get_layer(selection_layer_data->inverter)); #endif return layer; } Layer* selection_layer_create(GRect frame, int num_cells) { SelectionLayerData *selection_layer_data = NULL; return selection_layer_init(selection_layer_data, frame, num_cells); }
static void load(Window *window) { Layer *rl = window_get_root_layer(window); user_data *ud; Layer *l; GRect f; GSize s; ud = (user_data*) malloc(sizeof(*ud)); if (!ud) return; *ud = (user_data) { .moving = {-1, -1} }; window_set_user_data(window, ud); ud->icon = gbitmap_create_with_resource(RESOURCE_ID_MOVE); ud->tl = text_layer_create(layer_get_bounds(rl)); text_layer_set_text(ud->tl, "Use FreeOTP on your mobile device to add tokens."); text_layer_set_text_alignment(ud->tl, GTextAlignmentCenter); text_layer_set_overflow_mode(ud->tl, GTextOverflowModeWordWrap); s = text_layer_get_content_size(ud->tl); l = text_layer_get_layer(ud->tl); f = layer_get_frame(l); f.origin.y = (f.size.h - s.h) / 2; f.size.h = s.h; layer_set_frame(l, f); layer_set_hidden(l, true); ud->ml = menu_layer_create(layer_get_bounds(rl)); layer_set_hidden(menu_layer_get_layer(ud->ml), false); menu_layer_set_click_config_onto_window(ud->ml, window); menu_layer_set_callbacks(ud->ml, ud, (MenuLayerCallbacks) { .draw_row = menu_draw_row, .get_num_rows = menu_get_num_rows, .select_click = menu_select_click, .select_long_click = menu_select_long_click, .selection_changed = menu_selection_changed });
/* static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) { switch (key) { case BLINK_KEY: settings.Blink = new_tuple->value->uint8; tick_timer_service_unsubscribe(); if(settings.Blink) { tick_timer_service_subscribe(SECOND_UNIT, handle_tick); } else { tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); } break; case INVERT_KEY: settings.Invert = new_tuple->value->uint8; change_background(); break; case BLUETOOTHVIBE_KEY: settings.BluetoothVibe = new_tuple->value->uint8; break; case HOURLYVIBE_KEY: settings.HourlyVibe = new_tuple->value->uint8; break; case BRANDING_MASK_KEY: settings.BrandingMask = new_tuple->value->uint8; layer_set_hidden(bitmap_layer_get_layer(branding_mask_layer), !settings.BrandingMask); break; } } */ 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); if (old_image != NULL) { gbitmap_destroy(old_image); old_image = NULL; } } static void update_battery(BatteryChargeState charge_state) { batteryPercent = charge_state.charge_percent; if(batteryPercent==100) { change_battery_icon(false); layer_set_hidden(bitmap_layer_get_layer(battery_layer), false); for (int i = 0; i < TOTAL_BATTERY_PERCENT_DIGITS; ++i) { layer_set_hidden(bitmap_layer_get_layer(battery_percent_layers[i]), true); } return; } layer_set_hidden(bitmap_layer_get_layer(battery_layer), charge_state.is_charging); change_battery_icon(charge_state.is_charging); for (int i = 0; i < TOTAL_BATTERY_PERCENT_DIGITS; ++i) { layer_set_hidden(bitmap_layer_get_layer(battery_percent_layers[i]), false); } set_container_image(&battery_percent_image[0], battery_percent_layers[0], TINY_IMAGE_RESOURCE_IDS[charge_state.charge_percent/10], GPoint(89, 43)); set_container_image(&battery_percent_image[1], battery_percent_layers[1], TINY_IMAGE_RESOURCE_IDS[charge_state.charge_percent%10], GPoint(95, 43)); set_container_image(&battery_percent_image[2], battery_percent_layers[2], TINY_IMAGE_RESOURCE_IDS[10], GPoint(101, 43)); }
void LoadMainBmpImage(Window *window, int id) { int resourceId = id; if(!window) return; if(mainImageLoaded) { if(mainImageResourceLoaded == resourceId) { layer_add_child(&window->layer, &mainImage.layer.layer); return; // already loaded the correct one. } UnloadMainBmpImage(); } bmp_init_container(resourceId, &mainImage); layer_set_frame(&mainImage.layer.layer, mainFrame); layer_add_child(&window->layer, &mainImage.layer.layer); mainImageLoaded = true; mainImageResourceLoaded = resourceId; }
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 toggle_bluetooth_icon(bool connected) { if(appStarted && !connected && bluetoothvibe) { //vibe! vibes_long_pulse(); } } void bluetooth_connection_callback(bool connected) { toggle_bluetooth_icon(connected); }
void set_container_image(RotBmpContainer *bmp_container, const int resource_id, GPoint origin) { layer_remove_from_parent(&bmp_container->layer.layer); rotbmp_deinit_container(bmp_container); rotbmp_init_container(resource_id, bmp_container); //TODO: This doesn't seem to work when black on white time_digits_images[0].layer.compositing_mode = GCompOpOr; time_digits_images[1].layer.compositing_mode = GCompOpOr; time_colon_image.layer.compositing_mode = GCompOpOr; time_digits_images[2].layer.compositing_mode = GCompOpOr; time_digits_images[3].layer.compositing_mode = GCompOpOr; GRect frame = layer_get_frame(&bmp_container->layer.layer); frame.origin.x = origin.x; frame.origin.y = origin.y; layer_set_frame(&bmp_container->layer.layer, frame); layer_add_child(&window.layer, &bmp_container->layer.layer); }
MarqueeTextLayer* marquee_text_layer_create(GRect frame) { MarqueeTextLayer *marquee = layer_create_with_data(frame, sizeof(MarqueeData)); MarqueeData *marqueedata = (MarqueeData *)layer_get_data(marquee); //APP_LOG(APP_LOG_LEVEL_DEBUG, "marquee_text_layer_create: malloc MarqueeTextLayer"); //APP_LOG(APP_LOG_LEVEL_DEBUG, "marquee_text_layer_create: got a marquee pointer, allocated %d bytes at %p", sizeof(MarqueeTextLayer), marquee); marqueedata->text = malloc(128); // allocate some bytes for the string if (marqueedata->text) APP_LOG(APP_LOG_LEVEL_DEBUG, "allocated 128 bytes for marquee->text at %p", marqueedata->text); // And now we lie about our frame. See above. //frame.origin.x -= BOUND_OFFSET; //frame.size.w += BOUND_OFFSET; layer_set_frame(marquee,GRect(frame.origin.x - BOUND_OFFSET,frame.origin.y,frame.size.w + BOUND_OFFSET, frame.size.h)); APP_LOG(APP_LOG_LEVEL_DEBUG, "frame.origin.x = %d, frame.origin.y = %d, frame.size.w = %d, frame.size.h = %d", layer_get_frame(marquee).origin.x, layer_get_frame(marquee).origin.y, layer_get_frame(marquee).size.w, layer_get_frame(marquee).size.h); //GRect bounds = layer_get_bounds(marquee); //APP_LOG(APP_LOG_LEVEL_DEBUG, "pre bounds.origin.x = %d, bounds.origin.y = %d, bounds.size.w = %d, bounds.size.h = %d", bounds.origin.x, bounds.origin.y, bounds.size.w, bounds.size.h); //bounds.origin.x += BOUND_OFFSET + 25; //APP_LOG(APP_LOG_LEVEL_DEBUG, "post adjust bounds.origin.x = %d, bounds.origin.y = %d, bounds.size.w = %d, bounds.size.h = %d", bounds.origin.x, bounds.origin.y, bounds.size.w, bounds.size.h); //layer_set_bounds(marquee, bounds); layer_set_bounds(marquee,GRect(layer_get_bounds(marquee).origin.x + BOUND_OFFSET,0,frame.size.w + BOUND_OFFSET, frame.size.h)); APP_LOG(APP_LOG_LEVEL_DEBUG, "post set bounds.origin.x = %d, bounds.origin.y = %d, bounds.size.w = %d, bounds.size.h = %d", layer_get_bounds(marquee).origin.x, layer_get_bounds(marquee).origin.y, layer_get_bounds(marquee).size.w, layer_get_bounds(marquee).size.h); marqueedata->background_colour = GColorWhite; marqueedata->text_colour = GColorBlack; marqueedata->offset = 0; marqueedata->text_width = -1; marqueedata->countdown = 100; marqueedata->font = fonts_get_system_font(FONT_KEY_FONT_FALLBACK); layer_set_clips(marquee, false); layer_set_update_proc(marquee, do_draw); marquee_text_layer_mark_dirty(marquee); return marquee; }
void update_date_display(struct tm* tick_time) { // strftime(g_date_str, sizeof(g_date_str), "%A\n%x", tick_time); strftime(g_date_str, sizeof(g_date_str), "%a %b %d", tick_time); for (char* c = g_date_str; *c; ++c) { if (*c >= 'a' && *c <= 'z') *c += 'A' - 'a'; } GRect layerSize = GRect(0, 0, c_viewportWidth, c_viewportHeight); GSize dateSize = graphics_text_layout_get_content_size( g_date_str, g_font_info, layerSize, 0, GTextAlignmentLeft); layerSize.origin.x = c_viewportWidth - dateSize.w - DT_EDGE_PAD; layerSize.origin.y = c_viewportHeight - dateSize.h; layerSize.size = dateSize; text_layer_set_text(dateLayer, g_date_str); layer_set_frame((Layer*) dateLayer, layerSize); }
void rot_bitmap_set_src_ic(RotBitmapLayer *image, GPoint ic) { image->src_ic = ic; // adjust the frame so the whole image will still be visible const int32_t horiz = MAX(ic.x, abs(image->bitmap->bounds.size.w - ic.x)); const int32_t vert = MAX(ic.y, abs(image->bitmap->bounds.size.h - ic.y)); GRect r = layer_get_frame(&image->layer); //// const int32_t new_dist = integer_sqrt(horiz*horiz + vert*vert) * 2; const int32_t new_dist = (integer_sqrt(horiz*horiz + vert*vert) * 2) + 1; //// Fudge to deal with non-even dimensions--to ensure right-most and bottom-most edges aren't cut off. r.size.w = new_dist; r.size.h = new_dist; layer_set_frame(&image->layer, r); r.origin = GPoint(0, 0); ////layer_set_bounds(&image->layer, r); image->layer.bounds = r; image->dest_ic = GPoint(new_dist / 2, new_dist / 2); layer_mark_dirty(&(image->layer)); }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); layer_mark_dirty(s_hand_layer); int bhour = tick_time->tm_hour; int bmin = tick_time->tm_min; float angle = 30 * ((float)(bhour % 12) + ((float)bmin / 60)); if (debug) angle = 12 * tick_time->tm_sec; GRect frame = layer_get_frame(s_face_layer); GRect frame2 = layer_get_frame(s_hand_layer); float size = (frame.size.w + frame2.size.w) / 2; GPoint origin = gpoint_from_polar(grect_inset(frame2, GEdgeInsets(-150)), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle + 180)); frame.origin = origin; frame.origin.x -= frame.size.w / 2; frame.origin.y -= frame.size.w / 2; layer_set_frame(s_face_layer, frame); }
static void window_load(Window *window) { current_question = QA[4]; window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect inner = GRect(0,0,112,168); s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_background); s_background_layer = bitmap_layer_create(bounds); 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)); prompt_layer = text_layer_create(inner); text_layer_set_text_color(prompt_layer, GColorBlack); text_layer_set_background_color(prompt_layer, GColorClear); text_layer_set_font(prompt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(prompt_layer, GTextAlignmentCenter); layer_set_frame( text_layer_get_layer(prompt_layer), GRect(0, ((168 - (text_layer_get_content_size(prompt_layer).h)) / 2) - 4, 112, text_layer_get_content_size(prompt_layer).h) ); layer_add_child(window_layer, text_layer_get_layer(prompt_layer)); }
void screen_map_layer_init(Window* window) { for (int i = 0; i < NUM_POINTS; i++) { pts[i] = GPoint(0, 0); } s_data.page_map = layer_create(GRect(0,TOPBAR_HEIGHT,SCREEN_W,SCREEN_H-TOPBAR_HEIGHT)); layer_add_child(window_get_root_layer(window), s_data.page_map); for(int i = 0; i < NUM_LIVE_FRIENDS; i++) { s_live.friends[i].name_frame = GRect(0, 15, 100, 15); s_live.friends[i].name_layer = text_layer_create(s_live.friends[i].name_frame); set_layer_attr_full(s_live.friends[i].name_layer, s_live.friends[i].name, font_12, GTextAlignmentLeft, GColorBlack, GColorWhite, s_data.page_map); } pathFrame = GRect(0, 0, MAP_VSIZE_X, MAP_VSIZE_Y); path_layer = layer_create(pathFrame); pathFrame.origin.x = -XINI + SCREEN_W/2; pathFrame.origin.y = -YINI + SCREEN_H/2; layer_set_frame(path_layer, pathFrame); layer_set_update_proc(path_layer, path_layer_update_callback); layer_add_child(s_data.page_map, path_layer); bearing_layer = layer_create(GRect(0, 0, SCREEN_W, SCREEN_H)); layer_set_update_proc(bearing_layer, bearing_layer_update_callback); layer_add_child(s_data.page_map, bearing_layer); bearing_gpath = gpath_create(&BEARING_PATH_POINTS); gpath_move_to(bearing_gpath, GPoint(SCREEN_W/2, SCREEN_H/2)); layer_set_hidden(s_data.page_map, true); s_gpsdata.xpos=0; s_gpsdata.ypos=0; s_gpsdata.nb_received=0; }
void refresh_settings(){ phrases_set_settings(main_settings); //Little hack to update the words beforehand phrases_get_main_swear(true, true); phrases_get_main_swear(false, true); text_layer_set_text(second_word_t, phrases_get_main_swear(altWordBuffer, false)); layer_set_frame(text_layer_get_layer(second_word_t), get_new_frame(second_word_t, phrases_get_main_swear(altWordBuffer, false))); adapt_font_size_to_frame(second_word_t); layer_set_hidden(inverter_layer_get_layer(theme), !main_settings.invert); layer_set_hidden(battery_bar_layer, !main_settings.batteryBar); layer_set_hidden(text_layer_get_layer(slot_t), false); layer_set_hidden(text_layer_get_layer(seconds_t), !main_settings.seconds); switch(main_settings.slotUse){ case SLOT_USE_NOTHING: layer_set_hidden(text_layer_get_layer(slot_t), true); break; case SLOT_USE_CUSTOM_TEXT: text_layer_set_text(slot_t, main_settings.customslottext[0]); break; case SLOT_USE_BLUETOOTH_STATUS:; bool connected = bluetooth_connection_service_peek(); text_layer_set_text(slot_t, phrases_get_bluetooth(connected)); break; } if(main_settings.shakeAction == SHAKE_USE_DISABLED){ accel_tap_service_unsubscribe(); } else{ accel_tap_service_unsubscribe(); accel_tap_service_subscribe(shake_handler); } notify_bar_set_enabled(main_settings.alerts); set_animation_use(main_settings.animation); }
void changeTextFont(myTextLayer *mtl, int font_size) { int font_height; int font_id; int delta_y = 0; if(font_size==-1) { font_height = 10; font_id = RESOURCE_ID_FONT_XXS_10; } if(font_size==0) { font_height = 15; font_id = RESOURCE_ID_FONT_SMALL_14; } if(font_size==1) { font_height = 20; font_id = RESOURCE_ID_FONT_SMALL_18; } if(font_size==2) { font_height = 30; font_id = RESOURCE_ID_FONT_MEDIUM_22; } if(font_size==3) { font_height = 35; font_id = RESOURCE_ID_FONT_BIG_28; } if(font_size!=mtl->current_font_size) { delta_y = 2*(font_size - mtl->current_font_size); } mtl->current_font_size = font_size; Layer *l = text_layer_get_layer(mtl->tl_obj); GRect bounds = layer_get_frame(l); bounds.size.h = font_height; bounds.origin.y -= delta_y; layer_set_frame(l,bounds); text_layer_set_font(mtl->tl_obj, fonts_load_custom_font(resource_get_handle(font_id))); }
static void sustituye_imagen(GBitmap **imagen, BitmapLayer *bmp_layer, const int resource_id, GPoint origen) { GBitmap *vieja_imagen = *imagen; *imagen = gbitmap_create_with_resource(resource_id); GRect frame = (GRect) { .origin = origen, .size = (*imagen)->bounds.size }; bitmap_layer_set_bitmap(bmp_layer, *imagen); layer_set_frame(bitmap_layer_get_layer(bmp_layer), frame); gbitmap_destroy(vieja_imagen); } static void destroy_ui(void) { window_destroy(pwindow); bitmap_layer_destroy(BLFondo); text_layer_destroy(TLHora); text_layer_destroy(TLMinuto); text_layer_destroy(TLDiaSem); text_layer_destroy(TLDia); text_layer_destroy(TLMes); inverter_layer_destroy(ILFondo); text_layer_destroy(TLBateria); }
void handle_tick(AppContextRef ctx, PebbleTickEvent *event) { string_format_time(s_days_in_year_str_buffer, DAYS_IN_YEAR_STR_BUFFER_BYTES, "%j", event->tick_time); string_format_time(s_days_in_month_str_buffer, DAYS_IN_MONTH_STR_BUFFER_BYTES, "%e", event->tick_time); string_format_time(s_days_in_week_str_buffer, DAYS_IN_WEEK_STR_BUFFER_BYTES, "%w", event->tick_time); string_format_time(s_hours_str_buffer, HOURS_STR_BUFFER_BYTES, "%k", event->tick_time); string_format_time(s_minutes_str_buffer, MINUTES_STR_BUFFER_BYTES, "%M", event->tick_time); string_format_time(s_seconds_str_buffer, SECONDS_STR_BUFFER_BYTES, "%S", event->tick_time); /* draw specified objects once */ if (draw_once) { layer_mark_dirty(&bar_layer); draw_once = false; } /* advance progress bars using inverter layers */ /* being lazy about total days in month */ double days_in_year_width = get_width(s_days_in_year_str_buffer, 365); double days_in_month_width = get_width(s_days_in_month_str_buffer, 31); double days_in_week_width = get_width(s_days_in_week_str_buffer, 6); double hours_width = get_width(s_hours_str_buffer, 23.0); double minute_width = get_width(s_minutes_str_buffer, 59.0); double second_width = get_width(s_seconds_str_buffer, 59.0); layer_set_frame((Layer *)&days_in_year_inverter_layer, GRect(BAR_OFFSET + 1, FIRST_BAR_Y + 1 + ((BAR_HEIGHT + BAR_MARGIN) * 0), (int) days_in_year_width, BAR_HEIGHT - 2)); layer_set_frame((Layer *)&days_in_month_inverter_layer, GRect(BAR_OFFSET + 1, FIRST_BAR_Y + 1 + ((BAR_HEIGHT + BAR_MARGIN) * 0), (int) days_in_month_width, BAR_HEIGHT - 2)); layer_set_frame((Layer *)&days_in_week_inverter_layer, GRect(BAR_OFFSET + 1, FIRST_BAR_Y + 1 + ((BAR_HEIGHT + BAR_MARGIN) * 1), (int) days_in_week_width, BAR_HEIGHT - 2)); layer_set_frame((Layer *)&hours_inverter_layer, GRect(BAR_OFFSET + 1, FIRST_BAR_Y + 1 + ((BAR_HEIGHT + BAR_MARGIN) * 1), (int) hours_width, BAR_HEIGHT - 2)); layer_set_frame((Layer *)&minutes_inverter_layer, GRect(BAR_OFFSET + 1, FIRST_BAR_Y + 1 + ((BAR_HEIGHT + BAR_MARGIN) * 2), (int) minute_width, BAR_HEIGHT - 2)); /* seconds layer draws itself in the minutes layer for a dual-purpose progress bar! */ layer_set_frame((Layer *)&seconds_inverter_layer, GRect(BAR_OFFSET + 1, FIRST_BAR_Y + 1 + ((BAR_HEIGHT + BAR_MARGIN) * 2), (int) second_width, BAR_HEIGHT - 2)); }
// Handle the start-up of the app void handle_init() { // Create our app's base window window = window_create(); Layer *root_window_layer = window_get_root_layer(window); GRect root_window_bounds = layer_get_bounds(root_window_layer); window_stack_push(window, true); window_set_background_color(window, GColorBlack); // Set up a layer for the static watch face background background_layer = bitmap_layer_create(root_window_bounds); background_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND); bitmap_layer_set_bitmap(background_layer, background_image); layer_add_child(root_window_layer, bitmap_layer_get_layer(background_layer)); // Set up a layer for the minute hand. // Compositing tricks take the place of PNG transparency. minute_hand_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MINUTE_TRAIL); minute_hand_layer = rot_bitmap_layer_create(minute_hand_image); // Default frame for RotBitmapLayers is according to some // opaque algorithm. Automatically centre it now. GRect minute_frame = layer_get_frame(bitmap_layer_get_layer((BitmapLayer *)minute_hand_layer)); GRect new_minute_frame = GRect((144-minute_frame.size.w)/2, (168-minute_frame.size.h)/2, minute_frame.size.w, minute_frame.size.h); APP_LOG(APP_LOG_LEVEL_DEBUG, "minute frame: %i, %i, %i, %i", minute_frame.origin.x, minute_frame.origin.y, minute_frame.size.w, minute_frame.size.h); layer_set_frame(bitmap_layer_get_layer((BitmapLayer *)minute_hand_layer), new_minute_frame); rot_bitmap_set_compositing_mode(minute_hand_layer, GCompOpOr); layer_add_child(root_window_layer, bitmap_layer_get_layer((BitmapLayer *)minute_hand_layer)); // Set up a layer for the hour hand. // Compositing tricks take the place of PNG transparency. hour_hand_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HOUR_TRAIL); hour_hand_layer = rot_bitmap_layer_create(hour_hand_image); GRect hour_frame = layer_get_frame(bitmap_layer_get_layer((BitmapLayer *)hour_hand_layer)); // The current images seem to look best if this frame is offset // one more pixel. Still not perfect though. GRect new_hour_frame = GRect((144-hour_frame.size.w)/2 + 1, (168-hour_frame.size.h)/2 + 1, hour_frame.size.w, hour_frame.size.h); APP_LOG(APP_LOG_LEVEL_DEBUG, "hour frame: %i, %i, %i, %i", hour_frame.origin.x, hour_frame.origin.y, hour_frame.size.w, hour_frame.size.h); layer_set_frame(bitmap_layer_get_layer((BitmapLayer *)hour_hand_layer), new_hour_frame); rot_bitmap_set_compositing_mode(hour_hand_layer, GCompOpOr); layer_add_child(root_window_layer, bitmap_layer_get_layer((BitmapLayer *)hour_hand_layer)); time_t now = time(NULL); struct tm *t = localtime(&now); update_watch(t); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); }