Passable fullscreen mode

- Centering is still a bit off
This commit is contained in:
Linus Probert 2018-08-30 00:09:55 +02:00
parent 316325b98d
commit 0d1836a8ba
3 changed files with 39 additions and 13 deletions

View File

@ -109,6 +109,8 @@ get_event_modkey(SDL_Event *event)
key = KEY_CTRL_M; break; key = KEY_CTRL_M; break;
case SDLK_d: case SDLK_d:
key = KEY_CTRL_D; break; key = KEY_CTRL_D; break;
case SDLK_f:
key = KEY_CTRL_F; break;
} }
} else if (event->key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) { } else if (event->key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) {
switch (event->key.keysym.sym) { switch (event->key.keysym.sym) {
@ -122,8 +124,6 @@ get_event_modkey(SDL_Event *event)
key = KEY_SHIFT_NUM4; break; key = KEY_SHIFT_NUM4; break;
case SDLK_5: case SDLK_5:
key = KEY_SHIFT_NUM5; break; key = KEY_SHIFT_NUM5; break;
default:
key = 0; break;
} }
} }
return key; return key;

View File

@ -47,6 +47,7 @@
#define KEY_SHIFT_NUM3 0x20 #define KEY_SHIFT_NUM3 0x20
#define KEY_SHIFT_NUM4 0x40 #define KEY_SHIFT_NUM4 0x40
#define KEY_SHIFT_NUM5 0x80 #define KEY_SHIFT_NUM5 0x80
#define KEY_CTRL_F 0x100
#define MBUTTON_LEFT 1 #define MBUTTON_LEFT 1
#define MBUTTON_MIDDLE 2 #define MBUTTON_MIDDLE 2

View File

@ -152,6 +152,7 @@ static float deltaTime = 1.0;
static double renderScale = 1.0; static double renderScale = 1.0;
static Turn currentTurn = PLAYER; static Turn currentTurn = PLAYER;
static GameState gGameState; static GameState gGameState;
static SDL_Rect mainViewport;
static SDL_Rect gameViewport; static SDL_Rect gameViewport;
static SDL_Rect skillBarViewport; static SDL_Rect skillBarViewport;
static SDL_Rect bottomGuiViewport; static SDL_Rect bottomGuiViewport;
@ -250,26 +251,30 @@ bool initSDL(void)
} }
static void static void
initViewports(void) initViewports(Uint32 offset)
{ {
gameViewport = (SDL_Rect) { 0, 0, mainViewport = (SDL_Rect) { offset, 0,
SCREEN_HEIGHT, SCREEN_WIDTH
};
gameViewport = (SDL_Rect) { offset, 0,
GAME_VIEW_WIDTH, GAME_VIEW_HEIGHT }; GAME_VIEW_WIDTH, GAME_VIEW_HEIGHT };
skillBarViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT, skillBarViewport = (SDL_Rect) { offset, GAME_VIEW_HEIGHT,
SKILL_BAR_WIDTH, SKILL_BAR_HEIGHT }; SKILL_BAR_WIDTH, SKILL_BAR_HEIGHT };
bottomGuiViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT, bottomGuiViewport = (SDL_Rect) { offset, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT,
BOTTOM_GUI_WIDTH, BOTTOM_GUI_WIDTH }; BOTTOM_GUI_WIDTH, BOTTOM_GUI_WIDTH };
statsGuiViewport = (SDL_Rect) { GAME_VIEW_WIDTH, 0, statsGuiViewport = (SDL_Rect) { offset + GAME_VIEW_WIDTH, 0,
RIGHT_GUI_WIDTH, STATS_GUI_HEIGHT }; RIGHT_GUI_WIDTH, STATS_GUI_HEIGHT };
minimapViewport = (SDL_Rect) { GAME_VIEW_WIDTH, STATS_GUI_HEIGHT, minimapViewport = (SDL_Rect) { offset + GAME_VIEW_WIDTH, STATS_GUI_HEIGHT,
RIGHT_GUI_WIDTH, MINIMAP_GUI_HEIGHT }; RIGHT_GUI_WIDTH, MINIMAP_GUI_HEIGHT };
menuViewport = (SDL_Rect) { menuViewport = (SDL_Rect) {
(SCREEN_WIDTH - GAME_VIEW_WIDTH)/2, offset + ((SCREEN_WIDTH - GAME_VIEW_WIDTH) >> 1),
(SCREEN_HEIGHT - GAME_VIEW_HEIGHT)/2, (SCREEN_HEIGHT - GAME_VIEW_HEIGHT) >> 1,
GAME_VIEW_WIDTH, GAME_VIEW_WIDTH,
GAME_VIEW_HEIGHT GAME_VIEW_HEIGHT
}; };
@ -278,7 +283,7 @@ initViewports(void)
static bool static bool
initGame(void) initGame(void)
{ {
initViewports(); initViewports(0);
input_init(&input); input_init(&input);
texturecache_init(gRenderer); texturecache_init(gRenderer);
gCamera = camera_create(gRenderer); gCamera = camera_create(gRenderer);
@ -585,6 +590,26 @@ handle_main_input(void)
else else
gui_log("Tooltips disabled"); gui_log("Tooltips disabled");
} }
if (input_modkey_is_pressed(&input, KEY_CTRL_F)) {
bool isFullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP;
if (isFullscreen) {
initViewports(0);
SDL_SetWindowFullscreen(gWindow, 0);
}
else {
int w, h;
SDL_RenderGetLogicalSize(gRenderer, &w, &h);
SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_DisplayMode dMode;
SDL_GetWindowDisplayMode(gWindow, &dMode);
double ratio = (double) w / (double) dMode.w;
double offset = (double) (dMode.w - w) / 2;
initViewports((Uint32) (offset * ratio));
}
}
} }
static bool static bool
@ -755,7 +780,7 @@ render_gui(void)
skillbar_render(gSkillBar, gPlayer, gCamera); skillbar_render(gSkillBar, gPlayer, gCamera);
SDL_RenderSetViewport(gRenderer, &bottomGuiViewport); SDL_RenderSetViewport(gRenderer, &bottomGuiViewport);
gui_render_log(gGui, gCamera); gui_render_log(gGui, gCamera);
SDL_RenderSetViewport(gRenderer, NULL); SDL_RenderSetViewport(gRenderer, &mainViewport);
} }
static void static void
@ -902,7 +927,7 @@ run_menu(void)
map_render_top_layer(gMap, gRoomMatrix, gCamera); map_render_top_layer(gMap, gRoomMatrix, gCamera);
roommatrix_render_lightmap(gRoomMatrix, gCamera); roommatrix_render_lightmap(gRoomMatrix, gCamera);
SDL_RenderSetViewport(gRenderer, NULL); SDL_RenderSetViewport(gRenderer, &mainViewport);
if (gGameState == MENU) if (gGameState == MENU)
menu_render(mainMenu, gCamera); menu_render(mainMenu, gCamera);