GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::graphics::Window Class Reference

Graphical window that can be rendered to. More...

#include <GREM/graphics/Window.hpp>

Public Member Functions

 Window (const WindowOptions &options)
 Create a new standalone window.
 Window (Window &parent, const WindowOptions &options)
 Create a new child window.
 ~Window ()=default
 Destructor.
 Window (const Window &)=delete
 Copying a window is not allowed, since it manages global state.
 Window (Window &&)=delete
 Moving a window is not allowed, since it manages global state.
Window & operator= (const Window &)=delete
 Copying a window is not allowed, since it manages global state.
Window & operator= (Window &&)=delete
 Moving a window is not allowed, since it manages global state.
void setParent (Window *newParent)
 Set the parent window of the window.
void setIcon (const resource::ImageView &newIconImage)
 Set the icon of the window.
void setTitle (CStringView newTitle)
 Set the displayed title of the window.
void setPosition (Offset2D newPosition)
 Set the position of the window in the windowing system.
void setSize (Extent2D newSize)
 Set the size of the window.
void setOpacity (float newOpacity)
 Set the opacity of the window.
void show (bool activate=true)
 Show the window.
void hide ()
 Hide the window.
void raise ()
 Request the window to be raised above other windows and gain focus.
void minimize ()
 Request the window to be minimized to the taskbar.
void setResizable (bool newResizable)
 Set whether to allow the window to be resized by the user or not.
void setFullscreen (bool newFullscreen)
 Set the fullscreen state of the window.
void setFullscreenDisplayMode (Optional< DisplayMode > newDisplayMode)
 Set the display mode that will be used in fullscreen for this window if the window is not resizable.
void setRelativeMouseMode (bool newRelativeMouseMode)
 Enable or disable relative mouse mode for this window.
void setTextInputArea (const Region2D &area, int32_t cursorOffset)
 Set the window's input area for text input.
void startTextInput ()
 Start accepting text input events in the current text input rectangle.
void stopTextInput ()
 Stop accepting text input events.
bool isTextInputActive () const
 Check if text input events are currently being accepted.
bool hasScreenKeyboardSupport () const
 Check if the application supports a screen keyboard.
bool isScreenKeyboardShown () const
 Check if the screen keyboard is currently open.
bool isHighPixelDensity () const
 Check if the window's backbuffer is high pixel density.
bool hasFocus () const
 Check if the window currently has input focus.
bool isMinimized () const
 Check if the window is currently minimized.
bool isResizable () const
 Check if the window is currently resizable.
bool isFullscreen () const
 Check if the window is currently in fullscreen mode.
Window * getParent () const
 Get the parent of the window.
Offset2D getPosition () const
 Get the position of the window as reported by the windowing system.
Extent2D getSize () const
 Get the size of the window.
Extent2D getDrawableSize () const
 Get the drawable size of the window.
uint32_t getMultisampleCount () const
 Get the number of samples used for multisample anti-aliasing (MSAA) when rendering to the window.
float getDisplayScale () const
 Get the content display scale relative to the window's pixel size.
float getOpacity () const
 Get the opacity of the window.
Display getDisplay () const
 Get the display that this window is associated with.
Optional< DisplayMode > getFullscreenDisplayMode () const
 Get the fullscreen display mode of the window.
uint32_t getID () const
 Get a unique identifier for this window.
void * getNativeHandle ()
 Get a pointer to the native handle of the window, if available for the current platform.
const void * getNativeHandle () const
 Get a pointer to the native handle of the window, if available for the current platform.
void * get () noexcept
 Get an opaque pointer to the internal representation of the window.
const void * get () const noexcept
 Get an opaque pointer to the internal representation of the window.
void * getSurface () noexcept
 Get an opaque pointer to the internal representation of the window surface.
const void * getSurface () const noexcept
 Get an opaque pointer to the internal representation of the window surface.

Static Public Member Functions

static Window * getFocused ()
 Get the window that currently has keyboard focus.
static Window * findByID (uint32_t id)
 Get the window with a specific identifier.

Detailed Description

Graphical window that can be rendered to.

Constructor & Destructor Documentation

◆ Window() [1/4]

grem::graphics::Window::Window ( const WindowOptions & options)
explicit

Create a new standalone window.

Parameters
optionsinitial configuration of the window, see WindowOptions.
Exceptions
graphics::Errorif context or window setup failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ Window() [2/4]

