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
ToyMaker::WindowContext Class Reference

A class providing access to various window management methods and window event Signals. More...

#include <window_context_manager.hpp>

Public Member Functions

SDL_GLContext getGLContext () const
 Accessor for the OpenGL context pointer.
 
SDL_Window * getSDLWindow () const
 Accessor for the SDL Window pointer.
 
Assimp::Importer * getAssetImporter () const
 Accessor for asset importer (which for some reason is tied to this WindowContext)
 
void handleWindowEvent (const SDL_WindowEvent &windowEvent)
 Converts an SDL window event into its corresponding engine Signal equivalent, which it then broadcasts.
 
void swapBuffers ()
 Swaps the back and front buffers of the framebuffer associated with the application window.
 
const std::string & getTitle () const
 Gets the title of this window.
 
bool isMaximized () const
 Tests whether this window is maximized.
 
bool isMinimized () const
 Tests whether this window is minimized.
 
bool isResizable () const
 Tests whether this window is resizable.
 
bool isHidden () const
 Tests whether this window is hidden (as in, there is another window on top of it, or it is minimized (I think)).
 
bool isShown () const
 Tests whether this window is shown, inverse of hidden.
 
bool hasKeyFocus () const
 Tests whether this window has keyboard focus.
 
bool hasMouseFocus () const
 Tests whether this window has mouse focus.
 
bool hasCapturedMouse () const
 Tests whether this window has captured the mouse.
 
bool isFullscreen () const
 Tests whether this window is in fullscreen.
 
bool isExclusiveFullscreen () const
 Tests whether a fullscreen window is using exclusive fullscreen.
 
bool isBorderless () const
 Tests whether this window is using windowed borderless fullscreen.
 
int getDisplayID () const
 Gets the ID associated with the monitor this window is primarily being displayed on.
 
const glm::ivec2 getPosition () const
 Gets the position of this window (relative to the top left corner of the screen) in screen coordinates.
 
const glm::uvec2 getDimensions () const
 Gets the dimensions of this window (in pixels).
 
const glm::uvec2 getDimensionsMinimum () const
 Gets the minimum dimensions allowed for this window (in screen coordinates).
 
const glm::uvec2 getDimensionsMaximum () const
 Gets the maximum dimensions allowed for this window (in screen coordinates).
 
void setPosition (const glm::uvec2 &position)
 Sets the position of this window relative to the top left corner of the screen, in screen coordinates.
 
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 called).
 
void setResizeAllowed (bool allowed)
 Enables or disables the resizing of this window.
 
void setBorder (bool state)
 Adds or removes the border around this window.
 
void setHidden (bool hide)
 Sets this window's visibility.
 
void setTitle (const std::string &newTitle)
 Sets the title for this window.
 
void setDimensionsMinimum (const glm::uvec2 &dimensions)
 Sets the minimum allowable dimensions for this window in screen coordinates.
 
void setDimensionsMaximum (const glm::uvec2 &dimensions)
 Sets the maximum allowable dimensions for this window, in screen coordinates.
 
void setFullscreen (bool fullscreen, bool exclusive=false)
 Makes this window fullscreen.
 
void maximize ()
 Maximizes this window.
 
void minimize ()
 Minimizes this window.
 
void restore ()
 Restores this window (if it has been minimized).
 

Static Public Member Functions

static WindowContextgetInstance ()
 Gets this application's sole window instance.
 
static WindowContextinitialize (const nlohmann::json &initialWindowConfiguration)
 Initializes this window context with the settings specified in this project's project.json file.
 
static void clear ()
 Loses reference to the singleton window context, initiating its destruction.
 

Public Attributes

Signal mSigWindowResized { mSignalTracker, "WindowResized" }
 Signal emitted when this window's dimensions are changed.
 
Signal mSigWindowMaximized { mSignalTracker, "WindowMaximized" }
 Signal emitted when this window is maximized.
 
Signal mSigWindowMinimized { mSignalTracker, "WindowMinimized" }
 Signal emitted when this window is minimized.
 
Signal mSigWindowMoved { mSignalTracker, "WindowMoved" }
 Signal emitted when this window is repositioned.
 
Signal mSigWindowMouseEntered { mSignalTracker, "WindowMouseEntered" }
 Signal emitted when the mouse has entered this window.
 
