forked from ivansafrin/Polycode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolycodePlayerView.cpp
More file actions
281 lines (235 loc) · 7.15 KB
/
PolycodePlayerView.cpp
File metadata and controls
281 lines (235 loc) · 7.15 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include "PolycodePlayerView.h"
#include "resource.h"
#include <Commdlg.h>
using namespace Polycode;
Win32Core *core = NULL;
HWND consoleHwnd;
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->getServices()->getRenderer()->Resize(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;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
if(core)
core->Shutdown();
break;
case ID_FILE_OPEN:
{
TCHAR szFile[2048];
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = L"Polycode Application (*.polyapp)\0*.POLYAPP\0";
ofn.nFilterIndex = 0;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)==TRUE) {
TCHAR tpath[2049];
GetModuleFileName(NULL, (LPWSTR)tpath, 2048);
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
String fullLine = String(tpath);
CreateProcess(fullLine.getWDataWithEncoding(String::ENCODING_UTF8), szFile, NULL, NULL, false, 0, 0, NULL, &si, &pi);
}
}
break;
case ID_SHOW_CONSOLE:
ShowWindow(consoleHwnd, SW_SHOW);
UpdateWindow(consoleHwnd);
break;
}
break;
default:
useDefault = true;
break;
}
if (useDefault)
return DefWindowProc(hWnd, message, wParam, lParam);
else
return 0;
}
LRESULT CALLBACK ConsoleWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
int nWidth, nHeight;
switch (message)
{
case WM_CLOSE:
ShowWindow(consoleHwnd, SW_HIDE);
UpdateWindow(consoleHwnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void AppendTextToEditCtrl(HWND hWndEdit, LPCTSTR pszText)
{
int nLength = Edit_GetTextLength(hWndEdit);
Edit_SetSel(hWndEdit, nLength, nLength);
Edit_ReplaceSel(hWndEdit, pszText);
}
void PolycodePlayerView::handleEvent(Event *event){
PolycodeDebugEvent *debugEvent = (PolycodeDebugEvent*) event;
switch(event->getEventCode()) {
case PolycodeDebugEvent::EVENT_ERROR:
{
String lineString = String("Error on line ");
lineString = lineString + String::NumberToString(debugEvent->lineNumber);
lineString = lineString + " - ";
AppendTextToEditCtrl(consoleTextArea, lineString.getWDataWithEncoding(String::ENCODING_UTF8));
AppendTextToEditCtrl(consoleTextArea, debugEvent->errorString.getWDataWithEncoding(String::ENCODING_UTF8));
ShowWindow(consoleHwnd, SW_SHOW);
UpdateWindow(consoleHwnd);
}
break;
case PolycodeDebugEvent::EVENT_PRINT:
AppendTextToEditCtrl(consoleTextArea, debugEvent->errorString.getWDataWithEncoding(String::ENCODING_UTF8));
ShowWindow(consoleHwnd, SW_SHOW);
UpdateWindow(consoleHwnd);
break;
}
}
PolycodePlayerView::PolycodePlayerView(bool standaloneMode, HINSTANCE hInstance, int nCmdShow, LPCTSTR windowTitle) : PolycodeViewBase(), EventHandler() {
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(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
//wcex.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
if(standaloneMode) {
wcex.lpszMenuName = NULL;
} else {
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);;
}
wcex.lpszClassName = L"POLYCODEAPPLICATION";
wcex.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&wcex);
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);
WNDCLASSEX console_wcex;
console_wcex.cbSize = sizeof(WNDCLASSEX);
console_wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
console_wcex.lpfnWndProc = ConsoleWindowProc;
console_wcex.cbClsExtra = 0;
console_wcex.cbWndExtra = 0;
console_wcex.hInstance = hInstance;
console_wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
console_wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
console_wcex.hbrBackground = NULL;
console_wcex.lpszMenuName = NULL;
console_wcex.lpszClassName = L"CONSOLEWINDOW";
console_wcex.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&console_wcex);
consoleHwnd = CreateWindowEx(WS_EX_TOOLWINDOW, L"CONSOLEWINDOW", L"Debug console.", WS_OVERLAPPED|WS_SYSMENU,
640, 100, 500, 300, hwnd, NULL, hInstance, NULL);
//ShowWindow(consoleHwnd, SW_SHOW);
UpdateWindow(consoleHwnd);
consoleTextArea = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"", WS_CHILD | WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_READONLY,
0, 0, 500, 275, consoleHwnd, NULL, hInstance, NULL);
ShowWindow(consoleTextArea, SW_SHOW);
UpdateWindow(consoleTextArea);
HFONT defaultFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
SendMessage (consoleTextArea, WM_SETFONT, WPARAM (defaultFont), TRUE);
}
PolycodePlayerView::~PolycodePlayerView() {
}