forked from OpenKotOR/mdledit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedits.cpp
More file actions
1417 lines (1267 loc) · 72.6 KB
/
Copy pathedits.cpp
File metadata and controls
1417 lines (1267 loc) · 72.6 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
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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "frame.h"
#include <cstdint>
#include <cstring>
#include <cstdio>
char Edits::cClassName[] = "mdledithexcontrol";
LRESULT CALLBACK EditsProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
HWND Edits::hIntEdit;
HWND Edits::hUIntEdit;
HWND Edits::hFloatEdit;
Edits::Edits(){
// #1 Basics
WindowClass.cbSize = sizeof(WNDCLASSEX); // Must always be sizeof(WNDCLASSEX)
WindowClass.lpszClassName = cClassName; // Name of this class
WindowClass.hInstance = GetModuleHandle(nullptr); // Instance of the application
WindowClass.lpfnWndProc = EditsProc; // Pointer to callback procedure
// #2 Class styles
WindowClass.style = CS_DBLCLKS; // Class styles
// #3 Background
WindowClass.hbrBackground = CreateSolidBrush(RGB(255, 255, 255)); //(HBRUSH) (COLOR_WINDOW); // Background brush
// #4 Cursor
WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Class cursor
// #5 Icon
WindowClass.hIcon = NULL; // Class Icon
WindowClass.hIconSm = NULL; // Small icon for this class
// #6 Menu
WindowClass.lpszMenuName = NULL; // Menu Resource
// #7 Other
WindowClass.cbClsExtra = 0; // Extra bytes to allocate following the wndclassex structure
WindowClass.cbWndExtra = 0; // Extra bytes to allocate following an instance of the structure
sBuffer = nullptr;
nKnownArray = nullptr;
}
bool Edits::Run(HWND hParent, UINT nID){
if(!RegisterClassEx(&WindowClass)) return false;
RECT rcParent;
GetClientRect(hParent, &rcParent);
hMe = CreateWindowEx(WS_EX_TOPMOST, cClassName, "", WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
ME_HEX_WIN_OFFSET_X, ME_TABS_OFFSET_Y_TOP, ME_HEX_WIN_SIZE_X, rcParent.bottom - ME_TABS_OFFSET_Y_BOTTOM - ME_TABS_OFFSET_Y_TOP,
hParent, reinterpret_cast<HMENU>(static_cast<INT_PTR>(nID)), GetModuleHandle(nullptr), nullptr);
if(!hMe) return false;
ShowWindow(hMe, false);
return true;
}
extern Edits Edit1;
namespace {
std::string StatusBarPartText(int nPart){
if(hStatusBar == NULL) return std::string();
LRESULT nLengthInfo = SendMessage(hStatusBar, SB_GETTEXTLENGTH, static_cast<WPARAM>(nPart), 0);
int nChars = LOWORD(nLengthInfo);
if(nChars < 0) nChars = 0;
std::string sText(static_cast<std::size_t>(nChars) + 1, '\0');
SendMessage(hStatusBar, SB_GETTEXT, static_cast<WPARAM>(nPart), reinterpret_cast<LPARAM>(&sText[0]));
sText.resize(std::strlen(sText.c_str()));
return sText;
}
void SetStatusBarPartIfChanged(int nPart, const std::string & sCaption){
if(hStatusBar == NULL) return;
if(StatusBarPartText(nPart) != sCaption){
SendMessage(hStatusBar, SB_SETTEXT, static_cast<WPARAM>(nPart), reinterpret_cast<LPARAM>(sCaption.c_str()));
}
}
}
LRESULT CALLBACK EditsProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
Edits * Edit = nullptr;
if(GetDlgCtrlID(hwnd) == IDC_MAIN_EDIT) Edit = &Edit1;
if(Edit == nullptr){
std::cout << "MAJORMAJORMAJOR ERROR!! Running the EditsProc() for an unexisting Edit :S \n";
return DefWindowProc (hwnd, message, wParam, lParam);
}
//After here, Edit is definitely not NULL
PAINTSTRUCT ps;
HDC hdc;
SCROLLINFO si;
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
static bool bDrag;
static bool bDblClick;
static bool bClick;
static int nArea;
static int nClickArea;
/* handle the messages */
switch(message){
case WM_CREATE:
{
bDrag = false;
bDblClick = false;
bClick = false;
nArea = 0;
nClickArea = 0;
//Initialize points
Edit->ptClick.x = -1;
Edit->ptClick.y = -1;
Edit->ptRelease.x = -1;
Edit->ptRelease.y = -1;
Edit->ptHover.x = -1;
Edit->ptHover.y = -1;
//The extreme values are then defined as everything that is initially visible
Edit->UpdateClientRect();
Edit->yMaxScroll = Edit->rcClient.bottom;
Edit->yCurrentScroll = 0;
Edit->hScrollVert = CreateWindowEx(WS_EX_TOPMOST, "SCROLLBAR", "",
WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN ,
ME_HEX_WIN_OFFSET_X + ME_HEX_WIN_SIZE_X - ME_SCROLLBAR_X, 0, GetSystemMetrics(SM_CXHTHUMB), Edit->rcClient.bottom,
hwnd, (HMENU) IDC_SBS_SBV, GetModuleHandle(nullptr), nullptr);
ShowWindow(Edit->hScrollVert, false);
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_DISABLENOSCROLL | SIF_PAGE | SIF_POS | SIF_RANGE;
si.nMax = Edit->yMaxScroll;
si.nMin = 0;
si.nPage = Edit->rcClient.bottom;
si.nPos = 0;
SetScrollInfo(Edit->hScrollVert, SB_CTL, &si, true);
}
break;
case WM_COMMAND:
{
(void)wParam;
(void)lParam;
// Reserved for future editor commands.
}
break;
case WM_ERASEBKGND:
{
return 1;
}
case WM_MOUSEMOVE:
{
if(Edit->sBuffer == nullptr) return DefWindowProc(hwnd, message, wParam, lParam);
if(Edit->sBuffer->empty()) return DefWindowProc(hwnd, message, wParam, lParam);
//Determine drag
if(!bDrag && (bClick || bDblClick)) bDrag = true;
//Determine area
if(!bDrag){
if(xPos < 64) nArea = -1;
else if(xPos > 65 && xPos < 450) nArea = 1;
else if(xPos > 454 && xPos < 587) nArea = 2;
else nArea = 0;
}
if(nArea == 1){
SetCursor(LoadCursor(NULL, IDC_IBEAM));
SetClassLongPtr(hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor(NULL, IDC_IBEAM));
}
else if(nArea == 2){
SetCursor(LoadCursor(NULL, IDC_IBEAM));
SetClassLongPtr(hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor(NULL, IDC_IBEAM));
}
else{
SetCursor(LoadCursor(NULL, IDC_ARROW));
SetClassLongPtr(hwnd, GCLP_HCURSOR, (LONG_PTR) LoadCursor(NULL, IDC_ARROW));
}
bool bThreshold = false;
if(nArea == 1){
int nCurrentY = (yPos + Edit->yCurrentScroll - 1) / ME_EDIT_NEXT_ROW;
nCurrentY = std::max((0 + Edit->yCurrentScroll - 1 + 10) / ME_EDIT_NEXT_ROW, nCurrentY);
nCurrentY = std::min( (int) (Edit->rcClient.bottom + Edit->yCurrentScroll - 1) / ME_EDIT_NEXT_ROW - 1, nCurrentY);
if(Edit->ptHover.y != nCurrentY){
Edit->ptHover.y = nCurrentY;
bThreshold = true;
}
int nCurrentX = (xPos + 2 - ME_EDIT_ROWNUM_OFFSET) / ME_EDIT_CHAR_SIZE_X;
nCurrentX = std::max(nCurrentX, 0);
nCurrentX = std::min(nCurrentX, 47);
if(Edit->ptHover.x != nCurrentX){
Edit->ptHover.x = nCurrentX;
bThreshold = true;
}
}
else if(nArea == 2){
int nCurrentY = (yPos + Edit->yCurrentScroll - 1) / ME_EDIT_NEXT_ROW;
nCurrentY = std::max((0 + Edit->yCurrentScroll - 1 + 10) / ME_EDIT_NEXT_ROW, nCurrentY);
nCurrentY = std::min((int)(Edit->rcClient.bottom + Edit->yCurrentScroll - 1) / ME_EDIT_NEXT_ROW - 1, nCurrentY);
if(Edit->ptHover.y != nCurrentY){
Edit->ptHover.y = nCurrentY;
bThreshold = true;
}
int nCurrentX = (xPos + 2 - ME_EDIT_CHARSET_OFFSET) / ME_EDIT_CHAR_SIZE_X * 3;
nCurrentX = std::max(nCurrentX, 0);
nCurrentX = std::min(nCurrentX, 47);
if(Edit->ptHover.x != nCurrentX){
Edit->ptHover.x = nCurrentX;
bThreshold = true;
}
}
int nLength = HIWORD(SendMessage(hStatusBar, SB_GETTEXTLENGTH, 3, 0));
if(nLength > 0){
std::string sGet;
sGet.resize(nLength);
SendMessage(hStatusBar, SB_GETTEXT, 3, (LPARAM) sGet.c_str());
if(sGet.size() > 0 && sGet.at(0) != 0 && nArea == 0){
sGet = "";
SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(3, 0), NULL), (LPARAM) sGet.c_str());
}
}
if(bThreshold){
if(nArea > 0){
std::string sType = TabCtrl_GetCurSelName(hTabs);
if(sType == "MDL") Edit->UpdateStatusPositionModel();
else if(sType == "MDX") Edit->UpdateStatusPositionMdx();
else if(sType == "WOK" || sType == "PWK" || sType == "DWK 0" || sType == "DWK 1" || sType == "DWK 2") Edit->UpdateStatusPositionBwm(sType);
}
if(bDrag){
Edit->bSelection = true; /// If we are dragging, we are also selecting.
Edit->DetermineSelection();
Edit->UpdateStatusBar();
InvalidateRect(hwnd, &Edit->rcClient, false);
Edit->ptPrevious = Edit->ptHover;
Edit->PrintValues();
}
}
}
break;
case WM_LBUTTONDBLCLK:
{
if(Edit->sBuffer == nullptr) return DefWindowProc(hwnd, message, wParam, lParam);
if(Edit->sBuffer->empty()) return DefWindowProc(hwnd, message, wParam, lParam);
if(nArea == 1){ //We are in the byte view region
nClickArea = nArea;
bDblClick = true;
Edit->ptPrevious = Edit->ptHover;
Edit->bSelection = true; /// true because we select by double clicking
Edit->DetermineSelection();
Edit->UpdateStatusBar();
InvalidateRect(hwnd, &Edit->rcClient, false);
Edit->PrintValues();
}
else if(nArea == -1){
bHexLocation = !bHexLocation;
InvalidateRect(hwnd, &Edit->rcClient, false);
Edit->UpdateStatusBar();
}
}
break;
case WM_LBUTTONDOWN:
{
if(Edit->sBuffer == nullptr) return DefWindowProc(hwnd, message, wParam, lParam);
if(Edit->sBuffer->empty()) return DefWindowProc(hwnd, message, wParam, lParam);
if(nArea == 1 || nArea == 2){ //We are in the byte or chAR view region
nClickArea = nArea;
SetCapture(hwnd); //Capture the mouse even if it leaves the window
/// User pressed shift. Do not take this as a new click and a cancellation of the previous selection,
/// but as if by doing this, we are actually proceeding with a dragging operation.
/// The user must have selected something beforehand.
if(wParam & MK_SHIFT && Edit->bSelection){
bDrag = true; /// Make it as if we were dragging
/// I forgot what this does - it probably doesn't matter because if click was undefined, bSelection wouldn't be on anyway,
/// we would skip this if anyway.
if(Edit->ptClick.x == -1 || Edit->ptClick.y == -1)
Edit->ptClick = Edit->ptHover;
}
else{
if(Edit->bSelection){ /// If there was a previous selection (or we were dragging)
Edit->bSelection = false; /// by clicking we clear the selection
bDrag = false; /// we stop dragging
}
bClick = true;
Edit->ptPrevious = Edit->ptHover;
Edit->ptClick = Edit->ptHover;
}
Edit->DetermineSelection();
InvalidateRect(hwnd, &Edit->rcClient, false);
Edit->UpdateStatusBar();
Edit->PrintValues();
}
}
break;
case WM_LBUTTONUP:
{
if(Edit->sBuffer == nullptr) return DefWindowProc(hwnd, message, wParam, lParam);
if(Edit->sBuffer->empty()) return DefWindowProc(hwnd, message, wParam, lParam);
ReleaseCapture(); //Release mouse
if(bDrag){ /// If we are dragging
Edit->ptRelease = Edit->ptHover; /// The current hover point is our release point
if((Edit->ptRelease.x != Edit->ptClick.x || Edit->ptRelease.y != Edit->ptClick.y) && Edit->ptClick.x != -1 && Edit->ptClick.y != -1)
Edit->bSelection = true; /// If the drag selection is valid, selection is true
else if(bDblClick) Edit->bSelection = true; /// If we just double-clicked, selection is true
else Edit->bSelection = false; /// If we simply clicked and released, selection is false
}
bDrag = false;
bDblClick = false;
bClick = false;
//Edit->DetermineSelection();
InvalidateRect(hwnd, &Edit->rcClient, false);
Edit->UpdateStatusBar();
Edit->PrintValues();
}
break;
case WM_PAINT:
{
HDC hdcReal = BeginPaint(hwnd, &ps);
hdc = CreateCompatibleDC(hdcReal);
HBITMAP memBM = CreateCompatibleBitmap(hdcReal, ME_HEX_WIN_SIZE_X, Edit->rcClient.bottom);
HBITMAP hBMold = (HBITMAP) SelectObject(hdc, memBM);
HBRUSH hFill = CreateSolidBrush(RGB(255, 255, 255));
Edit->UpdateClientRect();
RECT rcFile = Edit->rcClient;
rcFile.left = 0;
rcFile.top = 0;
//rcFile.bottom = Edit->yMaxScroll;
FillRect(hdc, &rcFile, hFill);
DeleteObject(hFill);
/**/
if(Edit->sBuffer && !Edit->sBuffer->empty()){
/// Draw the two separator lines
HPEN hPenLine = CreatePen(PS_SOLID, 1, RGB(120, 120, 120));
SelectObject(hdc, hPenLine);
MoveToEx(hdc, ME_EDIT_PADDING_LEFT + ME_EDIT_SEPARATOR_OFFSET, 0, NULL);
LineTo(hdc, ME_EDIT_PADDING_LEFT + ME_EDIT_SEPARATOR_OFFSET, Edit->rcClient.bottom);
MoveToEx(hdc, ME_EDIT_PADDING_LEFT + ME_EDIT_SEPARATOR_2_OFFSET, 0, NULL);
LineTo(hdc, ME_EDIT_PADDING_LEFT + ME_EDIT_SEPARATOR_2_OFFSET, Edit->rcClient.bottom);
DeleteObject(hPenLine);
SetTextColor(hdc, RGB(50, 50, 50));
//SetBkColor(hdc, GetSysColor(COLOR_MENU));
SelectObject(hdc, hMonospace);
/// Determine whether we are hiliting.
bool bHilite = false;
POINT ptEnd;
if(bDrag) ptEnd = Edit->ptHover;
else ptEnd = Edit->ptRelease;
if(Edit->bSelection || bDrag){
bHilite = true;
//std::cout << string_format("bSelection: %i bDrag: %i\n", Edit->bSelection, bDrag);
}
if(ptEnd.y < Edit->ptClick.y || (ptEnd.y == Edit->ptClick.y && ptEnd.x < Edit->ptClick.x)){
}
else{
}
int n = Edit->yCurrentScroll / ME_EDIT_NEXT_ROW; /// n is the number of rows that are scrolled away, it will be ++ed later
int nMaxRowsInScreen = (Edit->rcClient.bottom) / ME_EDIT_NEXT_ROW + 2; /// Max number of rows the screen may display
int nMax = n + nMaxRowsInScreen; /// Max number of rows possible by the current scroll
nMax = std::min(nMax, (int) Edit->sBuffer->size()/16 + 1); /// Cap the max number of rows by the actual number of rows of the data
int nDataKnown;
char cHexText[48];
char cHexCompareText[48];
std::string sType = TabCtrl_GetCurSelName(hTabs);
for(; n < nMax; n++){
SetTextColor(hdc, RGB(50, 50, 50));
SetBkColor(hdc, RGB(255, 255, 255));
std::stringstream ssIntPrint;
ssIntPrint << std::uppercase << (bHexLocation ? std::hex : std::dec) << n * 16;
char cCounter[32];
std::snprintf(cCounter, sizeof(cCounter), "%s", ssIntPrint.str().c_str());
AddSignificantZeroes(cCounter, 8);
ExtTextOut(hdc, ME_EDIT_PADDING_LEFT, ME_EDIT_PADDING_TOP + n * ME_EDIT_NEXT_ROW - Edit->yCurrentScroll, 0, nullptr, cCounter, strlen(cCounter), nullptr);
int nBytes = std::max(0, std::min(16, static_cast<int>(Edit->sBuffer->size()) - n * 16));
int nCompareBytes = std::max(0, std::min(16, static_cast<int>(Edit->sCompareBuffer->size()) - n * 16));
if(nBytes > 0) CharsToHex(cHexText, *Edit->sBuffer, n * 16, nBytes);
else cHexText[0] = '\0';
if(nCompareBytes > 0) CharsToHex(cHexCompareText, *Edit->sCompareBuffer, n * 16, nCompareBytes);
else cHexCompareText[0] = '\0';
int nHexLength = strlen(cHexText);
for(int i = 0; i < nHexLength; i++){
if(static_cast<int>(Edit->nKnownArray->size()) > n*16 + i / 3) nDataKnown = Edit->nKnownArray->at(n*16 + i / 3) & 0xFFFF;
else nDataKnown = 0;
COLORREF rgbUnderline = DataColor(nDataKnown, false);// RGB(0,0,0);
COLORREF rgbText = DataColor(nDataKnown, false);// RGB(0,0,0);
COLORREF rgbBackground = RGB(255,255,255);
bool bHighlited = false, bDifferent = false, bOutOfRange = false;
if(bHilite && (
((Edit->nSelectStart / 16) < n && (Edit->nSelectEnd / 16) > n)
|| ((Edit->nSelectStart / 16) == n && (Edit->nSelectEnd / 16) == n && (Edit->nSelectStart % 16 * 3) <= i && (Edit->nSelectEnd % 16 * 3) >= i - 1)
|| ((Edit->nSelectStart / 16) == n && (Edit->nSelectEnd / 16) != n && (Edit->nSelectStart % 16 * 3) <= i)
|| ((Edit->nSelectEnd / 16) == n && (Edit->nSelectStart / 16) != n && (Edit->nSelectEnd % 16 * 3) >= i - 1))){
bHighlited = true;
}
if(bShowDiff && Edit->Compare(n*16 + i / 3) > 0){
if(i % 3 < 2 || // ignore the space
(Edit->Compare(n*16 + i / 3) == Edit->Compare(n*16 + i / 3 + 1) && Edit->Compare(n*16 + i / 3) == 2) || // color the space if out of range
(Edit->Compare(n*16 + i / 3) == Edit->Compare(n*16 + i / 3 + 1) && (Edit->nKnownArray->at(n*16 + i / 3) & 0xFFFF) == (Edit->nKnownArray->at(n*16 + i / 3 + 1) & 0xFFFF))) //color the space if same known value
{
if(Edit->Compare(n*16 + i / 3) == 1){ // Different
bDifferent = true;
}
if(Edit->Compare(n*16 + i / 3) == 2){
bOutOfRange = true;
}
}
}
bool bKeepTreeItemSelection = false;
if(bHighlited){
if(bDifferent){
if(nClickArea == 1){
rgbText = RGB(255, 170, 70);
rgbUnderline = RGB(255, 170, 70);
}
else{
rgbText = RGB(255, 210, 170);
rgbUnderline = RGB(255, 210, 170);
}
}
else{
rgbText = RGB(255, 255, 255);
rgbUnderline = RGB(255,255,255);
}
if(nClickArea == 1) rgbBackground = RGB(135, 135, 255);
else rgbBackground = RGB(185, 185, 255);
}
else if(bDifferent){
rgbText = RGB(255, 255, 255);
rgbUnderline = RGB(255,255,255);
rgbBackground = DataColor(nDataKnown, false);
}
else if(bOutOfRange){
rgbBackground = RGB(230, 180, 230); // Out of range
}
SetTextColor(hdc, rgbText);
SetBkColor(hdc, rgbBackground);
if(cHexText[i] != ' ' || (rgbBackground != RGB(255,255,255) && !bKeepTreeItemSelection)){
ExtTextOut(hdc, ME_EDIT_PADDING_LEFT + ME_EDIT_ROWNUM_OFFSET + i * ME_EDIT_CHAR_SIZE_X, ME_EDIT_PADDING_TOP + n * ME_EDIT_NEXT_ROW - Edit->yCurrentScroll, 0, nullptr,
(bHighlited && bDifferent ? &cHexCompareText[i] : &cHexText[i]), 1, nullptr);
}
int nVertical = ME_EDIT_PADDING_TOP + n * ME_EDIT_NEXT_ROW - Edit->yCurrentScroll + 12;
int nHorizontal = ME_EDIT_PADDING_LEFT + ME_EDIT_ROWNUM_OFFSET + i * ME_EDIT_CHAR_SIZE_X;
int nExtra = -1;
if(nHexLength >= i+1 && !(Edit->nKnownArray->at(n*16 + i / 3) & 0x00010000)) nExtra = 0;
if(bShowGroup && (i % 3 == 0 && (n*16 + i / 3 - 1 < 0 || Edit->nKnownArray->at(n*16 + i / 3 - 1) & 0x00010000))){
HPEN hPenUnderline = CreatePen(PS_SOLID, 1, rgbUnderline);
SelectObject(hdc, hPenUnderline);
MoveToEx(hdc, nHorizontal - 1, nVertical, NULL);
LineTo(hdc, nHorizontal - 1, nVertical - 3);
DeleteObject(hPenUnderline);
SelectObject(hdc, hMonospace);
}
if(bShowDataStruct && (i % 3 == 0 && (n*16 + i / 3 - 1 < 0 || Edit->nKnownArray->at(n*16 + i / 3 - 1) & 0x00020000))){
HPEN hPenUnderline = CreatePen(PS_SOLID, 1, RGB(0,0,0));
SelectObject(hdc, hPenUnderline);
MoveToEx(hdc, nHorizontal - 3, nVertical - 3, NULL);
LineTo(hdc, nHorizontal - 3, nVertical - 12);
LineTo(hdc, nHorizontal + 5, nVertical - 12);
//MoveToEx(hdc, nHorizontal - 3, nVertical - 5, NULL);
//LineTo(hdc, nHorizontal - 3, nVertical + 2);
//LineTo(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra + 1, nVertical + 2);
DeleteObject(hPenUnderline);
SelectObject(hdc, hMonospace);
}
if(bShowGroup && (cHexText[i] != ' ' || !(Edit->nKnownArray->at(n*16 + i / 3) & 0x00010000))){
HPEN hPenUnderline = CreatePen(PS_SOLID, 1, rgbUnderline);
SelectObject(hdc, hPenUnderline);
MoveToEx(hdc, nHorizontal - 1, nVertical, NULL);
LineTo(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra, nVertical);
DeleteObject(hPenUnderline);
SelectObject(hdc, hMonospace);
}
if(bShowGroup && (i % 3 == 1 && Edit->nKnownArray->at(n*16 + i / 3) & 0x00010000)){
HPEN hPenUnderline = CreatePen(PS_SOLID, 1, rgbUnderline);
SelectObject(hdc, hPenUnderline);
MoveToEx(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra, nVertical, NULL);
LineTo(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra, nVertical - 3);
DeleteObject(hPenUnderline);
SelectObject(hdc, hMonospace);
}
else if(bShowGroup && (i % 3 == 2 && (cHexText[i] != ' ' || rgbBackground != RGB(255,255,255)) && Edit->nKnownArray->at(n*16 + i / 3) & 0x00010000)){
HPEN hPenUnderline = CreatePen(PS_SOLID, 1, rgbUnderline);
SelectObject(hdc, hPenUnderline);
MoveToEx(hdc, nHorizontal + nExtra, nVertical, NULL);
LineTo(hdc, nHorizontal + nExtra, nVertical - 3);
DeleteObject(hPenUnderline);
SelectObject(hdc, hMonospace);
}
/*
if(i % 3 == 1 && Edit->nKnownArray->at(n*16 + i / 3) & 0x00020000){
HPEN hPenUnderline = CreatePen(PS_SOLID, 1, RGB(0,0,0));
SelectObject(hdc, hPenUnderline);
//MoveToEx(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra + 1, nVertical - 8, NULL);
//LineTo(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra + 1, nVertical - 13);
//LineTo(hdc, nHorizontal - 2, nVertical - 13);
MoveToEx(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra + 4, nVertical - 12, NULL);
LineTo(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra + 4, nVertical);
//LineTo(hdc, nHorizontal + ME_EDIT_CHAR_SIZE_X + nExtra, nVertical);
DeleteObject(hPenUnderline);
SelectObject(hdc, hMonospace);
}
else if(i % 3 == 2 && Edit->nKnownArray->at(n*16 + i / 3) & 0x00020000){
HPEN hPenUnderline = CreatePen(PS_SOLID, 1, RGB(0,0,0));
SelectObject(hdc, hPenUnderline);
//MoveToEx(hdc, nHorizontal + nExtra + 1, nVertical - 8, NULL);
//LineTo(hdc, nHorizontal + nExtra + 1, nVertical - 13);
//LineTo(hdc, nHorizontal - ME_EDIT_CHAR_SIZE_X - 2, nVertical - 13);
MoveToEx(hdc, nHorizontal + nExtra + 4, nVertical - 12, NULL);
LineTo(hdc, nHorizontal + nExtra + 4, nVertical);
//LineTo(hdc, nHorizontal + nExtra, nVertical);
DeleteObject(hPenUnderline);
SelectObject(hdc, hMonospace);
}
*/
/// Do a completely separate draw for the charset.
if(i % 3 == 0){
SetTextColor(hdc, RGB(220, 220, 220));
SetBkColor(hdc, RGB(255, 255, 255));
if(bHighlited){
if(bDifferent){
if(nClickArea == 2){
SetTextColor(hdc, RGB(255, 170, 70));
}
else{
SetTextColor(hdc, RGB(255, 210, 170));
}
}
else{
SetTextColor(hdc, RGB(255, 255, 255));
}
if(nClickArea == 2) SetBkColor(hdc, RGB(135, 135, 255));
else SetBkColor(hdc, RGB(185, 185, 255));
}
else if(nDataKnown == 3){
SetTextColor(hdc, DataColor(nDataKnown, false));
}
if(static_cast<int>(Edit->sBuffer->size()) > n*16 + (i/3)){
char cToWrite = (bHighlited && bDifferent ? Edit->sCompareBuffer->at(n*16 + (i/3)) : Edit->sBuffer->at(n * 16 + (i/3)));
PrepareCharForDisplay(&cToWrite);
ExtTextOut(hdc, ME_EDIT_PADDING_LEFT + ME_EDIT_CHARSET_OFFSET + (i/3) * ME_EDIT_CHAR_SIZE_X, ME_EDIT_PADDING_TOP + n * ME_EDIT_NEXT_ROW - Edit->yCurrentScroll, 0, nullptr, &cToWrite, 1, nullptr);
}
}
}
}
}
/**/
BitBlt(hdcReal, 0, 0, ME_HEX_WIN_SIZE_X, Edit->rcClient.bottom, hdc, 0, 0, SRCCOPY);
SelectObject(hdc, hBMold);
DeleteObject(memBM);
DeleteDC(hdc);
EndPaint(hwnd, &ps);
}
break;
case WM_VSCROLL:
{
int yNewPos; /* new position */
si.cbSize = sizeof(si);
si.fMask = SIF_DISABLENOSCROLL | SIF_POS | SIF_TRACKPOS | SIF_PAGE;
GetScrollInfo(Edit->hScrollVert, SB_CTL, &si);
switch(LOWORD(wParam)){
case SB_TOP:
yNewPos = 0;
break;
case SB_BOTTOM:
yNewPos = Edit->yMaxScroll - (signed int) si.nPage; // - nPage ?
break;
/* User clicked the shaft above the scroll box. */
case SB_PAGEUP:
yNewPos = Edit->yCurrentScroll - (signed int) si.nPage;
//yNewPos = std::min(Edit->yMaxScroll - (signed int) si.nPage, yNewPos);
//yNewPos = std::max(0, yNewPos);
break;
/* User clicked the shaft below the scroll box. */
case SB_PAGEDOWN:
yNewPos = Edit->yCurrentScroll + (signed int) si.nPage;
//yNewPos = std::min(Edit->yMaxScroll - (signed int) si.nPage, yNewPos);
//yNewPos = std::max(0, yNewPos);
break;
/* User clicked the top arrow. */
case SB_LINEUP:
yNewPos = Edit->yCurrentScroll - ME_EDIT_NEXT_ROW;
//yNewPos = std::max(0, yNewPos);
break;
/* User clicked the bottom arrow. */
case SB_LINEDOWN:
yNewPos = Edit->yCurrentScroll + ME_EDIT_NEXT_ROW;
////yNewPos = std::min(Edit->yMaxScroll - (signed int) si.nPage, yNewPos);
break;
/* User dragged the scroll box. */
case SB_THUMBPOSITION:
yNewPos = (signed int) si.nPos;
//std::cout << string_format("WM_HSCROLL: Thumb: %i \n", yNewPos);
//yNewPos = std::min(Edit->yMaxScroll - (signed int) si.nPage, yNewPos);
//std::cout << string_format("WM_HSCROLL: Thumb corrected: %i \n", yNewPos);
break;
/* User is dragging the scroll box. */
case SB_THUMBTRACK:
yNewPos = (signed int) si.nTrackPos;
//std::cout << string_format("WM_HSCROLL: Thumbtrack: %i \n", yNewPos);
//std::cout << string_format("WM_HSCROLL: Thumbtrack corrected: %i (compared to %i - %i)\n", yNewPos, Edit->yMaxScroll, (signed int) si.nPage);
break;
default:
yNewPos = Edit->yCurrentScroll;
}
//yNewPos = min(Edit->yMaxScroll, yNewPos);
//yNewPos = max(0, yNewPos);
/* If the current position does not change, do not scroll.*/
if (yNewPos == Edit->yCurrentScroll) break;
//CUSTOM ADDITION, make it so that we can only scroll for discrete amounts
/* Reset the current scroll position. */
yNewPos = (yNewPos / ME_EDIT_NEXT_ROW) * ME_EDIT_NEXT_ROW;
yNewPos = std::max(0, yNewPos);
yNewPos = std::min(Edit->yMaxScroll - (signed int) si.nPage, yNewPos);
Edit->yCurrentScroll = yNewPos;
/* Reset the current scroll position. */
//Edit->yCurrentScroll = yNewPos;
/*
* DONT SCROLL THE WINDOW, ITS THE SOURCE OF ALL EVIL
* JUST REPAINT NORMALLY
*/
InvalidateRect(hwnd, &Edit->rcClient, false);
UpdateWindow(hwnd);
/* Reset the scroll bar. */
si.cbSize = sizeof(si);
si.fMask = SIF_DISABLENOSCROLL | SIF_POS | SIF_RANGE;
si.nPos = Edit->yCurrentScroll;
si.nMax = Edit->yMaxScroll;
si.nMin = 0;
SetScrollInfo(Edit->hScrollVert, SB_CTL, &si, true);
//std::cout << string_format("Zoom DEBUG: Zooming. \nnMinP=%i, nMaxP=%i, xCurrentScroll=%i, \nxCurrentScroll+rcClient.right/2=%i\n0=%i, Edit->yMaxScroll=%i, Edit->yCurrentScroll=%i, \nyCurrentScroll+(rcClient.bottom-nNonScreenY)/2=%i\n", nMinP, nMaxP, xCurrentScroll, xCurrentScroll+rcClient.right/2, 0, Edit->yMaxScroll, Edit->yCurrentScroll, Edit->yCurrentScroll+(rcClient.bottom-nNonScreenY)/2);
return 0;
}
break;
case WM_MOUSEWHEEL:
{
si.cbSize = sizeof(si);
si.fMask = SIF_DISABLENOSCROLL | SIF_PAGE | SIF_RANGE;
GetScrollInfo(Edit->hScrollVert, SB_CTL, &si);
signed short nHiword = HIWORD(wParam);
//std::cout << "WM_MOUSEWHEEL: Hiword=" << nHiword << ", Page=" << si.nPage << ", scrollDelta=" << (signed) si.nPage / 3 * (nHiword/120) << ", CurrentScroll=" << Edit->yCurrentScroll << ", NewScroll=" << Edit->yCurrentScroll - (signed) si.nPage / 3 * (nHiword/120) << "\n";
Edit->yCurrentScroll -= (signed) (si.nPage / 6 * (nHiword/120));
Edit->yCurrentScroll = std::max(si.nMin, std::min(Edit->yCurrentScroll, (signed) (si.nMax - si.nPage)));
Edit->yCurrentScroll = (Edit->yCurrentScroll / ME_EDIT_NEXT_ROW) * ME_EDIT_NEXT_ROW;
InvalidateRect(hwnd, &Edit->rcClient, false);
UpdateWindow(hwnd);
si.fMask = SIF_DISABLENOSCROLL | SIF_POS;
si.nPos = Edit->yCurrentScroll;
SetScrollInfo(Edit->hScrollVert, SB_CTL, &si, true);
}
break;
/* for messages that we don't deal with */
case WM_DESTROY:
//Close
default:
{
return DefWindowProc (hwnd, message, wParam, lParam);
}
}
return 0;
}
void Edits::PrintValues(bool bCheck){
if(nSelectStart < 0 ||
nSelectEnd < 0 ||
!bCheck){
SetWindowText(hIntEdit, "");
SetWindowText(hUIntEdit, "");
SetWindowText(hFloatEdit, "");
return;
}
int nSize = nSelectEnd - nSelectStart + 1;
std::string sString;
char cInt [255];
char cUInt [255];
char cFloat [255];
for(int n = 0; nSelectStart + n <= nSelectEnd; n++){
sString += (bShowDiff && Compare(nSelectStart+n) == 1 ? sCompareBuffer->at(nSelectStart+n) : sBuffer->at(nSelectStart+n));
}
if(nSize == 1){
int8_t nSigned = 0;
uint8_t nUnsigned = 0;
std::memcpy(&nSigned, sString.data(), sizeof(nSigned));
std::memcpy(&nUnsigned, sString.data(), sizeof(nUnsigned));
std::snprintf(cInt, sizeof(cInt), "%hhi", static_cast<int>(nSigned));
std::snprintf(cUInt, sizeof(cUInt), "%hhu", static_cast<unsigned int>(nUnsigned));
cFloat[0] = '\0';
}
else if(nSize == 2){
int16_t nSigned = 0;
uint16_t nUnsigned = 0;
std::memcpy(&nSigned, sString.data(), sizeof(nSigned));
std::memcpy(&nUnsigned, sString.data(), sizeof(nUnsigned));
std::snprintf(cInt, sizeof(cInt), "%hi", static_cast<int>(nSigned));
std::snprintf(cUInt, sizeof(cUInt), "%hu", static_cast<unsigned int>(nUnsigned));
cFloat[0] = '\0';
}
else if(nSize == 4){
int32_t nSigned = 0;
uint32_t nUnsigned = 0;
float fValue = 0.0f;
std::memcpy(&nSigned, sString.data(), sizeof(nSigned));
std::memcpy(&nUnsigned, sString.data(), sizeof(nUnsigned));
std::memcpy(&fValue, sString.data(), sizeof(fValue));
std::snprintf(cInt, sizeof(cInt), "%i", nSigned);
std::snprintf(cUInt, sizeof(cUInt), "%u", static_cast<unsigned int>(nUnsigned));
std::snprintf(cFloat, sizeof(cFloat), "%.16f", fValue);
}
else if(nSize == 8){
int32_t nSigned = 0;
uint32_t nUnsigned = 0;
double fValue = 0.0;
std::memcpy(&nSigned, sString.data(), sizeof(nSigned));
std::memcpy(&nUnsigned, sString.data(), sizeof(nUnsigned));
std::memcpy(&fValue, sString.data(), sizeof(fValue));
std::snprintf(cInt, sizeof(cInt), "%li", static_cast<long>(nSigned));
std::snprintf(cUInt, sizeof(cUInt), "%lu", static_cast<unsigned long>(nUnsigned));
std::snprintf(cFloat, sizeof(cFloat), "%.16g", fValue);
}
else{
cInt[0] = '\0';
cUInt[0] = '\0';
cFloat[0] = '\0';
}
TruncateDec(cFloat);
SetWindowText(hIntEdit, cInt);
SetWindowText(hUIntEdit, cUInt);
SetWindowText(hFloatEdit, cFloat);
}
int Edits::Compare(unsigned nPos){
if(sCompareBuffer == nullptr || sBuffer == nullptr || sCompareBuffer->size() == 0 || sBuffer->size() == 0 || nPos >= sBuffer->size()) return -1; // Don't mark
if(nPos >= sCompareBuffer->size()) return 2; // Out of range
if(sBuffer->at(nPos) != sCompareBuffer->at(nPos)) return 1; // Different
return 0; // Not different
}
void Edits::Cleanup(){
nKnownArray = nullptr;
sBuffer = nullptr;
ShowWindow(hScrollVert, false);
UpdateEdit();
}
void Edits::LoadData(){
sSelected = TabCtrl_GetCurSelName(hTabs);
if(sSelected == "MDL" && !Model.empty()){
nKnownArray = &Model.GetKnownData();
sCompareBuffer = &Model.GetCompareData();
sBuffer = &Model.GetBuffer();
}
else if(sSelected == "MDX" && Model.Mdx){
nKnownArray = &Model.Mdx->GetKnownData();
sCompareBuffer = &Model.Mdx->GetCompareData();
sBuffer = &Model.Mdx->GetBuffer();
}
else if(sSelected == "WOK" && Model.Wok){
nKnownArray = &Model.Wok->GetKnownData();
sCompareBuffer = &Model.Wok->GetCompareData();
sBuffer = &Model.Wok->GetBuffer();
}
else if(sSelected == "PWK" && Model.Pwk){
nKnownArray = &Model.Pwk->GetKnownData();
sCompareBuffer = &Model.Pwk->GetCompareData();
sBuffer = &Model.Pwk->GetBuffer();
}
else if(sSelected == "DWK 0" && Model.Dwk0){
nKnownArray = &Model.Dwk0->GetKnownData();
sCompareBuffer = &Model.Dwk0->GetCompareData();
sBuffer = &Model.Dwk0->GetBuffer();
}
else if(sSelected == "DWK 1" && Model.Dwk1){
nKnownArray = &Model.Dwk1->GetKnownData();
sCompareBuffer = &Model.Dwk1->GetCompareData();
sBuffer = &Model.Dwk1->GetBuffer();
}
else if(sSelected == "DWK 2" && Model.Dwk2){
nKnownArray = &Model.Dwk2->GetKnownData();
sCompareBuffer = &Model.Dwk2->GetCompareData();
sBuffer = &Model.Dwk2->GetBuffer();
}
else{
nKnownArray = nullptr;
sCompareBuffer = nullptr;
sBuffer = nullptr;
}
if(!bShowHex) return;
if(sBuffer != nullptr && nKnownArray != nullptr){
if(sBuffer->empty()) ShowWindow(hScrollVert, false);
else ShowWindow(hScrollVert, true);
SetClassLongPtr(hMe, GCLP_HCURSOR, (LONG_PTR) LoadCursor(NULL, IDC_ARROW));
ptHover.x = -1;
ptHover.y = -1;
ptPrevious.x = -1;
ptPrevious.y = -1;
ptClick.x = -1;
ptClick.y = -1;
ptRelease.x = -1;
ptRelease.y = -1;
nSelectStart = -1;
nSelectEnd = -1;
bSelection = false;
yMaxScroll = ((sBuffer->size() - 1)/16 + 2) * ME_EDIT_NEXT_ROW;
yCurrentScroll = 0;
}
else{
SetClassLongPtr(hMe, GCLP_HCURSOR, (LONG_PTR) LoadCursor(NULL, IDC_ARROW));
ShowWindow(hScrollVert, false);
}
UpdateEdit();
UpdateStatusBar();
SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(3, 0), NULL), (LPARAM) "");
}
HWND Edits::GetWindowHandle(){
return hMe;
}
void Edits::UpdateClientRect(){
RECT rcParent;
GetClientRect(GetParent(hMe), &rcParent);
rcClient.top = 0;
rcClient.left = ME_HEX_WIN_OFFSET_X;
rcClient.bottom = rcParent.bottom - ME_STATUSBAR_Y - ME_TABS_OFFSET_Y_BOTTOM - ME_TABS_OFFSET_Y_TOP;
rcClient.right = ME_HEX_WIN_SIZE_X;
}
void Edits::ShowHideEdit(){
ShowWindow(hMe, bShowHex);
if(bShowHex){
LoadData();
}
}
void Edits::UpdateEdit(){
if(!bShowHex) return;
UpdateClientRect();
InvalidateRect(hMe, &rcClient, false);
if(sBuffer == nullptr) return;
if(!sBuffer->empty()){
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
si.nMax = yMaxScroll;
si.nMin = 0;
si.nPos = yCurrentScroll;
si.nPage = rcClient.bottom;
SetScrollInfo(hScrollVert, SB_CTL, &si, true);
}
}
void Edits::Resize(){
UpdateClientRect();
SetWindowPos(hMe, nullptr, rcClient.left, ME_TABS_OFFSET_Y_TOP, ME_HEX_WIN_SIZE_X, rcClient.bottom, 0);
SetWindowPos(hScrollVert, nullptr, ME_HEX_WIN_OFFSET_X + ME_HEX_WIN_SIZE_X - ME_SCROLLBAR_X, 0, GetSystemMetrics(SM_CXHTHUMB), rcClient.bottom, 0);
UpdateEdit();
}
void Edits::DetermineSelection(){
POINT ptLow;
POINT ptHigh;
if(ptClick.y > ptHover.y || (ptClick.y == ptHover.y && ptClick.x > ptHover.x)){
ptHigh = ptClick;
ptLow = ptHover;
}
else{
ptLow = ptClick;
ptHigh = ptHover;
}
nSelectStart = ptLow.y * 16 + (ptLow.x + 1) / 3;
if(ptHigh.x <= 0) nSelectEnd = ptHigh.y * 16 - 1;
else nSelectEnd = ptHigh.y * 16 + (ptHigh.x - 1) / 3;
// Reversed selections are invalid; out-of-range selections are clamped
// to the file end below.
if(nSelectEnd < nSelectStart){
nSelectStart = -1;
nSelectEnd = -1;
}
nSelectEnd = std::min(nSelectEnd, (int) sBuffer->size() - 1);
nSelectStart = std::min(nSelectStart, (int) sBuffer->size() - 1);
}
void Edits::UpdateStatusBar(bool bCheck){
char cString1 [255];
char cString2 [255];
char cString3 [255];
if(nSelectEnd == -1 || nSelectStart == -1 || !bCheck || sBuffer == nullptr){
SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(0, 0), NULL), (LPARAM) "");
SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(1, 0), NULL), (LPARAM) "");
SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(2, 0), NULL), (LPARAM) "");
SetWindowText(hIntEdit, "");
SetWindowText(hUIntEdit, "");
SetWindowText(hFloatEdit, "");
}
else{
if(bHexLocation){
std::snprintf(cString1, sizeof(cString1), "Offset: %X", nSelectStart);
std::snprintf(cString2, sizeof(cString2), "Block: %X-%X", nSelectStart, nSelectEnd);
std::snprintf(cString3, sizeof(cString3), "Length: %X", nSelectEnd - nSelectStart + 1);
}
else{
std::snprintf(cString1, sizeof(cString1), "Offset: %i", nSelectStart);
std::snprintf(cString2, sizeof(cString2), "Block: %i-%i", nSelectStart, nSelectEnd);
std::snprintf(cString3, sizeof(cString3), "Length: %i", nSelectEnd - nSelectStart + 1);
}
SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(0, 0), NULL), (LPARAM) cString1);
if(nSelectStart == nSelectEnd) SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(1, 0), NULL), (LPARAM) "");
else SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(1, 0), NULL), (LPARAM) cString2);
SendMessage(hStatusBar, SB_SETTEXT, MAKEWPARAM(MAKEWORD(2, 0), NULL), (LPARAM) cString3);
}
}
COLORREF DataColor(int nDataKnown, bool bHilite){
if(bHilite) return RGB(255, 255, 255);
switch(nDataKnown){
case 10: //known unknowns, mark red
return RGB(255, 0, 0);
case 1: //anything that counts something, unsigned by definition. (uint32 or uint16)
return RGB(235, 220, 0);
case 2: //float
return RGB(76, 206, 20);
case 3: //string
return RGB(110, 110, 110);
case 4: //int ((u)int32)
return RGB(0, 200, 200);
case 5: //short ((u)int16)
return RGB(200, 0, 200);
case 6: //offset/pointer (uint32)
return RGB(100, 100, 200);
case 7: //byte
return RGB(165, 103, 16);
case 8: //Possibly constant/meaningless/padding, but not random data
return RGB(232, 232, 232);
case 9: //function pointer - it can make the beginning certain structures stand out more
return RGB(255, 160, 80);
case 11: //Padding/unused portions filled with random data
return RGB(162, 177, 90);
}
return RGB(0, 0, 0);