Signal mSigWindowMouseExited { mSignalTracker, "WindowMouseExited" }
 Signal emitted when the mouse leaves this window.
 
Signal mSigWindowShown { mSignalTracker, "WindowShown" }
 Signal emitted when this window is shown.
 
Signal mSigWindowHidden { mSignalTracker, "WindowHidden" }
 Signal emitted when this window is hidden.
 
Signal mSigWindowExposed { mSignalTracker, "WindowExposed" }
 Signal emitted when this window is exposed.
 
Signal mSigWindowSizeChanged { mSignalTracker, "WindowSizeChanged" }
 Signal emitted when this window is resized.
 
Signal mSigWindowRestored { mSignalTracker, "WindowRestored" }
 Signal emitted when this window is restored (after being minimized).
 
Signal mSigWindowKeyFocusGained { mSignalTracker, "WindowKeyFocusGained" }
 Signal emitted when this window receives keyboard focus.
 
Signal mSigWindowKeyFocusLost { mSignalTracker, "WindowKeyFocusLost" }
 Signal emitted when this window loses keyboard focus.
 
Signal mSigWindowCloseRequested { mSignalTracker, "WindowClosed" }
 Signal emitted when the user attempts to close this window (by the X button in the window border usually).
 
Signal mSigWindowKeyFocusOffered { mSignalTracker, "WindowKeyFocusOffered" }
 Signal emitted when the application offers keyboard focus to the user.
 
Signal mSigWindowICCProfileChanged { mSignalTracker, "WindowICCProfileChanged" }
 I don't know what this is quite honestly.
 
Signal mSigWindowDisplayChanged { mSignalTracker, "WindowDisplayChanged" }
 Signal emitted when the window display changes.
 

Private Member Functions

void refreshWindowProperties ()
 Replaces currently cached window properties.
 
 WindowContext (const nlohmann::json &initialWindowConfiguration)
 Initializes SDL and OpenGL contexts, creates an SDL window and stores a reference to it.
 
 WindowContext (const WindowContext &other)=delete
 
 WindowContext (WindowContext &&other)=delete
 
WindowContextoperator= (const WindowContext &other)=delete
 
WindowContextoperator= (WindowContext &&other)=delete
 

Private Attributes

SignalTracker mSignalTracker {}
 The signal tracker responsible for publishing window related signals and tracking their observers.
 
SDL_Window * mpSDLWindow
 The SDL window handle this class is a wrapper over.
 
SDL_GLContext mpGLContext
 The OpenGL context associated with this window.
 
Assimp::Importer * mpAssetImporter
 The asset importer asset associated with this window (and therefore the whole project)
 
SDL_WindowFlags mCachedWindowFlags {}
 A number whose bits represent different modes a window can be in.
 
glm::i16vec2 mCachedWindowPosition {}
 The cached position of this window, in screen coordinates.
 
glm::u16vec2 mCachedWindowDimensions {}
 The cached dimensions of this window, in pixels.
 
glm::u16vec2 mCachedWindowMinimumDimensions {}
 The minimum allowed dimensions for this window, in screen coordinates.
 
glm::u16vec2 mCachedWindowMaximumDimensions {}
 The maximum allowed dimensions for this window, in screen coordinates.
 
int mCachedDisplayID {0}
 The ID of the display (or monitor) this window is rendered on.
 
std::string mCachedTitle {}
 The cached title of this window.
 

Static Private Attributes

static std::unique_ptr< WindowContexts_windowContextManager { nullptr }
 A pointer to the single static instance of the WindowContext associated with the application.
 

Detailed Description

A class providing access to various window management methods and window event Signals.

It is essentially a convenient wrapper over SDL_Window.

Member Function Documentation

◆ clear()

void WindowContext::clear ( )
static

Loses reference to the singleton window context, initiating its destruction.

Usually called as part of the application cleanup process.

◆ getDimensions()

const glm::uvec2 WindowContext::getDimensions ( ) const

Gets the dimensions of this window (in pixels).

Returns
const glm::uvec2 The dimensions of this window.

◆ getDimensionsMaximum()

const glm::uvec2 WindowContext::getDimensionsMaximum ( ) const

Gets the maximum dimensions allowed for this window (in screen coordinates).

