Repository navigation
Expand file tree
/
Copy pathdialogs.cpp
More file actions
431 lines (398 loc) · 15.5 KB
/
Copy pathdialogs.cpp
File metadata and controls
431 lines (398 loc) · 15.5 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
/*
Dimension
(c) LifesMinder
Module name:
dialogs.cpp
Purpose:
This is the separate dialogs definition file of Dimension client
*/
#include "dimension.h"
// Externs
extern HWND hwnd;
extern HINSTANCE hInst;
extern WCHAR szTitle[MAX_LOADSTRING], szWindowClass[MAX_LOADSTRING];
extern Engine engine;
extern Cursor cursor;
extern wstring currentFile, currentCode;
extern vector<LoggedAction> loggedActions;
extern unsigned int currentAction;
extern bool isSaved;
// File basic routines
void New() {
if (!isSaved && currentCode != L"") {
int confirm = MessageBoxW(hwnd, L"Do you wish to save this file before creating new one?", szTitle, MB_YESNOCANCEL | MB_ICONINFORMATION);
if (confirm == IDCANCEL) return;
if (confirm == IDYES) Save(true);
}
if (DialogBox(hInst, MAKEINTRESOURCE(IDD_NEW), hwnd, NewProject) == IDOK) {
// The dialog already installed a fresh project with the chosen options
currentFile = L"";
engine.Stop();
engine.Clean();
Frame first;
first.number = 0;
first.length = 1;
engine.CreateFrame(first);
engine.currentFrame = 0;
currentCode = engine.Cast();
loggedActions.clear();
currentAction = 0;
isSaved = true;
wstring caption = engine.project.name + L" - " + szTitle;
SetWindowTextW(hwnd, caption.c_str());
UIRefresh(hwnd, 0, 0);
UpdateMenu();
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
}
}
void Open() {
OPENFILENAMEW ofn;
WCHAR szFileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = L"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = L"txt";
if (GetOpenFileNameW(&ofn)) {
currentFile = szFileName;
wifstream stream(szFileName, ios::in);
if (stream.is_open()) {
wstring code = L"", line;
while (getline(stream, line)) {
if (!line.empty() && line.back() == L'\r')
line.pop_back();
code += line + L"\r\n";
}
currentCode = code;
if (!currentCode.empty()) {
engine.Parse(currentCode.data());
engine.Draw();
}
}
stream.close();
UpdateMenu();
}
}
void Save(bool force) {
wstring filePath = currentFile;
if (!force || currentFile.empty()) {
OPENFILENAMEW ofn;
WCHAR szFileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = L"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = (!force) ? L"Save As" : L"Save";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrDefExt = L"txt";
if (!GetSaveFileNameW(&ofn))
return;
filePath = wstring(szFileName);
currentFile = filePath;
}
wofstream stream(filePath.c_str(), ios::out | ios::trunc);
if (stream.good()) {
stream << engine.Cast();
isSaved = true;
}
stream.close();
}
void Export() {
OPENFILENAMEW ofn;
WCHAR szFileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = L"JPG/JPEG File\0*.jpeg\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = L"Export";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrDefExt = L"jpg";
if (GetSaveFileNameW(&ofn)) {
wstring path = wstring(szFileName);
engine.Export(path, engine.currentFrame);
}
}
void ExportVideo() {
OPENFILENAMEW ofn;
WCHAR szFileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = L"MP4 Video\0*.mp4\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = L"Export video";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrDefExt = L"mp4";
if (GetSaveFileNameW(&ofn)) {
engine.ExportVideo(wstring(szFileName));
InvalidateRect(hwnd, NULL, TRUE);
}
}
// Message handler for the editor
INT_PTR CALLBACK Editor(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);
switch (message) {
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN: {
if (DimCoreIsDark())
return UIRefresh(hDlg, lParam, wParam, message);
return 0;
}
case WM_INITDIALOG: {
UIRefresh(hDlg, lParam, wParam);
currentCode = engine.Cast();
// Create a rich edit control for editor, since from dialog we can't yet
LoadLibrary(TEXT("msftedit.dll"));
HWND hEdit = CreateWindowEx(
0, TEXT("RICHEDIT50W"), TEXT(""),
ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_VSCROLL,
10, 10, 442, 233,
hDlg, (HMENU)IDC_EDITOR, hInst, NULL
);
SendMessage(hEdit, EM_SETTARGETDEVICE, (WPARAM)NULL, 0);
if (engine.isV2) {
wstring code = engine.Interpret();
SetDlgItemTextW(hDlg, IDC_EDITOR, code.c_str());
}
else {
SetDlgItemTextW(hDlg, IDC_EDITOR, currentCode.c_str());
}
return (INT_PTR)TRUE;
}
case WM_COMMAND: {
if (LOWORD(wParam) == IDOK) {
HWND hEdit = GetDlgItem(hDlg, IDC_EDITOR);
int length = GetWindowTextLengthW(hEdit) + 1;
vector<WCHAR> buffer(length);
GetDlgItemTextW(hDlg, IDC_EDITOR, buffer.data(), length);
currentCode = wstring(buffer.data());
engine.Clean();
engine.Parse(currentCode.data());
currentCode = engine.Cast();
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
isSaved = false;
EndDialog(hDlg, LOWORD(wParam));
}
else if (LOWORD(wParam) == IDCANCEL) {
EndDialog(hDlg, LOWORD(wParam));
}
return (INT_PTR)TRUE;
}
}
return (INT_PTR)FALSE;
}
INT_PTR CALLBACK NewProject(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);
switch (message) {
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
case WM_CTLCOLOREDIT: {
if (DimCoreIsDark())
return UIRefresh(hDlg, lParam, wParam, message);
return 0;
}
case WM_INITDIALOG: {
UIRefresh(hDlg, lParam, wParam);
// Seed with the current project's real values rather than hardcoded ones
SetDlgItemTextW(hDlg, IDC_NEW_NAME, L"Untitled");
SetDlgItemInt(hDlg, IDC_NEW_SIZE_W, engine.GetAs<int>(L"width", 800), FALSE);
SetDlgItemInt(hDlg, IDC_NEW_SIZE_H, engine.GetAs<int>(L"height", 600), FALSE);
SetDlgItemInt(hDlg, IDC_NEW_FPS, engine.GetAs<int>(L"fps", 15), FALSE);
SendDlgItemMessageW(hDlg, IDC_NEW_NAME, EM_SETLIMITTEXT, 128, 0);
SendDlgItemMessageW(hDlg, IDC_NEW_NAME, EM_SETSEL, 0, -1);
SendDlgItemMessageW(hDlg, IDC_NEW_SIZE_W, EM_SETLIMITTEXT, 5, 0);
SendDlgItemMessageW(hDlg, IDC_NEW_SIZE_H, EM_SETLIMITTEXT, 5, 0);
SendDlgItemMessageW(hDlg, IDC_NEW_FPS, EM_SETLIMITTEXT, 3, 0);
// Spin control drives the FPS box
SendDlgItemMessageW(hDlg, IDC_NEW_FPS_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hDlg, IDC_NEW_FPS), 0);
SendDlgItemMessageW(hDlg, IDC_NEW_FPS_SPIN, UDM_SETRANGE32, 1, 120);
SendDlgItemMessageW(hDlg, IDC_NEW_FPS_SPIN, UDM_SETPOS32, 0, engine.GetAs<int>(L"fps", 15));
SetFocus(GetDlgItem(hDlg, IDC_NEW_NAME));
return (INT_PTR)FALSE;
}
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case IDOK: {
WCHAR title[129] = L"";
GetDlgItemTextW(hDlg, IDC_NEW_NAME, title, 129);
BOOL okW = FALSE, okH = FALSE, okF = FALSE;
UINT width = GetDlgItemInt(hDlg, IDC_NEW_SIZE_W, &okW, FALSE),
height = GetDlgItemInt(hDlg, IDC_NEW_SIZE_H, &okH, FALSE),
fps = GetDlgItemInt(hDlg, IDC_NEW_FPS, &okF, FALSE);
if (!okW || width < 16 || width > 8192) {
MessageBoxW(hDlg, L"Width must be between 16 and 8192.", szTitle, MB_ICONWARNING | MB_OK);
SetFocus(GetDlgItem(hDlg, IDC_NEW_SIZE_W));
return (INT_PTR)TRUE;
}
if (!okH || height < 16 || height > 8192) {
MessageBoxW(hDlg, L"Height must be between 16 and 8192.", szTitle, MB_ICONWARNING | MB_OK);
SetFocus(GetDlgItem(hDlg, IDC_NEW_SIZE_H));
return (INT_PTR)TRUE;
}
if (!okF || fps < 1 || fps > 120) {
MessageBoxW(hDlg, L"FPS must be between 1 and 120.", szTitle, MB_ICONWARNING | MB_OK);
SetFocus(GetDlgItem(hDlg, IDC_NEW_FPS));
return (INT_PTR)TRUE;
}
wstring name = title;
size_t first = name.find_first_not_of(L" \t\r\n");
size_t last = name.find_last_not_of(L" \t\r\n");
name = (first == wstring::npos) ? L"" : name.substr(first, last - first + 1);
if (name.empty()) name = L"Untitled";
map<wstring, any> projectOptions;
projectOptions[L"width"] = (int)width;
projectOptions[L"height"] = (int)height;
projectOptions[L"fps"] = (int)fps;
// Keep program-level settings across projects
for (const wchar_t* key : { L"darkTheme", L"frameLoop" }) {
auto it = engine.project.options.find(key);
if (it != engine.project.options.end()) projectOptions[key] = it->second;
}
engine.project = Project(name, projectOptions);
EndDialog(hDlg, IDOK);
return (INT_PTR)TRUE;
}
case IDCANCEL: {
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
}
break;
}
} return (INT_PTR)FALSE;
}
INT_PTR CALLBACK ExportProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);
switch (message) {
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN: {
if (DimCoreIsDark())
return UIRefresh(hDlg, lParam, wParam, message);
return 0;
}
case WM_INITDIALOG: {
UIRefresh(hDlg, lParam, wParam);
return (INT_PTR)TRUE;
}
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case ID_EXPORT_CURRENT: Export(); break;
case ID_EXPORT_VIDEO: ExportVideo(); break;
case IDOK:
case IDCANCEL: {
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
}
break;
}
}
return (INT_PTR)FALSE;
}
INT_PTR CALLBACK ColorsProcess(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);
static COLORREF colorForeground, colorBackground;
static bool useBackground;
switch (message) {
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN: {
if (DimCoreIsDark())
return UIRefresh(hDlg, lParam, wParam, message);
return 0;
}
case WM_INITDIALOG: {
UIRefresh(hDlg, lParam, wParam);
colorForeground = cursor.foreground;
colorBackground = cursor.background;
useBackground = cursor.useBackground;
CheckDlgButton(hDlg, ID_EDIT_COLOR_ISBACKGROUND, useBackground ? BST_CHECKED : BST_UNCHECKED);
EnableWindow(GetDlgItem(hDlg, ID_EDIT_COLORS_CHANGE_BACK), useBackground);
return (INT_PTR)TRUE;
}
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case ID_EDIT_COLORS_CHANGE: {
colorForeground = ShowColorDialog(hDlg);
break;
}
case ID_EDIT_COLORS_CHANGE_BACK: {
colorBackground = ShowColorDialog(hDlg);
break;
}
case ID_EDIT_COLOR_ISBACKGROUND: {
useBackground = IsDlgButtonChecked(hDlg, ID_EDIT_COLOR_ISBACKGROUND) == BST_CHECKED;
EnableWindow(GetDlgItem(hDlg, ID_EDIT_COLORS_CHANGE_BACK), useBackground);
break;
}
case IDOK: {
cursor.foreground = colorForeground;
cursor.background = colorBackground;
cursor.useBackground = useBackground;
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
case IDCANCEL: {
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
}
break;
}
}
return (INT_PTR)FALSE;
}
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);
switch (message) {
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN: {
if (DimCoreIsDark())
return UIRefresh(hDlg, lParam, wParam, message);
return 0;
}
case WM_INITDIALOG: {
SetClassLongPtr(hDlg, GCLP_HBRBACKGROUND, (LONG_PTR)CreateSolidBrush(RGB(32, 32, 32)));
UIRefresh(hDlg, lParam, wParam);
char programTitle[1024];
#if defined(DIM_CODENAME)
sprintf_s(programTitle, "%s %s %s", DIM_TITLE, DIM_CODENAME, DIM_VERSION);
#else
sprintf_s(programTitle, "%s %s", DIM_TITLE, DIM_VERSION);
#endif
SetWindowTextA(GetDlgItem(hDlg, IDC_DIM_TITLE), programTitle);
return (INT_PTR)TRUE;
}
case WM_NOTIFY: {
LPNMHDR nm = (LPNMHDR)lParam;
if (nm->idFrom == IDC_DIM_COPYRIGHT && (nm->code == NM_CLICK || nm->code == NM_RETURN)) {
PNMLINK link = (PNMLINK)lParam;
ShellExecuteW(hDlg, L"open", link->item.szUrl, NULL, NULL, SW_SHOWNORMAL);
return (INT_PTR)TRUE;
}
break;
}
case WM_COMMAND: {
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
}
return (INT_PTR)FALSE;
}