Skip to content

Commit c4a5616

Browse files
committed
Abstract mouse mode behind Window class
1 parent 0678ca0 commit c4a5616

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

Engine/include/private/Window.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class ENGINE_API Window {
4242

4343
void SetImGuiReady(bool ready) { m_imguiReady = ready; }
4444

45+
void SetRelativeMouseMode(bool enabled);
46+
4547
static int GetWidth() { return Width; }
4648
static int GetHeight() { return Height; }
4749

Engine/src/FirstPersonController.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <ECS/Components/FirstPersonController.hpp>
22
#include <Physics/RigidbodyComponent.hpp>
3+
#include <Core/Application.hpp>
4+
#include <Window.hpp>
35
#include <SDL3/SDL.h>
46
#include <Events/Event.h>
57
#include <Math/Math.hpp>
@@ -193,8 +195,8 @@ void FirstPersonController::SetEnabled(bool enabled) {
193195

194196
if (!camera) return;
195197

196-
SDL_Window* window = SDL_GetMouseFocus();
197-
SDL_SetWindowRelativeMouseMode(window, enabled);
198+
auto* app = Application::GetInstance();
199+
if (app) app->GetWindow().SetRelativeMouseMode(enabled);
198200
ToggleCursor(!enabled);
199201

200202
if (enabled) {

Engine/src/FreeLookCameraControllerComponent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <ECS/Components/FreeLookCameraController.hpp>
22
#include <Physics/RigidbodyComponent.hpp>
3+
#include <Core/Application.hpp>
4+
#include <Window.hpp>
35
#include <SDL3/SDL.h>
46
#include <Events/Event.h>
57
#include <Math/Math.hpp>
@@ -185,8 +187,8 @@ namespace Sleak {
185187
if(!camera)
186188
return;
187189

188-
SDL_Window* window = SDL_GetMouseFocus();
189-
SDL_SetWindowRelativeMouseMode(window, enabled);
190+
auto* app = Application::GetInstance();
191+
if (app) app->GetWindow().SetRelativeMouseMode(enabled);
190192

191193
ToggleCursor(!enabled);
192194

Engine/src/Window.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ void Window::SetFullScreen(bool isFullscreen) {
186186
}
187187
}
188188

189+
void Window::SetRelativeMouseMode(bool enabled) {
190+
SDL_SetWindowRelativeMouseMode(SDLWindow, enabled);
191+
}
192+
189193
void Window::Close() {
190194
event.type = SDL_EVENT_QUIT;
191195
SDL_Quit();

0 commit comments

Comments
 (0)