// -------------------------------------------------------- // 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 update_display(PblTm *current_time) { unsigned short display_hour = get_display_hour(current_time->tm_hour); // TODO: Remove leading zero? set_container_image(&time_digits_images[0], WHITE_IMAGE_RESOURCE_IDS[display_hour/10], BLACK_IMAGE_RESOURCE_IDS[display_hour/10], GPoint(-5, 91)); set_container_image(&time_digits_images[1], WHITE_IMAGE_RESOURCE_IDS[display_hour%10], BLACK_IMAGE_RESOURCE_IDS[display_hour%10], GPoint(18, 68)); set_container_image(&time_colon_image, RESOURCE_ID_IMAGE_COLON_WHITE, RESOURCE_ID_IMAGE_COLON_BLACK, GPoint(40,42)); set_container_image(&time_digits_images[2], WHITE_IMAGE_RESOURCE_IDS[current_time->tm_min/10], BLACK_IMAGE_RESOURCE_IDS[current_time->tm_min/10], GPoint(54, 34)); set_container_image(&time_digits_images[3], WHITE_IMAGE_RESOURCE_IDS[current_time->tm_min%10], BLACK_IMAGE_RESOURCE_IDS[current_time->tm_min%10], GPoint(77, 11)); if (!clock_is_24h_style()) { if (display_hour/10 == 0) { layer_remove_from_parent(&time_digits_images[0].layer.layer); rotbmp_pair_deinit_container(&time_digits_images[0]); } } }
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); }
static void set_image(Layer *window_layer, GRect bounds, int resource_id) { if (s_image_bitmap != NULL) { gbitmap_destroy(s_image_bitmap); } if (s_image_layer != NULL) { layer_remove_from_parent(bitmap_layer_get_layer(s_image_layer)); bitmap_layer_destroy(s_image_layer); } s_image_bitmap = gbitmap_create_with_resource(resource_id); // push the image down a bit to allow for the text at the top s_image_layer = bitmap_layer_create( GRect( 0, // x from left 24, // y from top bounds.size.w, // width bounds.size.h // height ) ); bitmap_layer_set_bitmap(s_image_layer, s_image_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_image_layer)); }
static void window_unload(Window *window) { thincfg_unsubscribe(); thincfg_deinit(); btmonitor_deinit(); tick_timer_service_unsubscribe(); app_timer_cancel(timer); free(timer); free(now); for (int x = 0; x < FONT_COUNT; x++) { fonts_unload_custom_font(fonts[x]); } for (int i = 0; i < LAYER_COUNT; i++) { layer_remove_from_parent(text_layer_get_layer(layers[i].layer)); text_layer_destroy(layers[i].layer); free(layers[i].layer); } }
void show_menu() { mainMenuSection[0].items = mainMenuItems; mainMenuSection[0].num_items = 2; mainMenuItems[0].title = "Active"; mainMenuItems[0].icon = currentIcon; mainMenuItems[0].callback = menu_picked; mainMenuItems[1].title = "History"; mainMenuItems[1].icon = historyIcon; mainMenuItems[1].callback = menu_picked; Layer* topLayer = window_get_root_layer(menuWindow); if (menuLayer != NULL) layer_remove_from_parent((Layer *) menuLayer); menuLayer = simple_menu_layer_create(GRect(0, 0, 144, 156), menuWindow, mainMenuSection, 1, NULL); layer_add_child(topLayer, (Layer *) menuLayer); layer_set_hidden((Layer *) menuLoadingLayer, true); layer_set_hidden((Layer *) menuLayer, false); layer_set_hidden((Layer *) quitTitle, true); layer_set_hidden((Layer *) quitText, true); }
void hideClassFlag() { layer_remove_from_parent(bitmap_layer_get_layer(s_pennantOneLayer)); }
// Hide loading screen static void hide_loading_icon(void) { layer_remove_from_parent(text_layer_get_layer(text_layer)); layer_remove_from_parent(bitmap_layer_get_layer(loading_icon_layer)); }
void RemoveMainBmpImage(void) { layer_remove_from_parent(bitmap_layer_get_layer(mainImage)); }
// Hide loading screen static void hide_loading_icon(void) { menu_layer_set_click_config_onto_window(s_menulayer_1, s_window); layer_remove_from_parent(text_layer_get_layer(text_layer)); layer_remove_from_parent(bitmap_layer_get_layer(loading_icon_layer)); }
void RemoveLevelLayer(void) { layer_remove_from_parent(&levelLayer.layer); }
//----------------------------------------------------------------------------------------------------------------------- static void update_configuration(void) { if (persist_exists(CONFIG_KEY_THEME)) { int32_t theme = persist_read_int(CONFIG_KEY_THEME); CfgData.circle = (theme == 0); } else CfgData.circle = false; if (persist_exists(CONFIG_KEY_FSM)) CfgData.fsm = persist_read_bool(CONFIG_KEY_FSM); else CfgData.fsm = false; if (persist_exists(CONFIG_KEY_INV)) CfgData.inv = !CfgData.circle && persist_read_bool(CONFIG_KEY_INV); else CfgData.inv = true; if (persist_exists(CONFIG_KEY_ANIM)) CfgData.anim = persist_read_bool(CONFIG_KEY_ANIM); else CfgData.anim = true; if (persist_exists(CONFIG_KEY_SEP)) CfgData.sep = persist_read_bool(CONFIG_KEY_SEP); else CfgData.sep = true; if (persist_exists(CONFIG_KEY_DATEFMT)) CfgData.datefmt = (int16_t)persist_read_int(CONFIG_KEY_DATEFMT); else CfgData.datefmt = 0; if (persist_exists(CONFIG_KEY_SMART)) CfgData.smart = persist_read_bool(CONFIG_KEY_SMART); else CfgData.smart = true; if (persist_exists(CONFIG_KEY_VIBR)) CfgData.vibr = persist_read_bool(CONFIG_KEY_VIBR); else CfgData.vibr = false; app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "Curr Conf: circle:%d, fsm:%d, inv:%d, anim:%d, sep:%d, datefmt:%d, smart:%d, vibr:%d", CfgData.circle, CfgData.fsm, CfgData.inv, CfgData.anim, CfgData.sep, CfgData.datefmt, CfgData.smart, CfgData.vibr); gbitmap_destroy(batteryAll); batteryAll = gbitmap_create_with_resource(CfgData.inv ? RESOURCE_ID_IMAGE_BATTERY_INV : RESOURCE_ID_IMAGE_BATTERY); bitmap_layer_set_bitmap(radio_layer, NULL); gbitmap_destroy(bmp_radio); bmp_radio = gbitmap_create_as_sub_bitmap(batteryAll, GRect(110, 0, 10, 20)); bitmap_layer_set_bitmap(radio_layer, bmp_radio); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_get_root_layer(window)); window_set_background_color(window, CfgData.inv ? GColorWhite : GColorBlack); //Face Layer first on round layer_remove_from_parent(face_layer); layer_destroy(face_layer); #if defined(PBL_RECT) face_layer = layer_create(GRect(0, 0, bounds.size.w, CfgData.fsm ? bounds.size.h : bounds.size.h-n_bottom_margin)); layer_set_update_proc(face_layer, face_update_proc); #elif defined(PBL_ROUND) face_layer = layer_create(GRect(0, 0, bounds.size.w, bounds.size.h)); layer_set_update_proc(face_layer, face_update_proc); layer_add_child(window_layer, face_layer); #endif //Bottom Layer next, then Radio and Battery layer_remove_from_parent(text_layer_get_layer(date_layer)); layer_remove_from_parent(bitmap_layer_get_layer(radio_layer)); layer_remove_from_parent(bitmap_layer_get_layer(battery_layer)); #if defined(PBL_RECT) if (!CfgData.fsm) #endif { #if defined(PBL_RECT) layer_add_child(window_layer, text_layer_get_layer(date_layer)); #ifdef PBL_COLOR text_layer_set_text_color(date_layer, CfgData.inv ? GColorDarkGray : GColorLightGray); #else text_layer_set_text_color(date_layer, CfgData.inv ? GColorBlack : GColorWhite); #endif text_layer_set_background_color(date_layer, CfgData.inv ? GColorWhite : GColorBlack); #endif if (CfgData.smart) { layer_add_child(window_layer, bitmap_layer_get_layer(radio_layer)); layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer)); } } //On Rect later #if defined(PBL_RECT) layer_add_child(window_layer, face_layer); #endif //Get a time structure so that it doesn't start blank time_t temp = time(NULL); struct tm *t = localtime(&temp); //Manually call the tick handler when the window is loading aktHH = t->tm_hour; aktMM = t->tm_min; handle_tick(t, MINUTE_UNIT); //Set Battery state BatteryChargeState btchg = battery_state_service_peek(); battery_state_service_handler(btchg); //Set Bluetooth state bool connected = bluetooth_connection_service_peek(); bluetooth_connection_handler(connected); }
static void reset_menu() { int num_a_items = 0; menu_items[num_a_items++] = (SimpleMenuItem){ .title = "Start", .subtitle = "Lets Push-ups", .callback = select_menu_handler, }; persist_exists(GOAL_KEY)?1: persist_write_int(GOAL_KEY,15); snprintf(goal_str,sizeof(goal_str), "%ld once", persist_read_int(GOAL_KEY)); menu_items[num_a_items++] = (SimpleMenuItem){ .title= "Goal", .subtitle = goal_str, .callback = select_menu_handler, }; snprintf(history_str,sizeof(history_str), "Total: %ld Top: %ld", persist_exists(TOTAL_PUSHUPS_KEY)?persist_read_int(TOTAL_PUSHUPS_KEY) : 0, persist_exists(MAX_PUSHUPS_KEY)?persist_read_int(MAX_PUSHUPS_KEY) : 0); menu_items[num_a_items++] = (SimpleMenuItem){ .title = "History", .subtitle = history_str, .callback = select_menu_handler, }; menu_items[num_a_items++] = (SimpleMenuItem){ .title= "Version", .subtitle = "1.0 @copyright shanfeng", .callback = select_menu_handler, }; sections[0] = (SimpleMenuSection){ .num_items = SECTION_COUNT, .items = menu_items, }; if(menu_layer) { layer_remove_from_parent(simple_menu_layer_get_layer(menu_layer)); simple_menu_layer_destroy(menu_layer); } Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); menu_layer = simple_menu_layer_create(bounds,window,sections, 1,NULL); simple_menu_layer_set_selected_index(menu_layer,menu_select,false); layer_add_child(window_layer, simple_menu_layer_get_layer(menu_layer)); } static void goal_select(struct NumberWindow *number_window, void *context) { persist_write_int(GOAL_KEY,number_window_get_value(number_window)); window_stack_pop(true); } static void select_menu_handler(int index, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG,"%d",index); switch(index) { case 0: if(!pushups_window) { APP_LOG(APP_LOG_LEVEL_DEBUG, "pushups_window create"); pushups_window = create_pushups_window(); } window_stack_push(pushups_window, true); break; case 1: if(!number_window) { number_window = number_window_create("Goal",(NumberWindowCallbacks){ .selected = goal_select, },NULL); number_window_set_value(number_window, persist_read_int(GOAL_KEY)); number_window_set_min(number_window,5); number_window_set_step_size(number_window, 5); number_window_set_max(number_window,1000); } window_stack_push((Window*)number_window,true); break; case 3: { if(!info_window) { info_window = aboutinfo_window_create(); } window_stack_push(info_window,true); } } menu_select = index; }
void disable_digital() { layer_remove_from_parent(text_layer_get_layer(digital_layer)); layer_mark_dirty(digital_container); }
void disable_info() { layer_remove_from_parent(info_layer); layer_mark_dirty(info_container); }
static void drop_block() { if (blockType == -1) { // Create a new block. blockType = nextBlockType; nextBlockType = rand() % 7; rotation = 0; int adjust = 0; if (blockType == Z || blockType == J) { adjust = -1; } if (blockType == LINE) { adjust = -2; } blockX = 5 + adjust; blockY = 0; nextBlockX = 0; nextBlockY = 0; make_block(block, blockType, blockX, blockY); make_block(nextBlock, nextBlockType, nextBlockX, nextBlockY); } else { // Handle the current block. // Drop it, and if it can't drop then f**k it. // Uh, I mean stick it in place and make a new block. bool canDrop = true; for (int i=0; i<4; i++) { int benthic = block[i].y + 1; if (benthic > 19) { canDrop = false; } if (grid[block[i].x][benthic]) { canDrop = false; } } if (canDrop) { for (int i=0; i<4; i++) { block[i].y += 1; } } else { for (int i=0; i<4; i++) { grid[block[i].x][block[i].y] = true; grid_col[block[i].x][block[i].y] = blockType; } layer_mark_dirty(s_bg_layer); blockType = -1; // Clear rows if possible. for (int j=0; j<20; j++) { bool isRow = true; for (int i=0; i<10; i++) { if (!grid[i][j]) { isRow = false; } } if (isRow) { // I hate all these nested loops... // But yeah, drop the above rows. lines_cleared += 1; if (level < 10 && lines_cleared >= (10 * level)) { level += 1; tick_time -= tick_interval; update_num_layer (level, levelStr, level_layer); } update_num_layer (lines_cleared, scoreStr, score_layer); for (int k=j; k>0; k--) { for (int i=0; i<10; i++) { grid[i][k] = grid[i][k-1]; grid_col[i][k] = grid_col[i][k-1]; } } for (int i=0; i<10; i++) { grid[i][0] = false; grid_col[i][0] = 255; } } } // Check whether you've lost. for (int i=0; i<4; i++) { if (block[i].y == 0) { playing = false; lost = true; Layer *window_layer = window_get_root_layer(window); layer_remove_from_parent(s_bg_layer); layer_remove_from_parent(s_left_pane_layer); layer_add_child(window_layer, text_layer_get_layer(title_layer)); text_layer_set_text(title_layer, "You lost!"); text_layer_set_text(score_label_layer, ""); text_layer_set_text(score_layer, ""); text_layer_set_text(level_label_layer, ""); text_layer_set_text(level_layer, ""); // When you lose, wipe the save. // No need to get fancy; just mark 'has save' false since // we'll re-create the whole thing when it gets set to true. persist_write_bool(HAS_SAVE_KEY, false); // High score? if (!persist_exists(HIGH_SCORE_KEY) || lines_cleared > persist_read_int(HIGH_SCORE_KEY)) { persist_write_int(HIGH_SCORE_KEY, lines_cleared); layer_add_child(window_layer, text_layer_get_layer(high_score_layer)); text_layer_set_text(high_score_layer, "New high score!"); } return; } } } } layer_mark_dirty(s_left_pane_layer); }
static void deinit(void) { app_sync_deinit(&sync); tick_timer_service_unsubscribe(); battery_state_service_unsubscribe(); bluetooth_connection_service_unsubscribe(); layer_remove_from_parent(bitmap_layer_get_layer(separator_layer)); bitmap_layer_destroy(separator_layer); gbitmap_destroy(separator_image); layer_remove_from_parent(bitmap_layer_get_layer(bluetooth_layer)); bitmap_layer_destroy(bluetooth_layer); gbitmap_destroy(bluetooth_image); bitmap_layer_destroy(layer_batt_img); gbitmap_destroy(img_battery_100); gbitmap_destroy(img_battery_90); gbitmap_destroy(img_battery_80); gbitmap_destroy(img_battery_70); gbitmap_destroy(img_battery_60); gbitmap_destroy(img_battery_50); gbitmap_destroy(img_battery_40); gbitmap_destroy(img_battery_30); gbitmap_destroy(img_battery_20); gbitmap_destroy(img_battery_10); gbitmap_destroy(img_battery_charge); fonts_unload_custom_font(custom_font); layer_remove_from_parent(bitmap_layer_get_layer(month_layer)); bitmap_layer_destroy(month_layer); gbitmap_destroy(month_image); layer_remove_from_parent(bitmap_layer_get_layer(day_name_layer)); bitmap_layer_destroy(day_name_layer); gbitmap_destroy(day_name_image); layer_remove_from_parent(bitmap_layer_get_layer(icon_layer)); bitmap_layer_destroy(icon_layer); gbitmap_destroy(icon_bitmap); effect_layer_destroy(effect_layer_2); if (effect_layer != NULL) { effect_layer_destroy(effect_layer); } text_layer_destroy( temp_layer ); layer_destroy(weather_holder); for (int i = 0; i < TOTAL_DATE_DIGITS; i++) { layer_remove_from_parent(bitmap_layer_get_layer(date_digits_layers[i])); gbitmap_destroy(date_digits_images[i]); bitmap_layer_destroy(date_digits_layers[i]); } for (int i = 0; i < TOTAL_SECONDS_DIGITS; i++) { layer_remove_from_parent(bitmap_layer_get_layer(seconds_digits_layers[i])); gbitmap_destroy(seconds_digits_images[i]); bitmap_layer_destroy(seconds_digits_layers[i]); } for (int i = 0; i < TOTAL_TIME_DIGITS; i++) { layer_remove_from_parent(bitmap_layer_get_layer(time_digits_layers[i])); gbitmap_destroy(time_digits_images[i]); bitmap_layer_destroy(time_digits_layers[i]); } window_destroy(window); }
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 unsigned short get_display_hour(unsigned short hour) { if (clock_is_24h_style()) { return hour; } unsigned short display_hour = hour % 12; // Converts "0" to "12" return display_hour ? display_hour : 12; } static void update_display(struct tm *current_time) { // TODO: Only update changed values? set_container_image(&day_name_image, day_name_layer, DAY_NAME_IMAGE_RESOURCE_IDS[current_time->tm_wday], GPoint(69, 61)); // TODO: Remove leading zero? set_container_image(&date_digits_images[0], date_digits_layers[0], DATENUM_IMAGE_RESOURCE_IDS[current_time->tm_mday/10], GPoint(108, 61)); set_container_image(&date_digits_images[1], date_digits_layers[1], DATENUM_IMAGE_RESOURCE_IDS[current_time->tm_mday%10], GPoint(121, 61)); unsigned short display_hour = get_display_hour(current_time->tm_hour); // TODO: Remove leading zero? set_container_image(&time_digits_images[0], time_digits_layers[0], BIG_DIGIT_IMAGE_RESOURCE_IDS[display_hour/10], GPoint(10, 84)); set_container_image(&time_digits_images[1], time_digits_layers[1], BIG_DIGIT_IMAGE_RESOURCE_IDS[display_hour%10], GPoint(40, 84)); set_container_image(&time_digits_images[2], time_digits_layers[2], BIG_DIGIT_IMAGE_RESOURCE_IDS[current_time->tm_min/10], GPoint(77, 84)); set_container_image(&time_digits_images[3], time_digits_layers[3], BIG_DIGIT_IMAGE_RESOURCE_IDS[current_time->tm_min%10], GPoint(105, 84)); if (!clock_is_24h_style()) { if (current_time->tm_hour >= 12) { set_container_image(&time_format_image, time_format_layer, RESOURCE_ID_IMAGE_PM_MODE, GPoint(17, 68)); } else { layer_remove_from_parent(bitmap_layer_get_layer(time_format_layer)); bitmap_layer_destroy(time_format_layer); gbitmap_destroy(time_format_image); } if (display_hour/10 == 0) { layer_remove_from_parent(bitmap_layer_get_layer(time_digits_layers[0])); bitmap_layer_destroy(time_digits_layers[0]); gbitmap_destroy(time_digits_images[0]); } } }
void RemoveHealthLayer(void) { layer_remove_from_parent(¤tHealthLayer.layer); layer_remove_from_parent(&maxHealthLayer.layer); }
void hidePapaFlag() { layer_remove_from_parent(bitmap_layer_get_layer(s_flagPapaLayer)); }
void RemoveBackgroundImage() { layer_remove_from_parent(&backgroundImage.layer.layer); }
void RemoveBackgroundImage() { layer_remove_from_parent(bitmap_layer_get_layer(backgroundImage)); }
void RemoveLevelLayer(void) { layer_remove_from_parent(text_layer_get_layer(levelLayer)); }
void RemoveMainBmpImage(void) { layer_remove_from_parent(&mainImage.layer.layer); }
void remove_container(BmpContainer *bmp_container) { layer_remove_from_parent(&bmp_container->layer.layer); //remove it from layer so it can be safely deinited bmp_deinit_container(bmp_container); //deinit the old image. }
void RemoveClockLayer(void) { layer_remove_from_parent(&clockLayer.layer); }
void RemoveClockLayer(void) { layer_remove_from_parent(text_layer_get_layer(clockLayer)); }
void hide_notification() { layer_remove_from_parent((Layer *)&layer_notification); }
void RemoveHealthLayer(void) { layer_remove_from_parent(text_layer_get_layer(currentHealthLayer)); layer_remove_from_parent(text_layer_get_layer(maxHealthLayer)); }
static void window_unload(Window *window) { layer_remove_from_parent(layer); layer_destroy(layer); }