ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
window_context_manager.hpp
Go to the documentation of this file.
1
11
12#ifndef FOOLSENGINE_WINDOWCONTEXT_H
13#define FOOLSENGINE_WINDOWCONTEXT_H
14
15#include <memory>
16
17#include <SDL3/SDL.h>
18#include <GL/glew.h>
19
20#include <assimp/Importer.hpp>
21
22#include <nlohmann/json.hpp>
23#include <glm/glm.hpp>
24
25#include "signals.hpp"
26
27namespace ToyMaker {
28
36 class WindowContext {
42 public:
43 /* Deletes SDL and GL contexts */
45
51 static WindowContext& getInstance();
52
53 WindowContext() = delete;
54
58 SDL_GLContext getGLContext() const;
62 SDL_Window* getSDLWindow() const;
66 Assimp::Importer* getAssetImporter() const;
67
73 void handleWindowEvent(const SDL_WindowEvent& windowEvent);
74
81 static WindowContext& initialize(const nlohmann::json& initialWindowConfiguration);
82
89 static void clear();
90
95 void swapBuffers();
96
104 const std::string& getTitle() const;
105
112 bool isMaximized() const;
113
120 bool isMinimized() const;
121
128 bool isResizable() const;
129
136 bool isHidden() const;
137
146 bool isShown() const;
147
154 bool hasKeyFocus() const;
155
162 bool hasMouseFocus() const;
163
170 bool hasCapturedMouse() const;
171
178 bool isFullscreen() const;
179
186 bool isExclusiveFullscreen() const;
187
194 bool isBorderless() const;
195
201 int getDisplayID() const;
202
210 const glm::ivec2 getPosition() const;
211
217 const glm::uvec2 getDimensions() const;
218
226 const glm::uvec2 getDimensionsMinimum() const;
234 const glm::uvec2 getDimensionsMaximum() const;
235
243 void setPosition(const glm::uvec2& position);
244
250 void setDimensions(const glm::uvec2& dimensions);
251
257 void setResizeAllowed(bool allowed);
258
264 void setBorder(bool state);
265
271 void setHidden(bool hide);
272
278 void setTitle(const std::string& newTitle);
279
285 void setDimensionsMinimum(const glm::uvec2& dimensions);
286
292 void setDimensionsMaximum(const glm::uvec2& dimensions);
293
299 void setFullscreen(bool fullscreen);
300
305 void maximize();
306
311 void minimize();
312
317 void restore();
318
324
330
336
342
348
354
360
366
372
380
386
392
398
404
410
418
426
427 private:
433
438 WindowContext(const nlohmann::json& initialWindowConfiguration);
439
440 // non copyable
441 WindowContext(const WindowContext& other) = delete;
442 // non moveable
443 WindowContext(WindowContext&& other) = delete;
444 // non copy-assignable
445 WindowContext& operator=(const WindowContext& other) = delete;
446 // non move-assignable
447 WindowContext& operator=(WindowContext&& other) = delete;
448
453 SDL_Window* mpSDLWindow;
454
461 SDL_GLContext mpGLContext;
462
469 Assimp::Importer* mpAssetImporter;
470
475 SDL_WindowFlags mCachedWindowFlags {};
476
482 SDL_DisplayMode* const mDisplayMode {};
483
489 glm::i16vec2 mCachedWindowPosition {};
490
495 glm::u16vec2 mCachedWindowDimensions {};
496
504
512
518
523 std::string mCachedTitle {};
524
530 inline static std::unique_ptr<WindowContext> s_windowContextManager { nullptr };
531 };
532}
533
534#endif
A signal tracker, the main interface between an object and the signal system.
Definition signals.hpp:161
A Signal object, designed to emit signals matching some data signature to be received by all the Sign...
Definition signals.hpp:323
A class providing access to various window management methods and window event Signals.
Definition window_context_manager.hpp:36
const std::string & getTitle() const
Gets the title of this window.
Definition window_context_manager.cpp:219
const glm::uvec2 getDimensionsMinimum() const
Gets the minimum dimensions allowed for this window (in screen coordinates).
Definition window_context_manager.cpp:213
void refreshWindowProperties()
Replaces currently cached window properties.
Definition window_context_manager.cpp:158
bool hasCapturedMouse() const
Tests whether this window has captured the mouse.
Definition window_context_manager.cpp:183
Signal mSigWindowSizeChanged
Signal emitted when this window is resized.
Definition window_context_manager.hpp:379
SDL_DisplayMode *const mDisplayMode
Immutable pointer to the current display mode for this window, whose data is managed by SDL.
Definition window_context_manager.hpp:482
void restore()
Restores this window (if it has been minimized).
Definition window_context_manager.cpp:251
Signal mSigWindowDisplayChanged
Signal emitted when the window display changes.
Definition window_context_manager.hpp:425
void setDimensions(const glm::uvec2 &dimensions)
Sets the width and height of the window, in pixels (since SDL_WINDOW_ALLOW_HIGHDPI ought to have been...
Definition window_context_manager.cpp:227
Assimp::Importer * getAssetImporter() const
Accessor for asset importer (which for some reason is tied to this WindowContext)
Definition window_context_manager.cpp:285
glm::u16vec2 mCachedWindowMinimumDimensions
The minimum allowed dimensions for this window, in screen coordinates.
Definition window_context_manager.hpp:503
Signal mSigWindowMouseExited
Signal emitted when the mouse leaves this window.
Definition window_context_manager.hpp:353
bool isBorderless() const
Tests whether this window is using windowed borderless fullscreen.
Definition window_context_manager.cpp:189
Signal mSigWindowShown
Signal emitted when this window is shown.
Definition window_context_manager.hpp:359
SDL_GLContext getGLContext() const
Accessor for the OpenGL context pointer.
Definition window_context_manager.cpp:277
const glm::uvec2 getDimensionsMaximum() const
Gets the maximum dimensions allowed for this window (in screen coordinates).
Definition window_context_manager.cpp:216
bool isFullscreen() const
Tests whether this window is in fullscreen.
Definition window_context_manager.cpp:192
glm::i16vec2 mCachedWindowPosition
The cached position of this window, in screen coordinates.
Definition window_context_manager.hpp:489
static void clear()
Loses reference to the singleton window context, initiating its destruction.
Definition window_context_manager.cpp:154
void maximize()
Maximizes this window.
Definition window_context_manager.cpp:243
bool isMaximized() const
Tests whether this window is maximized.
Definition window_context_manager.cpp:168
bool hasMouseFocus() const
Tests whether this window has mouse focus.
Definition window_context_manager.cpp:186
SDL_Window * mpSDLWindow
The SDL window handle this class is a wrapper over.
Definition window_context_manager.hpp:453
static WindowContext & initialize(const nlohmann::json &initialWindowConfiguration)
Initializes this window context with the settings specified in this project's project....
Definition window_context_manager.cpp:143
static WindowContext & getInstance()
Gets this application's sole window instance.
Definition window_context_manager.cpp:149
static std::unique_ptr< WindowContext > s_windowContextManager
A pointer to the single static instance of the WindowContext associated with the application.
Definition window_context_manager.hpp:530
const glm::uvec2 getDimensions() const
Gets the dimensions of this window (in pixels).
Definition window_context_manager.cpp:210
void handleWindowEvent(const SDL_WindowEvent &windowEvent)
Converts an SDL window event into its corresponding engine Signal equivalent, which it then broadcast...
Definition window_context_manager.cpp:87
Signal mSigWindowCloseRequested
Signal emitted when the user attempts to close this window (by the X button in the window border usua...
Definition window_context_manager.hpp:403
Signal mSigWindowKeyFocusGained
Signal emitted when this window receives keyboard focus.
Definition window_context_manager.hpp:391
Signal mSigWindowHidden
Signal emitted when this window is hidden.
Definition window_context_manager.hpp:365
Signal mSigWindowMinimized
Signal emitted when this window is minimized.
Definition window_context_manager.hpp:335
Signal mSigWindowExposed
Signal emitted when this window is exposed.
Definition window_context_manager.hpp:371
void setFullscreen(bool fullscreen)
Makes this window fullscreen.
Definition window_context_manager.cpp:272
SignalTracker mSignalTracker
The signal tracker responsible for publishing window related signals and tracking their observers.
Definition window_context_manager.hpp:41
Assimp::Importer * mpAssetImporter
The asset importer asset associated with this window (and therefore the whole project)
Definition window_context_manager.hpp:469
bool isMinimized() const
Tests whether this window is minimized.
Definition window_context_manager.cpp:171
bool isExclusiveFullscreen() const
Tests whether a fullscreen window is using exclusive fullscreen.
Definition window_context_manager.cpp:195
bool hasKeyFocus() const
Tests whether this window has keyboard focus.
Definition window_context_manager.cpp:180
void swapBuffers()
Swaps the back and front buffers of the framebuffer associated with the application window.
Definition window_context_manager.cpp:83
Signal mSigWindowResized
Signal emitted when this window's dimensions are changed.
Definition window_context_manager.hpp:323
Signal mSigWindowMaximized
Signal emitted when this window is maximized.
Definition window_context_manager.hpp:329
void setTitle(const std::string &newTitle)
Sets the title for this window.
Definition window_context_manager.cpp:259
glm::u16vec2 mCachedWindowMaximumDimensions
The maximum allowed dimensions for this window, in screen coordinates.
Definition window_context_manager.hpp:511
int getDisplayID() const
Gets the ID associated with the monitor this window is primarily being displayed on.
Definition window_context_manager.cpp:204
std::string mCachedTitle
The cached title of this window.
Definition window_context_manager.hpp:523
SDL_GLContext mpGLContext
The OpenGL context associated with this window.
Definition window_context_manager.hpp:461
Signal mSigWindowKeyFocusOffered
Signal emitted when the application offers keyboard focus to the user.
Definition window_context_manager.hpp:409
SDL_WindowFlags mCachedWindowFlags
A number whose bits represent different modes a window can be in.
Definition window_context_manager.hpp:475
void setResizeAllowed(bool allowed)
Enables or disables the resizing of this window.
Definition window_context_manager.cpp:231
bool isShown() const
Tests whether this window is shown, inverse of hidden.
Definition window_context_manager.cpp:201
void setBorder(bool state)
Adds or removes the border around this window.
Definition window_context_manager.cpp:255
bool isHidden() const
Tests whether this window is hidden (as in, there is another window on top of it, or it is minimized ...
Definition window_context_manager.cpp:177
void setDimensionsMaximum(const glm::uvec2 &dimensions)
Sets the maximum allowable dimensions for this window, in screen coordinates.
Definition window_context_manager.cpp:239
void minimize()
Minimizes this window.
Definition window_context_manager.cpp:247
int mCachedDisplayID
The ID of the display (or monitor) this window is rendered on.
Definition window_context_manager.hpp:517
void setDimensionsMinimum(const glm::uvec2 &dimensions)
Sets the minimum allowable dimensions for this window in screen coordinates.
Definition window_context_manager.cpp:235
Signal mSigWindowKeyFocusLost
Signal emitted when this window loses keyboard focus.
Definition window_context_manager.hpp:397
SDL_Window * getSDLWindow() const
Accessor for the SDL Window pointer.
Definition window_context_manager.cpp:281
Signal mSigWindowICCProfileChanged
I don't know what this is quite honestly.
Definition window_context_manager.hpp:417
const glm::ivec2 getPosition() const
Gets the position of this window (relative to the top left corner of the screen) in screen coordinate...
Definition window_context_manager.cpp:207
Signal mSigWindowMouseEntered
Signal emitted when the mouse has entered this window.
Definition window_context_manager.hpp:347
bool isResizable() const
Tests whether this window is resizable.
Definition window_context_manager.cpp:174
void setPosition(const glm::uvec2 &position)
Sets the position of this window relative to the top left corner of the screen, in screen coordinates...
Definition window_context_manager.cpp:223
void setHidden(bool hide)
Sets this window's visibility.
Definition window_context_manager.cpp:263
glm::u16vec2 mCachedWindowDimensions
The cached dimensions of this window, in pixels.
Definition window_context_manager.hpp:495
Signal mSigWindowMoved
Signal emitted when this window is repositioned.
Definition window_context_manager.hpp:341
Signal mSigWindowRestored
Signal emitted when this window is restored (after being minimized).
Definition window_context_manager.hpp:385
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:24
Classes relating to this engine's implementation of signals. Contains template classes used to define...