Skip to content

Commit

Permalink
Allow toggling fullscreen with F11
Browse files Browse the repository at this point in the history
  • Loading branch information
rollerozxa committed Jun 22, 2024
1 parent 8773e54 commit 67fad00
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
13 changes: 13 additions & 0 deletions src/src/pscreen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/src/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 3 additions & 11 deletions src/tms/backend/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
6 changes: 0 additions & 6 deletions src/tms/backend/main_emscripten.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,3 @@ const char *tbackend_get_storage_path(void)
}
return _storage_path;
}

void
tbackend_toggle_fullscreen(void)
{

}
4 changes: 0 additions & 4 deletions src/tms/core/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/tms/core/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#define GL_ETC1_RGB8_OES 0x8D64

struct tms_context;

struct tms_texture {
char *filename;
unsigned char *data;
Expand Down
2 changes: 1 addition & 1 deletion src/tms/core/tms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 67fad00

Please sign in to comment.