The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
LWindow Class Reference

The window class. More...

#include <Window.h>

Inheritance diagram for LWindow:
LWindowDesc LSettingsManager LSettings LRenderer3D LSpriteRenderer

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 LSettingsManager
void Load ()
 Load game settings. More...
 

Private Member Functions

HWND CreateGameWindow (HINSTANCE)
 Create default window. More...
 
bool InitGameWindow (_In_ HINSTANCE)
 Initialize the game window. More...
 
void OpenDebugConsole ()
 Open debug console window. More...
 
void CloseDebugConsole ()
 Close debug console window. More...
 

Static Private Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from LSettingsManager
void SetWinSize (int, int)
 Set window size information. More...
 
- Static Protected Attributes inherited from LWindowDesc
static HWND m_Hwnd = 0
 Window handle.
 
static HINSTANCE m_hInst = 0
 Instance handle.
 
static bool m_bExitSizeMove
 User just finished moving/resizing window.
 
- Static Protected Attributes inherited from LSettingsManager
static 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 LSettings
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

LWindow 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 LWindow::CloseDebugConsole ( )
private

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.

◆ CreateGameWindow()

HWND LWindow::CreateGameWindow ( HINSTANCE  h)
private

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.

◆ EnforceAspectRatio() [1/2]

void LWindow::EnforceAspectRatio ( MINMAXINFO *  pmmi)
staticprivate

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.

◆ EnforceAspectRatio() [2/2]

void LWindow::EnforceAspectRatio ( WPARAM  wParam,
RECT *  pRect 
)
staticprivate

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.

◆ GetBorderSizes()

void LWindow::GetBorderSizes ( int &  w,
int &  h 
)
staticprivate

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.

◆ InitGameWindow()

bool LWindow::InitGameWindow ( _In_ HINSTANCE  hInstance)
private

Create and initialize the game window.

Parameters
hInstanceHandle to the current instance of this application.
Returns
true if application terminates correctly.

◆ OpenDebugConsole()

void LWindow::OpenDebugConsole ( )
private

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

◆ WndProc()

LRESULT CALLBACK LWindow::WndProc ( HWND  h,
UINT  m,
WPARAM  wp,
LPARAM  lp 
)
staticprivate

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.