Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple alt-enter fullscreen toggle #30

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/inputsystem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "inputsystem.h"
//#include "window.h"
// #include "window.h"
#include "renderer/renderer.h"

#include "profile/game.h"
Expand Down Expand Up @@ -38,6 +38,8 @@ bool TouchWentDown = false;

static SDL_FingerID CurrentFinger = 0;

bool fullscreenToggle = false;

void BeginFrame() {
memset(ControllerButtonWentDown, false, sizeof(ControllerButtonWentDown));
memset(ControllerAxisWentDownLight, false,
Expand Down Expand Up @@ -110,10 +112,32 @@ bool HandleEvent(SDL_Event const* ev) {
return true;
break;
}
case SDL_KEYDOWN:
case SDL_KEYDOWN: {
SDL_KeyboardEvent const* evt = &ev->key;
CurrentInputDevice = IDEV_Keyboard;
// Alt+Enter fullscreen toggle
if (evt->keysym.mod & KMOD_ALT && evt->keysym.sym == SDLK_RETURN &&
!fullscreenToggle) {
Window->ToggleFullscreen();
fullscreenToggle = true;
return true;
}

KeyboardButtonWentDown[evt->keysym.scancode] =
(evt->state == SDL_PRESSED &&
!KeyboardButtonIsDown[evt->keysym.scancode]);
KeyboardButtonIsDown[evt->keysym.scancode] = evt->state == SDL_PRESSED;
} break;
case SDL_KEYUP: {
SDL_KeyboardEvent const* evt = &ev->key;
CurrentInputDevice = IDEV_Keyboard;
// Alt+Enter fullscreen toggle
if (evt->keysym.mod & KMOD_ALT && evt->keysym.sym == SDLK_RETURN &&
fullscreenToggle) {
fullscreenToggle = false;
return true;
}

KeyboardButtonWentDown[evt->keysym.scancode] =
(evt->state == SDL_PRESSED &&
!KeyboardButtonIsDown[evt->keysym.scancode]);
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/dx9/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ void DirectX9Window::Init() {
WindowWidth, WindowHeight);
}

void DirectX9Window::ToggleFullscreen() {
if (SDL_GetWindowFlags(SDLWindow) & SDL_WINDOW_FULLSCREEN) {
SDL_SetWindowFullscreen(SDLWindow, 0);
} else {
SDL_SetWindowFullscreen(SDLWindow, SDL_WINDOW_FULLSCREEN);
}
}

void DirectX9Window::SetDimensions(int width, int height, int msaa,
float renderScale) {}

Expand Down
1 change: 1 addition & 0 deletions src/renderer/dx9/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DirectX9Window : public BaseWindow {
void Init() override;
void SetDimensions(int width, int height, int msaa,
float renderScale) override;
void ToggleFullscreen() override;
RectF GetViewport() override;
RectF GetScaledViewport() override;
void SwapRTs() override;
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/opengl/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ void GLWindow::SetDimensions(int width, int height, int msaa,
RenderScale = renderScale;
}

void GLWindow::ToggleFullscreen() {
if (SDL_GetWindowFlags(SDLWindow) & SDL_WINDOW_FULLSCREEN) {
SDL_SetWindowFullscreen(SDLWindow, 0);
} else {
SDL_SetWindowFullscreen(SDLWindow, SDL_WINDOW_FULLSCREEN);
}
}

void GLWindow::CleanFBOs() {
if (drawRenderTexture) glDeleteTextures(1, &drawRenderTexture);
if (ReadRenderTexture) glDeleteTextures(1, &ReadRenderTexture);
Expand Down
1 change: 1 addition & 0 deletions src/renderer/opengl/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class GLWindow : public BaseWindow {
void Init() override;
void SetDimensions(int width, int height, int msaa,
float renderScale) override;
void ToggleFullscreen() override;
RectF GetViewport() override;
RectF GetScaledViewport() override;
void SwapRTs() override;
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/vulkan/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ void VulkanWindow::UpdateDimensions() {
MainRendererInstance->RecreateSwapChain();
}

void VulkanWindow::ToggleFullscreen() {
if (SDL_GetWindowFlags(SDLWindow) & SDL_WINDOW_FULLSCREEN) {
SDL_SetWindowFullscreen(SDLWindow, 0);
} else {
SDL_SetWindowFullscreen(SDLWindow, SDL_WINDOW_FULLSCREEN);
}
}

RectF VulkanWindow::GetViewport() {
RectF viewport;
float scale = fmin((float)WindowWidth / Profile::DesignWidth,
Expand Down
1 change: 1 addition & 0 deletions src/renderer/vulkan/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class VulkanWindow : public BaseWindow {
void Init() override;
void SetDimensions(int width, int height, int msaa,
float renderScale) override;
void ToggleFullscreen() override;
RectF GetViewport() override;
RectF GetScaledViewport() override;
void SwapRTs() override;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BaseWindow {
virtual void Init() = 0;
virtual void SetDimensions(int width, int height, int msaa,
float renderScale) = 0;
virtual void ToggleFullscreen() = 0;
// Aspect ratio corrected viewport in window coordinates
virtual RectF GetViewport() = 0;
// Aspect ratio corrected viewport in window coordinates scaled by RenderScale
Expand Down