void win_tutorial_create(void) { s_tutorial_window = window_create(); window_set_background_color(s_tutorial_window, PBL_IF_COLOR_ELSE(GColorJaegerGreen, GColorWhite)); window_set_window_handlers(s_tutorial_window, (WindowHandlers) { .load = window_load, .unload = window_unload, });
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); window_set_background_color(window, PBL_IF_COLOR_ELSE(GColorBlack, GColorWhite)); #ifdef PBL_COLOR #ifdef PBL_ROUND s_menu_layer = menu_layer_create( GRect(20,0,bounds.size.w - 40, bounds.size.h)); #else s_menu_layer = menu_layer_create( GRect(20,0,bounds.size.w - 20, bounds.size.h - 20)); #endif #else s_menu_layer = menu_layer_create( GRect(0,0,bounds.size.w, bounds.size.h)); #endif menu_layer_set_callbacks(s_menu_layer, NULL, (MenuLayerCallbacks) { .get_num_sections = menu_get_num_sections_callback, .get_num_rows = menu_get_num_rows_callback, .get_header_height = menu_get_header_height_callback, .get_cell_height = menu_get_cell_height_callback, .draw_header = menu_draw_header_callback, .draw_row = menu_draw_row_callback, .select_click = menu_select_callback });
void main_window_push() { if(!s_window) { s_window = window_create(); window_set_background_color(s_window, PBL_IF_COLOR_ELSE(GColorRed, GColorBlack)); window_set_window_handlers(s_window, (WindowHandlers) { .load = window_load, .unload = window_unload, });
void progress_layer_window_push() { if(!s_window) { s_window = window_create(); window_set_background_color(s_window, PBL_IF_COLOR_ELSE(GColorLightGray, GColorWhite)); window_set_window_handlers(s_window, (WindowHandlers) { .load = window_load, .appear = window_appear, .disappear = window_disappear, .unload = window_unload });
void stats_sets_time_window_push( ) { if(!s_stats_sets_time_window) { s_stats_sets_time_window = window_create(); window_set_background_color(s_stats_sets_time_window, PBL_IF_COLOR_ELSE(GColorMidnightGreen, GColorBlack)); window_set_click_config_provider(s_stats_sets_time_window, click_config_provider); window_set_window_handlers(s_stats_sets_time_window, (WindowHandlers) { .load = window_load, .unload = window_unload, });
static void init(void) { app_worker_launch(); app_worker_message_subscribe(worker_message_handler); s_window = window_create(); window_set_background_color(s_window, PBL_IF_COLOR_ELSE(GColorChromeYellow, GColorBlack)); window_set_click_config_provider(s_window, click_config_provider); window_set_window_handlers(s_window, (WindowHandlers) { .load = window_load, .unload = window_unload, });
static void gui_layer_bg_update(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, c_bg); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); int width = layer_get_frame(layer).size.w; int height = layer_get_frame(layer).size.h; graphics_context_set_stroke_color(ctx, PBL_IF_COLOR_ELSE(GColorLightGray, GColorBlack)); graphics_context_set_stroke_width(ctx, 1); graphics_draw_line(ctx, GPoint(PADDING_X, height/2-10), GPoint(width-PADDING_X, height/2-10)); graphics_draw_line(ctx, GPoint(PADDING_X, height/2+10), GPoint(width-PADDING_X, height/2+10)); }
static uint32_t getCapabilities(uint16_t maxInboxSize) { uint32_t serializedCapabilities = 0; serializedCapabilities |= PBL_IF_MICROPHONE_ELSE(0x01, 0x00); serializedCapabilities |= PBL_IF_COLOR_ELSE(0x02, 0x00); serializedCapabilities |= PBL_IF_ROUND_ELSE(0x04, 0x00); serializedCapabilities |= PBL_IF_SMARTSTRAP_ELSE(0x08, 0x00); serializedCapabilities |= PBL_IF_HEALTH_ELSE(0x10, 0x00); serializedCapabilities |= maxInboxSize << 16; return serializedCapabilities; }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_CONFIRM); const GEdgeInsets icon_insets = {.top = 7, .right = 28, .bottom = 56, .left = 14}; s_icon_layer = bitmap_layer_create(grect_inset(bounds, icon_insets)); 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)); const GEdgeInsets label_insets = {.top = 112, .right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2}; s_label_layer = text_layer_create(grect_inset(bounds, label_insets)); text_layer_set_text(s_label_layer, DIALOG_CHOICE_WINDOW_MESSAGE); text_layer_set_background_color(s_label_layer, GColorClear); text_layer_set_text_alignment(s_label_layer, GTextAlignmentCenter); text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(window_layer, text_layer_get_layer(s_label_layer)); s_tick_bitmap = gbitmap_create_with_resource(RESOURCE_ID_TICK); s_cross_bitmap = gbitmap_create_with_resource(RESOURCE_ID_CROSS); 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); } static void window_unload(Window *window) { text_layer_destroy(s_label_layer); action_bar_layer_destroy(s_action_bar_layer); bitmap_layer_destroy(s_icon_layer); gbitmap_destroy(s_icon_bitmap); gbitmap_destroy(s_tick_bitmap); gbitmap_destroy(s_cross_bitmap); window_destroy(window); s_main_window = NULL; } void dialog_choice_window_push() { if(!s_main_window) { s_main_window = window_create(); window_set_background_color(s_main_window, PBL_IF_COLOR_ELSE(GColorJaegerGreen, GColorWhite)); window_set_window_handlers(s_main_window, (WindowHandlers) { .load = window_load, .unload = window_unload, }); }
// Global variables for the demo part static Window *main_window; static Layer *dither_layer, *text_layer; uint8_t color[3] = {127, 127, 127}; // Start colors in the middle enum {red, green, blue}; // for color[] above enum {gray}; // for color[] above, but just uses "red" channel uint8_t grayscale = false; // Allows 2-bit grayscale on color displays (ignored on B&W) // Honestly, all the code below would look better if I could // come up with a word that conveys "the opposite of grayscale". // Then I could set this to TRUE and get rid of all the inversions // in the forms of "!grayscale" and "~grayscale" uint8_t cursor = 0; // Position for RGB caret uint8_t cursormax = PBL_IF_COLOR_ELSE(3, 1); // 3 cursor positions for color, just the 1 for B&W // ------------------------------------------------------------------------------------------------------------------------------------------------ // // Layer Update Functions // ------------------------------------------------------------------------ // static void dither_layer_update(Layer *layer, GContext *ctx) { GRect frame = layer_get_frame(layer); #if(PBL_COLOR) if(!grayscale) fill_rect_dithered(ctx, frame, color[red], color[green], color[blue]); // Fill the layer else #endif fill_rect_dithered(ctx, frame, color[gray], color[gray], color[gray]); // Use channel 0 (normally red) for all 3 colors }
static void gui_main_window_load(Window *window) { /* root layer */ Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); /* create action bar */ s_action_bar = action_bar_layer_create(); action_bar_layer_add_to_window(s_action_bar, window); action_bar_layer_set_background_color(s_action_bar, PBL_IF_COLOR_ELSE(GColorTiffanyBlue, GColorWhite)); action_bar_layer_set_click_config_provider(s_action_bar, gui_ab_click_provider); gui_ab_update_icons(); bounds.size.w -= ACTION_BAR_WIDTH; /* background layer */ s_layer_bg = layer_create(bounds); layer_set_update_proc(s_layer_bg, gui_layer_bg_update); layer_add_child(window_layer, s_layer_bg); /* create content layer on the left */ s_layer_content = layer_create(bounds); layer_set_update_proc(s_layer_content, gui_layer_content_update); layer_add_child(window_layer, s_layer_content); int kern = 2; /* text layer center */ int ch = 22; s_text_center_descr = text_layer_create(GRect(PADDING_X, bounds.size.h/2-(ch+kern)/2, bounds.size.w-2*PADDING_X, ch)); text_layer_set_font(s_text_center_descr, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(s_text_center_descr, GColorClear); text_layer_set_text_alignment(s_text_center_descr, GTextAlignmentCenter); text_layer_set_text(s_text_center_descr, ""); layer_add_child(s_layer_content, text_layer_get_layer(s_text_center_descr)); /* text layers upper */ /* description */ int dh = 22; int ds = 3; s_text_upper_descr = text_layer_create(GRect(PADDING_X, bounds.size.h/2-dh-ch/2, bounds.size.w-2*PADDING_X, dh)); text_layer_set_font(s_text_upper_descr, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(s_text_upper_descr, GColorClear); text_layer_set_text_alignment(s_text_upper_descr, PBL_IF_ROUND_ELSE(GTextAlignmentRight, GTextAlignmentCenter)); text_layer_set_text(s_text_upper_descr, ""); layer_add_child(s_layer_content, text_layer_get_layer(s_text_upper_descr)); /* time 1 */ int t1h = 32; int t1s = 5; s_text_upper_time1 = text_layer_create(GRect(PADDING_X*2, bounds.size.h/2-dh-ch/2+ds-t1h, bounds.size.w-2*PADDING_X*2, t1h)); text_layer_set_font(s_text_upper_time1, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_background_color(s_text_upper_time1, GColorClear); text_layer_set_text_alignment(s_text_upper_time1, PBL_IF_ROUND_ELSE(GTextAlignmentRight, GTextAlignmentCenter)); text_layer_set_text(s_text_upper_time1, ""); layer_add_child(s_layer_content, text_layer_get_layer(s_text_upper_time1)); /* time 2 */ int t2h = 20; s_text_upper_time2 = text_layer_create(GRect(PADDING_X, bounds.size.h/2-kern-dh-ch/2+ds-t1h+t1s-t2h, bounds.size.w-2*PADDING_X, t2h)); text_layer_set_font(s_text_upper_time2, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(s_text_upper_time2, GColorClear); text_layer_set_text_alignment(s_text_upper_time2, PBL_IF_ROUND_ELSE(GTextAlignmentRight, GTextAlignmentCenter)); text_layer_set_text(s_text_upper_time2, ""); layer_add_child(s_layer_content, text_layer_get_layer(s_text_upper_time2)); /* text layer lower */ /* description */ s_text_lower_descr = text_layer_create(GRect(PADDING_X, bounds.size.h/2-kern+ch/2, bounds.size.w-2*PADDING_X, dh)); text_layer_set_font(s_text_lower_descr, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(s_text_lower_descr, GColorClear); text_layer_set_text_alignment(s_text_lower_descr, PBL_IF_ROUND_ELSE(GTextAlignmentRight, GTextAlignmentCenter)); text_layer_set_text(s_text_lower_descr, ""); layer_add_child(s_layer_content, text_layer_get_layer(s_text_lower_descr)); /* time 1 */ s_text_lower_time1 = text_layer_create(GRect(PADDING_X*2, bounds.size.h/2-kern+ch/2+dh-ds, bounds.size.w-2*PADDING_X*2, t1h)); text_layer_set_font(s_text_lower_time1, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_background_color(s_text_lower_time1, GColorClear); text_layer_set_text_alignment(s_text_lower_time1, PBL_IF_ROUND_ELSE(GTextAlignmentRight, GTextAlignmentCenter)); text_layer_set_text(s_text_lower_time1, ""); layer_add_child(s_layer_content, text_layer_get_layer(s_text_lower_time1)); /* time 2 */ s_text_lower_time2 = text_layer_create(GRect(PADDING_X, bounds.size.h/2-kern+ch/2+dh-ds+t1h-t1s, bounds.size.w-2*PADDING_X, t2h)); text_layer_set_font(s_text_lower_time2, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(s_text_lower_time2, GColorClear); text_layer_set_text_alignment(s_text_lower_time2, PBL_IF_ROUND_ELSE(GTextAlignmentRight, GTextAlignmentCenter)); text_layer_set_text(s_text_lower_time2, ""); layer_add_child(s_layer_content, text_layer_get_layer(s_text_lower_time2)); }