static void main_window_load(Window *window) { s_root_layer = window_get_root_layer(window); // Time s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_EMULOGIC_24)); s_time_layer = text_layer_create(POS_TIME); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); // Date s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_EMULOGIC_12)); s_date_layer = text_layer_create(POS_DATE); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_font(s_date_layer, s_date_font); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); // Bluetooth s_bluetooth_layer = bitmap_layer_create(POS_BT); layer_add_child(s_root_layer, bitmap_layer_get_layer(s_bluetooth_layer)); // Battery s_battery_layer = bitmap_layer_create(POS_BATT); layer_add_child(s_root_layer, bitmap_layer_get_layer(s_battery_layer)); // Kirby s_kirby_layer = bitmap_layer_create(POS_KBY); layer_add_child(s_root_layer, bitmap_layer_get_layer(s_kirby_layer)); // === First update === // tick_handler time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); srand(temp); cur_kirby = rand() % NUM_KIRBIES; tick_handler(tick_time, INTERVAL_UPDATE); // Go back one Kirby so the next update keeps it the same cur_kirby = (cur_kirby - 1 + NUM_KIRBIES) % NUM_KIRBIES; // bt_handler bt_handler(bluetooth_connection_service_peek()); // batt_handler batt_handler(battery_state_service_peek()); }
void window_load(Window *window){ //load bitmap for background/watchface face_bitmap = gbitmap_create_with_resource(RESOURCE_ID_WATCHFACE); //add bitmap layer face_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_bitmap(face_layer, face_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(face_layer)); //create text layer for bluetooth status bt_layer = text_layer_create(GRect(0, 130, 144, 38)); text_layer_set_background_color(bt_layer, GColorClear); text_layer_set_text_color(bt_layer, GColorWhite); text_layer_set_text_alignment(bt_layer, GTextAlignmentCenter); text_layer_set_font(bt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_get_root_layer(window), (Layer*) bt_layer); //manually invoke bluetooth handler to refresh status on load bt_handler(); //create text layer for 'pebble' brand at 6oclock brand_layer = text_layer_create(GRect(0, 145, 144, 23)); text_layer_set_background_color(brand_layer, GColorClear); text_layer_set_text_color(brand_layer, GColorWhite); text_layer_set_text_alignment(brand_layer, GTextAlignmentCenter); text_layer_set_font(brand_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text(brand_layer, "pebble"); layer_add_child(window_get_root_layer(window), (Layer*) brand_layer); //create text layer for pebble battery status batt_layer = text_layer_create(GRect(5, 76, 20, 50)); text_layer_set_background_color(batt_layer, GColorClear); text_layer_set_text_color(batt_layer, GColorWhite); text_layer_set_text_alignment(batt_layer, GTextAlignmentCenter); text_layer_set_font(batt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); layer_add_child(window_get_root_layer(window), (Layer*) batt_layer); //manually invoke battery status handler to refresh status on load batt_handler(battery_state_service_peek()); //add text layer for digital time text_layer = text_layer_create(GRect(0, 0, 144, 168)); text_layer_set_background_color(text_layer, GColorClear); text_layer_set_text_color(text_layer, GColorWhite); text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); layer_add_child(window_get_root_layer(window), (Layer*) text_layer); //create text layer for date date_layer = text_layer_create(GRect(116, 76, 25, 50)); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); layer_add_child(window_get_root_layer(window), (Layer*) date_layer); //add layers for analog clock hours_layer = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(hours_layer, hours_layer_update_proc); minutes_layer = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(minutes_layer, minutes_layer_update_proc); //draw hands hour_path = gpath_create(&HOUR_PATH_INFO); layer_add_child(window_get_root_layer(window), (Layer*) hours_layer); minute_path = gpath_create(&MINUTE_PATH_INFO); layer_add_child(window_get_root_layer(window), (Layer*) minutes_layer); //time struct to display time on load struct tm *t; time_t temp; temp = time(NULL); t = localtime(&temp); //manually invoke tick handler to refresh time on load tick_handler(t, MINUTE_UNIT); //add centre point centre_layer = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(centre_layer, centre_layer_update_proc); layer_add_child(window_get_root_layer(window), (Layer*) centre_layer); }
//Обработка загрузки "окна" void window_load(Window *window) { //Инициализация ресурсов (шрифты/картинки блютуза/батареи) ResHandle font_handle42 = resource_get_handle(RESOURCE_ID_IMAGINE_42); ResHandle fontv_handle42 = resource_get_handle(RESOURCE_ID_VISITOR_62); bt_disconn = gbitmap_create_with_resource(RESOURCE_ID_BT_DISCONNECTED); batt_low = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_LOW); batt_charg = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGING); batt_full = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGED); //Создание слоёв батареи и блютуза bt_layer = bitmap_layer_create(GRect(5,124,32,32)); batt_layer = bitmap_layer_create(GRect(107,124,32,32)); //batp_layer = layer_create(GRect(2,110,140,1)); //Слой времени time_layer = text_layer_create(GRect(4, 56, 144, 56)); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_text_color(time_layer, GColorBlack); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); text_layer_set_font(time_layer,fonts_load_custom_font(font_handle42)); //Слой даты date_layer = text_layer_create(GRect(4, 0, 144, 56)); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_text_color(date_layer, GColorBlack); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); text_layer_set_font(date_layer,fonts_load_custom_font(font_handle42)); //Слой дня недели wday_layer = text_layer_create(GRect(4, 100, 144, 56)); text_layer_set_background_color(wday_layer, GColorClear); text_layer_set_text_color(wday_layer, GColorBlack); text_layer_set_text_alignment(wday_layer, GTextAlignmentCenter); text_layer_set_font(wday_layer,fonts_load_custom_font(fontv_handle42)); //Начальное состояние блютуза bt_handler(bluetooth_connection_service_peek()); //Начальное состояние батареи batt_handler(battery_state_service_peek()); //layer_mark_dirty(batp_layer); //"Вывод" слоёв в окно layer_add_child(window_get_root_layer(window), (Layer*) time_layer); layer_add_child(window_get_root_layer(window), (Layer*) date_layer); layer_add_child(window_get_root_layer(window), (Layer*) wday_layer); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bt_layer)); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(batt_layer)); //layer_set_update_proc(batp_layer,batp_layer_update_callback); //layer_add_child(window_get_root_layer(window), batp_layer); bool lang_rus = persist_read_bool(KEY_LANG); //bool show_bb = persist_read_bool(KEY_BATTBAR); if (lang_rus==true) { dow[0]="ВС"; dow[1]="ПН"; dow[2]="ВТ"; dow[3]="СР"; dow[4]="ЧТ"; dow[5]="ПТ"; dow[6]="СБ"; } else { dow[0]="SU"; dow[1]="MO"; dow[2]="TU"; dow[3]="WE"; dow[4]="TH"; dow[5]="FR"; dow[6]="SA"; } //Ручное начальнок срабатывание "тика", чтобы время не было пустым при открытии struct tm *t; time_t temp; temp = time(NULL); t = localtime(&temp); tick_handler(t, MINUTE_UNIT); //Создание и вывод инвертера inv_layer = inverter_layer_create(GRect(0, 56, 144, 56)); layer_add_child(window_get_root_layer(window), (Layer*) inv_layer); }