Skip to content

Commit

Permalink
allow screen res to be changed
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed May 5, 2024
1 parent 136b30d commit b855e3f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
Binary file modified data/gfx.tgz
Binary file not shown.
16 changes: 7 additions & 9 deletions src/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ uint8_t sdl_init(void)
return false;
}

int x = 0;
if (x) {
//
// Unused for now
//
if (0) {
sdl_init_joystick();
sdl_init_rumble();
}
Expand All @@ -181,7 +183,7 @@ uint8_t sdl_init(void)
//
// If we have a saved setting, use that.
//
if (game_window_pix_width_get(game) && game_window_pix_height_get(game)) {
if (game_config_pix_width_get(game) && game_config_pix_height_get(game)) {
video_width = game_config_pix_width_get(game);
video_height = game_config_pix_height_get(game);
} else {
Expand All @@ -205,10 +207,6 @@ uint8_t sdl_init(void)
}

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

//
// Don't use this. It seemed to mess up graphics on FireGL.
//
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

uint32_t video_is_unused_flags;
Expand Down Expand Up @@ -242,7 +240,7 @@ uint8_t sdl_init(void)
video_is_unused_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
LOG("SDL: Set SDL_WINDOW_ALLOW_HIGHDPI");
} else {
ERR("SDL: Cannot enable high DPI");
ERR("SDL: Cannot enable high DPI: %s", SDL_GetError());
}
}

Expand Down Expand Up @@ -303,7 +301,7 @@ uint8_t sdl_init(void)
LOG("SDL: OpenGL Vendor : %s", glGetString(GL_VENDOR));
LOG("SDL: OpenGL Renderer : %s", glGetString(GL_RENDERER));
LOG("SDL: OpenGL Version : %s", glGetString(GL_VERSION));
DBG("SDL: OpenGL Exts : %s", glGetString(GL_EXTENSIONS));
LOG("SDL: OpenGL Exts : %s", glGetString(GL_EXTENSIONS));

SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
LOG("SDL: Red size : %d", value);
Expand Down
62 changes: 48 additions & 14 deletions src/wid_cfg_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "my_callstack.hpp"
#include "my_game.hpp"
#include "my_main.hpp"
#include "my_sdl_event.hpp"
#include "my_sdl_proto.hpp"
#include "my_wids.hpp"

Expand Down Expand Up @@ -83,8 +84,21 @@ static bool wid_cfg_gfx_fullscreen_toggle(Widp w, int x, int y, uint32_t button)
game_gfx_fullscreen_desktop_set(game, false);
}

wid_cfg_gfx_select(game);
if (game_gfx_fullscreen_get(game)) {
SDL_SetWindowFullscreen(sdl.window, SDL_WINDOW_FULLSCREEN);
} else if (game_gfx_fullscreen_desktop_get(game)) {
SDL_SetWindowFullscreen(sdl.window, SDL_WINDOW_FULLSCREEN_DESKTOP);
} else {
SDL_SetWindowFullscreen(sdl.window, 0);
}

//
// These kind of changes seem to need a restart
//
local_g_need_restart = true;
wid_cfg_gfx_save(nullptr, 0, 0, 0);
wid_cfg_gfx_select(game);

return true;
}

Expand All @@ -98,8 +112,23 @@ static bool wid_cfg_gfx_fullscreen_desktop_toggle(Widp w, int x, int y, uint32_t
if (game_gfx_fullscreen_desktop_get(game)) {
game_gfx_fullscreen_set(game, false);
}
wid_cfg_gfx_select(game);

if (game_gfx_fullscreen_get(game)) {
SDL_SetWindowFullscreen(sdl.window, SDL_WINDOW_FULLSCREEN);
} else if (game_gfx_fullscreen_desktop_get(game)) {
SDL_SetWindowFullscreen(sdl.window, SDL_WINDOW_FULLSCREEN_DESKTOP);
local_g_need_restart = true;
} else {
SDL_SetWindowFullscreen(sdl.window, 0);
}

//
// These kind of changes seem to need a restart
//
local_g_need_restart = true;
wid_cfg_gfx_save(nullptr, 0, 0, 0);
wid_cfg_gfx_select(game);

return true;
}

Expand All @@ -120,8 +149,8 @@ static bool wid_cfg_gfx_borderless_toggle(Widp w, int x, int y, uint32_t button)
config_changed = true;
CON("INF: Toggle gfx borderless");
game_gfx_borderless_set(game, ! game_gfx_borderless_get(game));
SDL_SetWindowBordered(sdl.window, game_gfx_borderless_get(game) ? SDL_TRUE : SDL_FALSE);
wid_cfg_gfx_select(game);
local_g_need_restart = true;
return true;
}

