From 67fad00960fb6e9d067a6bf58862ce6db6e9104f Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Sat, 22 Jun 2024 20:51:57 +0200 Subject: [PATCH] Allow toggling fullscreen with F11 --- src/src/pscreen.cc | 13 +++++++++++++ src/src/settings.cc | 1 + src/tms/backend/main.cc | 14 +++----------- src/tms/backend/main_emscripten.cc | 6 ------ src/tms/core/backend.h | 4 ---- src/tms/core/texture.h | 2 -- src/tms/core/tms.h | 2 +- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/src/pscreen.cc b/src/src/pscreen.cc index 5d74a07b..5e9655b6 100644 --- a/src/src/pscreen.cc +++ b/src/src/pscreen.cc @@ -9,6 +9,8 @@ #include "soundmanager.hh" #include "game.hh" +#include + 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 diff --git a/src/src/settings.cc b/src/src/settings.cc index a3d987c2..c9d87768 100644 --- a/src/src/settings.cc +++ b/src/src/settings.cc @@ -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); diff --git a/src/tms/backend/main.cc b/src/tms/backend/main.cc index 53d48456..375a03d7 100644 --- a/src/tms/backend/main.cc +++ b/src/tms/backend/main.cc @@ -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); -} diff --git a/src/tms/backend/main_emscripten.cc b/src/tms/backend/main_emscripten.cc index 1cd7c468..47f46241 100644 --- a/src/tms/backend/main_emscripten.cc +++ b/src/tms/backend/main_emscripten.cc @@ -264,9 +264,3 @@ const char *tbackend_get_storage_path(void) } return _storage_path; } - -void -tbackend_toggle_fullscreen(void) -{ - -} diff --git a/src/tms/core/backend.h b/src/tms/core/backend.h index fe96ee16..603b7dad 100644 --- a/src/tms/core/backend.h +++ b/src/tms/core/backend.h @@ -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 diff --git a/src/tms/core/texture.h b/src/tms/core/texture.h index 1dc62d32..5fe13b62 100644 --- a/src/tms/core/texture.h +++ b/src/tms/core/texture.h @@ -9,8 +9,6 @@ #define GL_ETC1_RGB8_OES 0x8D64 -struct tms_context; - struct tms_texture { char *filename; unsigned char *data; diff --git a/src/tms/core/tms.h b/src/tms/core/tms.h index 134abd2e..65f6052a 100644 --- a/src/tms/core/tms.h +++ b/src/tms/core/tms.h @@ -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);