Repository navigation
Expand file tree
/
Copy pathPolycodeView.cpp
More file actions
189 lines (155 loc) · 4.48 KB
/
Copy pathPolycodeView.cpp
File metadata and controls
189 lines (155 loc) · 4.48 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "PolycodeView.h"
#include "PolyWinCore.h"
#include "PolyCoreServices.h"
#include "PolyCoreInput.h"
#include "PolyRenderer.h"
#include <io.h>
#include <fcntl.h>
using namespace Polycode;
Win32Core *core = NULL;
static void OpenConsole()
{
int outHandle, errHandle, inHandle;
FILE *outFile, *errFile, *inFile;
AllocConsole();
CONSOLE_SCREEN_BUFFER_INFO coninfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = 9999;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
outHandle = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
errHandle = _open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE),_O_TEXT);
inHandle = _open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE),_O_TEXT );
outFile = _fdopen(outHandle, "w" );
errFile = _fdopen(errHandle, "w");
inFile = _fdopen(inHandle, "r");
*stdout = *outFile;
*stderr = *errFile;
*stdin = *inFile;
setvbuf( stdout, NULL, _IONBF, 0 );
setvbuf( stderr, NULL, _IONBF, 0 );
setvbuf( stdin, NULL, _IONBF, 0 );
std::ios::sync_with_stdio();
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
int nWidth, nHeight;
bool useDefault = false;
if(!core)
return DefWindowProc(hWnd, message, wParam, lParam);
switch (message)
{
case WM_SIZE:
nWidth = LOWORD(lParam);
nHeight = HIWORD(lParam);
if(core) {
core->handleViewResize(nWidth, nHeight);
}
break;
case WM_MOUSEMOVE:
if(core)
core->handleMouseMove(lParam,wParam);
break;
case WM_MOUSEWHEEL:
if(core)
core->handleMouseWheel(lParam,wParam);
break;
case WM_LBUTTONDOWN:
if(core)
core->handleMouseDown(CoreInput::MOUSE_BUTTON1, lParam,wParam);
break;
case WM_LBUTTONUP:
if(core)
core->handleMouseUp(CoreInput::MOUSE_BUTTON1, lParam,wParam);
break;
case WM_RBUTTONDOWN:
if(core)
core->handleMouseDown(CoreInput::MOUSE_BUTTON2, lParam,wParam);
break;
case WM_RBUTTONUP:
if(core)
core->handleMouseUp(CoreInput::MOUSE_BUTTON2, lParam,wParam);
break;
case WM_TOUCH:
if(core) {
if(core->isMultiTouchEnabled()) {
core->handleTouchEvent(lParam, wParam);
}
}
break;
case WM_MBUTTONDOWN:
if(core)
core->handleMouseDown(CoreInput::MOUSE_BUTTON3, lParam,wParam);
break;
case WM_MBUTTONUP:
if(core)
core->handleMouseUp(CoreInput::MOUSE_BUTTON3, lParam,wParam);
break;
case WM_KEYDOWN:
if(core) {
wchar_t unicodeChar = 0;
MSG m;
m.hwnd = hWnd;
m.message = message;
m.wParam = wParam;
m.lParam = lParam;
m.time = 0;
if ( PeekMessage(&m, hWnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) {
GetMessage(&m, hWnd, 0, WM_USER);
unicodeChar = (wchar_t)m.wParam;
}
core->handleKeyDown(lParam,wParam, unicodeChar);
}
break;
case WM_KEYUP:
if(core)
core->handleKeyUp(lParam,wParam);
break;
case WM_CLOSE:
if(core)
core->Shutdown();
useDefault = true;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
useDefault = true;
break;
}
if (useDefault)
return DefWindowProc(hWnd, message, wParam, lParam);
else
return 0;
}
PolycodeView::PolycodeView(HINSTANCE hInstance, int nCmdShow, LPCTSTR windowTitle, bool resizable, bool showDebugConsole) : PolycodeViewBase() {
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"POLYCODEAPPLICATION";
wcex.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&wcex);
if(resizable) {
hwnd = CreateWindowEx(WS_EX_APPWINDOW, L"POLYCODEAPPLICATION", windowTitle, WS_OVERLAPPEDWINDOW|WS_SYSMENU, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
} else {
hwnd = CreateWindowEx(WS_EX_APPWINDOW, L"POLYCODEAPPLICATION", windowTitle, WS_OVERLAPPED|WS_SYSMENU, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
}
windowData = (void*)&hwnd;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
if(showDebugConsole) {
OpenConsole();
}
}
PolycodeView::~PolycodeView() {
}