-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemClass.cpp
More file actions
155 lines (136 loc) · 4.53 KB
/
SystemClass.cpp
File metadata and controls
155 lines (136 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "SystemClass.h"
#include <Windows.h>
SystemClass::SystemClass() {
m_Input = nullptr;
m_Graphics = nullptr;
}
bool SystemClass::Initialize() {
int ScreenWidth, ScreenHeight;
bool result;
ScreenWidth = ScreenHeight = 0;
InitializeWindows( ScreenWidth, ScreenHeight );
m_Input = new InputClass;
if ( !m_Input ) return false;
result = m_Input->Initialize(m_hInstance, m_hWnd, ScreenWidth, ScreenHeight);
if ( !result ) return false;
m_Graphics = new GraphicsClass;
if (!m_Graphics ) return false;
result = m_Graphics->Initialize( ScreenWidth, ScreenHeight, m_hWnd );
if ( !result ) return false;
return true;
}
void SystemClass::Run() {
MSG msg;
bool done, result;
done = false;
while ( !done ) {
if ( PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
if ( msg.message == WM_QUIT ) done = true;
else {
result = Frame();
if ( !result ) done = true;
}
if ( m_Input->IsKeyDown( DIK_ESCAPE ) ) done = true;
}
}
void SystemClass::Shutdown() {
if ( m_Graphics ) {
m_Graphics->Shutdown();
delete m_Graphics;
m_Graphics = nullptr;
}
if ( m_Input ) {
m_Input->Shutdown();
delete m_Input;
m_Input = nullptr;
}
ShutdownWindows();
}
bool SystemClass::Frame() {
bool result;
int MouseX, MouseY;
result = m_Input->Frame();
if ( !result ) return false;
m_Input->GetMouseLocation( MouseX, MouseY );
result = m_Graphics->Frame();
if ( !result ) return false;
return true;
}
LRESULT CALLBACK SystemClass::MessageHandler( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ) {
return DefWindowProc( hWnd, Msg, wParam, lParam );
}
void SystemClass::InitializeWindows( int& ScreenWidth, int& ScreenHeight ) {
WNDCLASSEX WindowClass;
DEVMODE dmScreenSettings;
int positionX, positionY;
positionX = positionY = 0;
ApplicationHandle = this;
m_hInstance = GetModuleHandle( nullptr );
m_ApplicationName = L"Ἀφροδίτη";
m_FullScreen = true;
ZeroMemory ( &WindowClass, sizeof( WNDCLASSEX ) );
WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
WindowClass.lpfnWndProc = WndProc;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = m_hInstance;
WindowClass.hIcon = LoadIcon( nullptr, IDI_WINLOGO );
WindowClass.hIconSm = WindowClass.hIcon;
WindowClass.hCursor = LoadCursor( nullptr, IDC_ARROW );
WindowClass.hbrBackground = (HBRUSH) GetStockObject( BLACK_BRUSH );
WindowClass.lpszMenuName = nullptr;
WindowClass.lpszClassName = m_ApplicationName;
WindowClass.cbSize = sizeof( WNDCLASSEX );
RegisterClassEx( &WindowClass );
ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
ScreenHeight = GetSystemMetrics( SM_CYSCREEN );
if ( m_FullScreen ) {
ZeroMemory ( &dmScreenSettings, sizeof( dmScreenSettings ) );
dmScreenSettings.dmSize = sizeof( dmScreenSettings );
dmScreenSettings.dmPelsWidth = (unsigned long)ScreenWidth;
dmScreenSettings.dmPelsHeight = (unsigned long)ScreenHeight;
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
}
m_hWnd = CreateWindowEx( WS_EX_APPWINDOW,
m_ApplicationName,
m_ApplicationName,
//WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
WS_OVERLAPPEDWINDOW,
positionX, positionY,
ScreenWidth, ScreenHeight,
nullptr, nullptr,
m_hInstance,
nullptr );
ShowWindow( m_hWnd, SW_SHOW );
SetForegroundWindow( m_hWnd );
SetFocus( m_hWnd );
//ShowCursor( false );
}
void SystemClass::ShutdownWindows() {
//ShowCursor( true );
if ( m_FullScreen ) ChangeDisplaySettings( nullptr, 0 );
DestroyWindow( m_hWnd );
m_hWnd = nullptr;
UnregisterClass( m_ApplicationName, m_hInstance );
m_hInstance = nullptr;
ApplicationHandle = nullptr;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam ) {
switch ( Message ) {
case WM_DESTROY: {
PostQuitMessage(0);
return 0;
}
case WM_CLOSE: {
PostQuitMessage(0);
return 0;
}
default: {
return ApplicationHandle->MessageHandler( hWnd, Message, wParam, lParam );
}
}
}