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) { .active_background_color = DEFAULT_ACTIVE_COLOR, .inactive_background_color = DEFAULT_INACTIVE_COLOR, .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); 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); }
//loading static void load(Window* window) { previous_question = -1; Layer *window_layer = window_get_root_layer(ui.window); GRect window_bounds = layer_get_bounds(window_layer); #ifdef PBL_COLOR layer_set_update_proc(window_layer, bg_update_proc); #endif // init text layers for(int i=0; i < 3; i++) { GRect answerBounds = GRect(144 - 34, 84 - 58 + i * 49, 30, 18); ui.romajiAnswer[i] = text_layer_create(answerBounds); text_layer_set_text_alignment(ui.romajiAnswer[i], GTextAlignmentRight); text_layer_set_font(ui.romajiAnswer[i], fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_text(ui.romajiAnswer[i], ""); #ifdef PBL_COLOR text_layer_set_background_color(ui.romajiAnswer[i], GColorClear); text_layer_set_text_color(ui.romajiAnswer[i], SEC_FG_COLOR); #endif } for(int i=0; i < 3; i++) ui.bitmaps[i] = NULL; GRect statsBounds = GRect(0, 0, 144, 18); ui.stats = text_layer_create(statsBounds); text_layer_set_text_alignment(ui.stats, GTextAlignmentCenter); text_layer_set_font(ui.stats, fonts_get_system_font(FONT_KEY_GOTHIC_18)); #ifdef PBL_COLOR text_layer_set_background_color(ui.stats, GColorClear); text_layer_set_text_color(ui.stats, SEC_FG_COLOR); #endif total_question_num = 0; correct_anserted_questions = 0; update_stats_disp(); // init icons GRect icon_rect = GRect(0, 0, window_bounds.size.w, window_bounds.size.h); grect_align(&icon_rect, &window_bounds, GAlignCenter, false); ui.glyph_layer = layer_create(icon_rect); layer_set_update_proc(ui.glyph_layer, glyph_layer_update_proc); layer_set_clips(ui.glyph_layer, true); // init layers layer_add_child(window_layer, ui.glyph_layer); layer_add_child(window_layer, text_layer_get_layer(ui.stats)); for(int i=0; i<3; i++) layer_add_child(window_layer, text_layer_get_layer(ui.romajiAnswer[i])); window_set_click_config_provider(ui.window, (ClickConfigProvider) config_provider); load_new_question(); }
DotsLayer* dots_layer_create(GRect frame) { DotsLayer* dl = malloc(sizeof(DotsLayer)); dl->layer = layer_create_with_data(frame, sizeof(DotsLayer*)); *(DotsLayer**)layer_get_data(dl->layer) = dl; layer_set_clips(dl->layer, false); dl->num_dots = 0; dl->active_dot = 0; layer_set_update_proc(dl->layer, dots_layer_update_proc); return dl; }
void mainWindowLoad(Window* parentWindow) { GRect b = layer_get_bounds( window_get_root_layer(parentWindow) ); s_windowSizeY = b.size.h - STATUS_BAR_LAYER_HEIGHT; s_statusBar = status_bar_layer_create(); layer_add_child(window_get_root_layer(parentWindow), status_bar_layer_get_layer(s_statusBar)); status_bar_layer_set_separator_mode(s_statusBar, StatusBarLayerSeparatorModeDotted); s_mainBackgroundLayer = layer_create( GRect(0, STATUS_BAR_LAYER_HEIGHT, b.size.w, b.size.h - STATUS_BAR_LAYER_HEIGHT) ); layer_add_child(window_get_root_layer(parentWindow), s_mainBackgroundLayer); layer_set_update_proc(s_mainBackgroundLayer, mainBackgroundUpdateProc); int dispX = (b.size.w - BOARD_SIZE_X) / 2; int dispY = dispX; #ifdef PBL_ROUND dispY = 5; #endif s_boardLayer = layer_create( GRect(dispX, dispY, BOARD_SIZE_X + 1, BOARD_SIZE_Y + 1) ); layer_add_child(s_mainBackgroundLayer, s_boardLayer); layer_set_update_proc(s_boardLayer, boardUpdateProc); layer_set_clips(s_boardLayer, true); s_mainForegroundLayer = layer_create( GRect(0, STATUS_BAR_LAYER_HEIGHT, b.size.w, b.size.h - STATUS_BAR_LAYER_HEIGHT) ); layer_add_child(window_get_root_layer(parentWindow), s_mainForegroundLayer); layer_set_update_proc(s_mainForegroundLayer, mainForegroundUpdateProc); s_wave[0] = GRect(0, b.size.h * SUB_PIXEL, b.size.w, 10); s_wave[1] = GRect(0, b.size.h * SUB_PIXEL, b.size.w, 15); s_wave[2] = GRect(0, b.size.h * SUB_PIXEL, b.size.w, 20); s_liquid = GRect(0, b.size.h * SUB_PIXEL, b.size.w, b.size.h); // TODO x2 for safety s_nWaves = 0; s_liquidEnd = s_windowSizeY * SUB_PIXEL; s_currentRun = 0; s_switch.first = GPoint(-1,-1); s_switch.second = GPoint(-1,-1); s_cursor = GPoint(0,0); s_motionCursor = GPoint(PIECE_SUB_PIXELS/2,PIECE_SUB_PIXELS/2); s_availableMove = GPoint(-1,-1); srand(time(NULL)); startGameTick(); }
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 layer_init_and_add(Layer *newlayer, GRect rect, Layer *parentLayer, bool clipping) { layer_init(newlayer,rect); layer_add_child(parentLayer,newlayer); layer_set_clips(newlayer,clipping); }
/** * Create the layers */ static void window_load(Window *window) { // get the current time time_t now = time(NULL); struct tm *ltime = localtime(&now); set_time(ltime); // globals window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); center = grect_center_point(&bounds); // create the dial layer dial_layer = layer_create(GRect(0,0,144,168)); layer_set_update_proc(dial_layer, dial_layer_draw); layer_add_child(window_layer, dial_layer); // create the minutes drawing layer minute_path = gpath_create(&PATH_INFO); minute_layer = layer_create(GRect(0,0,144,168)); layer_set_clips(minute_layer, true); layer_set_update_proc(minute_layer, minute_layer_draw); layer_add_child(window_layer, minute_layer); // decorations layer deco_layer = layer_create(GRect(0,0,144,168)); layer_set_update_proc(deco_layer, deco_layer_draw); layer_add_child(window_layer, deco_layer); // create the hour display layer int r1 = 21; hour_layer = text_layer_create(GRect((144/2)-r1, (168/2)-r1, 2*r1, 2*r1)); text_layer_set_text_alignment(hour_layer, GTextAlignmentCenter); text_layer_set_text_color(hour_layer, GColorWhite); text_layer_set_background_color(hour_layer, GColorClear); text_layer_set_font(hour_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK)); layer_set_hidden(text_layer_get_layer(hour_layer), false); layer_add_child(window_layer, text_layer_get_layer(hour_layer)); // info layer (text) unsigned int d_height = 38; unsigned int d_width = 42; day_layer = text_layer_create(GRect((144/2)-(d_width/2), (168/2)-(d_height)+11, d_width, d_height)); text_layer_set_text_color(day_layer, GColorWhite); text_layer_set_background_color(day_layer, GColorClear); text_layer_set_text_alignment(day_layer, GTextAlignmentCenter); text_layer_set_font(day_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text(day_layer, day_string); layer_set_hidden(text_layer_get_layer(day_layer), true); layer_add_child(window_layer, text_layer_get_layer(day_layer)); month_layer = text_layer_create(GRect((144/2)-(d_width/2), (168/2)-(d_height/2)+22, d_width, d_height)); text_layer_set_text_color(month_layer, GColorWhite); text_layer_set_background_color(month_layer, GColorClear); text_layer_set_text_alignment(month_layer, GTextAlignmentCenter); text_layer_set_font(month_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text(month_layer, month_string); layer_set_hidden(text_layer_get_layer(month_layer), true); layer_add_child(window_layer, text_layer_get_layer(month_layer)); }
static void setup_bullet_layer(struct Layer *window_root_layer, struct Layer *layer) { *(char*)layer_get_data(layer) = '0'; // not sure if this is neccesary? populating with an initial value layer_set_update_proc(layer, draw_bullet_layer); layer_set_clips(layer, false); layer_add_child(window_root_layer, layer); }