MAGE  v0.171.0
Matthias Advanced Game Engine
mage::Window Class Reference

#include <window.hpp>

Public Types

using WindowDescriptorPtr = SharedPtr< const WindowDescriptor >
 
using WindowMessageListenerPtr = NotNull< WindowMessageListener *>
 
using WindowMessageHandlerPtr = NotNull< WindowMessageHandler *>
 

Public Member Functions

 Window (WindowDescriptorPtr window_desc, std::wstring_view title_text, const U32x2 &resolution, DWORD style=s_default_window_style)
 
 Window (const Window &window)=delete
 
 Window (Window &&window) noexcept
 
 ~Window ()
 
Windowoperator= (const Window &window)=delete
 
Windowoperator= (Window &&window)=delete
 
void Show (int nCmdShow)
 
WindowDescriptorPtr GetWindowDescriptor () const noexcept
 
NotNull< HINSTANCE > GetInstance () const noexcept
 
HWND GetWindow () const noexcept
 
const std::wstring GetTitleText () const noexcept
 
void SetTitleText (NotNull< const_wzstring > title_text)
 
void AddListener (WindowMessageListenerPtr listener)
 
void RemoveListener (WindowMessageListenerPtr listener)
 
void RemoveAllListeners () noexcept
 
void AddHandler (WindowMessageHandlerPtr handler)
 
void RemoveHandler (WindowMessageHandlerPtr handler)
 
void RemoveAllHandlers () noexcept
 

Static Public Member Functions

static LRESULT CALLBACK HandleWindowMessage (HWND window, UINT message, WPARAM wParam, LPARAM lParam)
 

Static Public Attributes

static constexpr DWORD s_default_window_style
 

Private Member Functions

void InitializeWindow (std::wstring_view title_text, const U32x2 &resolution, DWORD style)
 
void InitializeWindow (std::wstring_view title_text, const RECT &rectangle, DWORD style)
 
const std::optional< LRESULT > HandleWindowMessage (NotNull< HWND > window, UINT message, WPARAM wParam, LPARAM lParam) const
 

Private Attributes

WindowDescriptorPtr m_window_desc
 
HWND m_window
 
std::vector< WindowMessageListenerPtrm_listeners
 
std::vector< WindowMessageHandlerPtrm_handlers
 

Detailed Description

A class of windows.

Member Typedef Documentation

◆ WindowDescriptorPtr

◆ WindowMessageHandlerPtr

◆ WindowMessageListenerPtr

Constructor & Destructor Documentation

◆ Window() [1/3]

mage::Window::Window ( WindowDescriptorPtr  window_desc,
std::wstring_view  title_text,
const U32x2 resolution,
DWORD  style = s_default_window_style 
)
explicit

Constructs a window.

Precondition
window_desc is not equal to nullptr.
Parameters
[in]window_descA pointer to the window descriptor.
[in]title_textThe title text.
[in]resolutionThe resolution of the window.
[in]styleThe style of the window.
Exceptions
ExceptionFailed to create the window.

◆ Window() [2/3]

mage::Window::Window ( const Window window)
delete

Constructs a window from the given window.

Parameters
[in]windowA reference to the window to copy.

◆ Window() [3/3]

mage::Window::Window ( Window &&  window)
defaultnoexcept

Constructs a window by moving the given window.

Parameters
[in]windowA reference to the window to move.

◆ ~Window()

mage::Window::~Window ( )
default

Destructs this window.

Member Function Documentation

◆ AddHandler()

void mage::Window::AddHandler ( WindowMessageHandlerPtr  handler)

Adds the given window message handler to this window.

Parameters
[in]handlerA pointer to the window message handler to add.

◆ AddListener()

void mage::Window::AddListener ( WindowMessageListenerPtr  listener)

Adds the given window message listener to this window.

Parameters
[in]listenerA pointer to the window message listener to add.

◆ GetInstance()

NotNull< HINSTANCE > mage::Window::GetInstance ( ) const
noexcept

Returns the application instance handle of this window.

Returns
The application instance handle of this window.

◆ GetTitleText()

const std::wstring mage::Window::GetTitleText ( ) const
noexcept

Returns the title text of this window.

Returns
The title text of this window.

◆ GetWindow()

HWND mage::Window::GetWindow ( ) const
noexcept