Returns
const glm::uvec2 The maximum dimensions allowed for this window (in screen coordinates).
Todo
Compute and cache minimum window dimensions in pixels instead.

◆ getDimensionsMinimum()

const glm::uvec2 WindowContext::getDimensionsMinimum ( ) const

Gets the minimum dimensions allowed for this window (in screen coordinates).

Returns
const glm::uvec2 The minimum dimensions allowed for this window (in screen coordinates).
Todo
Compute and cache minimum window dimensions in pixels instead.

◆ getDisplayID()

int WindowContext::getDisplayID ( ) const

Gets the ID associated with the monitor this window is primarily being displayed on.

Returns
int The ID of the monitor this window is being displayed on.

◆ getInstance()

WindowContext & WindowContext::getInstance ( )
static

Gets this application's sole window instance.

Returns
WindowContext& This application's window.

◆ getPosition()

const glm::ivec2 WindowContext::getPosition ( ) const

Gets the position of this window (relative to the top left corner of the screen) in screen coordinates.

Returns
const glm::ivec2 The position of this window.
Todo
Compute and cache the window position in pixels instead.

◆ getTitle()

const std::string & WindowContext::getTitle ( ) const

Gets the title of this window.

Returns
const std::string& This window's title.
Todo
This shouldn't be returning a const reference.

◆ handleWindowEvent()

void WindowContext::handleWindowEvent ( const SDL_WindowEvent & windowEvent)

Converts an SDL window event into its corresponding engine Signal equivalent, which it then broadcasts.

Parameters
windowEventThe SDL window event to be converted.

◆ hasCapturedMouse()

bool WindowContext::hasCapturedMouse ( ) const

Tests whether this window has captured the mouse.

Return values
trueThis window has captured the mouse.
falseThis window has not captured the mouse.

◆ hasKeyFocus()

bool WindowContext::hasKeyFocus ( ) const

Tests whether this window has keyboard focus.

Return values
trueThis window has keyboard focus.
falseThis window does not have keyboard focus.

◆ hasMouseFocus()

bool WindowContext::hasMouseFocus ( ) const

Tests whether this window has mouse focus.

Return values
trueThis window has mouse focus.
falseThis window does not have mouse focus.

◆ initialize()

WindowContext & WindowContext::initialize ( const nlohmann::json & initialWindowConfiguration)
static

Initializes this window context with the settings specified in this project's project.json file.

Parameters
initialWindowConfigurationThe window configuration for this application.
Returns
WindowContext& The created window context.

◆ isBorderless()

bool WindowContext::isBorderless ( ) const

Tests whether this window is using windowed borderless fullscreen.

Return values
trueThis window is using windowed borderless fullscreen.
falseThis window is using exclusive fullscreen, or isn't in fullscreen at all.

◆ isExclusiveFullscreen()

bool WindowContext::isExclusiveFullscreen ( ) const

Tests whether a fullscreen window is using exclusive fullscreen.

Return values
trueThis window is using exclusive fullscreen.
falseThis window is using borderless window fullscreen or isn't in fullscreen at all.

◆ isFullscreen()

bool WindowContext::isFullscreen ( ) const

Tests whether this window is in fullscreen.

Return values
trueThis window is in full screen.
falseThis window is not in full screen.

◆ isHidden()

bool WindowContext::isHidden ( ) const

Tests whether this window is hidden (as in, there is another window on top of it, or it is minimized (I think)).

Return values
trueThis window is hidden.
falseThis window is not hidden.

◆ isMaximized()

bool WindowContext::isMaximized ( ) const

Tests whether this window is maximized.

Return values
trueThis window is maximized.
falseThis window is not maximized.

◆ isMinimized()

bool WindowContext::isMinimized ( ) const

Tests whether this window is minimized.

Return values
trueThis window is minimized.
falseThis window is not minimized.

◆ isResizable()

bool WindowContext::isResizable ( ) const

Tests whether this window is resizable.

Return values
trueThis window is resizable.
falseThis window is unresizable.

◆ isShown()

bool WindowContext::isShown ( ) const

Tests whether this window is shown, inverse of hidden.

Return values
trueThis window is shown.
falseThis window is not shown.
See also
isHidden()

◆ setBorder()

void WindowContext::setBorder ( bool state)

