Skip to content

Commit

Permalink
Add a "Fullscreen" setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arignir committed Oct 12, 2024
1 parent 4403350 commit 2447a0e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
14 changes: 14 additions & 0 deletions include/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -194,6 +204,9 @@ struct settings {
} emulation;

struct {
// Display mode
enum display_mode display_mode;

// Display size
uint32_t display_size;

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions source/app/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -313,6 +318,7 @@ app_config_save(

// Video
"video": {
"display_mode": %d,
"display_size": %d,
"aspect_ratio": %d,
"vsync": %B,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions source/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 30 additions & 1 deletion source/app/sdl/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cimgui.h>
#include <cimgui_impl.h>
#include <nfd.h>
#include "SDL_video.h"
#include "hades.h"
#include "app/app.h"
#include "gba/gba.h"
Expand All @@ -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));
Expand Down Expand Up @@ -89,14 +91,22 @@ 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",
SDL_WINDOWPOS_CENTERED,
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) {
Expand Down Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions source/app/windows/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 2447a0e

Please sign in to comment.