grem::graphics::Window::Window ( Window & parent,
const WindowOptions & options )

Create a new child window.

Parameters
parentparent window to create this window from.
optionsinitial configuration of the window, see WindowOptions.
Exceptions
graphics::Errorif context or window setup failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ ~Window()

grem::graphics::Window::~Window ( )
default

Destructor.

◆ Window() [3/4]

grem::graphics::Window::Window ( const Window & )
delete

Copying a window is not allowed, since it manages global state.

◆ Window() [4/4]

grem::graphics::Window::Window ( Window && )
delete

Moving a window is not allowed, since it manages global state.

Member Function Documentation

◆ getFocused()

Window * grem::graphics::Window::getFocused ( )
staticnodiscard

Get the window that currently has keyboard focus.

Returns
a non-owning pointer to the window that currently has focus, or nullptr if no window that this application controls has focus.

◆ findByID()

Window * grem::graphics::Window::findByID ( uint32_t id)
staticnodiscard

Get the window with a specific identifier.

Parameters
ididentifier to get the window of.
Returns
a non-owning pointer to the window with the given identifier, or nullptr if no window with the given identifier exists.

◆ operator=() [1/2]

Window & grem::graphics::Window::operator= ( const Window & )
delete

Copying a window is not allowed, since it manages global state.

◆ operator=() [2/2]

Window & grem::graphics::Window::operator= ( Window && )
delete

Moving a window is not allowed, since it manages global state.

◆ setParent()

void grem::graphics::Window::setParent ( Window * newParent)

Set the parent window of the window.

Parameters
newParentwindow to parent the window to, or nullptr to make the window standalone. Must not be a current sibling or child of this window.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
Window(Parent&, const WindowOptions&)
getParent()

◆ setIcon()

void grem::graphics::Window::setIcon ( const resource::ImageView & newIconImage)

Set the icon of the window.

Parameters
newIconImagenew icon image to set. Should be a 2D image in resource::ImageFormat::R8G8B8A8_UINT format in sRGB color.
Exceptions
graphics::Erroron failure, or if the image type/size/format is invalid.
std::bad_allocon allocation failure.

◆ setTitle()

void grem::graphics::Window::setTitle ( CStringView newTitle)

Set the displayed title of the window.

Parameters
newTitlenull-terminated UTF-8 string containing the title.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
WindowOptions::title
getTitle()

◆ setPosition()

void grem::graphics::Window::setPosition ( Offset2D newPosition)

Set the position of the window in the windowing system.

Parameters
newPositionnew position of the window.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
getPosition()

◆ setSize()

void grem::graphics::Window::setSize ( Extent2D newSize)

Set the size of the window.

Parameters
newSizenew size of the window, in screen coordinates (typically pixels). Both the width and height must be positive.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
WindowOptions::size
getSize()

◆ setOpacity()

void grem::graphics::Window::setOpacity ( float newOpacity)

Set the opacity of the window.

Parameters
newOpacitynew opacity of the window, from 0 (transparent) to 1 (opaque).
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
WindowOptions::opacity
getOpacity()

◆ show()

void grem::graphics::Window::show ( bool activate = true)

Show the window.

Parameters
activatewhether the window should be activated when shown or not.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
WindowOptions::hidden
hide()
raise()

◆ hide()

void grem::graphics::Window::hide ( )

Hide the window.

Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
WindowOptions::hidden
show()

◆ raise()

void grem::graphics::Window::raise ( )

Request the window to be raised above other windows and gain focus.

Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
show()
hasFocus()

◆ minimize()

void grem::graphics::Window::minimize ( )

Request the window to be minimized to the taskbar.

Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
WindowOptions::minimized
isMinimized()

◆ setResizable()

void grem::graphics::Window::setResizable ( bool newResizable)

Set whether to allow the window to be resized by the user or not.

Parameters
newResizabletrue to allow resizing, false to disallow.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
WindowOptions::resizable
isResizable()

◆ setFullscreen()

void grem::graphics::Window::setFullscreen ( bool newFullscreen)

Set the fullscreen state of the window.

Parameters
newFullscreentrue for fullscreen mode, false for windowed mode.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
Note
If the window is resizable, the fullscreen display mode will be the desktop mode of the window's associated display. Otherwise, the fullscreen display mode will be the one set using setFullscreenDisplayMode().
See also
WindowOptions::fullscreen
isFullscreen()
setFullscreenDisplayMode()

◆ setFullscreenDisplayMode()

