-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSortingCDump.cpp
More file actions
4539 lines (4324 loc) · 187 KB
/
SortingCDump.cpp
File metadata and controls
4539 lines (4324 loc) · 187 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
/*
* ColorizingDMD: Program to edit cROM colorized roms
* Programmed in plain C with Visual Studio 2022 by Zedrummer, 2022
*
* Linked to the project Visual Pinball Engine for Unity and, as such, is licensed under the GNU General Public License v3.0 https://github.com/freezy/VisualPinball.Engine/blob/master/LICENSE
*
* Uses OpenGL Immediate Mode for display in 2D in window as this is by far fast enough to make it works at 100+ FPS even on a low end computer with any dedicated GPU
*
*/
#pragma region Includes
#include "framework.h"
#include "SortingCDump.h"
#include <strsafe.h>
#include <gdiplus.h>
using namespace Gdiplus;
#include <CommCtrl.h>
#include "resource.h"
#include <shlwapi.h>
#include "cRom.h"
#include <tchar.h>
#include <direct.h>
#include "OGL_Immediate_2D.h"
#include <windowsx.h>
#include <math.h>
#include <shlobj_core.h>
#include <crtdbg.h>
#include "LiteZip.h"
#pragma warning(disable : 4996)
#pragma endregion Includes
#pragma region Global_Variables
#define MAJ_VERSION 1
#define MIN_VERSION 5
#define BUILD_VERSION 5
static TCHAR szWindowClass[] = _T("ColorizingDMD");
HINSTANCE hInst; // current instance
HWND hWnd = NULL, hwTB = NULL, hMovSec = NULL;
UINT ColSetMode = 0, preColRot = 0, acColRot = 0; // 0- displaying colsets, 1- displaying colrots
GLFWwindow * glfwframestripo, * glfwframestripc; // handle+context of our window
bool fDone = false;
bool filter_time = false, filter_allmask = false, filter_color = false;
int filter_length = 15, filter_ncolor = 16;
bool ChooseMove = false;
bool WhiteMoveButton = true;
bool isLoadedProject = false;
typedef struct
{
UINT preframe;
UINT nselframes;
}sSelection;
#define MAX_SELECTIONS 256
sSelection selections[MAX_SELECTIONS] = { 0,1 };
UINT acframe = 0;
UINT nselections = 1;
cRom_struct MycRom = { "",0,0,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
cRP_struct MycRP = { "",{FALSE},{0},0,0,{0},FALSE,0,FALSE };
UINT TxFrameStripo[2] = { (UINT)-1, (UINT)-1 }; // Framebuffer texture for the strip displaying the original frames ID
UINT TxFrameStripc[2] = { (UINT)-1, (UINT)-1 }; // Framebuffer texture for the strip displaying the colorized frames ID
UINT TxChiffres, TxcRom, TxcRom2; // Number texture ID
UINT acFSoText = 0; // current texture displayed on the original frame strip
UINT acFScText = 0; // current texture displayed on the colorized frame strip
UINT8 Raw_Digit_Def[RAW_DIGIT_W * RAW_DIGIT_H * 10]; // buffer for raw numbers
UINT8* pFrameoStrip = NULL; // pointer to the memory to draw the original frame strips
UINT8* pFramecStrip = NULL; // pointer to the memory to draw the colorized frame strips
UINT SliderWidth, PosSlider; // Width of the frame strip slider and pos of the slider on the bar
UINT ScrW, ScrH; // client size of the main window
int MonWidth = 1920; // X resolution of the monitor
int PreFrameInStrip = 0; // First frame to display in the frame strip
UINT NFrameToDraw = 0; // how many frames to draw in the strip
UINT FS_LMargin = 0; // left margin (same as right) before the first frame in the strip
#define MAX_SEL_FRAMES 8192 // Max number of selected frames (has consequences on the undo/redo buffer size!)
const UINT8 AcColor[3] = { 255,255,255 };
const UINT8 SelColor[3] = { 100,150,255 };
const UINT8 UnselColor[3] = { 255,50,50 };
DWORD timeLPress = 0, timeRPress = 0, timeUPress = 0, timeDPress = 0; // timer to know how long the key has been pressed
int MouseFrSliderlx; // previous position on the slider
bool MouseFrSliderLPressed = false; // mouse pressed on the frame strip slider
HANDLE hStdout; // for log window
bool UpdateFSneeded = false; // Do we need to update the frame strip
bool UpdateSSneeded = false; // Do we need to update the sprite strip
#pragma endregion Global_Variables
#pragma region Frame_Actions
void ResetSelection(void)
{
nselections = 1;
selections[0].preframe = 0;
selections[0].nselframes = 1;
PreFrameInStrip = 0;
UpdateFSneeded = true;
}
UINT New_Frame_Moved_Pos(UINT nofr, UINT nofrins, UINT nosel)
{
if (((nofr < nofrins) && (nofr < selections[nosel].preframe)) || ((nofr > nofrins) && (nofr >= selections[nosel].preframe + selections[nosel].nselframes))) return nofr;
if (nofrins > selections[nosel].preframe + selections[nosel].nselframes)
{
if (nofr == nofrins) return nofrins;
if ((nofr >= selections[nosel].preframe) && (nofr < selections[nosel].preframe + selections[nosel].nselframes)) return nofr + nofrins - selections[nosel].preframe - selections[nosel].nselframes;
return nofr - selections[nosel].nselframes;
}
if ((nofr >= selections[nosel].preframe) && (nofr < selections[nosel].preframe + selections[nosel].nselframes)) return nofr - selections[nosel].preframe + nofrins;
return nofr + selections[nosel].nselframes;
}
UINT New_Frame_Del_Pos(UINT nofr, UINT predel, UINT ndel)
{
if (nofr < predel) return nofr;
if ((nofr >= predel) && (nofr < predel + ndel)) return (UINT)-1;
return nofr - ndel;
}
bool Move_Parts(UINT nofrins, UINT8* buffer, UINT size_unit, UINT size_val, UINT nosel)
{
UINT8* ptbuf = (UINT8*)malloc(selections[nosel].nselframes * size_unit * size_val);
if (!ptbuf)
{
MessageBoxA(hWnd, "Can't get memory for parts moving", "Error", MB_OK);
return false;
}
memcpy(ptbuf, &buffer[selections[nosel].preframe * size_unit * size_val], selections[nosel].nselframes * size_unit * size_val);
if (nofrins < selections[nosel].preframe)
{
memmove(&buffer[(nofrins + selections[nosel].nselframes) * size_unit * size_val], &buffer[nofrins * size_unit * size_val], (selections[nosel].preframe - nofrins) * size_unit * size_val);
memcpy(&buffer[nofrins * size_unit * size_val], ptbuf, selections[nosel].nselframes * size_unit * size_val);
}
else
{
memmove(&buffer[selections[nosel].preframe * size_unit * size_val], &buffer[(selections[nosel].preframe + selections[nosel].nselframes) * size_unit * size_val], (nofrins - selections[nosel].preframe - selections[nosel].nselframes) * size_unit * size_val);
memcpy(&buffer[(nofrins - selections[nosel].nselframes) * size_unit * size_val], ptbuf, selections[nosel].nselframes * size_unit * size_val);
}
free(ptbuf);
return true;
}
void Move_Frames(UINT nofrins, UINT nosel)
{
if ((nofrins >= selections[nosel].preframe) && (nofrins < selections[nosel].preframe + selections[nosel].nselframes))
{
MessageBoxA(hWnd, "Can't move the selection in the selection", "Error", MB_OK);
return;
}
if (nofrins == selections[nosel].preframe + selections[nosel].nselframes) return;
// nofrins = frame to move the selection before
Move_Parts(nofrins, MycRom.cFrames, MycRom.fWidth * MycRom.fHeight, sizeof(UINT8), nosel);
Move_Parts(nofrins, (UINT8*)MycRom.HashCode, 1, sizeof(UINT32), nosel);
Move_Parts(nofrins, MycRom.CompMaskID, 1, sizeof(UINT8), nosel);
Move_Parts(nofrins, MycRom.ShapeCompMode, 1, sizeof(UINT8), nosel);
Move_Parts(nofrins, MycRom.MovRctID, 1, sizeof(UINT8), nosel);
Move_Parts(nofrins, MycRom.cPal, 3 * MycRom.ncColors, sizeof(UINT8), nosel);
Move_Parts(nofrins, MycRom.DynaMasks, MycRom.fWidth * MycRom.fHeight, sizeof(UINT8), nosel);
Move_Parts(nofrins, MycRom.Dyna4Cols, MycRom.noColors * MAX_DYNA_SETS_PER_FRAME, sizeof(UINT8), nosel);
Move_Parts(nofrins, MycRom.FrameSprites, MAX_SPRITES_PER_FRAME, sizeof(UINT8), nosel);
Move_Parts(nofrins, MycRom.ColorRotations, 3 * MAX_COLOR_ROTATION, sizeof(UINT8), nosel);
Move_Parts(nofrins, (UINT8*)MycRom.TriggerID, 1, sizeof(UINT32), nosel);
Move_Parts(nofrins, MycRP.oFrames, MycRom.fWidth * MycRom.fHeight, sizeof(UINT8), nosel);
Move_Parts(nofrins, (UINT8*)MycRP.FrameDuration, 1, sizeof(UINT32), nosel);
// correct the first section frame
for (UINT ti = 0; ti < MycRP.nSections; ti++) MycRP.Section_Firsts[ti] = New_Frame_Moved_Pos(MycRP.Section_Firsts[ti], nofrins, nosel);
// correct the sprite frame reference
for (UINT ti = 0; ti < MycRom.nSprites; ti++) MycRP.Sprite_Col_From_Frame[ti] = New_Frame_Moved_Pos(MycRP.Sprite_Col_From_Frame[ti], nofrins, nosel);
UpdateFSneeded = true;
}
UINT isFirstSection[2 * MAX_SECTIONS];
UINT nfs = 0;
UINT isUsedBySprite[2 * 255];
UINT nubs = 0;
int Which_Section(UINT nofr)
{
int tres = -1, tfirst = -1;
for (int ti = 0; ti < (int)MycRP.nSections; ti++)
{
if (((int)MycRP.Section_Firsts[ti] > tfirst) && (MycRP.Section_Firsts[ti] <= nofr))
{
tfirst = (int)MycRP.Section_Firsts[ti];
tres = ti;
}
}
return tres;
}
void UpdateSectionList(void)
{
HWND hlst = GetDlgItem(hwTB, IDC_SECTIONLIST);
SendMessage(hlst, CB_RESETCONTENT, 0, 0);
SendMessageA(hlst, CB_ADDSTRING, 0, (LPARAM)"- None -");
for (UINT32 ti = 0; ti < MycRP.nSections; ti++)
{
char tbuf[256];
sprintf_s(tbuf, 256, "%i - %s", ti + 1, &MycRP.Section_Names[ti * SIZE_SECTION_NAMES]);
SendMessageA(hlst, CB_ADDSTRING, 0, (LPARAM)tbuf);
}
int ti = Which_Section(acframe);
SendMessage(hlst, CB_SETCURSEL, ti + 1, 0);
}
int Duplicate_Section_Name(char* name)
{
// check if a section already has this name
if (strcmp(name, "- None -") == 0) return 30000; // if we have the "- None -" name, we return as if it was used
for (UINT ti = 0; ti < MycRP.nSections; ti++)
{
if (strcmp(name, &MycRP.Section_Names[ti * SIZE_SECTION_NAMES]) == 0) return ti;
}
return -1;
}
int is_Section_First(UINT nofr)
{
for (UINT ti = 0; ti < MycRP.nSections; ti++)
{
if (MycRP.Section_Firsts[ti] == nofr) return (int)ti;
}
return -1;
}
INT_PTR CALLBACK CheckDel_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
char tbuf[256];
SendMessage(GetDlgItem(hDlg, IDC_LISTSEC), LB_RESETCONTENT, 0, 0);
for (UINT ti = 0; ti < nfs; ti++)
{
sprintf_s(tbuf, 256, "Section %i - %s -> Frame %i", isFirstSection[ti] + 1, &MycRP.Section_Names[isFirstSection[ti] * SIZE_SECTION_NAMES], MycRP.Section_Firsts[isFirstSection[ti]]);
SendMessageA(GetDlgItem(hDlg, IDC_LISTSEC), LB_ADDSTRING, 0, (LPARAM)tbuf);
}
SendMessage(GetDlgItem(hDlg, IDC_LISTSPR), LB_RESETCONTENT, 0, 0);
for (UINT ti = 0; ti < nubs; ti++)
{
sprintf_s(tbuf, 256, "Sprite %i - %s -> Frame %i", isUsedBySprite[ti] + 1, &MycRP.Sprite_Names[isUsedBySprite[ti] * SIZE_SECTION_NAMES], MycRP.Sprite_Col_From_Frame[isUsedBySprite[ti]]);
SendMessageA(GetDlgItem(hDlg, IDC_LISTSPR), LB_ADDSTRING, 0, (LPARAM)tbuf);
}
Button_SetCheck(GetDlgItem(hDlg, IDC_CANCEL), TRUE);
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_BUTTON:
{
if (Button_GetCheck(GetDlgItem(hDlg, IDC_DELFREE)) == BST_CHECKED) EndDialog(hDlg, 2);
else if (Button_GetCheck(GetDlgItem(hDlg, IDC_DELALL)) == BST_CHECKED) EndDialog(hDlg, 1);
else EndDialog(hDlg, 0);
return TRUE;
}
}
}
}
return FALSE;
}
bool Del_Parts(UINT pfr, UINT nfr, UINT8** buffer, UINT size_unit, UINT size_val)
{
if (pfr + nfr < MycRom.nFrames)
{
memmove(&(*buffer)[pfr * size_unit * size_val], &(*buffer)[(pfr + nfr) * size_unit * size_val], (MycRom.nFrames - (pfr + nfr)) * size_unit * size_val);
}
*buffer = (UINT8*)realloc(*buffer, (MycRom.nFrames - nfr) * size_unit * size_val);
return true;
}
void Del_Frame_Range(UINT pfr, UINT nfr)
{
Del_Parts(pfr, nfr, &MycRom.cFrames, MycRom.fWidth * MycRom.fHeight, sizeof(UINT8));
Del_Parts(pfr, nfr, (UINT8**)&MycRom.HashCode, 1, sizeof(UINT32));
Del_Parts(pfr, nfr, &MycRom.CompMaskID, 1, sizeof(UINT8));
Del_Parts(pfr, nfr, &MycRom.ShapeCompMode, 1, sizeof(UINT8));
Del_Parts(pfr, nfr, &MycRom.MovRctID, 1, sizeof(UINT8));
Del_Parts(pfr, nfr, &MycRom.cPal, 3 * MycRom.ncColors, sizeof(UINT8));
Del_Parts(pfr, nfr, &MycRom.DynaMasks, MycRom.fWidth * MycRom.fHeight, sizeof(UINT8));
Del_Parts(pfr, nfr, &MycRom.Dyna4Cols, MycRom.noColors * MAX_DYNA_SETS_PER_FRAME, sizeof(UINT8));
Del_Parts(pfr, nfr, &MycRom.FrameSprites, MAX_SPRITES_PER_FRAME, sizeof(UINT8));
Del_Parts(pfr, nfr, &MycRom.ColorRotations, 3 * MAX_COLOR_ROTATION, sizeof(UINT8));
Del_Parts(pfr, nfr, (UINT8**)&MycRom.TriggerID, 1, sizeof(UINT32));
Del_Parts(pfr, nfr, &MycRP.oFrames, MycRom.fWidth * MycRom.fHeight, sizeof(UINT8));
Del_Parts(pfr, nfr, (UINT8**)&MycRP.FrameDuration, 1, sizeof(UINT32));
for (UINT ti = 0; ti < MycRom.nSprites; ti++) MycRP.Sprite_Col_From_Frame[ti] = New_Frame_Del_Pos(MycRP.Sprite_Col_From_Frame[ti], pfr, nfr);
for (UINT ti = 0; ti < MycRP.nSections; ti++) MycRP.Section_Firsts[ti] = New_Frame_Del_Pos(MycRP.Section_Firsts[ti], pfr, nfr);
MycRom.nFrames -= nfr;
}
bool is_Section_Pointed(UINT fr)
{
for (UINT ti = 0; ti < MycRP.nSections; ti++)
{
if (fr == MycRP.Section_Firsts[ti]) return true;
}
return false;
}
bool is_Sprite_Pointed(UINT fr)
{
for (UINT ti = 0; ti < MycRom.nSprites; ti++)
{
if (fr == MycRP.Sprite_Col_From_Frame[ti]) return true;
}
return false;
}
void Del_Sprite(UINT nspr)
{
// delete any reference to this sprite in the framesprites
for (UINT ti = 0; ti < MycRom.nFrames; ti++)
{
UINT tj = 0;
while ((MycRom.FrameSprites[ti * MAX_SPRITES_PER_FRAME + tj] != 255) && (MycRom.FrameSprites[ti * MAX_SPRITES_PER_FRAME + tj] != nspr) && (tj < MAX_SPRITES_PER_FRAME)) tj++;
if (MycRom.FrameSprites[ti * MAX_SPRITES_PER_FRAME + tj] == nspr)
{
if (tj < MAX_SPRITES_PER_FRAME - 1) memmove(&MycRom.FrameSprites[ti * MAX_SPRITES_PER_FRAME + tj], &MycRom.FrameSprites[ti * MAX_SPRITES_PER_FRAME + tj], MAX_SPRITES_PER_FRAME - 1 - tj);
MycRom.FrameSprites[(ti + 1) * MAX_SPRITES_PER_FRAME - 1] = 255;
}
}
// delete the sprite
if (nspr < MycRom.nSprites - 1)
{
memmove(&MycRom.SpriteDescriptions[nspr * MAX_SPRITE_SIZE * MAX_SPRITE_SIZE], &MycRom.SpriteDescriptions[(nspr + 1) * MAX_SPRITE_SIZE * MAX_SPRITE_SIZE], sizeof(UINT16) * MAX_SPRITE_SIZE * MAX_SPRITE_SIZE * (MycRom.nSprites - 1 - nspr));
memmove(&MycRom.SpriteDetAreas[nspr * 4 * MAX_SPRITE_DETECT_AREAS], &MycRom.SpriteDescriptions[(nspr + 1) * 4 * MAX_SPRITE_DETECT_AREAS], sizeof(UINT16) * 4 * MAX_SPRITE_DETECT_AREAS * (MycRom.nSprites - 1 - nspr));
memmove(&MycRom.SpriteDetDwords[nspr * MAX_SPRITE_DETECT_AREAS], &MycRom.SpriteDetDwords[(nspr + 1) * MAX_SPRITE_DETECT_AREAS], sizeof(UINT32) * MAX_SPRITE_DETECT_AREAS * (MycRom.nSprites - 1 - nspr));
memmove(&MycRom.SpriteDetDwordPos[nspr * MAX_SPRITE_DETECT_AREAS], &MycRom.SpriteDetDwordPos[(nspr + 1) * MAX_SPRITE_DETECT_AREAS], sizeof(UINT16) * MAX_SPRITE_DETECT_AREAS * (MycRom.nSprites - 1 - nspr));
memmove(&MycRP.Sprite_Names[nspr * SIZE_SECTION_NAMES], &MycRP.Sprite_Names[(nspr + 1) * SIZE_SECTION_NAMES], SIZE_SECTION_NAMES * (255 - 1 - nspr));
memmove(&MycRP.Sprite_Col_From_Frame[nspr], &MycRP.Sprite_Col_From_Frame[nspr + 1], sizeof(UINT32) * (255 - 1 - nspr));
memmove(&MycRP.Sprite_Edit_Colors[16 * nspr], &MycRP.Sprite_Edit_Colors[16 * (nspr + 1)], 16 * (255 - 1 - nspr));
memmove(&MycRP.SpriteRect[4 * nspr], &MycRP.SpriteRect[4 * (nspr + 1)], sizeof(UINT16) * 4 * (255 - 1 - nspr));
memmove(&MycRP.SpriteRectMirror[2 * nspr], &MycRP.SpriteRectMirror[2 * (nspr + 1)], sizeof(BOOL) * 2 * (255 - 1 - nspr));
}
MycRom.nSprites--;
}
void Del_Section(UINT nsec)
{
if (nsec < MycRP.nSections - 1)
{
memmove(&MycRP.Section_Firsts[nsec], &MycRP.Section_Firsts[nsec + 1], sizeof(UINT32) * (MycRP.nSections - 1 - nsec));
memmove(&MycRP.Section_Names[SIZE_SECTION_NAMES * nsec], &MycRP.Section_Names[SIZE_SECTION_NAMES * (nsec + 1)], SIZE_SECTION_NAMES * (MycRP.nSections - 1 - nsec));
}
MycRP.nSections--;
}
void Del_Frames(UINT nosel, int dbres)
{
if (dbres == 0) return; // delete cancelled
else if (dbres == 1) // delete all and their related sprites and sections
{
Del_Frame_Range(selections[nosel].preframe, selections[nosel].nselframes);
for (UINT ti = 0; ti < nfs; ti++) Del_Section(isFirstSection[ti]);
for (UINT ti = 0; ti < nubs; ti++) Del_Sprite(isUsedBySprite[ti]);
}
else if (dbres == 2) // delete only the frames with no related sprite or section
{
UINT pfr, nfr;
UINT ti = 0;
while (ti < selections[nosel].nselframes)
{
while (((is_Section_Pointed(selections[nosel].preframe + ti)) || (is_Sprite_Pointed(selections[nosel].preframe + ti))) && (ti < selections[nosel].nselframes)) ti++;
if (ti == selections[nosel].nselframes) break;
pfr = ti + selections[nosel].preframe;
nfr = 0;
while (((!is_Section_Pointed(selections[nosel].preframe + ti)) && (!is_Sprite_Pointed(selections[nosel].preframe + ti))) && (ti < selections[nosel].nselframes))
{
nfr++;
ti++;
}
Del_Frame_Range(pfr, nfr);
selections[nosel].nselframes -= nfr;
ti -= nfr;
}
}
else Del_Frame_Range(selections[nosel].preframe, selections[nosel].nselframes);
PreFrameInStrip = max((int)selections[nosel].preframe - 1, 0);
}
#pragma endregion Frame_Actions
#pragma region Debug_Tools
void cprintf(const char* format,...) // write to the console
{
char tbuf[490];
va_list argptr;
va_start(argptr, format);
vsprintf_s(tbuf,490, format, argptr);
va_end(argptr);
char tbuf2[512];
SYSTEMTIME lt;
GetLocalTime(<);
sprintf_s(tbuf2, 512, "%02d:%02d: %s\n\r", lt.wHour,lt.wMinute, tbuf);
WriteFile(hStdout, tbuf2, (DWORD)strlen(tbuf2), NULL, NULL);
}
void AffLastError(char* lpszFunction)
{
// Retrieve the system error message for the last-error code
char* lpMsgBuf;
char* lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpMsgBuf,
0, NULL);
// Display the error message and exit the process
lpDisplayBuf = (char*)LocalAlloc(LMEM_ZEROINIT,
(strlen((LPCSTR)lpMsgBuf) + strlen((LPCSTR)lpszFunction) + 40) * sizeof(char));
StringCchPrintfA(lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(char),
"%s failed with error %d: %s",
lpszFunction, dw, lpMsgBuf);
cprintf(lpDisplayBuf);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
}
bool SetIcon(HWND ButHWND, UINT ButIco)
{
HICON hicon = LoadIcon(hInst, MAKEINTRESOURCE(ButIco));
if (!hicon) AffLastError((char*)"SetIcon");
SendMessageW(ButHWND, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hicon);
DestroyIcon(hicon);
return true;
}
#pragma endregion Debug_Tools
#pragma region Memory_Tools
void Del_Buffer_Element(UINT8* pBuf, UINT* pnElt, UINT noElt, UINT Elt_Size)
{
/* Erase the noElt-th element of the buffer pointed by pBuf.
* Before the function, the buffer contains *pnElt element and each element is Elt_Size byte long.
* Shift all the elements after noElt to the left and reduce the buffer size with realloc. *pnElt is decremetend at the end.*/
if (noElt >= (*pnElt)) return;
if ((*pnElt) == 1)
{
free(pBuf);
pBuf = NULL;
(*pnElt) = 0;
return;
}
if (noElt < ((*pnElt) - 1)) memcpy(&pBuf[noElt * Elt_Size], &pBuf[(noElt + 1) * Elt_Size], ((*pnElt) - 1 - noElt) * Elt_Size);
pBuf = (UINT8*)realloc(pBuf, ((*pnElt) - 1) * Elt_Size);
(*pnElt)--;
}
bool Add_Buffer_Element(UINT8* pBuf, UINT* pnElt, UINT Elt_Size, UINT8* pSrc)
{
/* Add an element to the buffer pointed by pBuf.
* Before the function, the buffer contains *pnElt element and each element is Elt_Size byte long.
* Increase the buffer size by Elt_Size bytes using realloc then copy the new element from pSrc copiing Elt_Size bytes at the end of the buffer.
* if pSrc==NULL, fill the memory with 0s
* *pnElt is incremented at the end*/
pBuf = (UINT8*)realloc(pBuf, ((*pnElt) + 1) * Elt_Size);
if (!pBuf)
{
cprintf("Unable to increase the buffer size in Add_Buffer_Element");
return false;
}
if (pSrc != NULL) memcpy(&pBuf[(*pnElt) * Elt_Size], pSrc, Elt_Size); else memset(&pBuf[(*pnElt) * Elt_Size], 0, Elt_Size);
(*pnElt)++;
return true;
}
#pragma endregion Memory_Tools
UINT32 crc32_table[256];
void build_crc32_table(void) // initiating the CRC table, must be called at startup
{
for (UINT32 i = 0; i < 256; i++)
{
UINT32 ch = i;
UINT32 crc = 0;
for (UINT32 j = 0; j < 8; j++)
{
UINT32 b = (ch ^ crc) & 1;
crc >>= 1;
if (b) crc = crc ^ 0xEDB88320;
ch >>= 1;
}
crc32_table[i] = crc;
}
}
uint32_t crc32_fast(const UINT8* s, size_t n, BOOL ShapeMode) // computing a buffer CRC32, "build_crc32_table()" must have been called before the first use
{
uint32_t crc = 0xFFFFFFFF;
for (size_t i = 0; i < n; i++)
{
UINT8 val = s[i];
if ((ShapeMode == TRUE) && (val > 1)) val = 1;
crc = (crc >> 8) ^ crc32_table[(val ^ crc) & 0xFF];
}
return ~crc;
}
uint32_t crc32_fast_count(const UINT8* s, size_t n, BOOL ShapeMode, UINT8* pncols) // computing a buffer CRC32, "build_crc32_table()" must have been called before the first use
// this version counts the number of different values found in the buffer
{
*pncols = 0;
bool usedcolors[256];
memset(usedcolors, false, 256);
uint32_t crc = 0xFFFFFFFF;
for (size_t i = 0; i < n; i++)
{
UINT8 val = s[i];
if (!usedcolors[val])
{
usedcolors[val] = true;
(*pncols)++;
}
if ((ShapeMode == TRUE) && (val > 1)) val = 1;
crc = (crc >> 8) ^ crc32_table[(val ^ crc) & 0xFF];
}
return ~crc;
}
uint32_t crc32_fast_mask(const UINT8* source, const UINT8* mask, size_t n, BOOL ShapeMode) // computing a buffer CRC32 on the non-masked area, "build_crc32_table()" must have been called before the first use
// take into account if we are in shape mode
{
uint32_t crc = 0xFFFFFFFF;
for (size_t i = 0; i < n; i++)
{
if (mask[i] == 0)
{
UINT8 val = source[i];
if ((ShapeMode == TRUE) && (val > 1)) val = 1;
crc = (crc >> 8) ^ crc32_table[(val ^ crc) & 0xFF];
}
}
return ~crc;
}
#pragma region Window_Tools_And_Drawings
unsigned char draw_color[4] = { 255,255,255,255 };
void Draw_Rectangle(GLFWwindow* glfwin, int ix, int iy, int fx, int fy)
{
glfwMakeContextCurrent(glfwin);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glBegin(GL_LINE_LOOP);
glColor4ubv(draw_color);
glVertex2i(ix, iy);
glVertex2i(fx, iy);
glVertex2i(fx, fy);
glVertex2i(ix, fy);
glEnd();
}
void Draw_Fill_Rectangle_Text(GLFWwindow* glfwin, int ix, int iy, int fx, int fy, UINT textID, float tx0, float tx1, float ty0, float ty1)
{
glfwMakeContextCurrent(glfwin);
glColor4ub(255, 255, 255, 255);
glBindTexture(GL_TEXTURE_2D, textID);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBegin(GL_TRIANGLES);
glTexCoord2f(tx0, ty0);
glVertex2i(ix, iy);
glTexCoord2f(tx1, ty0);
glVertex2i(fx, iy);
glTexCoord2f(tx0, ty1);
glVertex2i(ix, fy);
glTexCoord2f(tx0, ty1);
glVertex2i(ix, fy);
glTexCoord2f(tx1, ty0);
glVertex2i(fx, iy);
glTexCoord2f(tx1, ty1);
glVertex2i(fx, fy);
glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
void Draw_Raw_Digit(UINT8 digit, UINT x, UINT y, UINT8* pbuf, UINT width, UINT height)
{
// Draw a digit in a RGBA memory buffer pbuf at (x,y) dimension of the buffer (width,height)
UINT8* pdig = &Raw_Digit_Def[digit * RAW_DIGIT_W];
UINT8* pdig2;
const UINT dwid = 10 * RAW_DIGIT_W;
UINT mx = x + RAW_DIGIT_W;
if (mx > width) mx = width;
UINT my = y + RAW_DIGIT_H;
if (my > height) my = height;
for (UINT tj = y; tj < my; tj++)
{
pdig2 = pdig;
for (UINT ti = x; ti < mx; ti++)
{
float lval = (float)(255-(*pdig)) / 255.0f;
UINT val = (UINT)((1.0f - lval) * pbuf[ti * 4 + tj * 4 * width] + lval * draw_color[0]);
if (val > 255) pbuf[ti * 4 + tj * 4 * width] = 255; else pbuf[ti * 4 + tj * 4 * width] = val;
val = (UINT)((1.0f - lval) * pbuf[ti * 4 + tj * 4 * width + 1] + lval * draw_color[1]);
if (val > 255) pbuf[ti * 4 + tj * 4 * width + 1] = 255; else pbuf[ti * 4 + tj * 4 * width + 1] = val;
val = (UINT)((1.0f - lval) * pbuf[ti * 4 + tj * 4 * width + 2] + lval * draw_color[2]);
if (val > 255) pbuf[ti * 4 + tj * 4 * width + 2] = 255; else pbuf[ti * 4 + tj * 4 * width + 2] = val;
pbuf[ti * 4 + tj * 4 * width + 3] = 255;
pdig++;
}
pdig = pdig2 + dwid;
}
}
void Draw_Raw_Number(UINT number, UINT x, UINT y, UINT8* pbuf, UINT width, UINT height)
{
// Draw a number to opengl from a texture giving the 10 digits
UINT div = 1000000000;
bool started = false;
UINT num = number;
UINT tx = x;
while (div > 0)
{
if (started || (num / div > 0) || (div == 1))
{
started = true;
UINT8 digit = (UINT8)(num / div);
Draw_Raw_Digit(digit, tx, y, pbuf, width, height);
num = num - div * digit;
tx += RAW_DIGIT_W;
}
div = div / 10;
}
}
void Draw_Digit(UINT8 digit, UINT x, UINT y, float zoom)
{
// Draw a digit to opengl with a texture (to use with Draw_Number)
glColor4ubv(draw_color);
glTexCoord2f(digit / 10.0f, 0);
glVertex2i(x, y);
glTexCoord2f((digit + 1) / 10.0f, 0);
glVertex2i(x + (int)(zoom * DIGIT_TEXTURE_W), y);
glTexCoord2f((digit + 1) / 10.0f, 1);
glVertex2i(x + (int)(zoom * DIGIT_TEXTURE_W), y + (int)(zoom * DIGIT_TEXTURE_H));
glTexCoord2f(digit / 10.0f, 1);
glVertex2i(x, y + (int)(zoom * DIGIT_TEXTURE_H));
glTexCoord2f(digit / 10.0f, 0);
glVertex2i(x, y);
glTexCoord2f((digit + 1) / 10.0f, 1);
glVertex2i(x + (int)(zoom * DIGIT_TEXTURE_W), y + (int)(zoom * DIGIT_TEXTURE_H));
}
void Draw_Number(UINT number, UINT x, UINT y, float zoom)
{
// Draw a number to opengl from a texture giving the 10 digits
UINT div = 1000000000;
bool started = false;
UINT num = number;
UINT tx = x;
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, TxChiffres);
glEnable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);
while (div > 0)
{
if (started || (num / div > 0) || (div == 1))
{
started = true;
UINT8 digit = (UINT8)(num / div);
Draw_Digit(digit, tx, y, zoom);
num = num - div * digit;
tx += (UINT)(zoom * DIGIT_TEXTURE_W);
}
div = div / 10;
}
glEnd();
}
void putpixel(int x, int y, UINT8* surface, UINT8 color, bool coloronly, byte* frame)
{
// set a pixel in a monochrome memory surface or frame
if ((x < 0) || (x >= (int)MycRom.fWidth) || (y < 0) || (y >= (int)MycRom.fHeight)) return;
if (coloronly) // do we just mask the non-0 pixels
{
if (frame[y * MycRom.fWidth + x] == 0) return;
}
surface[y * MycRom.fWidth + x] = color;
}
void putpixel2(int x, int y, UINT8* surface, UINT8 color)
{
// set a pixel in a monochrome memory surface or frame for sprites
if ((x < 0) || (x >= (int)MAX_SPRITE_SIZE) || (y < 0) || (y >= (int)MAX_SPRITE_SIZE)) return;
surface[y * MAX_SPRITE_SIZE + x] = color;
}
void drawline(int x, int y, int x2, int y2, UINT8* surface, UINT8 color, bool coloronly, byte* frame)
{
int w = x2 - x;
int h = y2 - y;
int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
if (w < 0) dx1 = -1; else if (w > 0) dx1 = 1;
if (h < 0) dy1 = -1; else if (h > 0) dy1 = 1;
if (w < 0) dx2 = -1; else if (w > 0) dx2 = 1;
int longest = abs(w);
int shortest = abs(h);
if (!(longest > shortest))
{
longest = abs(h);
shortest = abs(w);
if (h < 0) dy2 = -1;
else if (h > 0) dy2 = 1;
dx2 = 0;
}
int numerator = longest >> 1;
for (int i = 0; i <= longest; i++)
{
putpixel(x, y, surface, color, coloronly, frame);
numerator += shortest;
if (!(numerator < longest))
{
numerator -= longest;
x += dx1;
y += dy1;
}
else {
x += dx2;
y += dy2;
}
}
}
void drawline2(int x, int y, int x2, int y2, UINT8* surface, UINT8 color)
{
int w = x2 - x;
int h = y2 - y;
int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
if (w < 0) dx1 = -1; else if (w > 0) dx1 = 1;
if (h < 0) dy1 = -1; else if (h > 0) dy1 = 1;
if (w < 0) dx2 = -1; else if (w > 0) dx2 = 1;
int longest = abs(w);
int shortest = abs(h);
if (!(longest > shortest))
{
longest = abs(h);
shortest = abs(w);
if (h < 0) dy2 = -1;
else if (h > 0) dy2 = 1;
dx2 = 0;
}
int numerator = longest >> 1;
for (int i = 0; i <= longest; i++)
{
putpixel2(x, y, surface, color);
numerator += shortest;
if (!(numerator < longest))
{
numerator -= longest;
x += dx1;
y += dy1;
}
else {
x += dx2;
y += dy2;
}
}
}
void drawAllOctantsF(int xc, int yc, int xp, int yp, UINT8* surface, UINT8 color, bool coloronly, byte* frame)
{
for (int x = 0; x <= xp; x++)
{
for (int y = 0; y <= yp; y++)
{
putpixel(xc + x, yc + y, surface, color, coloronly, frame);
putpixel(xc - x, yc + y, surface, color, coloronly, frame);
putpixel(xc + x, yc - y, surface, color, coloronly, frame);
putpixel(xc - x, yc - y, surface, color, coloronly, frame);
putpixel(xc + y, yc + x, surface, color, coloronly, frame);
putpixel(xc - y, yc + x, surface, color, coloronly, frame);
putpixel(xc + y, yc - x, surface, color, coloronly, frame);
putpixel(xc - y, yc - x, surface, color, coloronly, frame);
}
}
}
void drawAllOctants(int xc, int yc, int x, int y, UINT8* surface, UINT8 color, bool coloronly, byte* frame)
{
putpixel(xc + x, yc + y, surface, color, coloronly, frame);
putpixel(xc - x, yc + y, surface, color, coloronly, frame);
putpixel(xc + x, yc - y, surface, color, coloronly, frame);
putpixel(xc - x, yc - y, surface, color, coloronly, frame);
putpixel(xc + y, yc + x, surface, color, coloronly, frame);
putpixel(xc - y, yc + x, surface, color, coloronly, frame);
putpixel(xc + y, yc - x, surface, color, coloronly, frame);
putpixel(xc - y, yc - x, surface, color, coloronly, frame);
}
void drawAllOctantsF2(int xc, int yc, int xp, int yp, UINT8* surface, UINT8 color)
{
for (int x = 0; x <= xp; x++)
{
for (int y = 0; y <= yp; y++)
{
putpixel2(xc + x, yc + y, surface, color);
putpixel2(xc - x, yc + y, surface, color);
putpixel2(xc + x, yc - y, surface, color);
putpixel2(xc - x, yc - y, surface, color);
putpixel2(xc + y, yc + x, surface, color);
putpixel2(xc - y, yc + x, surface, color);
putpixel2(xc + y, yc - x, surface, color);
putpixel2(xc - y, yc - x, surface, color);
}
}
}
void drawAllOctants2(int xc, int yc, int x, int y, UINT8* surface, UINT8 color)
{
putpixel2(xc + x, yc + y, surface, color);
putpixel2(xc - x, yc + y, surface, color);
putpixel2(xc + x, yc - y, surface, color);
putpixel2(xc - x, yc - y, surface, color);
putpixel2(xc + y, yc + x, surface, color);
putpixel2(xc - y, yc + x, surface, color);
putpixel2(xc + y, yc - x, surface, color);
putpixel2(xc - y, yc - x, surface, color);
}
void drawcircle(int xc, int yc, int r, UINT8* surface, UINT8 color, BOOL filled, bool coloronly, byte* frame)
{
// draw a circle with the bresenham algorithm in a monochrome memory surface (same size as the frames) or frame
int x = 0, y = r;
int d = 3 - 2 * r;
if (!filled) drawAllOctants(xc, yc, x, y, surface, color, coloronly, frame); else drawAllOctantsF(xc, yc, x, y, surface, color, coloronly, frame);
while (y >= x)
{
x++;
if (d > 0)
{
y--;
d = d + 4 * (x - y) + 10;
}
else
d = d + 4 * x + 6;
if (!filled) drawAllOctants(xc, yc, x, y, surface, color, coloronly, frame); else drawAllOctantsF(xc, yc, x, y, surface, color, coloronly, frame);
}
}
void drawcircle2(int xc, int yc, int r, UINT8* surface, UINT8 color, BOOL filled)
{
// draw a circle with the bresenham algorithm in a monochrome memory surface (same size as the frames) or frame
int x = 0, y = r;
int d = 3 - 2 * r;
if (!filled) drawAllOctants2(xc, yc, x, y, surface, color); else drawAllOctantsF2(xc, yc, x, y, surface, color);
while (y >= x)
{
x++;
if (d > 0)
{
y--;
d = d + 4 * (x - y) + 10;
}
else
d = d + 4 * x + 6;
if (!filled) drawAllOctants2(xc, yc, x, y, surface, color); else drawAllOctantsF2(xc, yc, x, y, surface, color);
}
}
void drawrectangle(int x, int y, int x2, int y2, UINT8* surface, UINT8 color, BOOL isfilled, bool coloronly, byte* frame)
{
for (int tj = min(x, x2); tj <= max(x, x2); tj++)
{
for (int ti = min(y, y2); ti <= max(y, y2); ti++)
{
if ((tj != x) && (tj != x2) && (ti != y) && (ti != y2) && (!isfilled)) continue;
if (coloronly) // do we just mask the non-0 pixels
{
if (frame[ti * MycRom.fWidth + tj] == 0) continue;
}
surface[ti * MycRom.fWidth + tj] = color;
}
}
}
void drawrectangle2(int x, int y, int x2, int y2, UINT8* surface, UINT8 color, BOOL isfilled)
{
// for sprites
for (int tj = min(x, x2); tj <= max(x, x2); tj++)
{
for (int ti = min(y, y2); ti <= max(y, y2); ti++)
{
if ((tj != x) && (tj != x2) && (ti != y) && (ti != y2) && (!isfilled)) continue;
surface[ti * MAX_SPRITE_SIZE + tj] = color;
}
}
}
void Draw_Line(float x0, float y0, float x1, float y1)
{
glVertex2i((int)x0, (int)y0);
glVertex2i((int)x1, (int)y1);
}
void SetViewport(GLFWwindow* glfwin)
{
// Set the OpenGL viewport in 2D according the client area of the child window
int Resx, Resy;
glfwMakeContextCurrent(glfwin);
glfwGetFramebufferSize(glfwin, &Resx, &Resy);
glViewport(0, 0, Resx, Resy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Resx, Resy, 0, -2, 2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Calc_Resize_Frame(void)
{
// Calculate the global variables depending on the main window dimension
RECT winrect;
GetClientRect(hWnd, &winrect);
ScrW = winrect.right;
ScrH = winrect.bottom;
NFrameToDraw = (int)((float)(ScrW - FRAME_STRIP_W_MARGIN) / (float)(256 + FRAME_STRIP_W_MARGIN)); // Calculate the number of frames to display in the strip
FS_LMargin = (ScrW - (NFrameToDraw * 256 + (NFrameToDraw - 1) * FRAME_STRIP_W_MARGIN)) / 2; // calculate the left and right margin in the strip
if (MycRom.name[0])
{
if (MycRom.fWidth == 192)
{
NFrameToDraw = (int)((float)(ScrW - FRAME_STRIP_W_MARGIN) / (float)(192 + FRAME_STRIP_W_MARGIN)); // Calculate the number of frames to display in the strip
FS_LMargin = (ScrW - (NFrameToDraw * 192 + (NFrameToDraw - 1) * FRAME_STRIP_W_MARGIN)) / 2; // calculate the left and right margin in the strip
}
}
glfwSetWindowSize(glfwframestripo, ScrW, FRAME_STRIP_HEIGHT);
glfwSetWindowPos(glfwframestripo, 0, ScrH - 2 * FRAME_STRIP_HEIGHT);
SetViewport(glfwframestripo);
glfwSetWindowSize(glfwframestripc, ScrW, FRAME_STRIP_HEIGHT);
glfwSetWindowPos(glfwframestripc, 0, ScrH - FRAME_STRIP_HEIGHT);
SetViewport(glfwframestripc);
}
void RenderDrawPointClip(GLFWwindow* glfwin, unsigned int x, unsigned int y, unsigned int xmax, unsigned int ymax, unsigned int zoom)
{
// square out of the clipping zone
if ((x > xmax) || (y > ymax)) return;
// square entirely in the clipping zone
if ((x + zoom - 1 <= xmax) && (y + zoom - 1 <= ymax))
{
glColor4ubv(draw_color);
glTexCoord2f(0, 0);
glVertex2i(x, y);
glTexCoord2f(1, 0);
glVertex2i(x + zoom - 1, y);
glTexCoord2f(1, 1);
glVertex2i(x + zoom - 1, y + zoom - 1);
glTexCoord2f(0, 1);
glVertex2i(x, y + zoom - 1);
glTexCoord2f(0, 0);
glVertex2i(x, y);
glTexCoord2f(1, 1);
glVertex2i(x + zoom - 1, y + zoom - 1);
return;
}
// square partially out of the clipping zone
unsigned int tx = x + zoom - 1;
unsigned int ty = y + zoom - 1;
float ttx = 1, tty = 1;
if (tx > xmax)
{
tx = xmax;