SleakEngine 0.1.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Window.hpp
Go to the documentation of this file.
1#ifndef _WINDOW_HPP_
2#define _WINDOW_HPP_
3
4#include <Core/OSDef.hpp>
5#include <SDL3/SDL.h>
6#include <string>
7#include "SDL3/SDL_events.h"
8#include "SDL3/SDL_video.h"
9#include <backends/imgui_impl_sdl3.h>
10
11#define DEF_WIDTH 800
12#define DEF_HEIGHT 600
13
14namespace Sleak {
15
16/// SDL window wrapper: owns the native window and pumps SDL events into
17/// engine Events. Application owns exactly one.
18class ENGINE_API Window {
19public:
20 /// Constructs a window with the default size and no title.
21 Window();
22 /// Constructs a window with the given size and title.
23 Window(int width, int height, std::string name);
24 /// Destroys the SDL window and shuts down SDL.
25 ~Window();
26
27 Window(const Window&) = delete;
28 Window& operator=(const Window&) = delete;
29
30 /// Creates the SDL window and picks the graphics API flag for the active
31 /// renderer.
32 bool InitializeWindow();
33 /// Pumps the SDL event queue, dispatching engine events (resize, input, close,
34 /// ...).
35 void Update();
36 /// Marks the window for close; actual teardown happens in the destructor.
37 void Close();
38
39 /// True once the window has received a close request.
40 inline bool ShouldClose() { return bShouldClose; }
41
42 /// Returns the underlying SDL window handle.
43 inline SDL_Window* GetSDLWindow() { return SDLWindow; }
44 /// Returns the window title.
45 inline std::string GetWindowTitle() { return WindowName; }
46
47 /// Enables or disables fullscreen mode.
48 void SetFullScreen(bool bEnable);
49 /// Flips between fullscreen and windowed mode.
50 inline void ToggleFullScreen() { SetFullScreen(!bIsFullScreen); }
51 /// True if the window is currently fullscreen.
52 inline bool GetIsFullScreen() { return bIsFullScreen; }
53
54 /// Marks whether ImGui is ready to receive SDL events.
55 void SetImGuiReady(bool ready) { m_imguiReady = ready; }
56
57 /// Enables or disables relative (locked, delta-only) mouse mode.
58 void SetRelativeMouseMode(bool enabled);
59
60 /// Returns the current window width in pixels.
61 static int GetWidth() { return Width; }
62 /// Returns the current window height in pixels.
63 static int GetHeight() { return Height; }
64
65private:
66 bool bIsInitialized = false;
67 bool bIsFullScreen = false;
68 bool bShouldClose = false;
69 bool m_imguiReady = false;
70 std::string WindowName;
71
72 SDL_Window* SDLWindow = nullptr;
73 SDL_Event event;
74
75 static int Width;
76 static int Height;
77};
78
79
80}
81
82#endif
int width
int height
Window(const Window &)=delete
void SetFullScreen(bool bEnable)
Enables or disables fullscreen mode.
Definition Window.cpp:185
void SetImGuiReady(bool ready)
Marks whether ImGui is ready to receive SDL events.
Definition Window.hpp:55
static int GetHeight()
Returns the current window height in pixels.
Definition Window.hpp:63
bool InitializeWindow()
Definition Window.cpp:35
Window()
Constructs a window with the default size and no title.
Definition Window.cpp:17
SDL_Window * GetSDLWindow()
Returns the underlying SDL window handle.
Definition Window.hpp:43
bool ShouldClose()
True once the window has received a close request.
Definition Window.hpp:40
static int GetWidth()
Returns the current window width in pixels.
Definition Window.hpp:61
void Update()
Definition Window.cpp:87
bool GetIsFullScreen()
True if the window is currently fullscreen.
Definition Window.hpp:52
Window & operator=(const Window &)=delete
void ToggleFullScreen()
Flips between fullscreen and windowed mode.
Definition Window.hpp:50
std::string GetWindowTitle()
Returns the window title.
Definition Window.hpp:45
void Close()
Marks the window for close; actual teardown happens in the destructor.
Definition Window.cpp:200
Root namespace for everything the engine exposes.
Definition Camera.hpp:10