Allow toggling fullscreen with F11

This commit is contained in:
ROllerozxa 2024-06-22 20:51:57 +02:00
commit 67fad00960
7 changed files with 18 additions and 24 deletions

View file

@ -9,6 +9,8 @@
#include "soundmanager.hh"
#include "game.hh"
#include <SDL.h>
p_text *pscreen::text_username;
game_message *pscreen::message;
game_graph pscreen::fps_graph("FPS");
@ -239,6 +241,17 @@ pscreen::handle_input(tms::event *ev, int action)
++ snd_counter;
}
break;
case TMS_KEY_F11:
uint32_t flags = SDL_GetWindowFlags(_tms._window);
if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP)
SDL_SetWindowFullscreen(_tms._window, 0);
else
SDL_SetWindowFullscreen(_tms._window, SDL_WINDOW_FULLSCREEN_DESKTOP);
settings["window_fullscreen"]->v.b = (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == 0;
break;
}
} else if (ev->type == TMS_EV_POINTER_UP) {
#ifndef NO_UI

View file

@ -39,6 +39,7 @@ _settings::init()
this->add("window_width", S_INT32, _tms.window_width);
this->add("window_height", S_INT32, _tms.window_height);
this->add("window_maximized", S_BOOL, 0);
this->add("window_fullscreen", S_BOOL, false);
// False for now to allow for resetting the screensize if resizing somehow breaks it.
this->add("autosave_screensize",S_BOOL, false);

View file

@ -362,6 +362,9 @@ tbackend_init_surface()
if (settings["window_maximized"]->v.b)
flags |= SDL_WINDOW_MAXIMIZED;
if (settings["window_fullscreen"]->v.b)
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
tms_infof("Creating window..."); \
_window = SDL_CreateWindow("Principia", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
_tms.window_width, _tms.window_height, flags);
@ -644,14 +647,3 @@ const char *tbackend_get_storage_path(void)
}
return _storage_path;
}
void
tbackend_toggle_fullscreen(void)
{
uint32_t flags = SDL_GetWindowFlags(_window);
if (flags & SDL_WINDOW_FULLSCREEN)
SDL_SetWindowFullscreen(_window, SDL_FALSE);
else
SDL_SetWindowFullscreen(_window, SDL_TRUE);
}

View file

@ -264,9 +264,3 @@ const char *tbackend_get_storage_path(void)
}
return _storage_path;
}
void
tbackend_toggle_fullscreen(void)
{
}

View file

@ -30,14 +30,10 @@
extern "C" {
#endif
struct tms_context;
int tbackend_init_surface(void);
const char *tbackend_get_storage_path();
void tbackend_toggle_fullscreen(void);
#ifdef __cplusplus
}
#endif

View file

@ -9,8 +9,6 @@
#define GL_ETC1_RGB8_OES 0x8D64
struct tms_context;
struct tms_texture {
char *filename;
unsigned char *data;

View file

@ -109,7 +109,7 @@ extern struct tms_singleton {
int dt_count;
uint64_t last_time;
void *_window;
SDL_Window *_window;
} _tms;
int tms_init(void);