Skip to content

Commit

Permalink
Add option to resize window to fit content. Fix #58
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 7, 2024
1 parent 9b0fa35 commit f281aaa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion platforms/desktop-shared/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ void application_trigger_fullscreen(bool fullscreen)
SDL_SetWindowFullscreen(sdl_window, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
}

void application_trigger_fit_to_content(int width, int height)
{
SDL_SetWindowSize(sdl_window, width, height);
}

static int sdl_init(void)
{
#ifdef _WIN32
Expand All @@ -151,7 +156,7 @@ static int sdl_init(void)
SDL_GL_MakeCurrent(sdl_window, gl_context);
SDL_GL_SetSwapInterval(0);

SDL_SetWindowMinimumSize(sdl_window, 770, 600);
SDL_SetWindowMinimumSize(sdl_window, 500, 300);

application_gamepad_mappings = SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile("gamecontrollerdb.txt", "rb"), 1);

Expand Down
1 change: 1 addition & 0 deletions platforms/desktop-shared/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ EXTERN void application_destroy(void);
EXTERN void application_mainloop(void);
EXTERN void application_trigger_quit(void);
EXTERN void application_trigger_fullscreen(bool fullscreen);
EXTERN void application_trigger_fit_to_content(int width, int height);

#undef APPLICATION_IMPORT
#undef EXTERN
Expand Down
18 changes: 14 additions & 4 deletions platforms/desktop-shared/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static char sms_bootrom_path[4096] = "";
static char gg_bootrom_path[4096] = "";
static char savefiles_path[4096] = "";
static char savestates_path[4096] = "";
static int main_window_width = 0;
static int main_window_height = 0;

static void main_menu(void);
static void main_window(void);
Expand Down Expand Up @@ -618,6 +620,14 @@ static void main_menu(void)
gui_event_get_shortcut_string(shortcut, sizeof(shortcut), gui_ShortcutShowMainMenu);
ImGui::MenuItem("Show Menu", shortcut, &config_emulator.show_menu);

if (ImGui::MenuItem("Resize Window to Content"))
{
if (!config_debug.debug && (config_video.ratio != 3))
{
application_trigger_fit_to_content(main_window_width, main_window_height + main_menu_height);
}
}

ImGui::Separator();

if (ImGui::BeginMenu("Scale"))
Expand All @@ -630,8 +640,8 @@ static void main_menu(void)

if (ImGui::BeginMenu("Aspect Ratio"))
{
ImGui::PushItemWidth(140.0f);
ImGui::Combo("##ratio", &config_video.ratio, "Square Pixels\0Standard (4:3)\0Wide (16:9)\0Fit Window\0\0");
ImGui::PushItemWidth(160.0f);
ImGui::Combo("##ratio", &config_video.ratio, "Square Pixels\0Standard (4:3)\0Wide (16:9)\0Fit Content to Window\0\0");
ImGui::PopItemWidth();
ImGui::EndMenu();
}
Expand Down Expand Up @@ -1034,8 +1044,8 @@ static void main_window(void)
factor = (factor_w < factor_h) ? factor_w : factor_h;
}

int main_window_width = w_corrected * factor;
int main_window_height = h_corrected * factor;
main_window_width = w_corrected * factor;
main_window_height = h_corrected * factor;

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

0 comments on commit f281aaa

Please sign in to comment.