void grem::graphics::Window::setFullscreenDisplayMode ( Optional< DisplayMode > newDisplayMode)

Set the display mode that will be used in fullscreen for this window if the window is not resizable.

Parameters
newDisplayModethe display mode to use in fullscreen, or an empty optional for borderless desktop display mode.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
Note
The effect of this function will only be visible after calling setFullscreen(true) while the window is not resizable.
See also
setFullscreen()
getFullscreenDisplayMode()

◆ setRelativeMouseMode()

void grem::graphics::Window::setRelativeMouseMode ( bool newRelativeMouseMode)

Enable or disable relative mouse mode for this window.

When relative mouse mode is enabled, it hides the mouse cursor, locks it to the window and causes all further mouse motion to be provided as relative motion events until it is disabled again.

Parameters
newRelativeMouseModetrue to enable relative mouse mode, false to disable.
Exceptions
graphics::Erroron failure to set the relative mouse mode.
std::bad_allocon allocation failure.
See also
WindowOptions::relativeMouseMode

◆ setTextInputArea()

void grem::graphics::Window::setTextInputArea ( const Region2D & area,
int32_t cursorOffset )

Set the window's input area for text input.

Parameters
areainput area rectangle, in screen coordinates.
cursorOffsethorizontal offset of the cursor from area.offset.x, in screen coordinates.
Exceptions
graphics::Erroron failure to set the input area.
std::bad_allocon allocation failure.
See also
startTextInput()
stopTextInput()
isTextInputActive()

◆ startTextInput()

void grem::graphics::Window::startTextInput ( )

Start accepting text input events in the current text input rectangle.

See also
setTextInputArea()
stopTextInput()
isTextInputActive()
Exceptions
graphics::Erroron failure to start text input.
std::bad_allocon allocation failure.

◆ stopTextInput()

void grem::graphics::Window::stopTextInput ( )

Stop accepting text input events.

See also
setTextInputArea()
startTextInput()
isTextInputActive()
Exceptions
graphics::Erroron failure to stop text input.
std::bad_allocon allocation failure.

◆ isTextInputActive()

bool grem::graphics::Window::isTextInputActive ( ) const
nodiscard

Check if text input events are currently being accepted.

Returns
true if text input is active, false otherwise.
See also
setTextInputArea()
startTextInput()
stopTextInput()

◆ hasScreenKeyboardSupport()

bool grem::graphics::Window::hasScreenKeyboardSupport ( ) const
nodiscard

Check if the application supports a screen keyboard.

Returns
true if a screen keyboard is supported, false otherwise.
See also
isScreenKeyboardShown()

◆ isScreenKeyboardShown()

bool grem::graphics::Window::isScreenKeyboardShown ( ) const
nodiscard

Check if the screen keyboard is currently open.

Returns
true if the screen keyboard is open, false otherwise.
See also
hasScreenKeyboardSupport()

◆ isHighPixelDensity()

bool grem::graphics::Window::isHighPixelDensity ( ) const
nodiscard

Check if the window's backbuffer is high pixel density.

Returns
true if the window's backbuffer is high pixel density, false otherwise.
See also
WindowOptions::highPixelDensity

◆ hasFocus()

bool grem::graphics::Window::hasFocus ( ) const
nodiscard

Check if the window currently has input focus.

Returns
true if the window has focus, false otherwise.
See also
WindowOptions::focus
raise()

◆ isMinimized()

bool grem::graphics::Window::isMinimized ( ) const
nodiscard

Check if the window is currently minimized.

Returns
true if the window is minimized, false otherwise.
See also
minimize()

◆ isResizable()

bool grem::graphics::Window::isResizable ( ) const
nodiscard

Check if the window is currently resizable.

Returns
true if the window is resizable, false otherwise.
See also
setResizable()

◆ isFullscreen()

bool grem::graphics::Window::isFullscreen ( ) const
nodiscard

Check if the window is currently in fullscreen mode.

Returns
true if the window is in fullscreen mode, false otherwise.
See also
setFullscreen()
setFullscreenDisplayMode()

◆ getParent()

Window * grem::graphics::Window::getParent ( ) const
nodiscard

Get the parent of the window.

Returns
a non-owning pointer to the current parent window, or nullptr if the window has no parent.
See also
setParent()

◆ getPosition()

Offset2D grem::graphics::Window::getPosition ( ) const
nodiscard

Get the position of the window as reported by the windowing system.