Returns the window handle of this window.

Returns
The window handle of this window.

◆ GetWindowDescriptor()

WindowDescriptorPtr mage::Window::GetWindowDescriptor ( ) const
noexcept

Returns the window descriptor of this window.

Returns
A pointer to the window descriptor of this window.

◆ HandleWindowMessage() [1/2]

LRESULT CALLBACK mage::Window::HandleWindowMessage ( HWND  window,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)
static

Processes the given message sent to a window.

Parameters
[in]windowA handle to the window.
[in]messageThe message.
[in]wParamAdditional message information. The contents of this parameter depend on the value of msg.
[in]lParamAdditional message information. The contents of this parameter depend on the value of msg.
Returns
The return value is the result of the message processing and depends on the message sent.

◆ HandleWindowMessage() [2/2]

const std::optional< LRESULT > mage::Window::HandleWindowMessage ( NotNull< HWND >  window,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
) const
private

Handles the given message sent to this window.

Parameters
[in]windowA handle to the window.
[in]messageThe message.
[in]wParamAdditional message information. The contents of this parameter depend on the value of msg.
[in]lParamAdditional message information. The contents of this parameter depend on the value of msg.
Returns
The result of the message processing, if the given message is handled by this window.

◆ InitializeWindow() [1/2]

void mage::Window::InitializeWindow ( std::wstring_view  title_text,
const U32x2 resolution,
DWORD  style 
)
private

Initializes the window of this window.

Parameters
[in]title_textThe title text.
[in]resolutionThe resolution of the client rectangle of the window.
[in]styleThe style of the window.
Exceptions
ExceptionFailed to create the window.

◆ InitializeWindow() [2/2]

void mage::Window::InitializeWindow ( std::wstring_view  title_text,
const RECT &  rectangle,
DWORD  style 
)
private

Initializes the window of this window.

Parameters
[in]title_textThe title text.
[in]rectangleA reference to the client rectangle of the window.
[in]styleThe style of the window.
Exceptions
ExceptionFailed to create the window.

◆ operator=() [1/2]

Window& mage::Window::operator= ( const Window window)
delete

Copies the given window to this window.

Parameters
[in]windowA reference to the window to copy.
Returns
A reference to the copy of the given window (i.e. this window).

◆ operator=() [2/2]

Window& mage::Window::operator= ( Window &&  window)
delete

Moves the given window to this window.

Parameters
[in]windowA reference to the window to move.
Returns
A reference to the moved window (i.e. this window).

◆ RemoveAllHandlers()

void mage::Window::RemoveAllHandlers ( )
noexcept

Removes all the window message handlers from this window.

◆ RemoveAllListeners()

void mage::Window::RemoveAllListeners ( )
noexcept

Removes all the window message listeners from this window.

◆ RemoveHandler()

void mage::Window::RemoveHandler ( WindowMessageHandlerPtr  handler)

Removes the given window message handler from this window.

Parameters
[in]handlerA pointer to the window message handler to remove.

◆ RemoveListener()

void mage::Window::RemoveListener ( WindowMessageListenerPtr  listener)

Removes the given window message listener from this window.

Parameters
[in]listenerA pointer to the window message listener to remove.

◆ SetTitleText()

void mage::Window::SetTitleText ( NotNull< const_wzstring title_text)

Sets the title text of this window to the given title text.

Parameters
[in]title_textA pointer to the title text.
Exceptions
ExceptionFailed to set the title text of this window.

◆ Show()

void mage::Window::Show ( int  nCmdShow)

Sets the show state of this window.

Parameters
[in]nCmdShowControls how this window is to be shown.
Exceptions
ExceptionFailed to update the window.

Member Data Documentation

◆ m_handlers

std::vector< WindowMessageHandlerPtr > mage::Window::m_handlers
private

A vector containing the message handler of this window.

◆ m_listeners

std::vector< WindowMessageListenerPtr > mage::Window::m_listeners
private

A vector containing the message listeners of this window.

◆ m_window

HWND mage::Window::m_window
private

The window handle of this window.

◆ m_window_desc

WindowDescriptorPtr mage::Window::m_window_desc
private

A pointer to the window descriptor of this window.

◆ s_default_window_style

constexpr DWORD mage::Window::s_default_window_style
static
Initial value:
= WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX

The default window style of windows.