Repository navigation
Expand file tree
/
Copy pathdimension.cpp
More file actions
577 lines (532 loc) · 24.9 KB
/
Copy pathdimension.cpp
File metadata and controls
577 lines (532 loc) · 24.9 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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
/*
Dimension
(c) LifesMinder
Module name:
dimension.cpp
Purpose:
This is the main executable file of Dimension client
*/
#include "dimension.h"
// Global Variables
Engine engine;
Project project;
HINSTANCE hInst; HWND hwnd;
WCHAR szTitle[MAX_LOADSTRING], szWindowClass[MAX_LOADSTRING];
// Program-specific variables
Cursor cursor;
bool isSaved = false;
wstring currentFile = L"", currentCode = L"";
map<int, wchar_t> flags; map<wstring, any> options;
vector<LoggedAction> loggedActions; unsigned int currentAction = (loggedActions.size() > 0) ? loggedActions.size() : 0;
int
APIENTRY
wWinMain(
__in HINSTANCE hInstance,
__in_opt HINSTANCE hPrevInstance,
__in LPWSTR lpCmdLine,
__in int nCmdShow
) {
// These guys are useless (at least for now)
UNREFERENCED_PARAMETER(hPrevInstance);
// Parse command line
UNREFERENCED_PARAMETER(lpCmdLine); // <- this is done, because it's unusable for parsing, at least... for now
CLI();
// Initialize GDI+
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_DIMENSION, szWindowClass, MAX_LOADSTRING);
// Register the class
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DIMENSION));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = NULL; // (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_DIMENSION);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_DIMENSION));
if (!RegisterClassExW(&wcex))
return FALSE;
// Perform application initialization
hInst = hInstance;
// Common controls: SysLink (About), up-down (New Project)
INITCOMMONCONTROLSEX icc = { sizeof(icc), ICC_LINK_CLASS | ICC_UPDOWN_CLASS | ICC_STANDARD_CLASSES };
InitCommonControlsEx(&icc);
hwnd = CreateWindowW(
szWindowClass, szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
nullptr, nullptr, hInstance, nullptr
);
if (hwnd) {
engine = Engine(hwnd);
engine.isV2 = true;
engine.project = project;
engine.isDarkTheme = DimCoreIsDark();
UIRefresh(hwnd, 0, 0);
UpdateMenu();
} else {
return FALSE;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DIMENSION));
MSG msg;
// Main message loop
while (GetMessage(&msg, nullptr, 0, 0)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GdiplusShutdown(gdiplusToken);
return (int)msg.wParam;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
LRESULT lr = 0;
auto FinishPath = [&]() {
cursor.drawing = false;
if (cursor.pathPoints.size() < 2) {
cursor.pathPoints.clear();
cursor.points.clear();
return;
}
RECT clientRect;
GetClientRect(hwnd, &clientRect);
int canvasW = engine.GetAs<int>(L"width", 800);
int canvasH = engine.GetAs<int>(L"height", 600);
int cx = (clientRect.right - canvasW) / 2;
int cy = (clientRect.bottom - canvasH) / 2;
Shape sh = { .id = -1, .type = SHAPE_PATH };
for (int i = 0; i < (int)cursor.pathPoints.size(); i++) {
sh.options[L"x" + to_wstring(i + 1)] = to_wstring(cursor.pathPoints[i].point.x - cx);
sh.options[L"y" + to_wstring(i + 1)] = to_wstring(cursor.pathPoints[i].point.y - cy);
if (cursor.pathPoints[i].smooth) {
sh.options[L"cx" + to_wstring(i + 1)] = to_wstring(cursor.pathPoints[i].controlPoint.x - cx);
sh.options[L"cy" + to_wstring(i + 1)] = to_wstring(cursor.pathPoints[i].controlPoint.y - cy);
}
}
sh.options[L"r"] = to_wstring(GetRValue(cursor.foreground));
sh.options[L"g"] = to_wstring(GetGValue(cursor.foreground));
sh.options[L"b"] = to_wstring(GetBValue(cursor.foreground));
sh.options[L"size"] = to_wstring(cursor.size);
if (cursor.useBackground) {
sh.options[L"fill"] = wstring(L"1");
sh.options[L"br"] = to_wstring(GetRValue(cursor.background));
sh.options[L"bg"] = to_wstring(GetGValue(cursor.background));
sh.options[L"bb"] = to_wstring(GetBValue(cursor.background));
}
if (engine.project.frames.empty()) engine.CreateFrame(Frame());
engine.CreateShape(sh);
currentCode = engine.Cast();
cursor.pathPoints.clear();
cursor.points.clear();
isSaved = false;
// Log the path creation
vector<Shape> shs; shs.push_back(sh);
ActionUpdate(2, { .type = 5000, .frame = (unsigned int)engine.currentFrame, .shape = 0, .shapes = shs });
InvalidateRect(hwnd, NULL, FALSE);
UpdateMenu();
};
if (DimCoreIsDark() && UAHWndProc(hwnd, message, wParam, lParam, &lr)) {
return lr;
}
switch (message) {
case WM_ACTIVATE: {
CheckMenuRadioItem(GetMenu(hWnd), ID_TOOLBOX_CURSOR, ID_TOOLBOX_PATH, ID_TOOLBOX_CURSOR, MF_BYCOMMAND);
break;
}
case WM_SIZE: {
SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
UIRefresh(hWnd, lParam, wParam);
break;
}
case WM_COMMAND: {
int wmId = LOWORD(wParam);
switch (wmId) {
// File
case IDM_NEW: New(); break;
case IDM_OPEN: Open(); break;
case IDM_SAVE: Save(true); break;
case IDM_SAVEAS: Save(false); break;
case IDM_EDIT: DialogBox(hInst, MAKEINTRESOURCE(IDD_EDITOR), hWnd, Editor); break;
//// Export
case ID_EXPORT: DialogBox(hInst, MAKEINTRESOURCE(IDD_EXPORTER), hWnd, ExportProc); break;
case IDM_EXIT: DestroyWindow(hWnd); break;
// Edit
//// Toolbox
case ID_TOOLBOX_CURSOR:
case ID_TOOLBOX_RECTANGLE:
case ID_TOOLBOX_ELLIPSE:
case ID_TOOLBOX_LINE:
case ID_TOOLBOX_PATH: {
switch (wmId) {
case ID_TOOLBOX_CURSOR: cursor.tool = SHAPE_NONE; break;
case ID_TOOLBOX_RECTANGLE: cursor.tool = SHAPE_RECTANGLE; break;
case ID_TOOLBOX_ELLIPSE: cursor.tool = SHAPE_ELLIPSE; break;
case ID_TOOLBOX_LINE: cursor.tool = SHAPE_LINE; break;
case ID_TOOLBOX_PATH: cursor.tool = SHAPE_PATH; break;
}
CheckMenuRadioItem(GetMenu(hWnd), ID_TOOLBOX_CURSOR, ID_TOOLBOX_PATH, wmId, MF_BYCOMMAND);
UpdateMenu();
break;
}
//// Timeline
case ID_TIMELINE_PLAY: (engine.isPlaying) ? engine.Pause() : engine.Play(); break;
case ID_TIMELINE_STOP: engine.Pause(); break;
case ID_TIMELINE_NEXT: engine.NextFrame(); break;
case ID_TIMELINE_PREVIOUS: engine.PreviousFrame(); break;
case ID_TIMELINE_NEW: {
engine.CreateFrame(Frame());
engine.currentFrame = (int)engine.project.frames.size() - 1; // go to newly created frame
InvalidateRect(hWnd, NULL, FALSE);
ActionUpdate(2, { .type = ID_TIMELINE_NEW, .frame = engine.currentFrame });
UpdateMenu();
break;
}
case ID_TIMELINE_EXTEND: {
engine.project.frames[engine.currentFrame].length++;
InvalidateRect(hWnd, NULL, FALSE);
ActionUpdate(2, { .type = ID_TIMELINE_EXTEND, .frame = engine.currentFrame });
UpdateMenu();
break;
}
case ID_TIMELINE_DUPLICATE: {
if (engine.project.frames.empty()) break;
Frame copy = engine.project.frames[engine.currentFrame]; // duplicate current, not next
engine.CreateFrame(copy);
engine.currentFrame = (int)engine.project.frames.size() - 1;
InvalidateRect(hWnd, NULL, FALSE);
ActionUpdate(2, { .type = ID_TIMELINE_DUPLICATE, .frame = (unsigned int)engine.currentFrame, .shape = 0, .shapes = copy.shapes });
UpdateMenu();
break;
}
case ID_TIMELINE_DELETE: {
if (engine.project.frames.empty()) break;
Frame dying = engine.project.frames[engine.currentFrame]; // save before delete
unsigned int deletedFrame = engine.currentFrame;
engine.DeleteFrame(engine.currentFrame);
if (engine.currentFrame >= (int)engine.project.frames.size())
engine.currentFrame = max(0, (int)engine.project.frames.size() - 1);
if (engine.project.frames.empty()) {
engine.CreateFrame(Frame());
engine.currentFrame = 0;
}
InvalidateRect(hWnd, NULL, FALSE);
ActionUpdate(2, { .type = ID_TIMELINE_DELETE, .frame = deletedFrame, .shape = 0, .shapes = dying.shapes });
UpdateMenu();
break;
}
case ID_TIMELINE_LOOP: {
bool doFrameLoop = engine.GetAs<bool>(L"frameLoop", false);
doFrameLoop = !doFrameLoop;
engine.Set(L"frameLoop", doFrameLoop);
CheckMenuItem(GetMenu(hWnd), ID_TIMELINE_LOOP, doFrameLoop ? MF_CHECKED : MF_UNCHECKED);
UpdateMenu();
break;
}
//// Brush
case ID_BRUSH_INCREASE: cursor.size += 1; break;
case ID_BRUSH_DECREASE: cursor.size = (cursor.size > 1) ? --cursor.size : 1; break;
case ID_BRUSH_RESET: cursor.size = 1; break;
case ID_BRUSH_COLORS: DialogBox(hInst, MAKEINTRESOURCE(IDD_COLORS), hWnd, ColorsProcess); break;
//// Shape operations
case ID_ACTION_UNDO: ActionUpdate(0, {}); break;
case ID_ACTION_REDO: ActionUpdate(1, {}); break;
case ID_SHAPE_SELECT_ALL: {
if (engine.project.frames.size() > 0) {
auto& shapes = engine.project.frames[engine.currentFrame].shapes;
if (shapes.size() > 0) {
for (int i = (int)shapes.size() - 1; i >= 0; i--) {
if (!shapes[i].selected) {
shapes[i].selected = true;
}
}
InvalidateRect(hWnd, NULL, FALSE);
UpdateMenu();
}
}
break;
}
case ID_SHAPE_DELETE: {
if (engine.project.frames.size() > 0) {
auto& shapes = engine.project.frames[engine.currentFrame].shapes;
if (shapes.size() > 0) {
vector<Shape> shs;
for (int i = (int)shapes.size() - 1; i >= 0; i--) {
if (shapes[i].selected) {
shs.push_back(shapes[i]);
shapes.erase(shapes.begin() + i);
}
}
InvalidateRect(hWnd, NULL, FALSE);
ActionUpdate(2, { .type = ID_SHAPE_DELETE, .frame = (unsigned int)engine.currentFrame, .shape = 0, .shapes = shs });
UpdateMenu();
}
}
break;
}
// Help
case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break;
case ID_HELP_WIKI: ShellExecuteW(NULL, TEXT("open"), TEXT("http://git.lmd.vg/ash/dimension/wiki/Welcome"), NULL, NULL, SW_SHOW); break;
case ID_HELP_CHANGELOG: ShellExecuteW(NULL, TEXT("open"), TEXT("http://git.lmd.vg/ash/dimension/src/branch/master/CHANGELOG.md"), NULL, NULL, SW_SHOW); break;
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
}
case WM_CHAR: {
if (wParam == VK_ESCAPE && cursor.drawing) {
cursor.drawing = false;
InvalidateRect(hWnd, NULL, FALSE);
}
if (wParam == VK_RETURN) {
if (cursor.tool == SHAPE_PATH && cursor.drawing)
FinishPath();
}
return 0;
}
case WM_TIMER: {
if (wParam == 1) {
static unsigned int ticksOnFrame = 0;
unsigned int length = 1;
if (!engine.project.frames.empty())
length = max(1u, engine.project.frames[engine.currentFrame].length);
ticksOnFrame++;
if (ticksOnFrame >= length) {
ticksOnFrame = 0;
engine.NextFrame();
}
}
UpdateMenu();
break;
}
case WM_LBUTTONDOWN: {
cursor.dragging = false;
cursor.drag = { LOWORD(lParam), HIWORD(lParam) };
cursor.start.x = cursor.now.x = LOWORD(lParam);
cursor.start.y = cursor.now.y = HIWORD(lParam);
if (cursor.tool == SHAPE_NONE) {
RECT rc; GetClientRect(hWnd, &rc);
int canvasW = engine.GetAs<int>(L"width", 800), canvasH = engine.GetAs<int>(L"height", 600);
int cx = (rc.right - canvasW) / 2, cy = (rc.bottom - canvasH) / 2;
int px = cursor.start.x - cx, py = cursor.start.y - cy;
if (!engine.project.frames.empty()) {
auto& shapes = engine.project.frames[engine.currentFrame].shapes;
// single-select: clear first
for (auto& s : shapes)
s.selected = false;
for (int i = (int)shapes.size() - 1; i >= 0; i--) {
// topmost first
if (engine.HitTest(shapes[i], px, py)) {
shapes[i].selected = true;
break;
}
}
}
} else if (cursor.tool == SHAPE_PATH) {
cursor.drawing = true;
cursor.drag = { LOWORD(lParam), HIWORD(lParam) };
} else {
cursor.drawing = (cursor.tool != SHAPE_NONE);
}
InvalidateRect(hWnd, NULL, FALSE);
UpdateMenu();
return 0;
}
case WM_MOUSEMOVE: {
cursor.now.x = LOWORD(lParam);
cursor.now.y = HIWORD(lParam);
if (cursor.drawing) {
if (cursor.tool == SHAPE_PATH && (wParam & MK_LBUTTON)) {
cursor.dragging = true;
}
InvalidateRect(hWnd, NULL, FALSE);
UpdateMenu();
}
return 0;
}
case WM_LBUTTONUP: {
if (!cursor.drawing) return 0;
if (cursor.tool != SHAPE_PATH) cursor.drawing = false;
// get canvas offset from engine
RECT clientRect;
GetClientRect(hWnd, &clientRect);
int clientWidth = clientRect.right, clientHeight = clientRect.bottom;
int canvasW = engine.GetAs<int>(L"width", 800), canvasH = engine.GetAs<int>(L"height", 600);
int cx = (clientWidth - canvasW) / 2, cy = (clientHeight - canvasH) / 2;
// check for path being
if (cursor.tool == SHAPE_PATH) {
// clicking close to the first point closes (finishes) the path
bool closing = false;
if (cursor.pathPoints.size() >= 2) {
int dx = (int)LOWORD(lParam) - cursor.pathPoints[0].point.x, dy = (int)HIWORD(lParam) - cursor.pathPoints[0].point.y;
closing = (dx * dx + dy * dy < 15 * 15);
}
// the clicked point always counts, including the one that ends the path
PathPoint p = { .point = cursor.drag, .smooth = cursor.dragging };
p.controlPoint = (cursor.dragging) ? POINT{ cursor.now.x, cursor.now.y } : cursor.drag;
cursor.pathPoints.push_back(p);
cursor.points.push_back(cursor.drag);
cursor.dragging = false;
if (closing) {
FinishPath();
UpdateMenu();
return 0;
}
InvalidateRect(hWnd, NULL, FALSE);
return 0;
}
// build shape — subtract canvas offset so coords are canvas-relative
Shape sh = { .id = -1, .type = cursor.tool };
if (cursor.tool == SHAPE_LINE) {
// lines keep exact start/end points, no min/max normalization
sh.options[L"x"] = to_wstring(cursor.start.x - cx);
sh.options[L"y"] = to_wstring(cursor.start.y - cy);
sh.options[L"x2"] = to_wstring(cursor.now.x - cx);
sh.options[L"y2"] = to_wstring(cursor.now.y - cy);
} else {
int x1 = min(cursor.start.x, cursor.now.x) - cx, y1 = min(cursor.start.y, cursor.now.y) - cy;
int x2 = max(cursor.start.x, cursor.now.x) - cx, y2 = max(cursor.start.y, cursor.now.y) - cy;
sh.options[L"x"] = to_wstring(x1);
sh.options[L"y"] = to_wstring(y1);
sh.options[L"width"] = to_wstring(x2 - x1);
sh.options[L"height"] = to_wstring(y2 - y1);
}
// Remaining parameters, fetched from our cursor
sh.options[L"r"] = to_wstring(GetRValue(cursor.foreground));
sh.options[L"g"] = to_wstring(GetGValue(cursor.foreground));
sh.options[L"b"] = to_wstring(GetBValue(cursor.foreground));
sh.options[L"size"] = to_wstring(cursor.size);
if (cursor.useBackground) {
sh.options[L"fill"] = wstring(L"1");
sh.options[L"br"] = to_wstring(GetRValue(cursor.background));
sh.options[L"bg"] = to_wstring(GetGValue(cursor.background));
sh.options[L"bb"] = to_wstring(GetBValue(cursor.background));
}
// If there's no any frame, attach one like in Adobe Animate (Flash)
if (engine.project.frames.empty()) {
Frame frame;
engine.CreateFrame(frame);
}
engine.CreateShape(sh);
currentCode = engine.Cast();
isSaved = false;
InvalidateRect(hWnd, NULL, FALSE);
vector<Shape> shs;
shs.push_back(sh);
ActionUpdate(2, { .type = 5000, .frame = (unsigned int)engine.currentFrame, .shape = 0, .shapes = shs });
UpdateMenu();
return 0;
}
case WM_LBUTTONDBLCLK: {
if (cursor.tool != SHAPE_PATH || !cursor.drawing) return 0;
FinishPath();
UpdateMenu();
return 0;
}
case WM_PAINT: {
if (engine.isV2) {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
engine.DrawV2(hdc);
EndPaint(hWnd, &ps);
} else {
engine.Draw();
}
// rubber band overlay
if (cursor.drawing && cursor.tool != SHAPE_NONE) {
RECT cr;
GetClientRect(hWnd, &cr);
// clamp to canvas bounds
int x1 = min(cursor.start.x, cursor.now.x), y1 = min(cursor.start.y, cursor.now.y);
int x2 = max(cursor.start.x, cursor.now.x), y2 = max(cursor.start.y, cursor.now.y);
HDC hdc = GetDC(hWnd);
SetROP2(hdc, R2_NOTXORPEN);
HPEN rbPen = CreatePen(PS_DOT, 1, RGB(0, 0, 0));
HGDIOBJ oldPen = SelectObject(hdc, rbPen), oldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
switch (cursor.tool) {
case SHAPE_NONE:
case SHAPE_RECTANGLE:
Rectangle(hdc, x1, y1, x2, y2);
break;
case SHAPE_ELLIPSE:
Ellipse(hdc, x1, y1, x2, y2);
break;
case SHAPE_LINE:
MoveToEx(hdc, cursor.start.x, cursor.start.y, NULL);
LineTo(hdc, cursor.now.x, cursor.now.y);
break;
case SHAPE_PATH: {
if (cursor.drawing && cursor.pathPoints.size() > 0) {
MoveToEx(hdc, cursor.pathPoints[0].point.x, cursor.pathPoints[0].point.y, NULL);
for (int i = 1; i < (int)cursor.pathPoints.size(); i++) {
PathPoint previous = cursor.pathPoints[i - 1], current = cursor.pathPoints[i];
if (previous.smooth || current.smooth) {
// outgoing handle of previous point
POINT c1 = previous.smooth ? previous.controlPoint : previous.point;
// incoming handle of current = reflection of its stored (outgoing) handle
POINT c2 = current.smooth
? POINT{ 2 * current.point.x - current.controlPoint.x,
2 * current.point.y - current.controlPoint.y }
: current.point;
POINT points[3] = { c1, c2, current.point };
MoveToEx(hdc, previous.point.x, previous.point.y, NULL);
PolyBezierTo(hdc, points, sizeof(points) / sizeof(points[0]));
}
else {
MoveToEx(hdc, previous.point.x, previous.point.y, NULL);
LineTo(hdc, current.point.x, current.point.y);
}
}
// preview segment from last placed point to the point being dragged
PathPoint last = cursor.pathPoints.back();
SetROP2(hdc, R2_NOTXORPEN);
MoveToEx(hdc, last.point.x, last.point.y, NULL);
if (cursor.dragging) {
// outgoing handle of last point
POINT c1 = last.smooth ? last.controlPoint : last.point;
// incoming handle of the point being dragged, reflection of current cursor and across anchor (draggable cursor)
POINT c2 = { 2 * cursor.drag.x - cursor.now.x, 2 * cursor.drag.y - cursor.now.y };
POINT seg[3] = { c1, c2, cursor.drag };
PolyBezierTo(hdc, seg, 3);
MoveToEx(hdc, cursor.drag.x, cursor.drag.y, NULL);
LineTo(hdc, cursor.now.x, cursor.now.y);
} else {
LineTo(hdc, cursor.now.x, cursor.now.y);
}
}
break;
}
}
SelectObject(hdc, oldPen);
SelectObject(hdc, oldBrush);
DeleteObject(rbPen);
ReleaseDC(hWnd, hdc);
}
break;
}
case WM_DESTROY: {
FreeConsole();
PostQuitMessage(0);
break;
}
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}