Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
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 <SDL2/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
300 void setFullscreen(bool fullscreen, bool exclusive=false);
301
306 void maximize();
307
312 void minimize();
313
318 void restore();
319
325
331
337
343
349
355
361
367
373
381
387
393
399
405
411
419
427
428 private:
434
439 WindowContext(const nlohmann::json& initialWindowConfiguration);
440
441 // non copyable
442 WindowContext(const WindowContext& other) = delete;
443 // non moveable
444 WindowContext(WindowContext&& other) = delete;
445 // non copy-assignable
446 WindowContext& operator=(const WindowContext& other) = delete;
447 // non move-assignable
448 WindowContext& operator=(WindowContext&& other) = delete;
449
454 SDL_Window* mpSDLWindow;
455
462 SDL_GLContext mpGLContext;
463
470 Assimp::Importer* mpAssetImporter;
471
476 SDL_WindowFlags mCachedWindowFlags {};
477
483 glm::i16vec2 mCachedWindowPosition {};
484
489 glm::u16vec2 mCachedWindowDimensions {};
490
498
506
512
517 std::string mCachedTitle {};
518
524 inline static std::unique_ptr<WindowContext> s_windowContextManager { nullptr };
525 };
526}
527
528#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:237
const glm::uvec2 getDimensionsMinimum() const
Gets the minimum dimensions allowed for this window (in screen coordinates).
Definition window_context_manager.cpp:231
void refreshWindowProperties()
Replaces currently cached window properties.
Definition window_context_manager.cpp:177
bool hasCapturedMouse() const
Tests whether this window has captured the mouse.
Definition window_context_manager.cpp:202
Signal mSigWindowSizeChanged
Signal emitted when this window is resized.
Definition window_context_manager.hpp:380
void setFullscreen(bool fullscreen, bool exclusive=false)
Makes this window fullscreen.
Definition window_context_manager.cpp:290
void restore()
Restores this window (if it has been minimized).
Definition window_context_manager.cpp:269
Signal mSigWindowDisplayChanged
Signal emitted when the window display changes.
Definition window_context_manager.hpp:426
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:245
Assimp::Importer * getAssetImporter() const
Accessor for asset importer (which for some reason is tied to this WindowContext)
Definition window_context_manager.cpp:307
glm::u16vec2 mCachedWindowMinimumDimensions
The minimum allowed dimensions for this window, in screen coordinates.
Definition window_context_manager.hpp:497
Signal mSigWindowMouseExited
Signal emitted when the mouse leaves this window.
Definition window_context_manager.hpp:354
bool isBorderless() const
Tests whether this window is using windowed borderless fullscreen.
Definition window_context_manager.cpp:208
Signal mSigWindowShown
Signal emitted when this window is shown.
Definition window_context_manager.hpp:360
SDL_GLContext getGLContext() const
Accessor for the OpenGL context pointer.
Definition window_context_manager.cpp:299
const glm::uvec2 getDimensionsMaximum() const
Gets the maximum dimensions allowed for this window (in screen coordinates).
Definition window_context_manager.cpp:234
bool isFullscreen() const
Tests whether this window is in fullscreen.
Definition window_context_manager.cpp:211
glm::i16vec2 mCachedWindowPosition
The cached position of this window, in screen coordinates.
Definition window_context_manager.hpp:483
static void clear()
Loses reference to the singleton window context, initiating its destruction.
Definition window_context_manager.cpp:173
void maximize()
Maximizes this window.
Definition window_context_manager.cpp:261
bool isMaximized() const
Tests whether this window is maximized.
Definition window_context_manager.cpp:187
bool hasMouseFocus() const
Tests whether this window has mouse focus.
Definition window_context_manager.cpp:205
SDL_Window * mpSDLWindow
The SDL window handle this class is a wrapper over.
Definition window_context_manager.hpp:454
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:162
static WindowContext & getInstance()
Gets this application's sole window instance.
Definition window_context_manager.cpp:168
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:524
const glm::uvec2 getDimensions() const
Gets the dimensions of this window (in pixels).
Definition window_context_manager.cpp:228
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:101
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:404
Signal mSigWindowKeyFocusGained
Signal emitted when this window receives keyboard focus.
Definition window_context_manager.hpp:392
Signal mSigWindowHidden
Signal emitted when this window is hidden.
Definition window_context_manager.hpp:366
Signal mSigWindowMinimized
Signal emitted when this window is minimized.
Definition window_context_manager.hpp:336
Signal mSigWindowExposed
Signal emitted when this window is exposed.
Definition window_context_manager.hpp:372
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:470
bool isMinimized() const
Tests whether this window is minimized.
Definition window_context_manager.cpp:190
bool isExclusiveFullscreen() const
Tests whether a fullscreen window is using exclusive fullscreen.
Definition window_context_manager.cpp:214
bool hasKeyFocus() const
Tests whether this window has keyboard focus.
Definition window_context_manager.cpp:199
void swapBuffers()
Swaps the back and front buffers of the framebuffer associated with the application window.
Definition window_context_manager.cpp:97
Signal mSigWindowResized
Signal emitted when this window's dimensions are changed.
Definition window_context_manager.hpp:324
Signal mSigWindowMaximized
Signal emitted when this window is maximized.
Definition window_context_manager.hpp:330
void setTitle(const std::string &newTitle)
Sets the title for this window.
Definition window_context_manager.cpp:277
glm::u16vec2 mCachedWindowMaximumDimensions
The maximum allowed dimensions for this window, in screen coordinates.
Definition window_context_manager.hpp:505
int getDisplayID() const
Gets the ID associated with the monitor this window is primarily being displayed on.
Definition window_context_manager.cpp:222
std::string mCachedTitle
The cached title of this window.
Definition window_context_manager.hpp:517
SDL_GLContext mpGLContext
The OpenGL context associated with this window.
Definition window_context_manager.hpp:462
Signal mSigWindowKeyFocusOffered
Signal emitted when the application offers keyboard focus to the user.
Definition window_context_manager.hpp:410
SDL_WindowFlags mCachedWindowFlags
A number whose bits represent different modes a window can be in.
Definition window_context_manager.hpp:476
void setResizeAllowed(bool allowed)
Enables or disables the resizing of this window.
Definition window_context_manager.cpp:249
bool isShown() const
Tests whether this window is shown, inverse of hidden.
Definition window_context_manager.cpp:219
void setBorder(bool state)
Adds or removes the border around this window.
Definition window_context_manager.cpp:273
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:196
void setDimensionsMaximum(const glm::uvec2 &dimensions)
Sets the maximum allowable dimensions for this window, in screen coordinates.
Definition window_context_manager.cpp:257
void minimize()
Minimizes this window.
Definition window_context_manager.cpp:265
int mCachedDisplayID
The ID of the display (or monitor) this window is rendered on.
Definition window_context_manager.hpp:511
void setDimensionsMinimum(const glm::uvec2 &dimensions)
Sets the minimum allowable dimensions for this window in screen coordinates.
Definition window_context_manager.cpp:253
Signal mSigWindowKeyFocusLost
Signal emitted when this window loses keyboard focus.
Definition window_context_manager.hpp:398
SDL_Window * getSDLWindow() const
Accessor for the SDL Window pointer.
Definition window_context_manager.cpp:303
Signal mSigWindowICCProfileChanged
I don't know what this is quite honestly.
Definition window_context_manager.hpp:418
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:225
Signal mSigWindowMouseEntered
Signal emitted when the mouse has entered this window.
Definition window_context_manager.hpp:348
bool isResizable() const
Tests whether this window is resizable.
Definition window_context_manager.cpp:193
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:241
void setHidden(bool hide)
Sets this window's visibility.
Definition window_context_manager.cpp:281
glm::u16vec2 mCachedWindowDimensions
The cached dimensions of this window, in pixels.
Definition window_context_manager.hpp:489
Signal mSigWindowMoved
Signal emitted when this window is repositioned.
Definition window_context_manager.hpp:342
Signal mSigWindowRestored
Signal emitted when this window is restored (after being minimized).
Definition window_context_manager.hpp:386
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
Classes relating to this engine's implementation of signals. Contains template classes used to define...