SAGE
A Simple Academic Game Engine
Loading...
Searching...
No Matches
Sage::CWindow Class Reference

The window class. More...

#include <SageWindow.h>

Inheritance diagram for Sage::CWindow:
Collaboration diagram for Sage::CWindow:

Public Member Functions

template<typename t0 , typename t1 , typename t2 >
int WinMain (_In_ HINSTANCE, bool, const t0 &, const t1 &, const t2 &)
 WinMain.
 
- Public Member Functions inherited from Sage::CSettingsManager
void Load ()
 Load game settings.
 

Protected Member Functions

HWND CreateGameWindow (HINSTANCE)
 Create default window.
 
bool InitGameWindow (_In_ HINSTANCE)
 Initialize the game window.
 
void OpenDebugConsole ()
 Open debug console window.
 
void CloseDebugConsole ()
 Close debug console window.
 
- Protected Member Functions inherited from Sage::CSettingsManager
void SetWinSize (int, int)
 Set window size information.
 

Static Protected Member Functions

static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM)
 The Window Procedure.
 
static void GetBorderSizes (int &w, int &h)
 Get window border width and height.
 
static void EnforceAspectRatio (WPARAM, RECT *)
 Enforce aspect ratio.
 
static void EnforceAspectRatio (MINMAXINFO *)
 Enforce aspect ratio.
 

Static Protected Attributes

static Vector2 m_vMousePos
 Mouse position.
 
- Static Protected Attributes inherited from Sage::CWindowDesc
static HWND m_Hwnd = 0
 Window handle.
 
static HINSTANCE m_hInst = 0
 Instance handle.
 
static bool m_bExitSizeMove = true
 User just finished moving/resizing window.
 
- Static Protected Attributes inherited from Sage::CSettingsManager
static tinyxml2::XMLElement * m_pXmlSettings = nullptr
 Pointer to the settings tag in the XML settings file.

 
static float m_fAspectRatio = 1.0f
 Aspect ratio, width/ht.
 
- Static Protected Attributes inherited from Sage::CSettings
static char m_szName [MAX_PATH]
 Name of this game.
 
static int m_nWinWidth = 0
 Window width in pixels.
 
static int m_nWinHeight = 0
 Window height in pixels.
 
static Vector2 m_vWinCenter = Vector2::Zero
 Window center.
 

Detailed Description

CWindow handles Windows specific things. This will help you to keep the rest of your code as OS-independent as possible. Gnarly things that it handles includes making a window whose client area is a specific width and height, and making sure that the window maintains its aspect ratio if the user is brave enough to resize it by dragging on one of the window's edges or corners.

Member Function Documentation

◆ CloseDebugConsole()

void CWindow::CloseDebugConsole ( )
protected

Delay closing the console window so that the user can read any debug messages that might have occurred while closing the game. This function should be one of the last functions called before exiting.

Here is the caller graph for this function:

◆ CreateGameWindow()

HWND CWindow::CreateGameWindow ( HINSTANCE h)
protected

Register and create a window. Care is taken to ensure that the client area of the window is the right size, because the default way of creating a window has you specify the width and height including the frame.

Parameters
hinstance handle.
Returns
Window handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnforceAspectRatio() [1/2]

void CWindow::EnforceAspectRatio ( MINMAXINFO * pmmi)
staticprotected

Enforce the aspect ratio in response to a WM_GETMINMAXINFO message. This function ensures that when the window is bigger than the screen, then it has the correct aspect ratio when Windows automatically resizes it.

Parameters
pmmi[OUT] Pointer to a MINMAXINFO structure.
Here is the call graph for this function:

◆ EnforceAspectRatio() [2/2]

void CWindow::EnforceAspectRatio ( WPARAM wParam,
RECT * pRect )
staticprotected

Force the aspect ratio of the client area of the window in response to a WM_SIZING message. This function resizes the drag rectangle provided by the WM_SIZING message.

Parameters
wParamWMSZ message telling us which edge is being dragged on.
pRect[IN, OUT] Pointer to drag rectangle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBorderSizes()

void CWindow::GetBorderSizes ( int & w,
int & h )
staticprotected

Get the combined width and height of the borders on the window. Combined width is the sum of the widths of the left and right borders. Combined height is the sum of the heights of the top and bottom borders.

Parameters
w[OUT] Combined border width.
h[OUT] Combined border height.
Here is the caller graph for this function:

◆ InitGameWindow()

bool CWindow::InitGameWindow ( _In_ HINSTANCE hInstance)
protected

Create and initialize the game window.

Parameters
hInstanceHandle to the current instance of this application.
Returns
true if application terminates correctly.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenDebugConsole()

void CWindow::OpenDebugConsole ( )
protected

Open a console window and redirect stdout, stderr and stdin to it so that can be used for debug output using printf.

Here is the caller graph for this function:

◆ WinMain()

template<typename t0 , typename t1 , typename t2 >
int Sage::CWindow::WinMain ( _In_ HINSTANCE hInst,
bool console,
const t0 & InitFn,
const t1 & UpdateFn,
const t2 & CloseFn )

Do setup, maintain a message pump that does game animation whenever there's no message waiting, and exit the message pump on WM_QUIT. Then do cleanup and exit the application.

Template Parameters
t0Type of initialization function.
t1Type of update function.
t2Type of close function.
Parameters
hInstHandle to window instance.
consoleTrue if a console debug window is wanted.
InitFnInitialization function.
UpdateFnUpdate function.
CloseFnClose function.
Returns
Wparam from the WM_QUIT message.
Here is the call graph for this function:

◆ WndProc()

LRESULT CALLBACK CWindow::WndProc ( HWND h,
UINT m,
WPARAM wp,
LPARAM lp )
staticprotected

Default window procedure.

This is the handler for messages from the operating system.

Parameters
hWindow handle.
mMessage code.
wpParameter for message.
lpSecond parameter for message.
Returns
0 If message is handled.
Here is the call graph for this function:
Here is the caller graph for this function: