Incremental Engine  1.0.6
A 2D Game Engine to create Idle Games
IncrementalEngine::RenderWindow Class Reference

#include <RenderWindow.h>

Public Member Functions

 RenderWindow (Config config)
 
virtual ~RenderWindow ()
 
HWND GetHWND ()
 
HINSTANCE * GetHInstance ()
 
int GetScreenWidth ()
 
int GetScreenHeight ()
 
float GetScreenNear ()
 
float GetScreenDepth ()
 
void SetIcon (LPCWSTR icon)
 

Private Attributes

HINSTANCE _hInstance
 
HWND _hWnd
 
Config _config
 
int _screenWidth
 
int _screenHeight
 

Detailed Description

Definition at line 10 of file RenderWindow.h.

Constructor & Destructor Documentation

◆ RenderWindow()

IncrementalEngine::RenderWindow::RenderWindow ( Config  config)

Definition at line 12 of file RenderWindow.cpp.

13  {
14  WNDCLASSEX wc;
15  DEVMODE dmScreenSettings;
16  int posX, posY;
17  StringAsWCHAR_ptr(config.ApplicationName, LPCWSTR applicationName);
18 
19  _config = config;
20  _hInstance = GetModuleHandle(NULL);
21 
22  wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
23  wc.lpfnWndProc = WindowProc;
24  wc.cbClsExtra = 0;
25  wc.cbWndExtra = 0;
26  wc.hInstance = _hInstance;
27  wc.hIcon = LoadIcon(_hInstance, IDI_WINLOGO);
28  wc.hIconSm = wc.hIcon;
29  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
30  wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
31  wc.lpszMenuName = NULL;
32  wc.lpszClassName = applicationName;
33  wc.cbSize = sizeof(WNDCLASSEX);
34 
35  RegisterClassEx(&wc);
36 
37  _screenWidth = GetSystemMetrics(SM_CXSCREEN);
38  _screenHeight = GetSystemMetrics(SM_CYSCREEN);
39 
40  if (config.Fullscreen)
41  {
42  memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
43  dmScreenSettings.dmSize = sizeof(dmScreenSettings);
44  dmScreenSettings.dmPelsWidth = (unsigned long)_screenWidth;
45  dmScreenSettings.dmPelsHeight = (unsigned long)_screenHeight;
46  dmScreenSettings.dmBitsPerPel = 32;
47  dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
48 
49  ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
50 
51  posX = posY = 0;
52  }
53  else
54  {
55  _screenWidth = config.WindowSize.x;
56  _screenHeight = config.WindowSize.y;
57 
58  posX = (GetSystemMetrics(SM_CXSCREEN) - _screenWidth) / 2;
59  posY = (GetSystemMetrics(SM_CYSCREEN) - _screenHeight) / 2;
60  }
61 
62  RECT wr = { 0, 0, _screenWidth, _screenHeight };
63  AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
64 
65  _hWnd = CreateWindowEx(
66  WS_EX_APPWINDOW,
67  applicationName,
68  applicationName,
69  WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME,
70  posX,
71  posY,
72  wr.right - wr.left,
73  wr.bottom - wr.top,
74  NULL,
75  NULL,
76  _hInstance,
77  NULL
78  );
79 
80  ShowWindow(_hWnd, SW_SHOW);
81  SetWindowLong(_hWnd, GWL_STYLE, GetWindowLong(_hWnd, GWL_STYLE) & ~WS_MAXIMIZEBOX);
82  SetForegroundWindow(_hWnd);
83  SetFocus(_hWnd);
84 
85  ShowCursor(config.ShowCursor);
86  }

◆ ~RenderWindow()

IncrementalEngine::RenderWindow::~RenderWindow ( )
virtual

Definition at line 88 of file RenderWindow.cpp.

89  {
90  ShowCursor(true);
91 
92  if (_config.Fullscreen)
93  {
94  ChangeDisplaySettings(NULL, 0);
95  }
96 
97  DestroyWindow(_hWnd);
98  _hWnd = NULL;
99 
100  StringAsWCHAR_ptr(_config.ApplicationName, LPCWSTR applicationName);
101  UnregisterClass(applicationName, _hInstance);
102  _hInstance = NULL;
103  }

Member Function Documentation

◆ GetHInstance()

HINSTANCE * IncrementalEngine::RenderWindow::GetHInstance ( )

Definition at line 110 of file RenderWindow.cpp.

111  {
112  return &_hInstance;
113  }

◆ GetHWND()

HWND IncrementalEngine::RenderWindow::GetHWND ( )

Definition at line 105 of file RenderWindow.cpp.

106  {
107  return _hWnd;
108  }

◆ GetScreenDepth()

float IncrementalEngine::RenderWindow::GetScreenDepth ( )

Definition at line 130 of file RenderWindow.cpp.

131  {
132  return _config.ScreenDepth;
133  }

◆ GetScreenHeight()

int IncrementalEngine::RenderWindow::GetScreenHeight ( )

Definition at line 120 of file RenderWindow.cpp.

121  {
122  return _screenHeight;
123  }

◆ GetScreenNear()

float IncrementalEngine::RenderWindow::GetScreenNear ( )

Definition at line 125 of file RenderWindow.cpp.

126  {
127  return _config.ScreenNear;
128  }

◆ GetScreenWidth()

int IncrementalEngine::RenderWindow::GetScreenWidth ( )

Definition at line 115 of file RenderWindow.cpp.

116  {
117  return _screenWidth;
118  }

◆ SetIcon()

void IncrementalEngine::RenderWindow::SetIcon ( LPCWSTR  icon)

Definition at line 135 of file RenderWindow.cpp.

136  {
137  HICON hIcon = LoadIcon(_hInstance, MAKEINTRESOURCE(icon));
138  SendMessage(_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
139  SendMessage(_hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
140  }

Member Data Documentation

◆ _config

Config IncrementalEngine::RenderWindow::_config
private

Definition at line 28 of file RenderWindow.h.

◆ _hInstance

HINSTANCE IncrementalEngine::RenderWindow::_hInstance
private

Definition at line 26 of file RenderWindow.h.

◆ _hWnd

HWND IncrementalEngine::RenderWindow::_hWnd
private

Definition at line 27 of file RenderWindow.h.

◆ _screenHeight

int IncrementalEngine::RenderWindow::_screenHeight
private

Definition at line 29 of file RenderWindow.h.

◆ _screenWidth

int IncrementalEngine::RenderWindow::_screenWidth
private

Definition at line 29 of file RenderWindow.h.

IncrementalEngine::Config::ApplicationName
std::string ApplicationName
Definition: Config.h:18
IncrementalEngine::RenderWindow::_hWnd
HWND _hWnd
Definition: RenderWindow.h:27
IncrementalEngine::Config::Fullscreen
bool Fullscreen
Definition: Config.h:20
IncrementalEngine::RenderWindow::_screenHeight
int _screenHeight
Definition: RenderWindow.h:29
IncrementalEngine::Config::ScreenNear
float ScreenNear
Definition: Config.h:24
IncrementalEngine::Config::ScreenDepth
float ScreenDepth
Definition: Config.h:23
IncrementalEngine::WindowProc
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: RenderWindow.cpp:142
IncrementalEngine::RenderWindow::_screenWidth
int _screenWidth
Definition: RenderWindow.h:29
IncrementalEngine::RenderWindow::_hInstance
HINSTANCE _hInstance
Definition: RenderWindow.h:26
IncrementalEngine::RenderWindow::_config
Config _config
Definition: RenderWindow.h:28