Skip to content

Commit

Permalink
[desktop] Persist 'Full Screen' and 'Hide Menu' options. Fixes #82
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Dec 8, 2023
1 parent ed62779 commit 54e3805
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
9 changes: 5 additions & 4 deletions platforms/desktop-shared/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ int application_init(const char* arg)

int ret = sdl_init();

application_fullscreen = false;

config_init();
config_read();

Expand All @@ -75,6 +73,9 @@ int application_init(const char* arg)

SDL_GL_SetSwapInterval(config_video.sync ? 1 : 0);

if (config_emulator.fullscreen)
application_trigger_fullscreen(true);

if (IsValidPointer(arg) && (strlen(arg) > 0))
{
gui_load_rom(arg);
Expand Down Expand Up @@ -393,8 +394,8 @@ static void sdl_events_emu(const SDL_Event* event)

if (key == SDL_SCANCODE_F11)
{
application_fullscreen = !application_fullscreen;
application_trigger_fullscreen(application_fullscreen);
config_emulator.fullscreen = !config_emulator.fullscreen;
application_trigger_fullscreen(config_emulator.fullscreen);
break;
}

Expand Down
1 change: 0 additions & 1 deletion platforms/desktop-shared/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ EXTERN int application_gamepad_mappings;
EXTERN float application_display_scale;
EXTERN SDL_version application_sdl_build_version;
EXTERN SDL_version application_sdl_link_version;
EXTERN bool application_fullscreen;

EXTERN int application_init(const char* arg);
EXTERN void application_destroy(void);
Expand Down
4 changes: 4 additions & 0 deletions platforms/desktop-shared/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ void config_read(void)
config_shortcuts.shortcuts[i] = read_shortcut_key("Shortcuts", name, config_shortcuts.shortcuts[i]);
}

config_emulator.fullscreen = read_bool("Emulator", "FullScreen", false);
config_emulator.show_menu = read_bool("Emulator", "ShowMenu", true);
config_emulator.ffwd_speed = read_int("Emulator", "FFWD", 1);
config_emulator.save_slot = read_int("Emulator", "SaveSlot", 0);
config_emulator.start_paused = read_bool("Emulator", "StartPaused", false);
Expand Down Expand Up @@ -274,6 +276,8 @@ void config_write(void)
write_bool("Debug", "Video", config_debug.show_video);
write_int("Debug", "FontSize", config_debug.font_size);

write_bool("Emulator", "FullScreen", config_emulator.fullscreen);
write_bool("Emulator", "ShowMenu", config_emulator.show_menu);
write_int("Emulator", "FFWD", config_emulator.ffwd_speed);
write_int("Emulator", "SaveSlot", config_emulator.save_slot);
write_bool("Emulator", "StartPaused", config_emulator.start_paused);
Expand Down
2 changes: 2 additions & 0 deletions platforms/desktop-shared/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static const int config_max_recent_roms = 10;

struct config_Emulator
{
bool fullscreen = false;
bool show_menu = true;
bool paused = false;
int save_slot = 0;
bool start_paused = false;
Expand Down
15 changes: 7 additions & 8 deletions platforms/desktop-shared/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static ImVec4 custom_palette[4];
static std::list<std::string> cheat_list;
static bool shortcut_open_rom = false;
static ImFont* default_font[4];
static bool show_main_menu = true;
static char sms_bootrom_path[4096] = "";
static char gg_bootrom_path[4096] = "";
static char savefiles_path[4096] = "";
Expand Down Expand Up @@ -185,7 +184,7 @@ void gui_shortcut(gui_ShortCutEvent event)
gui_debug_go_back();
break;
case gui_ShortcutShowMainMenu:
show_main_menu = !show_main_menu;
config_emulator.show_menu = !config_emulator.show_menu;
break;
default:
break;
Expand Down Expand Up @@ -261,7 +260,7 @@ static void main_menu(void)
constexpr int MAX_SHORTCUT_NAME = 32;
char shortcut[MAX_SHORTCUT_NAME];

if (show_main_menu && ImGui::BeginMainMenuBar())
if (config_emulator.show_menu && ImGui::BeginMainMenuBar())
{
if (ImGui::BeginMenu(GEARSYSTEM_TITLE))
{
Expand Down Expand Up @@ -605,13 +604,13 @@ static void main_menu(void)
{
gui_in_use = true;

if (ImGui::MenuItem("Full Screen", "F11", &application_fullscreen))
if (ImGui::MenuItem("Full Screen", "F11", &config_emulator.fullscreen))
{
application_trigger_fullscreen(application_fullscreen);
application_trigger_fullscreen(config_emulator.fullscreen);
}

gui_event_get_shortcut_string(shortcut, sizeof(shortcut), gui_ShortcutShowMainMenu);
ImGui::MenuItem("Show Menu", shortcut, &show_main_menu);
ImGui::MenuItem("Show Menu", shortcut, &config_emulator.show_menu);

ImGui::Separator();

Expand Down Expand Up @@ -986,7 +985,7 @@ static void main_window(void)
emu_get_runtime(runtime);

int w = (int)ImGui::GetIO().DisplaySize.x;
int h = (int)ImGui::GetIO().DisplaySize.y - (show_main_menu ? main_menu_height : 0);
int h = (int)ImGui::GetIO().DisplaySize.y - (config_emulator.show_menu ? main_menu_height : 0);

int selected_ratio = config_debug.debug ? 0 : config_video.ratio;
float ratio = (float)runtime.screen_width / (float)runtime.screen_height;
Expand Down Expand Up @@ -1033,7 +1032,7 @@ static void main_window(void)
int main_window_height = h_corrected * factor;

int window_x = (w - (w_corrected * factor)) / 2;
int window_y = ((h - (h_corrected * factor)) / 2) + (show_main_menu ? main_menu_height : 0);
int window_y = ((h - (h_corrected * factor)) / 2) + (config_emulator.show_menu ? main_menu_height : 0);

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
Expand Down

0 comments on commit 54e3805

Please sign in to comment.