Skip to content

Commit

Permalink
[desktop] Remember window size. Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Dec 8, 2023
1 parent a4f0511 commit 9fceba4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 13 additions & 3 deletions platforms/desktop-shared/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static void sdl_shortcuts_gui(const SDL_Event* event);
static void run_emulator(void);
static void render(void);
static void frame_throttle(void);
static void save_window_size(void);

int application_init(const char* arg)
{
Expand All @@ -53,11 +54,10 @@ int application_init(const char* arg)
Log ("Loading with argv: %s");
}

int ret = sdl_init();

config_init();
config_read();

int ret = sdl_init();
emu_init();

strcpy(emu_savefiles_path, config_emulator.savefiles_path.c_str());
Expand Down Expand Up @@ -86,6 +86,7 @@ int application_init(const char* arg)

void application_destroy(void)
{
save_window_size();
config_write();
config_destroy();
renderer_destroy();
Expand Down Expand Up @@ -136,7 +137,8 @@ static int sdl_init(void)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
sdl_window = SDL_CreateWindow(GEARCOLECO_TITLE " " GEARCOLECO_VERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 770, 698, window_flags);

sdl_window = SDL_CreateWindow(GEARCOLECO_TITLE " " GEARCOLECO_VERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, config_emulator.window_width, config_emulator.window_height, window_flags);
gl_context = SDL_GL_CreateContext(sdl_window);
SDL_GL_MakeCurrent(sdl_window, gl_context);
SDL_GL_SetSwapInterval(0);
Expand Down Expand Up @@ -656,3 +658,11 @@ static void frame_throttle(void)
SDL_Delay((Uint32)(min - elapsed));
}
}

static void save_window_size(void)
{
int width, height;
SDL_GetWindowSize(sdl_window, &width, &height);
config_emulator.window_width = width;
config_emulator.window_height = height;
}
4 changes: 4 additions & 0 deletions platforms/desktop-shared/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ void config_read(void)
config_emulator.savestates_dir_option = read_int("Emulator", "SaveStatesDirOption", 0);
config_emulator.savestates_path = read_string("Emulator", "SaveStatesPath");
config_emulator.last_open_path = read_string("Emulator", "LastOpenPath");
config_emulator.window_width = read_int("Emulator", "WindowWidth", 770);
config_emulator.window_height = read_int("Emulator", "WindowHeight", 600);

if (config_emulator.savefiles_path.empty())
{
Expand Down Expand Up @@ -318,6 +320,8 @@ void config_write(void)
write_int("Emulator", "SaveStatesDirOption", config_emulator.savestates_dir_option);
write_string("Emulator", "SaveStatesPath", config_emulator.savestates_path);
write_string("Emulator", "LastOpenPath", config_emulator.last_open_path);
write_int("Emulator", "WindowWidth", config_emulator.window_width);
write_int("Emulator", "WindowHeight", config_emulator.window_height);

for (int i = 0; i < config_max_recent_roms; i++)
{
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 @@ -52,6 +52,8 @@ struct config_Emulator
int savestates_dir_option = 0;
std::string savestates_path;
std::string last_open_path;
int window_width = 770;
int window_height = 600;
};

struct config_Video
Expand Down

0 comments on commit 9fceba4

Please sign in to comment.