-
Notifications
You must be signed in to change notification settings - Fork 1
/
Debugger.cpp
714 lines (660 loc) · 25.2 KB
/
Debugger.cpp
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
#include "StdAfx.h"
#include "resource.h"
#include <windowsx.h>
#define RECOMPUTEBUTTONCHECK WM_USER+100
#define RESIZE_FROM_EXPAND WM_USER+101
TBBUTTON const g_tbbuttonDebug[] = {
#ifdef _WIN64
{ 0, IDC_PLAY, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, 0, 0, 0, 0, IDS_PLAY, 0 },
{ 1, IDC_PAUSE, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, 0, 0, 0, 0, IDS_PAUSE, 1 },
{ 2, IDC_STEP, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, 0, 0, 0, 0, IDS_STEP, 2 },
#else
{ 0, IDC_PLAY, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, IDS_PLAY, 0 },
{ 1, IDC_PAUSE, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, IDS_PAUSE, 1 },
{ 2, IDC_STEP, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, IDS_STEP, 2 },
#endif
};
void AssignIconToButton(HWND hwnd, int controlid, int resourceid)
{
HWND hwndButton = GetDlgItem(hwnd, controlid);
HICON hicon = (HICON)LoadImage(g_hinst, MAKEINTRESOURCE(resourceid), IMAGE_ICON, 16, 16, 0);
SendMessage(hwndButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hicon);
}
Light *GetLight(HWND hCombo)
{
int idx_row;
char strText[255] = { 0 };
idx_row = ComboBox_GetCurSel(hCombo);
ComboBox_GetLBText(hCombo, idx_row, strText);
IEditable *pedit = g_pplayer->m_ptable->GetElementByName(strText);
if (pedit != NULL)
return (Light*)pedit;
return NULL;
}
void SetCheckButtonState(HWND hwndDlg, Light *plight)
{
if (plight->m_d.m_state == LightStateOn)
{
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_ON_CHECK), BST_CHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_OFF_CHECK), BST_UNCHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_BLINKING_CHECK), BST_UNCHECKED);
}
else if (plight->m_d.m_state == LightStateOff)
{
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_ON_CHECK), BST_UNCHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_OFF_CHECK), BST_CHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_BLINKING_CHECK), BST_UNCHECKED);
}
else if (plight->m_d.m_state == LightStateBlinking)
{
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_ON_CHECK), BST_UNCHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_OFF_CHECK), BST_UNCHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_DBG_LIGHT_BLINKING_CHECK), BST_CHECKED);
}
}
INT_PTR CALLBACK MaterialDebuggerProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PinTable *ptable = g_pplayer->m_ptable;
HWND hCombo = GetDlgItem(hwndDlg, IDC_DBG_MATERIALCOMBO);
switch (uMsg)
{
case WM_INITDIALOG:
{
vector<string> matNames;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
for (size_t i = 0; i < ptable->m_materials.size(); i++)
{
matNames.push_back(ptable->m_materials[i]->m_szName);
}
std::sort(matNames.begin(), matNames.end());
for (size_t i = 0; i < matNames.size(); i++)
ComboBox_AddString(hCombo, matNames[i].c_str());
ShowWindow(g_pplayer->m_hwndDebugger, SW_HIDE);
ComboBox_SetCurSel(hCombo, 0);
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_DBG_MATERIALCOMBO, CBN_SELCHANGE), 0);
return TRUE;
}
case WM_CLOSE:
{
ShowWindow(g_pplayer->m_hwndDebugger, SW_SHOW);
EndDialog(hwndDlg, FALSE);
break;
}
case GET_COLOR_TABLE:
{
*((unsigned long **)lParam) = ptable->m_rgcolorcustom;
return TRUE;
}
case WM_ACTIVATE:
{
g_pplayer->m_fDebugWindowActive = (wParam != WA_INACTIVE);
g_pplayer->RecomputePauseState();
g_pplayer->RecomputePseudoPauseState();
break;
}
case WM_COMMAND:
{
switch (HIWORD(wParam))
{
case COLOR_CHANGED:
{
char strText[255] = { 0 };
const size_t color = GetWindowLongPtr((HWND)lParam, GWLP_USERDATA);
const HWND hwndcolor1 = GetDlgItem(hwndDlg, IDC_COLOR);
const HWND hwndcolor2 = GetDlgItem(hwndDlg, IDC_COLOR2);
const HWND hwndcolor3 = GetDlgItem(hwndDlg, IDC_COLOR3);
const LRESULT idx_row = SendMessage(hCombo, CB_GETCURSEL, 0, 0);
SendMessage(hCombo, CB_GETLBTEXT, idx_row, (LPARAM)strText);
Material * const pMat = ptable->GetMaterial(strText);
if (pMat != NULL)
{
if (hwndcolor1 == (HWND)lParam)
pMat->m_cBase = (COLORREF)color;
else if (hwndcolor2 == (HWND)lParam)
pMat->m_cGlossy = (COLORREF)color;
else if (hwndcolor3 == (HWND)lParam)
pMat->m_cClearcoat = (COLORREF)color;
ptable->AddDbgMaterial(pMat);
}
break;
}
case BN_CLICKED:
{
switch (LOWORD(wParam))
{
case IDOK:
{
int idx_row;
char strText[255] = { 0 };
idx_row = ComboBox_GetCurSel(hCombo);
ComboBox_GetLBText(hCombo, idx_row, strText);
Material *pMat = ptable->GetMaterial(strText);
if (pMat != NULL)
{
char value[256];
GetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_BASE_WRAP_EDIT, value, 31);
pMat->m_fWrapLighting = saturate(sz2f(value));
GetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_SHININESS_EDIT, value, 31);
pMat->m_fRoughness = saturate(sz2f(value));
GetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_GLOSSY_IMGLERP_EDIT, value, 31);
pMat->m_fGlossyImageLerp = saturate(sz2f(value));
GetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_THICKNESS_EDIT, value, 31);
pMat->m_fThickness = saturate(sz2f(value));
GetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_EDGE_EDIT, value, 31);
pMat->m_fEdge = saturate(sz2f(value));
GetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_OPACITY_AMOUNT_EDIT, value, 31);
pMat->m_fOpacity = saturate(sz2f(value));
GetDlgItemText(hwndDlg, DBG_MATERIAL_OPACITY_EDGE_EDIT, value, 31);
pMat->m_fEdgeAlpha = saturate(sz2f(value));
size_t checked = SendDlgItemMessage(hwndDlg, IDC_DBG_METAL_MATERIAL_CHECK, BM_GETCHECK, 0, 0);
pMat->m_bIsMetal = (checked == 1);
checked = SendDlgItemMessage(hwndDlg, IDC_DBG_MATERIAL_OPACITY_ACTIVE_CHECK, BM_GETCHECK, 0, 0);
pMat->m_bOpacityActive = (checked == 1);
ptable->AddDbgMaterial(pMat);
}
break;
}
case IDCANCEL:
{
ShowWindow(g_pplayer->m_hwndDebugger, SW_SHOW);
EndDialog(hwndDlg, FALSE);
return TRUE;
}
}
break;
}
}
switch (LOWORD(wParam))
{
case IDC_DBG_MATERIAL_OPACITY_ACTIVE_CHECK:
case IDC_DBG_METAL_MATERIAL_CHECK:
{
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), 0);
break;
}
case IDC_DBG_MATERIALCOMBO:
{
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
{
int idx_row;
char strText[255] = { 0 };
idx_row = ComboBox_GetCurSel(hCombo);
ComboBox_GetLBText(hCombo, idx_row, strText);
Material *pMat = ptable->GetMaterial(strText);
if (pMat != NULL)
{
char value[256];
f2sz(pMat->m_fWrapLighting, value);
SetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_BASE_WRAP_EDIT, value);
f2sz(pMat->m_fRoughness, value);
SetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_SHININESS_EDIT, value);
f2sz(pMat->m_fGlossyImageLerp, value);
SetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_GLOSSY_IMGLERP_EDIT, value);
f2sz(pMat->m_fThickness, value);
SetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_THICKNESS_EDIT, value);
f2sz(pMat->m_fEdge, value);
SetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_EDGE_EDIT, value);
f2sz(pMat->m_fOpacity, value);
SetDlgItemText(hwndDlg, IDC_DBG_MATERIAL_OPACITY_AMOUNT_EDIT, value);
f2sz(pMat->m_fEdgeAlpha, value);
SetDlgItemText(hwndDlg, DBG_MATERIAL_OPACITY_EDGE_EDIT, value);
SendMessage(GetDlgItem(hwndDlg, IDC_DBG_METAL_MATERIAL_CHECK), BM_SETCHECK, pMat->m_bIsMetal ? BST_CHECKED : BST_UNCHECKED, 0);
SendMessage(GetDlgItem(hwndDlg, IDC_DBG_MATERIAL_OPACITY_ACTIVE_CHECK), BM_SETCHECK, pMat->m_bOpacityActive ? BST_CHECKED : BST_UNCHECKED, 0);
SendMessage(GetDlgItem(hwndDlg, IDC_COLOR), CHANGE_COLOR, 0, pMat->m_cBase);
SendMessage(GetDlgItem(hwndDlg, IDC_COLOR2), CHANGE_COLOR, 0, pMat->m_cGlossy);
SendMessage(GetDlgItem(hwndDlg, IDC_COLOR3), CHANGE_COLOR, 0, pMat->m_cClearcoat);
}
break;
}
}
break;
}
}
break;
}
}
return FALSE;
}
INT_PTR CALLBACK LightDebuggerProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PinTable *ptable = g_pplayer->m_ptable;
HWND hCombo = GetDlgItem(hwndDlg, IDC_LIGHTSCOMBO);
switch (uMsg)
{
case WM_INITDIALOG:
{
vector<string> lightNames;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
for (size_t i = 0; i < ptable->m_vedit.size(); i++)
{
IEditable * const pedit = ptable->m_vedit[i];
if (pedit->GetItemType() == eItemLight)
{
lightNames.push_back(ptable->GetElementName(pedit));
}
}
std::sort(lightNames.begin(), lightNames.end());
for (size_t i = 0; i < lightNames.size();i++)
ComboBox_AddString(hCombo, lightNames[i].c_str());
ShowWindow(g_pplayer->m_hwndDebugger, SW_HIDE);
ComboBox_SetCurSel(hCombo, 0);
SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_LIGHTSCOMBO, CBN_SELCHANGE), 0);
return TRUE;
}
case WM_CLOSE:
{
ShowWindow(g_pplayer->m_hwndDebugger, SW_SHOW);
EndDialog(hwndDlg, FALSE);
break;
}
case GET_COLOR_TABLE:
{
*((unsigned long **)lParam) = ptable->m_rgcolorcustom;
return TRUE;
}
case WM_ACTIVATE:
{
g_pplayer->m_fDebugWindowActive = (wParam != WA_INACTIVE);
g_pplayer->RecomputePauseState();
g_pplayer->RecomputePseudoPauseState();
break;
}
case WM_COMMAND:
{
switch (HIWORD(wParam))
{
case COLOR_CHANGED:
{
LRESULT idx_row;
char strText[255] = { 0 };
const size_t color = GetWindowLongPtr((HWND)lParam, GWLP_USERDATA);
HWND hwndcolor1 = GetDlgItem(hwndDlg, IDC_COLOR);
HWND hwndcolor2 = GetDlgItem(hwndDlg, IDC_COLOR2);
idx_row = SendMessage(hCombo, CB_GETCURSEL, 0, 0);
SendMessage(hCombo, CB_GETLBTEXT, idx_row, (LPARAM)strText);
IEditable *pedit = ptable->GetElementByName(strText);
if (pedit != NULL)
{
Light *plight = (Light*)pedit;
if (hwndcolor1 == (HWND)lParam)
plight->m_d.m_color = (COLORREF)color;
else if (hwndcolor2 == (HWND)lParam)
plight->m_d.m_color2 = (COLORREF)color;
}
break;
}
case BN_CLICKED:
{
switch (LOWORD(wParam))
{
case IDOK:
{
Light *plight = GetLight(hCombo);
if (plight != NULL)
{
char value[256];
float fv;
GetDlgItemText(hwndDlg, IDC_DBG_LIGHT_FALLOFF, value, 31);
fv = sz2f(value);
plight->put_Falloff(fv);
GetDlgItemText(hwndDlg, IDC_DBG_LIGHT_FALLOFF_POWER, value, 31);
fv = sz2f(value);
plight->put_FalloffPower(fv);
GetDlgItemText(hwndDlg, IDC_DBG_LIGHT_INTENSITY, value, 31);
fv = sz2f(value);
plight->put_Intensity(fv);
GetDlgItemText(hwndDlg, IDC_DBG_BULB_MODULATE_VS_ADD, value, 31);
fv = sz2f(value);
plight->m_d.m_modulate_vs_add = fv;
GetDlgItemText(hwndDlg, IDC_DBG_TRANSMISSION_SCALE, value, 31);
fv = sz2f(value);
plight->m_d.m_transmissionScale = fv;
GetDlgItemText(hwndDlg, IDC_DBG_LIGHT_FADE_UP_EDIT, value, 31);
fv = sz2f(value);
plight->put_FadeSpeedUp(fv);
GetDlgItemText(hwndDlg, IDC_DBG_LIGHT_FADE_DOWN_EDIT, value, 31);
fv = sz2f(value);
plight->put_FadeSpeedDown(fv);
ptable->AddDbgLight(plight);
};
break;
}
case IDCANCEL:
{
ShowWindow(g_pplayer->m_hwndDebugger, SW_SHOW);
EndDialog(hwndDlg, FALSE);
return TRUE;
}
case IDC_DBG_LIGHT_ON_CHECK:
{
Light *plight = GetLight(hCombo);
if (plight != NULL)
{
plight->put_State(LightStateOn);
SetCheckButtonState(hwndDlg, plight);
ptable->AddDbgLight(plight);
}
break;
}
case IDC_DBG_LIGHT_OFF_CHECK:
{
Light *plight = GetLight(hCombo);
if (plight != NULL)
{
plight->put_State(LightStateOff);
SetCheckButtonState(hwndDlg, plight);
ptable->AddDbgLight(plight);
}
break;
}
case IDC_DBG_LIGHT_BLINKING_CHECK:
{
Light *plight = GetLight(hCombo);
if (plight != NULL)
{
plight->put_State(LightStateBlinking);
SetCheckButtonState(hwndDlg, plight);
ptable->AddDbgLight(plight);
}
break;
}
}
break;
}
}
switch (LOWORD(wParam))
{
case IDC_LIGHTSCOMBO:
{
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
{
Light *plight = GetLight(hCombo);
if (plight != NULL)
{
char value[256];
float v;
plight->get_Falloff(&v);
f2sz(v, value);
SetDlgItemText(hwndDlg, IDC_DBG_LIGHT_FALLOFF, value);
plight->get_FalloffPower(&v);
f2sz(v, value);
SetDlgItemText(hwndDlg, IDC_DBG_LIGHT_FALLOFF_POWER, value);
plight->get_Intensity(&v);
f2sz(v, value);
SetDlgItemText(hwndDlg, IDC_DBG_LIGHT_INTENSITY, value);
v = plight->m_d.m_modulate_vs_add;
f2sz(v, value);
SetDlgItemText(hwndDlg, IDC_DBG_BULB_MODULATE_VS_ADD, value);
v = plight->m_d.m_transmissionScale;
f2sz(v, value);
SetDlgItemText(hwndDlg, IDC_DBG_TRANSMISSION_SCALE, value);
plight->get_FadeSpeedUp(&v);
f2sz(v, value);
SetDlgItemText(hwndDlg, IDC_DBG_LIGHT_FADE_UP_EDIT, value);
plight->get_FadeSpeedDown(&v);
f2sz(v, value);
SetDlgItemText(hwndDlg, IDC_DBG_LIGHT_FADE_DOWN_EDIT, value);
SendMessage(GetDlgItem(hwndDlg, IDC_COLOR), CHANGE_COLOR, 0, plight->m_d.m_color);
SendMessage(GetDlgItem(hwndDlg, IDC_COLOR2), CHANGE_COLOR, 0, plight->m_d.m_color2);
SetCheckButtonState(hwndDlg, plight);
};
break;
}
}
}
}
break;
}
}
return FALSE;
}
INT_PTR CALLBACK DebuggerProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
RECT rcDialog;
RECT rcMain;
GetWindowRect(GetParent(hwndDlg), &rcMain);
GetWindowRect(hwndDlg, &rcDialog);
SetWindowPos(hwndDlg, NULL,
(rcMain.right + rcMain.left) / 2 - (rcDialog.right - rcDialog.left) / 2,
(rcMain.bottom + rcMain.top) / 2 - (rcDialog.bottom - rcDialog.top) / 2,
0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE/* | SWP_NOMOVE*/);
AssignIconToButton(hwndDlg, IDC_PLAY, IDI_PLAY);
AssignIconToButton(hwndDlg, IDC_PAUSE, IDI_PAUSE);
AssignIconToButton(hwndDlg, IDC_STEP, IDI_STEP);
SendMessage(hwndDlg, RECOMPUTEBUTTONCHECK, 0, 0);
RECT rcEditSize;
HWND hwndEditSize = GetDlgItem(hwndDlg, IDC_EDITSIZE);
GetWindowRect(hwndEditSize, &rcEditSize);
ScreenToClient(hwndDlg, (POINT *)&rcEditSize);
ScreenToClient(hwndDlg, &((POINT *)&rcEditSize)[1]);
g_pplayer->m_hwndDebugOutput = CreateWindowEx(0, "Scintilla", "",
WS_CHILD | ES_NOHIDESEL | WS_VISIBLE | ES_SUNKEN | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN | WS_BORDER,
rcEditSize.left, rcEditSize.top, rcEditSize.right - rcEditSize.left, rcEditSize.bottom - rcEditSize.top, hwndDlg, NULL, g_hinst, 0);
SendMessage(g_pplayer->m_hwndDebugOutput, SCI_STYLESETSIZE, 32, 10);
SendMessage(g_pplayer->m_hwndDebugOutput, SCI_STYLESETFONT, 32, (LPARAM)"Courier");
SendMessage(g_pplayer->m_hwndDebugOutput, SCI_SETMARGINWIDTHN, 1, 0);
SendMessage(g_pplayer->m_hwndDebugOutput, SCI_SETTABWIDTH, 4, 0);
SendDlgItemMessage(hwndDlg, IDC_BALL_THROWING, BM_SETCHECK, g_pplayer->m_fThrowBalls ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hwndDlg, IDC_BALL_CONTROL, BM_SETCHECK, g_pplayer->m_fBallControl ? BST_CHECKED : BST_UNCHECKED, 0);
SetDlgItemInt(hwndDlg, IDC_THROW_BALL_SIZE_EDIT2, g_pplayer->m_DebugBallSize, FALSE);
char textBuf[256] = { 0 };
f2sz(g_pplayer->m_DebugBallMass, textBuf);
SetDlgItemText(hwndDlg, IDC_THROW_BALL_MASS_EDIT2, textBuf);
SendMessage(hwndDlg, RESIZE_FROM_EXPAND, 0, 0);
return TRUE;
}
case WM_NOTIFY:
{
//int idCtrl = (int) wParam;
NMHDR *pnmh = (LPNMHDR)lParam;
SCNotification *pscnmh = (SCNotification *)lParam;
//HWND hwndRE = pnmh->hwndFrom;
const int code = pnmh->code;
switch (code)
{
case SCN_CHARADDED:
{
if (pscnmh->ch == '\n')
{
SendMessage(pnmh->hwndFrom, SCI_DELETEBACK, 0, 0);
const size_t curpos = SendMessage(pnmh->hwndFrom, SCI_GETCURRENTPOS, 0, 0);
const size_t line = SendMessage(pnmh->hwndFrom, SCI_LINEFROMPOSITION, curpos, 0);
const size_t lineStart = SendMessage(pnmh->hwndFrom, SCI_POSITIONFROMLINE, line, 0);
const size_t lineEnd = SendMessage(pnmh->hwndFrom, SCI_GETLINEENDPOSITION, line, 0);
char * const szText = new char[lineEnd - lineStart + 1];
TextRange tr;
tr.chrg.cpMin = lineStart;
tr.chrg.cpMax = lineEnd;
tr.lpstrText = szText;
SendMessage(pnmh->hwndFrom, SCI_GETTEXTRANGE, 0, (LPARAM)&tr);
const size_t maxlines = SendMessage(pnmh->hwndFrom, SCI_GETLINECOUNT, 0, 0);
if (maxlines == line + 1)
{
// need to add a new line to the end
SendMessage(pnmh->hwndFrom, SCI_DOCUMENTEND, 0, 0);
SendMessage(pnmh->hwndFrom, SCI_ADDTEXT, lstrlen("\n"), (LPARAM)"\n");
}
else
{
const size_t pos = SendMessage(pnmh->hwndFrom, SCI_POSITIONFROMLINE, line + 1, 0);
SendMessage(pnmh->hwndFrom, SCI_SETCURRENTPOS, pos, 0);
}
g_pplayer->m_ptable->m_pcv->EvaluateScriptStatement(szText);
delete[] szText;
}
break;
}
}//switch (code)
break;
}
case RECOMPUTEBUTTONCHECK:
{
int PlayDown = BST_UNCHECKED;
int PauseDown = BST_UNCHECKED;
int StepDown = BST_UNCHECKED;
if (g_pplayer->m_fUserDebugPaused)
{
PauseDown = BST_CHECKED;
}
else if (g_pplayer->m_PauseTimeTarget > 0)
{
StepDown = BST_CHECKED;
}
else
{
PlayDown = BST_CHECKED;
}
HWND hwndTBParent = GetDlgItem(hwndDlg, IDC_TOOLBARSIZE);
HWND hwndToolbar = GetWindow(hwndTBParent, GW_CHILD);
SendDlgItemMessage(hwndDlg, IDC_PLAY, BM_SETCHECK, PlayDown, 0);
SendDlgItemMessage(hwndDlg, IDC_PAUSE, BM_SETCHECK, PauseDown, 0);
SendDlgItemMessage(hwndDlg, IDC_STEP, BM_SETCHECK, StepDown, 0);
SendMessage(hwndToolbar, TB_CHECKBUTTON, IDC_PLAY, PlayDown);
SendMessage(hwndToolbar, TB_CHECKBUTTON, IDC_PAUSE, PauseDown);
SendMessage(hwndToolbar, TB_CHECKBUTTON, IDC_STEP, StepDown);
break;
}
case WM_CLOSE:
{
g_pplayer->m_PauseTimeTarget = 0;
g_pplayer->m_fUserDebugPaused = false;
g_pplayer->RecomputePseudoPauseState();
g_pplayer->m_DebugBallSize = GetDlgItemInt(hwndDlg, IDC_THROW_BALL_SIZE_EDIT2, NULL, FALSE);
char textBuf[256] = { 0 };
float fv;
GetDlgItemText(hwndDlg, IDC_THROW_BALL_MASS_EDIT2, textBuf, 255);
fv = sz2f(textBuf);
g_pplayer->m_DebugBallMass = fv;
g_pplayer->m_fDebugMode = false;
g_pplayer->m_fShowDebugger = false;
ShowWindow(hwndDlg, SW_HIDE);
break;
}
case WM_ACTIVATE:
{
g_pplayer->m_fDebugWindowActive = (wParam != WA_INACTIVE);
g_pplayer->RecomputePauseState();
g_pplayer->RecomputePseudoPauseState();
break;
}
case RESIZE_FROM_EXPAND:
{
const size_t state = SendDlgItemMessage(hwndDlg, IDC_EXPAND, BM_GETCHECK, 0, 0);
HWND hwndSizer1 = GetDlgItem(hwndDlg, IDC_GUIDE1);
HWND hwndSizer2 = GetDlgItem(hwndDlg, IDC_GUIDE2);
int mult;
if (state == BST_CHECKED)
{
mult = 1;
SetWindowText(GetDlgItem(hwndDlg, IDC_EXPAND), "<");
}
else
{
mult = -1;
SetWindowText(GetDlgItem(hwndDlg, IDC_EXPAND), ">");
}
RECT rcSizer1;
RECT rcSizer2;
GetWindowRect(hwndSizer1, &rcSizer1);
GetWindowRect(hwndSizer2, &rcSizer2);
const int diffx = rcSizer2.right - rcSizer1.right;
const int diffy = rcSizer2.bottom - rcSizer1.bottom;
RECT rcDialog;
GetWindowRect(hwndDlg, &rcDialog);
SetWindowPos(hwndDlg, NULL,
rcDialog.left,
rcDialog.top,
rcDialog.right - rcDialog.left + diffx * mult, rcDialog.bottom - rcDialog.top + diffy * mult, SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
break;
}
case WM_COMMAND:
{
switch (HIWORD(wParam))
{
case BN_CLICKED:
{
switch (LOWORD(wParam))
{
case IDC_PLAY:
{
g_pplayer->m_PauseTimeTarget = 0;
g_pplayer->m_fUserDebugPaused = false;
g_pplayer->RecomputePseudoPauseState();
SendMessage(hwndDlg, RECOMPUTEBUTTONCHECK, 0, 0);
break;
}
case IDC_PAUSE:
{
g_pplayer->m_PauseTimeTarget = 0;
g_pplayer->m_fUserDebugPaused = true;
g_pplayer->RecomputePseudoPauseState();
SendMessage(hwndDlg, RECOMPUTEBUTTONCHECK, 0, 0);
break;
}
case IDC_STEP:
{
int ms = GetDlgItemInt(hwndDlg, IDC_STEPAMOUNT, NULL, FALSE);
g_pplayer->m_PauseTimeTarget = g_pplayer->m_time_msec + ms;
g_pplayer->m_fUserDebugPaused = false;
g_pplayer->RecomputePseudoPauseState();
SendMessage(hwndDlg, RECOMPUTEBUTTONCHECK, 0, 0);
break;
}
case IDC_EXPAND:
{
SendMessage(hwndDlg, RESIZE_FROM_EXPAND, 0, 0);
break;
}
case IDC_BALL_THROWING:
{
HWND hwndControl = GetDlgItem(hwndDlg, IDC_BALL_THROWING);
size_t checked = SendMessage(hwndControl, BM_GETCHECK, 0, 0);
g_pplayer->m_fThrowBalls = !!checked;
break;
}
case IDC_BALL_CONTROL:
{
HWND hwndControl = GetDlgItem(hwndDlg, IDC_BALL_CONTROL);
size_t checked = SendMessage(hwndControl, BM_GETCHECK, 0, 0);
g_pplayer->m_fBallControl = !!checked;
break;
}
case IDC_DBGLIGHTSBUTTON:
{
g_pplayer->m_hwndLightDebugger = CreateDialogParam(g_hinst, MAKEINTRESOURCE(IDD_DBGLIGHTDIALOG), hwndDlg, LightDebuggerProc, NULL);
break;
}
case IDC_DBG_MATERIALS_BUTTON:
{
g_pplayer->m_hwndLightDebugger = CreateDialogParam(g_hinst, MAKEINTRESOURCE(IDD_DBGMATERIALDIALOG), hwndDlg, MaterialDebuggerProc, NULL);
break;
}
}
break;
}//case BN_CLICKED:
}//switch (HIWORD(wParam))
break;
}//case WM_COMMAND:
default:
{
switch (LOWORD(wParam))
{
case IDC_THROW_BALL_SIZE_EDIT2:
{
g_pplayer->m_DebugBallSize = GetDlgItemInt(hwndDlg, IDC_THROW_BALL_SIZE_EDIT2, NULL, FALSE);
break;
}
}
break;
}
}
return FALSE;
}