Adds or removes the border around this window.

Parameters
stateWhether the border is enabled or disabled.

◆ setDimensions()

void WindowContext::setDimensions ( const glm::uvec2 & dimensions)

Sets the width and height of the window, in pixels (since SDL_WINDOW_ALLOW_HIGHDPI ought to have been called).

Parameters
dimensionsThe new dimensions for this window.

◆ setDimensionsMaximum()

void WindowContext::setDimensionsMaximum ( const glm::uvec2 & dimensions)

Sets the maximum allowable dimensions for this window, in screen coordinates.

Parameters
dimensionsThis window's new maximum allowable dimensions.

◆ setDimensionsMinimum()

void WindowContext::setDimensionsMinimum ( const glm::uvec2 & dimensions)

Sets the minimum allowable dimensions for this window in screen coordinates.

Parameters
dimensionsThis window's new minimum allowable dimensions.

◆ setFullscreen()

void WindowContext::setFullscreen ( bool fullscreen,
bool exclusive = false )

Makes this window fullscreen.

Parameters
fullscreenWhether or not to enable fullscreen.
exclusiveUse exclusive fullscreen, borderless windowed mode otherwise.

◆ setHidden()

void WindowContext::setHidden ( bool hide)

Sets this window's visibility.

Parameters
hideWhether to hide or show this window.

◆ setPosition()

void WindowContext::setPosition ( const glm::uvec2 & position)

Sets the position of this window relative to the top left corner of the screen, in screen coordinates.

Parameters
positionThe new position of this window.
Todo
Have position be specified in pixels instead.

◆ setResizeAllowed()

void WindowContext::setResizeAllowed ( bool allowed)

Enables or disables the resizing of this window.

Parameters
allowedWhether this window should be resizable.

◆ setTitle()

void WindowContext::setTitle ( const std::string & newTitle)

Sets the title for this window.

Parameters
newTitleThis window's new title.

Member Data Documentation

◆ mCachedWindowMaximumDimensions

glm::u16vec2 ToyMaker::WindowContext::mCachedWindowMaximumDimensions {}
private

The maximum allowed dimensions for this window, in screen coordinates.

Todo
Make it so that this is stored in pixels instead, somehow.

◆ mCachedWindowMinimumDimensions

glm::u16vec2 ToyMaker::WindowContext::mCachedWindowMinimumDimensions {}
private

The minimum allowed dimensions for this window, in screen coordinates.

Todo
Make it so that this is stored in pixels instead, somehow.

◆ mCachedWindowPosition

glm::i16vec2 ToyMaker::WindowContext::mCachedWindowPosition {}
private

The cached position of this window, in screen coordinates.

Todo
Make it so that this is stored in pixels instead, somehow.

◆ mpAssetImporter

Assimp::Importer* ToyMaker::WindowContext::mpAssetImporter
private

The asset importer asset associated with this window (and therefore the whole project)

Todo
move this out of the window context manager, or move window management itself into a class with a smaller scope.

◆ mpGLContext

SDL_GLContext ToyMaker::WindowContext::mpGLContext
private

The OpenGL context associated with this window.

Todo
move this out of the window context manager, or move window management itself into a class with a smaller scope.

◆ mSigWindowDisplayChanged

Signal ToyMaker::WindowContext::mSigWindowDisplayChanged { mSignalTracker, "WindowDisplayChanged" }

Signal emitted when the window display changes.

Todo
Figure out what this means.

◆ mSigWindowICCProfileChanged

Signal ToyMaker::WindowContext::mSigWindowICCProfileChanged { mSignalTracker, "WindowICCProfileChanged" }

I don't know what this is quite honestly.

Todo
Figure out what this means.

◆ mSigWindowSizeChanged

Signal ToyMaker::WindowContext::mSigWindowSizeChanged { mSignalTracker, "WindowSizeChanged" }

Signal emitted when this window is resized.

Todo
Figure out how this is related with mSigWindowResized()

◆ s_windowContextManager

std::unique_ptr<WindowContext> ToyMaker::WindowContext::s_windowContextManager { nullptr }
inlinestaticprivate

A pointer to the single static instance of the WindowContext associated with the application.

Todo
Eventually support multi-window applications.

The documentation for this class was generated from the following files: