diff --git a/src/c/bahn_interface.c b/src/c/bahn_interface.c index 8478b2e..3a6e6f2 100644 --- a/src/c/bahn_interface.c +++ b/src/c/bahn_interface.c @@ -131,7 +131,6 @@ bool BahnInterface_handle_app_message(DictionaryIterator *iter, void *context) { // This value was stored as JS Number, which is stored here as int32_t int32_t msg_request_id = tuple->value->int32; if (msg_request_id != request_id) { - int m = msg_request_id; return true; } diff --git a/src/c/connection_details_window.c b/src/c/connection_details_window.c index 7a75c17..0de08f7 100644 --- a/src/c/connection_details_window.c +++ b/src/c/connection_details_window.c @@ -1,4 +1,5 @@ #include +#include "resources.h" #include "scroll_text_layer.h" #include "bahn_interface.h" #include "connection_details_window.h" @@ -6,6 +7,7 @@ static Window* s_window; static ScrollTextLayer* s_scroll_layer; +static StatusBarLayer *s_status_bar; #define NUM_FONTS 6 @@ -36,7 +38,19 @@ static void click_config_provider(void *context) { static void window_load(Window* window) { if (!s_scroll_layer) { - s_scroll_layer = scroll_text_layer_create_fullscreen(window); + s_status_bar = addStatusBar(window); + GRect scroll_layer_bounds = computeEffectiveWindowBounds(window, s_status_bar); +#if defined(PBL_ROUND) + int original_height = scroll_layer_bounds.size.h; + int original_width = scroll_layer_bounds.size.w; + + scroll_layer_bounds.size.w -= 20; + scroll_layer_bounds.size.h = original_height * 2 / 3; + + scroll_layer_bounds.origin.x = (original_width - scroll_layer_bounds.size.w) / 2; + scroll_layer_bounds.origin.y = (original_height - scroll_layer_bounds.size.h) / 2; +#endif + s_scroll_layer = scroll_text_layer_create(scroll_layer_bounds); } scroll_text_layer_set_system_font(s_scroll_layer, fonts[font]); scroll_text_layer_set_text(s_scroll_layer, BahnInterface_get_current_connection_details()); @@ -49,6 +63,8 @@ static void window_load(Window* window) { static void window_unload(Window *window) { scroll_text_layer_destroy(s_scroll_layer); s_scroll_layer = NULL; + status_bar_layer_destroy(s_status_bar); + s_status_bar = NULL; } static void show_window() { diff --git a/src/c/connection_results_menu.c b/src/c/connection_results_menu.c index b9dd321..6c4b758 100644 --- a/src/c/connection_results_menu.c +++ b/src/c/connection_results_menu.c @@ -8,6 +8,7 @@ static MenuLayer* s_menu_layer; static Window* s_window; static char s_header[2 * CONNECTION_SUBTITLE_LENGTH + 10]; +static StatusBarLayer *s_status_bar; static uint16_t menu_get_num_sections_callback(MenuLayer *menu_layer, void *data) { return 1; @@ -101,8 +102,9 @@ static void build_connection_results_window() { s_window = window_create(); Layer *window_layer = window_get_root_layer(s_window); - GRect bounds = layer_get_frame(window_layer); - + s_status_bar = addStatusBar(s_window); + GRect bounds = computeEffectiveWindowBounds(s_window, s_status_bar); + s_menu_layer = menu_layer_create(bounds); menu_layer_set_click_config_onto_window(s_menu_layer, s_window); menu_layer_set_callbacks(s_menu_layer, NULL, (MenuLayerCallbacks){ @@ -152,7 +154,9 @@ void ConnectionResultsMenu_destroy() { } menu_layer_destroy(s_menu_layer); + status_bar_layer_destroy(s_status_bar); window_destroy(s_window); + s_status_bar = NULL; s_menu_layer = NULL; s_window = NULL; } diff --git a/src/c/load_failed_window.c b/src/c/load_failed_window.c index 957f979..191f372 100644 --- a/src/c/load_failed_window.c +++ b/src/c/load_failed_window.c @@ -8,7 +8,8 @@ static bool initialized = false; static void window_load(Window *window) { if (!initialized) { - MessageWindow_build(window, LOAD_FAILED_MESSAGE, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); + GRect bounds = computeEffectiveWindowBounds(window, NULL); + MessageWindow_build(window, bounds, LOAD_FAILED_MESSAGE, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); initialized = true; } } diff --git a/src/c/loading_window.c b/src/c/loading_window.c index 3f12c2e..16fdc74 100644 --- a/src/c/loading_window.c +++ b/src/c/loading_window.c @@ -20,7 +20,8 @@ static void config_provider(void *context) { static void window_load(Window *window) { if (!initialized) { - MessageWindow_build(s_main_window, LOADING_MESSAGE, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); + GRect bounds = computeEffectiveWindowBounds(window, NULL); + MessageWindow_build(s_main_window, bounds, LOADING_MESSAGE, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); window_set_click_config_provider(s_main_window, config_provider); initialized = true; } diff --git a/src/c/main_menu.c b/src/c/main_menu.c index 2b45aea..9d35bad 100644 --- a/src/c/main_menu.c +++ b/src/c/main_menu.c @@ -7,6 +7,7 @@ #include "main_menu.h" static MenuLayer *s_menu_layer; +static StatusBarLayer *s_status_bar; static bool is_connections_section(uint16_t section_index) { if (section_index > 0) { @@ -98,10 +99,11 @@ static void menu_select_callback(MenuLayer *menu_layer, MenuIndex *cell_index, v } void MainMenu_create(Window *window) { - MainMenu_destroy(); + MainMenu_destroy(); Layer *window_layer = window_get_root_layer(window); - GRect bounds = layer_get_frame(window_layer); + s_status_bar = addStatusBar(window); + GRect bounds = computeEffectiveWindowBounds(window, s_status_bar); s_menu_layer = menu_layer_create(bounds); @@ -126,6 +128,8 @@ void MainMenu_destroy() { } menu_layer_destroy(s_menu_layer); s_menu_layer = NULL; + status_bar_layer_destroy(s_status_bar); + s_status_bar = NULL; ToStationsMenu_destroy(); ConnectionResultsMenu_destroy(); ConnectionDetailsWindow_destroy(); diff --git a/src/c/message_window.c b/src/c/message_window.c index 82c7ed8..01bf129 100644 --- a/src/c/message_window.c +++ b/src/c/message_window.c @@ -11,28 +11,41 @@ static void icon_update_proc(Layer *layer, GContext *ctx) { graphics_draw_bitmap_in_rect(ctx, APP_ICON, (GRect){.origin = bounds.origin, .size = bitmap_bounds.size}); } -void MessageWindow_build(Window *window, char* message, GFont message_font) { +void MessageWindow_build(Window *window, GRect bounds, char* message, GFont message_font) { TextLayer *s_label_layer; Layer *s_icon_layer; TextLayer *s_message_layer; Layer *window_layer = window_get_root_layer(window); - GRect bounds = layer_get_bounds(window_layer); +#if defined(PBL_ROUND) + int original_height = bounds.size.h; + int original_width = bounds.size.w; + + bounds.size.w -= 20; + bounds.size.h = original_height * 2 / 3; + + bounds.origin.x = (original_width - bounds.size.w) / 2; + bounds.origin.y = (original_height - bounds.size.h) / 2; +#endif + bounds.origin.x += DIALOG_MESSAGE_WINDOW_MARGIN; + bounds.origin.y += DIALOG_MESSAGE_WINDOW_MARGIN; + bounds.size.w -= DIALOG_MESSAGE_WINDOW_MARGIN * 2; + bounds.size.h -= DIALOG_MESSAGE_WINDOW_MARGIN * 2; GRect bitmap_bounds = gbitmap_get_bounds(APP_ICON); - s_icon_layer = layer_create(GRect(DIALOG_MESSAGE_WINDOW_MARGIN, DIALOG_MESSAGE_WINDOW_MARGIN, bitmap_bounds.size.w, bitmap_bounds.size.h)); + s_icon_layer = layer_create(GRect(bounds.origin.x, bounds.origin.y, bitmap_bounds.size.w, bitmap_bounds.size.h)); layer_set_update_proc(s_icon_layer, icon_update_proc); layer_add_child(window_layer, s_icon_layer); - s_label_layer = text_layer_create(GRect(DIALOG_MESSAGE_WINDOW_MARGIN + bitmap_bounds.size.w + 5, DIALOG_MESSAGE_WINDOW_MARGIN / 2, bounds.size.w - bitmap_bounds.size.w - 5 - (2 * DIALOG_MESSAGE_WINDOW_MARGIN), bounds.size.h)); + s_label_layer = text_layer_create(GRect(bounds.origin.x + bitmap_bounds.size.w + 5, bounds.origin.y, bounds.size.w - bitmap_bounds.size.w - 5, bounds.size.h)); text_layer_set_text(s_label_layer, APP_NAME); text_layer_set_background_color(s_label_layer, GColorClear); text_layer_set_text_alignment(s_label_layer, GTextAlignmentLeft); 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_message_layer = text_layer_create(GRect(DIALOG_MESSAGE_WINDOW_MARGIN, DIALOG_MESSAGE_WINDOW_MARGIN + bitmap_bounds.size.h, bounds.size.w - (2 * DIALOG_MESSAGE_WINDOW_MARGIN), bounds.size.h)); + s_message_layer = text_layer_create(GRect(bounds.origin.x, bounds.origin.y + bitmap_bounds.size.h, bounds.size.w, bounds.size.h)); text_layer_set_text(s_message_layer, message); text_layer_set_background_color(s_message_layer, GColorClear); text_layer_set_text_alignment(s_message_layer, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft)); diff --git a/src/c/message_window.h b/src/c/message_window.h index c424ff6..c947579 100644 --- a/src/c/message_window.h +++ b/src/c/message_window.h @@ -1,3 +1,3 @@ #pragma once -void MessageWindow_build(Window *window, char* message, GFont message_font); \ No newline at end of file +void MessageWindow_build(Window *window, GRect bounds, char* message, GFont message_font); \ No newline at end of file diff --git a/src/c/mybahn_settings.c b/src/c/mybahn_settings.c index 0178848..28cfc83 100644 --- a/src/c/mybahn_settings.c +++ b/src/c/mybahn_settings.c @@ -2,7 +2,7 @@ #include "resources.h" #include "mybahn_settings.h" -//#define CREATE_DUMMY_SETTINGS +// #define CREATE_DUMMY_SETTINGS static MyBahnSettings settings; static void prv_validate_station(StationConfig* station) { @@ -76,42 +76,6 @@ static void prv_create_default_settings() { strcpy(settings.stations[i].title, "Wpt. Hbf"); settings.stations[i].is_enabled = true; settings.stations[i].use_default_products = true; - - i++; - strcpy(settings.stations[i].ibnr, "8006719"); - strcpy(settings.stations[i].title, "Wpt. Oberbarmen"); - settings.stations[i].is_enabled = true; - settings.stations[i].use_default_products = true; - - i++; - strcpy(settings.stations[i].ibnr, "8006620"); - strcpy(settings.stations[i].title, "Wpt. Unterbarmen"); - settings.stations[i].is_enabled = true; - settings.stations[i].use_default_products = true; - - i++; - strcpy(settings.stations[i].ibnr, "8000152"); - strcpy(settings.stations[i].title, "Hannover Hbf"); - settings.stations[i].is_enabled = true; - settings.stations[i].use_default_products = true; - - i++; - strcpy(settings.stations[i].ibnr, "8000142"); - strcpy(settings.stations[i].title, "Hagen Hbf"); - settings.stations[i].is_enabled = true; - settings.stations[i].use_default_products = true; - - i++; - strcpy(settings.stations[i].ibnr, "8006226"); - strcpy(settings.stations[i].title, "Wattenscheid"); - settings.stations[i].is_enabled = true; - settings.stations[i].use_default_products = true; - - i++; - strcpy(settings.stations[i].ibnr, "8000085"); - strcpy(settings.stations[i].title, "D'dorf Hbf"); - settings.stations[i].is_enabled = true; - settings.stations[i].use_default_products = true; i = -1; i++; @@ -132,25 +96,6 @@ static void prv_create_default_settings() { settings.connections[i].allowed_products.ubahn = true; settings.connections[i].allowed_products.tram = true; settings.connections[i].allowed_products.ast = true; - - i++; - strcpy(settings.connections[i].start_ibnr, "8000266"); - strcpy(settings.connections[i].dest_ibnr, "8003368"); - strcpy(settings.connections[i].title, "Wpt. Hbf"); - strcpy(settings.connections[i].subtitle, "->Köln Messe/Deutz"); - settings.connections[i].is_enabled = true; - settings.connections[i].use_default_products = false; - settings.connections[i].allowed_products.allow_all = false; - settings.connections[i].allowed_products.ice = false; - settings.connections[i].allowed_products.ic = false; - settings.connections[i].allowed_products.ir = false; - settings.connections[i].allowed_products.zug = true; - settings.connections[i].allowed_products.sbahn = true; - settings.connections[i].allowed_products.bus = true; - settings.connections[i].allowed_products.schiff = true; - settings.connections[i].allowed_products.ubahn = true; - settings.connections[i].allowed_products.tram = true; - settings.connections[i].allowed_products.ast = true; #endif } diff --git a/src/c/resources.c b/src/c/resources.c index 6441e8a..8d2eee2 100644 --- a/src/c/resources.c +++ b/src/c/resources.c @@ -9,3 +9,23 @@ GBitmap* getAppIcon() { } return s_app_icon_bitmap; } + +GRect computeEffectiveWindowBounds(Window* window, StatusBarLayer* status_bar_layer) { + Layer *window_layer = window_get_root_layer(window); + GRect bounds = layer_get_unobstructed_bounds(window_layer); + if (status_bar_layer != NULL) { + GRect status_bar_frame = layer_get_frame(status_bar_layer_get_layer(status_bar_layer)); + bounds.size.h -= status_bar_frame.size.h; + bounds.origin.y += status_bar_frame.size.h; + } + return bounds; +} + +StatusBarLayer* addStatusBar(Window* window) { + return NULL; + StatusBarLayer* status_bar = status_bar_layer_create(); + + Layer *window_layer = window_get_root_layer(window); + layer_add_child(window_layer, status_bar_layer_get_layer(status_bar)); + return status_bar; +} diff --git a/src/c/resources.h b/src/c/resources.h index 0577316..cced677 100644 --- a/src/c/resources.h +++ b/src/c/resources.h @@ -1,6 +1,6 @@ #pragma once #include -#define APP_NAME "myBahn" +#define APP_NAME "myBahn 1.1" #define NOT_CONFIGURED "Nicht konfiguriert!" #define PLEASE_CONFIGURE "Bitte konfigurieren!" #define CONNECTIONS "Verbindungen" @@ -13,5 +13,8 @@ #define APP_ICON getAppIcon() GBitmap* getAppIcon(); +StatusBarLayer* addStatusBar(Window* window); +GRect computeEffectiveWindowBounds(Window* window, StatusBarLayer* status_bar_layer); + diff --git a/src/c/scroll_text_layer.c b/src/c/scroll_text_layer.c index f221c73..41b49bc 100644 --- a/src/c/scroll_text_layer.c +++ b/src/c/scroll_text_layer.c @@ -71,6 +71,10 @@ void scroll_text_layer_set_font(ScrollTextLayer* layer, GFont font) { static void scroll_text_layer_update(ScrollTextLayer* layer) { +//#if defined(PBL_ROUND) +// text_layer_set_text_alignment(layer->text_layer, GTextAlignmentCenter); +// text_layer_enable_screen_text_flow_and_paging(layer->text_layer, 1); +//#endif GSize max_size = text_layer_get_content_size(layer->text_layer); text_layer_set_size(layer->text_layer, max_size); GRect bounds = layer_get_bounds(scroll_layer_get_layer(layer->scroll_layer)); diff --git a/src/c/scroll_text_layer.h b/src/c/scroll_text_layer.h index 88c28f0..deed45a 100644 --- a/src/c/scroll_text_layer.h +++ b/src/c/scroll_text_layer.h @@ -17,7 +17,7 @@ void scroll_text_layer_set_text(ScrollTextLayer* layer, char* text); void scroll_text_layer_set_font(ScrollTextLayer*, GFont font); -#define scroll_text_layer_create_fullscreen(window) scroll_text_layer_create(layer_get_bounds(window_get_root_layer(window))); +#define scroll_text_layer_create_fullscreen(window) scroll_text_layer_create(layer_get_unobstructed_bounds(window_get_root_layer(window))); #define scroll_text_layer_set_text_color(layer, color) text_layer_set_text_color(scroll_text_layer_get_text_layer(layer), color) #define scroll_text_layer_set_background_color(layer, color) text_layer_set_background_color(scroll_text_layer_get_text_layer(layer), color) #define scroll_text_layer_set_text_alignment(layer, alignment) text_layer_set_text_alignment(scroll_text_layer_get_text_layer(layer), alignment) diff --git a/src/c/to_stations_menu.c b/src/c/to_stations_menu.c index 509dbbe..6939ce0 100644 --- a/src/c/to_stations_menu.c +++ b/src/c/to_stations_menu.c @@ -6,6 +6,7 @@ static MenuLayer* s_menu_layer; static Window* s_window; +static StatusBarLayer * s_status_bar; static char s_header[STATION_TITLE_LENGTH + 10]; static int from_station_index; @@ -61,7 +62,8 @@ void ToStationsMenu_display(int _from_station_index) { s_window = window_create(); Layer *window_layer = window_get_root_layer(s_window); - GRect bounds = layer_get_frame(window_layer); + s_status_bar = addStatusBar(s_window); + GRect bounds = computeEffectiveWindowBounds(s_window, s_status_bar); s_menu_layer = menu_layer_create(bounds); menu_layer_set_click_config_onto_window(s_menu_layer, s_window); @@ -84,7 +86,9 @@ void ToStationsMenu_destroy() { return; } menu_layer_destroy(s_menu_layer); + status_bar_layer_destroy(s_status_bar); window_destroy(s_window); + s_status_bar = NULL; s_menu_layer = NULL; s_window = NULL; }