From 022183969954bc8c44db1bfda69acc92ecb4db86 Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Sat, 16 Dec 2023 09:14:38 -0500 Subject: [PATCH] port: add maximize window option to extended menu --- port/fast3d/gfx_sdl2.cpp | 24 ++++++++++++++++++++---- port/fast3d/gfx_window_manager_api.h | 1 + port/src/optionsmenu.c | 21 +++++++++++++++++++++ port/src/video.c | 13 +++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/port/fast3d/gfx_sdl2.cpp b/port/fast3d/gfx_sdl2.cpp index 778232eb8..8e9dcfaf7 100644 --- a/port/fast3d/gfx_sdl2.cpp +++ b/port/fast3d/gfx_sdl2.cpp @@ -36,6 +36,7 @@ static bool vsync_enabled = true; static int window_width = DESIRED_SCREEN_WIDTH; static int window_height = DESIRED_SCREEN_HEIGHT; static bool fullscreen_state; +static bool maximized_state; static bool is_running = true; static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen); @@ -76,6 +77,18 @@ static void set_fullscreen(bool on, bool call_callback) { } } +static void set_maximize_window(bool on) { + if (maximized_state == on) { + return; + } + maximized_state = on; + if (on) { + SDL_MaximizeWindow(wnd); + } else { + SDL_RestoreWindow (wnd); + } +} + static void gfx_sdl_get_active_window_refresh_rate(uint32_t* refresh_rate) { int display_in_use = SDL_GetWindowDisplayIndex(wnd); @@ -110,10 +123,7 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s posY = 100; } - Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL; - if (start_maximized) { - flags |= SDL_WINDOW_MAXIMIZED; - } + const Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL; wnd = SDL_CreateWindow(title, posX, posY, window_width, window_height, flags); if (!wnd) { @@ -185,6 +195,7 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s } #endif + set_maximize_window(start_maximized); set_fullscreen(start_in_fullscreen, false); } @@ -200,6 +211,10 @@ static void gfx_sdl_set_fullscreen(bool enable) { set_fullscreen(enable, true); } +static void gfx_sdl_set_maximize_window(bool enable) { + set_maximize_window(enable); +} + static void gfx_sdl_set_cursor_visibility(bool visible) { if (visible) { SDL_ShowCursor(SDL_ENABLE); @@ -320,6 +335,7 @@ struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_close, gfx_sdl_set_fullscreen_changed_callback, gfx_sdl_set_fullscreen, + gfx_sdl_set_maximize_window, gfx_sdl_get_active_window_refresh_rate, gfx_sdl_set_cursor_visibility, gfx_sdl_get_dimensions, diff --git a/port/fast3d/gfx_window_manager_api.h b/port/fast3d/gfx_window_manager_api.h index cc8893ace..44eda4160 100644 --- a/port/fast3d/gfx_window_manager_api.h +++ b/port/fast3d/gfx_window_manager_api.h @@ -10,6 +10,7 @@ struct GfxWindowManagerAPI { void (*close)(void); void (*set_fullscreen_changed_callback)(void (*on_fullscreen_changed)(bool is_now_fullscreen)); void (*set_fullscreen)(bool enable); + void (*set_maximize)(bool enable); void (*get_active_window_refresh_rate)(uint32_t* refresh_rate); void (*set_cursor_visibility)(bool visible); void (*get_dimensions)(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY); diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 0c6b2a9d3..3a22069b9 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -652,6 +652,19 @@ static MenuItemHandlerResult menuhandlerFullScreen(s32 operation, struct menuite return 0; } +static MenuItemHandlerResult menuhandlerMaximizeWindow(s32 operation, struct menuitem *item, union handlerdata *data) +{ + switch (operation) { + case MENUOP_GET: + return videoGetMaximizeWindow(); + case MENUOP_SET: + videoSetMaximizeWindow(data->checkbox.value); + break; + } + + return 0; +} + static MenuItemHandlerResult menuhandlerTexFilter(s32 operation, struct menuitem *item, union handlerdata *data) { switch (operation) { @@ -748,6 +761,14 @@ struct menuitem g_ExtendedVideoMenuItems[] = { 0, menuhandlerFullScreen, }, + { + MENUITEMTYPE_CHECKBOX, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Maximize Window", + 0, + menuhandlerMaximizeWindow, + }, { MENUITEMTYPE_CHECKBOX, 0, diff --git a/port/src/video.c b/port/src/video.c index d645522bd..18da94fc0 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -148,6 +148,11 @@ s32 videoGetFullscreen(void) return vidFullscreen; } +s32 videoGetMaximizeWindow(void) +{ + return vidMaximize; +} + f32 videoGetAspect(void) { return gfx_current_dimensions.aspect_ratio; @@ -177,6 +182,14 @@ void videoSetFullscreen(s32 fs) } } +void videoSetMaximizeWindow(s32 fs) +{ + if (fs != vidMaximize) { + vidMaximize = !!fs; + wmAPI->set_maximize(vidMaximize); + } +} + void videoSetTextureFilter(u32 filter) { if (filter > FILTER_THREE_POINT) filter = FILTER_THREE_POINT;