Expand All @@ -147,7 +176,7 @@ static bool wid_cfg_gfx_resolution_incr(Widp w, int x, int y, uint32_t button)
SDL_DisplayMode mode;
SDL_GetDisplayMode(0, i, &mode);
auto cand = std::to_string(mode.w) + "x" + std::to_string(mode.h);
CON(" - candidate: %s", cand.c_str());
LOG(" - candidate: %s", cand.c_str());
if (res == cand) {
chosen = i - 1;
}
Expand All @@ -157,10 +186,12 @@ static bool wid_cfg_gfx_resolution_incr(Widp w, int x, int y, uint32_t button)
if (i == chosen) {
SDL_GetDisplayMode(0, i, &mode);
auto cand = std::to_string(mode.w) + "x" + std::to_string(mode.h);
CON(" - chosen: %s", cand.c_str());
LOG(" - chosen: %s", cand.c_str());
game_window_pix_width_set(game, mode.w);
game_window_pix_height_set(game, mode.h);
local_g_need_restart = true;
game_config_pix_width_set(game, mode.w);
game_config_pix_height_set(game, mode.h);
SDL_SetWindowSize(sdl.window, mode.w, mode.h);
}
}
wid_cfg_gfx_save(nullptr, 0, 0, 0);
Expand All @@ -181,7 +212,7 @@ static bool wid_cfg_gfx_resolution_decr(Widp w, int x, int y, uint32_t button)
SDL_DisplayMode mode;
SDL_GetDisplayMode(0, i, &mode);
auto cand = std::to_string(mode.w) + "x" + std::to_string(mode.h);
CON(" - candidate: %s", cand.c_str());
LOG(" - candidate: %s", cand.c_str());
if (res == cand) {
chosen = i + 1;
}
Expand All @@ -191,10 +222,12 @@ static bool wid_cfg_gfx_resolution_decr(Widp w, int x, int y, uint32_t button)
if (i == chosen) {
SDL_GetDisplayMode(0, i, &mode);
auto cand = std::to_string(mode.w) + "x" + std::to_string(mode.h);
CON(" - chosen: %s", cand.c_str());
LOG(" - chosen: %s", cand.c_str());
game_window_pix_width_set(game, mode.w);
game_window_pix_height_set(game, mode.h);
local_g_need_restart = true;
game_config_pix_width_set(game, mode.w);
game_config_pix_height_set(game, mode.h);
SDL_SetWindowSize(sdl.window, mode.w, mode.h);
}
}
wid_cfg_gfx_save(nullptr, 0, 0, 0);
Expand Down Expand Up @@ -258,8 +291,8 @@ void wid_cfg_gfx_select(class Game *game)
auto box_highlight_style = UI_WID_STYLE_HORIZ_LIGHT;
auto m = TERM_WIDTH / 2;

point tl = make_point(m - 20, TERM_HEIGHT / 2 - 11);
point br = make_point(m + 20, TERM_HEIGHT / 2 + 13);
point tl = make_point(m - 23, TERM_HEIGHT / 2 - 11);
point br = make_point(m + 22, TERM_HEIGHT / 2 + 13);

auto width = br.x - tl.x - 2;

Expand Down Expand Up @@ -382,6 +415,7 @@ void wid_cfg_gfx_select(class Game *game)
wid_set_on_mouse_up(w, wid_cfg_gfx_resolution_decr);
wid_set_text(w, "-");
}
y_at++;

/////////////////////////////////////////////////////////////////////////
// Fullscreen
Expand All @@ -397,7 +431,7 @@ void wid_cfg_gfx_select(class Game *game)
wid_set_shape_none(w);
wid_set_pos(w, tl, br);
wid_set_text_lhs(w, true);
wid_set_text(w, "Fullscreen video");
wid_set_text(w, "Fullscreen(restart)");
}
{
TRACE_AND_INDENT();
Expand All @@ -421,7 +455,7 @@ void wid_cfg_gfx_select(class Game *game)
}

/////////////////////////////////////////////////////////////////////////
// fullscreen desktop
// Fullscreen desktop
/////////////////////////////////////////////////////////////////////////
y_at++;
{
Expand All @@ -434,7 +468,7 @@ void wid_cfg_gfx_select(class Game *game)
wid_set_shape_none(w);
wid_set_pos(w, tl, br);
wid_set_text_lhs(w, true);
wid_set_text(w, "Fullscreen desktop");
wid_set_text(w, "Full desktop(restart)");
}
{
TRACE_AND_INDENT();
Expand Down

0 comments on commit b855e3f

Please sign in to comment.