From 5df3dbe6715e5c08a28b69780fa56a7f04afebbb Mon Sep 17 00:00:00 2001 From: adrian17 Date: Wed, 30 Jul 2014 14:13:32 +0200 Subject: [PATCH] Add the fullscreen mode to .ini config --- src/config.c | 18 ++++++++++++++++++ src/config.h | 3 +++ src/osinterface.c | 18 ++++++++++-------- src/osinterface.h | 1 - src/window_options.c | 4 ++-- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/config.c b/src/config.c index 0903f071b0..78a3d9d2cc 100644 --- a/src/config.c +++ b/src/config.c @@ -89,6 +89,7 @@ general_configuration_t gGeneral_config_default = { 1, // landscape_smoothing 0, // show_height_as_units 1, // save_plugin_data + 0, // fullscreen mode (default: windowed) }; sound_configuration_t gSound_config; @@ -373,6 +374,13 @@ void config_write_ini_general(FILE *fp) else { fprintf(fp, "save_plugin_data = false\n"); } + + if (gGeneral_config.fullscreen_mode == 0) + fprintf(fp, "fullscreen_mode = window\n"); + else if (gGeneral_config.fullscreen_mode == 1) + fprintf(fp, "fullscreen_mode = fullscreen\n"); + else + fprintf(fp, "fullscreen_mode = borderless_fullscreen\n"); } /** @@ -603,6 +611,16 @@ static void config_general(char *setting, char *value){ gGeneral_config.save_plugin_data = 0; } } + else if (strcmp(setting, "fullscreen_mode") == 0){ + if (strcmp(value, "window") == 0){ + gGeneral_config.fullscreen_mode = 0; + } + else if (strcmp(value, "fullscreen") == 0){ + gGeneral_config.fullscreen_mode = 1; + } + else + gGeneral_config.fullscreen_mode = 2; + } } /** diff --git a/src/config.h b/src/config.h index 0d3ffa8ad8..1bb1ea386f 100644 --- a/src/config.h +++ b/src/config.h @@ -127,6 +127,9 @@ typedef struct general_configuration { sint8 landscape_smoothing; sint8 show_height_as_units; sint8 save_plugin_data; + + //new + uint8 fullscreen_mode; } general_configuration_t; static const struct { char *key; int value; } _currencyLookupTable[] = { diff --git a/src/osinterface.c b/src/osinterface.c index 47b10de334..5efe2a2a75 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -26,6 +26,7 @@ #include #include "addresses.h" +#include "config.h" #include "gfx.h" #include "osinterface.h" #include "window.h" @@ -53,6 +54,8 @@ static void *_screenBuffer; static SDL_Cursor* _cursors[NO_CURSORS]; +static const int fullscreen_modes[] = { 0, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP }; + void osinterface_init() { osinterface_create_window(); @@ -170,9 +173,8 @@ static void osinterface_create_window() RCT2_GLOBAL(0x009E2D8C, sint32) = 0; - g_current_fullscreen_mode = 0; - - _window = SDL_CreateWindow("OpenRCT2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_RESIZABLE); + _window = SDL_CreateWindow("OpenRCT2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, + fullscreen_modes[gGeneral_config.fullscreen_mode]); if (!_window) { RCT2_ERROR("SDL_CreateWindow failed %s", SDL_GetError()); exit(-1); @@ -384,7 +386,7 @@ void osinterface_process_messages() gLastKeyPressed = e.key.keysym.sym; gKeysPressed[e.key.keysym.scancode] = 1; if (e.key.keysym.sym == SDLK_RETURN && e.key.keysym.mod & KMOD_ALT) - osinterface_set_fullscreen_mode(!g_current_fullscreen_mode); + osinterface_set_fullscreen_mode(!gGeneral_config.fullscreen_mode); break; default: break; @@ -417,10 +419,8 @@ void osinterface_free() SDL_Quit(); } -static const int fullscreen_modes[] = { 0, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP }; - void osinterface_set_fullscreen_mode(int mode){ - if (mode == g_current_fullscreen_mode) + if (mode == gGeneral_config.fullscreen_mode) return; if (SDL_SetWindowFullscreen(_window, fullscreen_modes[mode])){ @@ -430,7 +430,9 @@ void osinterface_set_fullscreen_mode(int mode){ //SDL automatically resizes the fullscreen window to the nearest allowed screen resolution //No need to call osinterface_resize() here, SDL_WINDOWEVENT_SIZE_CHANGED event will be triggered anyway - g_current_fullscreen_mode = mode; + gGeneral_config.fullscreen_mode = mode; + + config_save(); } /** diff --git a/src/osinterface.h b/src/osinterface.h index a660086c50..6d2cade7aa 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -77,7 +77,6 @@ void osinterface_draw(); void osinterface_free(); void osinterface_update_palette(char* colours, int start_index, int num_colours); -int g_current_fullscreen_mode; void osinterface_set_fullscreen_mode(int mode); void osinterface_set_cursor(char cursor); diff --git a/src/window_options.c b/src/window_options.c index 766f75a3f6..ca760d8980 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -397,7 +397,7 @@ static void window_options_mousedown(int widgetIndex, rct_window*w, rct_widget* gDropdownItemsArgs[0] = STR_CELSIUS; gDropdownItemsArgs[1] = STR_FAHRENHEIT; gDropdownItemsArgs[2] = STR_METRIC; - gDropdownItemsChecked = 1 << g_current_fullscreen_mode; + gDropdownItemsChecked = 1 << gGeneral_config.fullscreen_mode; break; case WIDX_TEMPERATURE_DROPDOWN: window_options_draw_dropdown_box(w, widget, 2); @@ -516,7 +516,7 @@ static void window_options_dropdown() RCT2_CALLPROC_EBPSAFE(0x006BB37D); break; case WIDX_FULLSCREEN_DROPDOWN: - if (dropdownIndex != g_current_fullscreen_mode){ + if (dropdownIndex != gGeneral_config.fullscreen_mode){ osinterface_set_fullscreen_mode(dropdownIndex); } break;