Returns
the current position of the window.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.

◆ getSize()

Extent2D grem::graphics::Window::getSize ( ) const
nodiscard

Get the size of the window.

Returns
the current size of the window, in screen coordinates (typically pixels).
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
getDrawableSize()

◆ getDrawableSize()

Extent2D grem::graphics::Window::getDrawableSize ( ) const
nodiscard

Get the drawable size of the window.

Returns
the current drawable size of the window, in pixels.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
getSize()

◆ getMultisampleCount()

uint32_t grem::graphics::Window::getMultisampleCount ( ) const
inlinenodiscard

Get the number of samples used for multisample anti-aliasing (MSAA) when rendering to the window.

Returns
the MSAA level of the window.

◆ getDisplayScale()

float grem::graphics::Window::getDisplayScale ( ) const
nodiscard

Get the content display scale relative to the window's pixel size.

Returns
the display scale of this window.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.

◆ getOpacity()

float grem::graphics::Window::getOpacity ( ) const
nodiscard

Get the opacity of the window.

Returns
the current opacity of the window, from 0 (transparent) to 1 (opaque).
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
setOpacity()

◆ getDisplay()

Display grem::graphics::Window::getDisplay ( ) const
nodiscard

Get the display that this window is associated with.

Returns
the display containing the center of the window.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.

◆ getFullscreenDisplayMode()

Optional< DisplayMode > grem::graphics::Window::getFullscreenDisplayMode ( ) const
nodiscard

Get the fullscreen display mode of the window.

Returns
the display mode that will be used in fullscreen for this window if the window is not resizable, or an empty optional for borderless desktop display mode.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.
See also
setFullscreenDisplayMode()

◆ getID()

uint32_t grem::graphics::Window::getID ( ) const
nodiscard

Get a unique identifier for this window.

Returns
the identifier corresponding to this window.
Exceptions
graphics::Erroron failure.
std::bad_allocon allocation failure.

◆ getNativeHandle() [1/2]

void * grem::graphics::Window::getNativeHandle ( )
nodiscard

Get a pointer to the native handle of the window, if available for the current platform.

Returns
a non-owning pointer representing the native handle of the window used by the host platform, or nullptr if such a handle is not available.
Note
On Windows, this is the HWND pointer. Other platforms are likely to return null.
Exceptions
graphics::Erroron failure to get the handle on a supported platform.
std::bad_allocon allocation failure.

◆ getNativeHandle() [2/2]

const void * grem::graphics::Window::getNativeHandle ( ) const
inlinenodiscard

Get a pointer to the native handle of the window, if available for the current platform.

Returns
a non-owning read-only pointer representing the native handle of the window used by the host platform, or nullptr if such a handle is not available.
Note
On Windows, this is the HWND pointer. Other platforms are likely to return null.
Exceptions
graphics::Erroron failure to get the handle on a supported platform.
std::bad_allocon allocation failure.

◆ get() [1/2]

void * grem::graphics::Window::get ( )
inlinenodiscardnoexcept

Get an opaque pointer to the internal representation of the window.

Returns
an untyped non-owning pointer to the internal representation of the window.
Note
This function is used internally by the implementations of various abstractions and is not intended to be used outside of the graphics module. The returned pointer has no meaning to application code.

◆ get() [2/2]

const void * grem::graphics::Window::get ( ) const
inlinenodiscardnoexcept

Get an opaque pointer to the internal representation of the window.

Returns
an untyped non-owning read-only pointer to the internal representation of the window.
Note
This function is used internally by the implementations of various abstractions and is not intended to be used outside of the graphics module. The returned pointer has no meaning to application code.

◆ getSurface() [1/2]

void * grem::graphics::Window::getSurface ( )
inlinenodiscardnoexcept

Get an opaque pointer to the internal representation of the window surface.

Returns
an untyped non-owning pointer to the internal representation of the window surface.
Note
This function is used internally by the implementations of various abstractions and is not intended to be used outside of the graphics module. The returned pointer has no meaning to application code.

◆ getSurface() [2/2]

const void * grem::graphics::Window::getSurface ( ) const
inlinenodiscardnoexcept

Get an opaque pointer to the internal representation of the window surface.

Returns
an untyped non-owning read-only pointer to the internal representation of the window surface.
Note
This function is used internally by the implementations of various abstractions and is not intended to be used outside of the graphics module. The returned pointer has no meaning to application code.

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