This repository was archived by the owner on Dec 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCFSystem.cpp
More file actions
94 lines (83 loc) · 1.88 KB
/
CFSystem.cpp
File metadata and controls
94 lines (83 loc) · 1.88 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
#include "CFSystem.h"
LRESULT CALLBACK CFSystem::WndProc(
HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam) {
CFSystem* sys = (CFSystem*)GetWindowLongPtr(hWnd, GWL_USERDATA);
if (sys == nullptr) {
CREATESTRUCT* cs = (CREATESTRUCT*)lParam;
if (cs != nullptr) {
sys = (CFSystem*)cs->lpCreateParams;
SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)sys);
}
else return DefWindowProc(hWnd, message, wParam, lParam);
}
switch (message) {
case WM_DISPLAYCHANGE:
InvalidateRect(hWnd, nullptr, false);
break;
case WM_PAINT:
sys->ui.draw();
ValidateRect(hWnd, nullptr);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_MOUSEMOVE:
sys->mouseMove(LOWORD(lParam), HIWORD(lParam));
InvalidateRect(hWnd, nullptr, false);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
void CFSystem::createDeviceIndependentResources() {
HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &directFactory);
CHECK;
hr = CoCreateInstance(CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&imagingFactory)
);
CHECK;
}
void CFSystem::createWindow(bool nCmdShow) {
display.createWindow(*this, nCmdShow);
}
CFSystem::CFSystem(HINSTANCE hInst) : WNDCLASSEX{
sizeof(WNDCLASSEX),
CS_HREDRAW | CS_VREDRAW,
WndProc,
0,
sizeof(this),
hInst,
nullptr,
LoadCursor(NULL, IDC_ARROW),
nullptr,
0,
WndClassName,
nullptr,
}, ui(*this) {
createDeviceIndependentResources();
if (!RegisterClassEx(this))
throw std::runtime_error("Call to RegisterCLassEx failed!");
}
int CFSystem::run() {
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
void CFSystem::mouseMove(UINT x, UINT y) {
mouseMoveEvent((float)x, (float)y);
}
CFSystem::~CFSystem() {
ui.unload();
release(directFactory);
release(imagingFactory);
}