static void window_load(Window *window) { mBackgroundColor = GColorBlack; mTextColor = GColorWhite; #if PBL_COLOR lightColor = GColorMintGreen; darkColor = GColorDarkGreen; window_set_background_color(window, darkColor); #else window_set_background_color(window, mBackgroundColor); #endif // PBL_COLOR bgLayer = layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); layer_set_update_proc(bgLayer, (LayerUpdateProc)render_bg); layer_add_child(window_get_root_layer(window), bgLayer); timeLayer = layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); layer_set_update_proc(timeLayer, (LayerUpdateProc)render_time); layer_add_child(window_get_root_layer(window), timeLayer); mTimeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BITWISE_16)); mTimeText = malloc(5); // HH:MM mDateText = malloc(5); // MM-DD struct tm* t; time_t temp; temp = time(NULL); t = localtime(&temp); set_time_display(t); bt_handler(bluetooth_connection_service_peek()); battery_handler(battery_state_service_peek()); }
// WINDOW CREATION // static void main_window_load(Window *window) { // Create time TextLayer s_time_layer = text_layer_create(GRect(0, -3, 144, 171)); // Note the negative Y-axis value for better positioning. text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_text(s_time_layer, "TIME: 00:00"); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft); // Create Bluetooth TextLayer s_bluetooth_layer = text_layer_create(GRect(0, 95, 144, 14)); // A single text line is 14px high text_layer_set_background_color(s_bluetooth_layer, GColorClear); text_layer_set_text_color(s_bluetooth_layer, GColorBlack); text_layer_set_text(s_bluetooth_layer, "CONNECTED (Y/N): N"); text_layer_set_font(s_bluetooth_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_bluetooth_layer, GTextAlignmentLeft); // Create Battery TextLayer s_battery_layer = text_layer_create(GRect(0, 109, 144, 14)); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_text_color(s_battery_layer, GColorBlack); text_layer_set_text(s_battery_layer, "BATTERY LEVEL: N/A"); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft); // Create Battery TextLayer s_weather_layer = text_layer_create(GRect(0, 123, 144, 28)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, GColorBlack); text_layer_set_text(s_weather_layer, "TEMPERATURE: Loading...\nWEATHER: Loading..."); text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentLeft); // Create uptime TextLayer s_uptime_layer = text_layer_create(GRect(0, 151, 144, 14)); text_layer_set_background_color(s_uptime_layer, GColorClear); text_layer_set_text_color(s_uptime_layer, GColorBlack); text_layer_set_text(s_uptime_layer, "LOG UPTIME: 0h 0m 0s"); text_layer_set_font(s_uptime_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_uptime_layer, GTextAlignmentLeft); // Make sure the time is displayed from the start update_time(); // Show current connection state bt_handler(bluetooth_connection_service_peek()); // Get the current battery level battery_handler(battery_state_service_peek()); // Add child layers to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_uptime_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_bluetooth_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); }
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 main_reload_config() { // Must be before BT handle overwrites the BG color! #if defined(PBL_COLOR) pge_set_background_color(data_get_color(ColorBackground)); #elif defined(PBL_BW) pge_set_background_color(GColorBlack); #endif // If bluetooth alert enabled if(data_get_bluetooth_alert()) { connection_service_subscribe((ConnectionHandlers) { .pebble_app_connection_handler = bt_handler }); bt_handler(connection_service_peek_pebble_app_connection()); } else {
static void main_window_load(Window *window) { s_time_layer = text_layer_create(GRect(0, 50, 144, 50)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); s_date_layer = text_layer_create(GRect(0, 100, 144, 50)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_color(s_date_layer, GColorBlack); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); s_battery_layer = text_layer_create(GRect(0, 0, 144, 25)); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_text_color(s_battery_layer, GColorBlack); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer)); battery_handler(battery_state_service_peek()); s_bt_layer = text_layer_create(GRect(0, 0, 144, 25)); text_layer_set_background_color(s_bt_layer, GColorClear); text_layer_set_text_color(s_bt_layer, GColorBlack); text_layer_set_font(s_bt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_bt_layer, GTextAlignmentLeft); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_bt_layer)); bt_handler(bluetooth_connection_service_peek()); s_day_layer = text_layer_create(GRect(0, 150, 144, 50)); text_layer_set_background_color(s_day_layer, GColorClear); text_layer_set_text_color(s_day_layer, GColorBlack); text_layer_set_font(s_day_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_day_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_day_layer)); }
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); }
static void main_window_load(Window *window) { // Create time TextLayer s_time_layer = text_layer_create(GRect(0, 51, 144, 100)); s_date_layer = text_layer_create(GRect(0, 101, 144, 80)); s_day_layer = text_layer_create(GRect(4, 3, 144, 80)); s_ampm_layer = text_layer_create(GRect(127, 85, 30, 30)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_background_color(s_day_layer, GColorClear); text_layer_set_background_color(s_ampm_layer, GColorClear); // Get stored colors #ifdef PBL_COLOR int red, green, blue; if (persist_exists(KEY_BGCOLOR_R)) { red = persist_read_int(KEY_BGCOLOR_R); green = persist_read_int(KEY_BGCOLOR_G); blue = persist_read_int(KEY_BGCOLOR_B); GColor bg_color = GColorFromRGB(red, green, blue); window_set_background_color(s_main_window, bg_color); } else { window_set_background_color(s_main_window, GColorBlack); } if (persist_exists(KEY_TIME_COLOR_R)) { red = persist_read_int(KEY_TIME_COLOR_R); green = persist_read_int(KEY_TIME_COLOR_G); blue = persist_read_int(KEY_TIME_COLOR_B); GColor time_color = GColorFromRGB(red, green, blue); text_layer_set_text_color(s_time_layer, time_color); } else { text_layer_set_text_color(s_time_layer, GColorWhite); } if (persist_exists(KEY_SECONDARY_COLOR_R)) { red = persist_read_int(KEY_SECONDARY_COLOR_R); green = persist_read_int(KEY_SECONDARY_COLOR_G); blue = persist_read_int(KEY_SECONDARY_COLOR_B); secondary_color = GColorFromRGB(red, green, blue); text_layer_set_text_color(s_date_layer, secondary_color); text_layer_set_text_color(s_day_layer, secondary_color); text_layer_set_text_color(s_ampm_layer, secondary_color); } else { // Set secondary colors text_layer_set_text_color(s_date_layer, GColorVividCerulean); text_layer_set_text_color(s_day_layer, GColorVividCerulean); text_layer_set_text_color(s_ampm_layer, GColorVividCerulean); } #endif // Get stored BT var if (persist_exists(KEY_BLUETOOTH_ICON_ENABLED)) { int enabled = persist_read_int(KEY_BLUETOOTH_ICON_ENABLED); bluetoothIconEnabled = enabled != 0; } else { bluetoothIconEnabled = true; } // Create bluetooth icon layer and register it bluetooth_icon_layer = layer_create(GRect(129, 141, 144, 168)); layer_set_update_proc(bluetooth_icon_layer, bluetooth_icon_update_proc); // Improve the layout to be more like a watchface text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); text_layer_set_text_alignment(s_day_layer, GTextAlignmentLeft); // Add child layers to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_day_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_ampm_layer)); layer_add_child(window_get_root_layer(window), bluetooth_icon_layer); // Make sure the time is displayed from the start update_time(); // Show current connection state bt_handler(bluetooth_connection_service_peek()); // Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TIME_46)); s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DATE_20)); s_ampm_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_AMPM_10)); // Apply to TextLayer text_layer_set_font(s_time_layer, s_time_font); text_layer_set_font(s_date_layer, s_date_font); text_layer_set_font(s_day_layer, s_date_font); text_layer_set_font(s_ampm_layer, s_ampm_font); }
static void main_window_load(Window *window) { //Create background bitmap, then set to created BitmapLayer s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_DEDSEC_LOGO); s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); 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)); //Create BT bitmap, then set to created BitmapLayer s_bluetooth_bitmap = gbitmap_create_with_resource(RESOURCE_ID_SIGNAL); s_bluetooth_layer = bitmap_layer_create(GRect(0, 144, 20, 20)); bitmap_layer_set_bitmap(s_bluetooth_layer, s_bluetooth_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bluetooth_layer)); //Create Battery bitmap, then set to created BitmapLayer s_battery_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGING); s_battery_layer = bitmap_layer_create(GRect(122, 123, 22, 18)); bitmap_layer_set_bitmap(s_battery_layer, s_battery_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_battery_layer)); // Create time TextLayer s_hour_layer = text_layer_create(GRect(0, -5, 60, 84)); text_layer_set_background_color(s_hour_layer, GColorClear); text_layer_set_text_color(s_hour_layer, GColorWhite); text_layer_set_text(s_hour_layer, "00"); s_minute_layer = text_layer_create(GRect(0, 55, 60, 84)); text_layer_set_background_color(s_minute_layer, GColorClear); text_layer_set_text_color(s_minute_layer, GColorWhite); text_layer_set_text(s_minute_layer, "00"); //Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_WATCHDOGS_SUBSET_58)); //Apply to TextLayer text_layer_set_font(s_hour_layer, s_time_font); text_layer_set_text_alignment(s_hour_layer, GTextAlignmentCenter); text_layer_set_font(s_minute_layer, s_time_font); text_layer_set_text_alignment(s_minute_layer, GTextAlignmentCenter); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hour_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_minute_layer)); //Create date text layer s_date_layer = text_layer_create(GRect(0, 150, 144, 18)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_text(s_date_layer, "MON_01_01_2001"); text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); //Create connection background layer s_connection_bg_layer = text_layer_create(GRect(0, 123, 122, 18)); #ifdef PBL_COLOR text_layer_set_background_color(s_connection_bg_layer, GColorTiffanyBlue); #else text_layer_set_background_color(s_connection_bg_layer, GColorClear); #endif text_layer_set_text_color(s_connection_bg_layer, GColorWhite); text_layer_set_text(s_connection_bg_layer, CONNECTION_TEXT); text_layer_set_font(s_connection_bg_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_connection_bg_layer)); //Create connection text layer s_connection_layer = text_layer_create(GRect(0, 123, 122, 18)); text_layer_set_text(s_connection_layer, CONNECTION_TEXT); s_connection_bar_color = GColorWhite; layer_set_update_proc((Layer*) s_connection_layer, text_update_proc); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_connection_layer)); //Create hacking text layer s_hacking_layer = text_layer_create(GRect(0, 137, 144, 18)); text_layer_set_background_color(s_hacking_layer, GColorClear); text_layer_set_text_color(s_hacking_layer, GColorWhite); text_layer_set_text(s_hacking_layer, "_hacking is our weapon"); text_layer_set_text_alignment(s_hacking_layer, GTextAlignmentRight); text_layer_set_font(s_hacking_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hacking_layer)); // Make sure the time is displayed from the start update_time(); // Show current connection state bt_handler(bluetooth_connection_service_peek()); // Show current battery state battery_handler(battery_state_service_peek()); }
static void window_load(Window* window) { // Handle the settings. #ifdef PBL_COLOR // Set default colors. mLightColor = GColorCeleste; mMediumColor = GColorJaegerGreen; mDarkColor = GColorDarkGreen; mBackgroundColor = GColorBlack; // Try to get saved colors. // Colors are auto mapped to the nearest color out of 64 available. APP_LOG(APP_LOG_LEVEL_DEBUG, "KEY_COLOR_ 1"); if (persist_exists(KEY_COLOR_RED1) && persist_exists(KEY_COLOR_GREEN1) && persist_exists(KEY_COLOR_BLUE1)) { int red = persist_read_int(KEY_COLOR_RED1); int green = persist_read_int(KEY_COLOR_GREEN1); int blue = persist_read_int(KEY_COLOR_BLUE1); mDarkColor = GColorFromRGB(red, green, blue); } APP_LOG(APP_LOG_LEVEL_DEBUG, "KEY_COLOR_ 2"); if (persist_exists(KEY_COLOR_RED2) && persist_exists(KEY_COLOR_GREEN2) && persist_exists(KEY_COLOR_BLUE2)) { int red = persist_read_int(KEY_COLOR_RED2); int green = persist_read_int(KEY_COLOR_GREEN2); int blue = persist_read_int(KEY_COLOR_BLUE2); mLightColor = GColorFromRGB(red, green, blue); } #else /*APP_LOG(APP_LOG_LEVEL_DEBUG, "KEY_INVERT"); if (persist_exists(KEY_INVERT)) { mIsInverted = persist_read_bool(KEY_INVERT); APP_LOG(APP_LOG_LEVEL_DEBUG, "KEY_INVERT: %d", mIsInverted); } if (mIsInverted) { mBackgroundColor = GColorWhite; mTextColor = GColorBlack; } else*/ { mBackgroundColor = GColorBlack; mTextColor = GColorWhite; } #endif // PBL_COLOR mIs24HourStyle = clock_is_24h_style(); APP_LOG(APP_LOG_LEVEL_DEBUG, "mIs24HourStyle: %d", mIs24HourStyle); APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: set_background"); window_set_background_color(window, mBackgroundColor); APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: add layers"); sBgLayer = layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); layer_set_update_proc(sBgLayer, (LayerUpdateProc)render_bg); layer_add_child(window_get_root_layer(window), sBgLayer); sTimeLayer = layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); layer_set_update_proc(sTimeLayer, (LayerUpdateProc)render_time); layer_add_child(window_get_root_layer(window), sTimeLayer); APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: setup fonts"); mDayFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CONSOLAB_14)); mTimeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DSEG_BOLD_30)); mTimeFontSmall = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DSEG_BOLD_16)); mDateFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DSEG_NORMAL_14)); //mDateFontSmall = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DSEG_NORMAL_10)); mDayText = malloc(9+1); // WEDNESDAY mTimeText = malloc(5+1); // HH:MM mTopText = malloc(5+1); // P T T mDateText = malloc(5+1); // MM.DD APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: set time"); struct tm* t; time_t temp; temp = time(NULL); t = localtime(&temp); set_time_display(t); // Init the BT and battery indicators. APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: setup bt and battery"); bt_handler(bluetooth_connection_service_peek()); battery_handler(battery_state_service_peek()); }
static void main_window_load(Window *window) { //bg_color = GColorGreen; #define bg_color GColorBlack hour_layer = text_layer_create(GRect(-10,-15,94, 75)); min_layer = text_layer_create(GRect(66,60,85,85)); text_layer_set_text_color(hour_layer, COLOR_FALLBACK(GColorGreen, GColorWhite)); text_layer_set_text_color(min_layer, COLOR_FALLBACK(GColorGreen, GColorWhite)); text_layer_set_background_color(hour_layer, bg_color); text_layer_set_background_color(min_layer, bg_color); s_bg_layer = text_layer_create(GRect(0,0,144,168)); text_layer_set_background_color(s_bg_layer, COLOR_FALLBACK(GColorBlack, GColorBlack)); s_time_layer = text_layer_create(GRect(0,94,144,74));//0, 133, 115, 35)); am_layer = text_layer_create(GRect(125, 150, 19, 18)); battery_text_layer = text_layer_create(GRect(0, 150, 144, 20)); date_layer = text_layer_create(GRect(70 ,0, 74, 70)); s_battery_layer = text_layer_create(GRect(0, 160, 125, 20)); condition_layer = text_layer_create(GRect(0, 70, 70, 28)); //85 px tall temp_layer = text_layer_create(GRect(0, 90, 70, 28)); city_layer = text_layer_create(GRect(0, 112, 70, 28)); no_phone_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_NO_PHONE); no_phone_layer = bitmap_layer_create(GRect(0, 80, 60, 70)); bitmap_layer_set_bitmap(no_phone_layer, no_phone_bitmap); bitmap_layer_set_background_color(no_phone_layer, COLOR_FALLBACK(GColorCyan, GColorWhite)); layer_set_hidden(bitmap_layer_get_layer(no_phone_layer), true); bt_handler(bluetooth_connection_service_peek()); ///text_layer_set_text_color(s_battery_layer, COLOR_FALLBACK(GColorWhite, GColorWhite)); text_layer_set_background_color(s_time_layer, COLOR_FALLBACK(bg_color, GColorBlack)); text_layer_set_background_color(am_layer, COLOR_FALLBACK(GColorClear, GColorBlack)); text_layer_set_background_color(battery_text_layer, COLOR_FALLBACK(GColorClear, GColorClear)); //battery layer text_layer_set_background_color(s_battery_layer, COLOR_FALLBACK(GColorGreen, GColorWhite)); text_layer_set_background_color(condition_layer, COLOR_FALLBACK(GColorCyan, GColorWhite)); text_layer_set_background_color(temp_layer, COLOR_FALLBACK(GColorCyan, GColorWhite)); text_layer_set_background_color(city_layer, COLOR_FALLBACK(GColorCyan, GColorWhite)); text_layer_set_text_color(condition_layer, COLOR_FALLBACK(GColorBlack, GColorBlack)); text_layer_set_text_color(temp_layer, COLOR_FALLBACK(GColorBlack, GColorBlack)); text_layer_set_text_color(city_layer, COLOR_FALLBACK(GColorBlack, GColorBlack)); text_layer_set_text_color(battery_text_layer, COLOR_FALLBACK(GColorOrange, GColorWhite)); text_layer_set_background_color(date_layer, COLOR_FALLBACK(GColorOrange, GColorWhite)); text_layer_set_text_color(date_layer, COLOR_FALLBACK(GColorBlack, GColorBlack)); text_layer_set_text_color(am_layer, COLOR_FALLBACK(GColorRed, GColorWhite)); text_layer_set_text_color(s_time_layer, COLOR_FALLBACK(GColorGreen, GColorWhite)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); text_layer_set_text_alignment(battery_text_layer, GTextAlignmentCenter); text_layer_set_text_alignment(condition_layer, GTextAlignmentCenter); text_layer_set_text_alignment(temp_layer, GTextAlignmentCenter); text_layer_set_text_alignment(city_layer, GTextAlignmentCenter); text_layer_set_text(s_time_layer, " : "); s_custom_font_24 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CHAMPAGNE_72)); s_custom_font_18 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CHAMPAGNE_20));//DS_DIGI_18)); s_custom_font_12 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CHAMPAGNE_12)); text_layer_set_font(s_time_layer, s_custom_font_24); //fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK)); text_layer_set_font(date_layer, s_custom_font_18); text_layer_set_font(hour_layer, s_custom_font_24); text_layer_set_font(min_layer, s_custom_font_24); text_layer_set_font(condition_layer, s_custom_font_18); text_layer_set_font(temp_layer, s_custom_font_18); text_layer_set_font(city_layer, s_custom_font_12); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_bg_layer)); //text_layer_set_font(s_battery_layer, s_custom_font_18); //layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer)); //layer_add_child(window_get_root_layer(window), text_layer_get_layer(am_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(hour_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(min_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(condition_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(temp_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(city_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(battery_text_layer)); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(no_phone_layer)); Tuplet initial_values[] = { //TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1), TupletCString(WEATHER_TEMPERATURE_KEY, ""), TupletCString(WEATHER_CITY_KEY, ""), TupletCString(WEATHER_CONDITION_KEY, "Loading") }; app_sync_init(&s_sync, s_sync_buffer, sizeof(s_sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL ); request_weather(); }
//Обработка загрузки "окна" 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); }