From 2447a0e18d88e029280e0116b0c42d426cdc7f0a Mon Sep 17 00:00:00 2001 From: Arignir Date: Sat, 12 Oct 2024 02:42:32 +0200 Subject: [PATCH] Add a "Fullscreen" setting. --- include/app/app.h | 14 ++++++++++++++ source/app/config.c | 7 +++++++ source/app/main.c | 7 ++++--- source/app/sdl/video.c | 31 ++++++++++++++++++++++++++++++- source/app/windows/settings.c | 24 ++++++++++++++++++++---- 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/include/app/app.h b/include/app/app.h index 5ba3645..cc7d1b8 100644 --- a/include/app/app.h +++ b/include/app/app.h @@ -28,6 +28,16 @@ struct ImGuiIO; +enum display_mode { + DISPLAY_MODE_WINDOWED = 0, + DISPLAY_MODE_BORDERLESS = 1, + DISPLAY_MODE_FULLSCREEN = 2, + + DISPLAY_MODE_LEN, + DISPLAY_MODE_MIN = 0, + DISPLAY_MODE_MAX = 2, +}; + enum texture_filter_kind { TEXTURE_FILTER_NEAREST = 0, TEXTURE_FILTER_LINEAR = 1, @@ -194,6 +204,9 @@ struct settings { } emulation; struct { + // Display mode + enum display_mode display_mode; + // Display size uint32_t display_size; @@ -496,6 +509,7 @@ void app_sdl_video_cleanup(struct app *app); void app_sdl_video_render_frame(struct app *app); void app_sdl_video_rebuild_pipeline(struct app *app); void app_sdl_video_resize_window(struct app *app); +void app_sdl_video_update_display_mode(struct app *app); /* app/shaders/frag-color-correction.c */ extern char const *SHADER_FRAG_COLOR_CORRECTION; diff --git a/source/app/config.c b/source/app/config.c index 8b72cee..4a9f129 100644 --- a/source/app/config.c +++ b/source/app/config.c @@ -114,6 +114,11 @@ app_config_load( int b; double d; + if (mjson_get_number(data, data_len, "$.video.display_mode", &d)) { + app->settings.video.display_mode = (int)d; + app->settings.video.display_mode = max(DISPLAY_MODE_MIN, min(app->settings.video.display_mode, DISPLAY_MODE_MAX)); + } + if (mjson_get_number(data, data_len, "$.video.display_size", &d)) { app->settings.video.display_size = (int)d; app->settings.video.display_size = max(1, min(app->settings.video.display_size, 5)); @@ -313,6 +318,7 @@ app_config_save( // Video "video": { + "display_mode": %d, "display_size": %d, "aspect_ratio": %d, "vsync": %B, @@ -354,6 +360,7 @@ app_config_save( (int)app->settings.emulation.backup_storage.type, (int)app->settings.emulation.gpio_device.autodetect, (int)app->settings.emulation.gpio_device.type, + (int)app->settings.video.display_mode, (int)app->settings.video.display_size, (int)app->settings.video.aspect_ratio, (int)app->settings.video.vsync, diff --git a/source/app/main.c b/source/app/main.c index 0b05ff1..c3973ca 100644 --- a/source/app/main.c +++ b/source/app/main.c @@ -63,12 +63,13 @@ app_settings_default( memset(settings->audio.enable_psg_channels, true, sizeof(settings->audio.enable_psg_channels)); memset(settings->audio.enable_fifo_channels, true, sizeof(settings->audio.enable_fifo_channels)); settings->emulation.bios_path = strdup("./bios.bin"); - settings->video.pixel_color_filter = PIXEL_COLOR_FILTER_COLOR_CORRECTION; - settings->video.pixel_scaling_filter = PIXEL_SCALING_FILTER_LCD_GRID; - settings->video.vsync = false; + settings->video.display_mode = DISPLAY_MODE_WINDOWED; settings->video.display_size = 3; settings->video.aspect_ratio = ASPECT_RATIO_BORDERS; + settings->video.vsync = false; settings->video.texture_filter = TEXTURE_FILTER_NEAREST; + settings->video.pixel_color_filter = PIXEL_COLOR_FILTER_COLOR_CORRECTION; + settings->video.pixel_scaling_filter = PIXEL_SCALING_FILTER_LCD_GRID; settings->audio.mute = false; settings->audio.level = 1.0f; settings->misc.hide_cursor_when_mouse_inactive = true; diff --git a/source/app/sdl/video.c b/source/app/sdl/video.c index 0fe4d40..40d648d 100644 --- a/source/app/sdl/video.c +++ b/source/app/sdl/video.c @@ -11,6 +11,7 @@ #include #include #include +#include "SDL_video.h" #include "hades.h" #include "app/app.h" #include "gba/gba.h" @@ -24,6 +25,7 @@ app_sdl_video_init( char const *glsl_version; SDL_DisplayMode mode; ImFontConfig *cfg; + uint32_t win_flags; int err; memset(&mode, 0, sizeof(mode)); @@ -89,6 +91,14 @@ app_sdl_video_init( app->ui.display.win.height = (GBA_SCREEN_HEIGHT * app->settings.video.display_size + app->ui.menubar_size.y) * app->ui.scale; app_win_game_refresh_game_area(app); + win_flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; + + switch (app->settings.video.display_mode) { + case DISPLAY_MODE_BORDERLESS: win_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; break; + case DISPLAY_MODE_FULLSCREEN: win_flags |= SDL_WINDOW_FULLSCREEN; break; + default: break; + } + // Create the SDL window app->sdl.window = SDL_CreateWindow( "Hades", @@ -96,7 +106,7 @@ app_sdl_video_init( SDL_WINDOWPOS_CENTERED, app->ui.display.win.width, app->ui.display.win.height, - SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE + win_flags ); if (!app->sdl.window) { @@ -201,6 +211,25 @@ app_sdl_video_resize_window( SDL_SetWindowSize(app->sdl.window, w, h); } +void +app_sdl_video_update_display_mode( + struct app *app +) { + uint32_t win_flags; + + switch (app->settings.video.display_mode) { + case DISPLAY_MODE_WINDOWED: win_flags = 0; break; + case DISPLAY_MODE_FULLSCREEN: win_flags = SDL_WINDOW_FULLSCREEN; break; + case DISPLAY_MODE_BORDERLESS: win_flags = SDL_WINDOW_FULLSCREEN_DESKTOP; break; + default: { + panic(HS_INFO, "Invalid display mode %u", app->settings.video.display_mode); + break; + } + } + + SDL_SetWindowFullscreen(app->sdl.window, win_flags); +} + void app_sdl_video_rebuild_pipeline( struct app *app diff --git a/source/app/windows/settings.c b/source/app/windows/settings.c index a212f48..eaa4fb7 100644 --- a/source/app/windows/settings.c +++ b/source/app/windows/settings.c @@ -42,6 +42,12 @@ static char const *aspect_ratio_names[ASPECT_RATIO_LEN] = { [ASPECT_RATIO_STRETCH] = "Stretch", }; +static char const *display_mode_names[DISPLAY_MODE_LEN] = { + [DISPLAY_MODE_WINDOWED] = "Windowed", + [DISPLAY_MODE_BORDERLESS] = "Borderless", + [DISPLAY_MODE_FULLSCREEN] = "Fullscreen", +}; + static char const * const display_size_names[] = { "x1", "x2", @@ -371,14 +377,14 @@ app_win_settings_video( igTableSetupColumn("##VideoSettingsDisplayLabel", ImGuiTableColumnFlags_WidthFixed, vp->WorkSize.x / 5.f, 0); igTableSetupColumn("##VideoSettingsDisplayValue", ImGuiTableColumnFlags_WidthStretch, 0.f, 0); - // VSync + // Display Mode igTableNextRow(ImGuiTableRowFlags_None, 0.f); igTableNextColumn(); - igTextWrapped("VSync"); + igTextWrapped("Display Mode"); igTableNextColumn(); - if (igCheckbox("##VSync", &app->settings.video.vsync)) { - SDL_GL_SetSwapInterval(app->settings.video.vsync); + if (igCombo_Str_arr("##DisplayMode", (int *)&app->settings.video.display_mode, display_mode_names, DISPLAY_MODE_LEN, 0)) { + app_sdl_video_update_display_mode(app); } // Display Size @@ -427,6 +433,16 @@ app_win_settings_video( app_win_game_refresh_game_area(app); } + // VSync + igTableNextRow(ImGuiTableRowFlags_None, 0.f); + igTableNextColumn(); + igTextWrapped("VSync"); + + igTableNextColumn(); + if (igCheckbox("##VSync", &app->settings.video.vsync)) { + SDL_GL_SetSwapInterval(app->settings.video.vsync); + } + igEndTable(); }