-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
166 lines (136 loc) · 3.43 KB
/
Copy pathMainWindow.cpp
File metadata and controls
166 lines (136 loc) · 3.43 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
156
157
158
159
160
161
162
163
164
165
166
#include "MainWindow.h"
#include "Graphics.h"
#include <fstream>
#include <string>
#include <math.h>
int iWidth = 1280;
int iHeight = 720;
LPCTSTR sWndClassName = L"normalWindow";
HWND hHwnd = NULL;
MSG mMsg;
bool InitMainWindow(HINSTANCE hInstance, int nCmdShow, bool windowed)
{
//Read (Global) Variables from 'preferences.ini'
std::ifstream prefFile ("preferences.ini", std::ios::in);
std::string line;
if (prefFile.is_open())
{
while (std::getline(prefFile, line))
{
if (line.find("cWidth") != std::string::npos)
{
iWidth = stoi(line.substr(line.find(" ") + 1, line.length()));
}
else if (line.find("cHeight") != std::string::npos)
{
iHeight = stoi(line.substr(line.find(" ") + 1, line.length()));
}
}
prefFile.close();
}
else
{
std::ofstream prefFile;
prefFile.open("preferences.ini");
prefFile << "cWidth: " << iWidth << std::endl;
prefFile << "cHeight: " << iHeight << std::endl;
prefFile.close();
}
//Windows Klasse erstellen
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
//Windows Klasse einrichten
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.lpszClassName = sWndClassName;
//Registriere Klasse
RegisterClassEx(&wc);
RECT rect;
ZeroMemory(&rect, sizeof(RECT));
rect.right = iWidth;
rect.bottom = iHeight;
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, NULL, NULL);
hHwnd = CreateWindowEx( NULL,
sWndClassName,
L"Photoshooting",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
if (!hHwnd)
{
MessageBox(NULL, L"Error creating window",
L"Error", MB_OK | MB_ICONERROR);
return false;
}
//Fenster zeigen und einmal updaten
ShowWindow(hHwnd, nCmdShow);
UpdateWindow(hHwnd);
return true;
}
void messageLoop(Graphics& graphics, Sphere& sphere, Cube& cube)
{
ZeroMemory(&mMsg, sizeof(MSG));
while (true)
{
//Nach Nachrichten schauen
if (PeekMessage(&mMsg, NULL, 0, 0, PM_REMOVE))
{
if (mMsg.message == WM_QUIT)
{
break;
}
TranslateMessage(&mMsg);
DispatchMessage(&mMsg);
}
//Run Game Code
else
{
static float delta = DirectX::XM_PI / 360.0f;
static float degree = 0.0f;
graphics.startDraw();
graphics.moveLight(0.0f, 0.0f, 1.8f * std::sin(degree) + 2.5f);
sphere.move(0.0f, 0.0f, 1.8f * std::sin(degree) + 2.5f);
cube.move(-1.0f, 0.0f, 0.0f);
cube.draw();
cube.move(2.0f, 0.0f, 0.0f);
cube.draw();
cube.move(-1.0f, 1.0f, 0.0f);
cube.draw();
cube.move(0.0f, -2.0f, 0.0f);
cube.draw();
cube.move(0.0f, 1.0f, 0.0f);
cube.rotate(delta, 0.0f, 0.0f);
sphere.draw();
graphics.endDraw();
degree += 0.005;
}
}
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_KEYDOWN:
if (wParam == VK_ESCAPE) {
DestroyWindow(hwnd);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}