forked from bradharding/doomretro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc_console.c
2858 lines (2386 loc) · 102 KB
/
c_console.c
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
/*
==============================================================================
DOOM Retro
The classic, refined DOOM source port. For Windows PC.
==============================================================================
Copyright © 1993-2024 by id Software LLC, a ZeniMax Media company.
Copyright © 2013-2024 by Brad Harding <mailto:[email protected]>.
This file is a part of DOOM Retro.
DOOM Retro is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the license, or (at your
option) any later version.
DOOM Retro is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with DOOM Retro. If not, see <https://www.gnu.org/licenses/>.
DOOM is a registered trademark of id Software LLC, a ZeniMax Media
company, in the US and/or other countries, and is used without
permission. All other trademarks are the property of their respective
holders. DOOM Retro is in no way affiliated with nor endorsed by
id Software.
==============================================================================
*/
#if defined(_WIN32)
#include <Windows.h>
#endif
#include "SDL_image.h"
#include "SDL_mixer.h"
#include "am_map.h"
#include "c_cmds.h"
#include "c_console.h"
#include "d_deh.h"
#include "d_main.h"
#include "doomstat.h"
#include "g_game.h"
#include "hu_stuff.h"
#include "i_colors.h"
#include "i_controller.h"
#include "i_swap.h"
#include "i_system.h"
#include "i_timer.h"
#include "m_config.h"
#include "m_menu.h"
#include "m_misc.h"
#include "p_spec.h"
#include "s_sound.h"
#include "st_stuff.h"
#include "v_video.h"
#include "version.h"
#include "w_wad.h"
console_t *console = NULL;
bool consoleactive = false;
int consoleheight = 0;
int consoledirection = -1;
static int consoleanim;
patch_t *consolefont[CONSOLEFONTSIZE];
patch_t *degree;
patch_t *unknownchar;
patch_t *altunderscores;
patch_t *lsquote;
patch_t *ldquote;
static patch_t *brand;
static patch_t *endash;
static patch_t *trademark;
static patch_t *copyright;
static patch_t *regomark;
static patch_t *multiply;
static patch_t *warning;
patch_t *bindlist;
patch_t *cmdlist;
patch_t *cvarlist;
patch_t *maplist;
patch_t *mapstats;
patch_t *playerstats;
patch_t *thinglist;
static short brandwidth;
static short brandheight;
static short spacewidth;
char consoleinput[255] = "";
int numconsolestrings = 0;
size_t consolestringsmax = 0;
static size_t undolevels;
static undohistory_t *undohistory;
static bool showcaret = true;
static uint64_t caretwait;
int caretpos;
int selectstart;
int selectend;
bool pathoverlay;
char consolecheat[255];
char consolecheatparm[3];
static int inputhistory = -1;
static int outputhistory = -1;
static bool topofconsole;
static int degreewidth;
static int suckswidth;
static int timerwidth;
static int timewidth;
static int zerowidth;
static byte *consoleautomapbevelcolor;
static byte *consolebackcolor1;
static byte *consolebackcolor2;
static byte *consolebevelcolor1;
static byte *consolebevelcolor2;
static int consoleboldcolor;
static int consolebolditalicscolor;
int consolebrandingcolor1;
int consolebrandingcolor2;
static int consolecaretcolor;
static int consoledividercolor;
static int consoleinputcolor;
static int consoleoutputcolor;
static int consoleplayermessagecolor;
static int consolescrollbarfacecolor;
static int consolescrollbartrackcolor;
static int consoleselectedinputbackgroundcolor;
static int consoleselectedinputcolor;
static int consolewarningboldcolor;
static int consolewarningcolor;
static int consolecolors[STRINGTYPES];
static int consoleboldcolors[STRINGTYPES];
bool scrollbardrawn;
int scrollbarfacestart;
int scrollbarfaceend;
static void (*consoletextfunc)(const int, const int, const patch_t *,
const int, const int, const int, const bool, const byte *);
void C_Input(const char *string, ...)
{
va_list args;
char buffer[CONSOLETEXTMAXLENGTH];
if (togglingvanilla)
return;
va_start(args, string);
M_vsnprintf(buffer, CONSOLETEXTMAXLENGTH - 1, string, args);
va_end(args);
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringCopy(console[numconsolestrings].string, buffer, sizeof(console[0].string));
console[numconsolestrings].indent = 0;
console[numconsolestrings].wrap = 0;
console[numconsolestrings++].stringtype = inputstring;
inputhistory = -1;
outputhistory = -1;
consoleinput[0] = '\0';
caretpos = 0;
selectstart = 0;
selectend = 0;
}
void C_Cheat(const char *string)
{
char buffer[CONSOLETEXTMAXLENGTH];
const int len = (int)strlen(string);
for (int i = 0; i < len; i++)
buffer[i] = '\x95';
buffer[len] = '\0';
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringCopy(console[numconsolestrings].string, buffer, sizeof(console[0].string));
console[numconsolestrings].indent = 0;
console[numconsolestrings].wrap = 0;
console[numconsolestrings++].stringtype = cheatstring;
inputhistory = -1;
outputhistory = -1;
consoleinput[0] = '\0';
caretpos = 0;
selectstart = 0;
selectend = 0;
}
void C_IntegerCVAROutput(const char *cvar, const int value)
{
char *temp = commify(value);
C_Input("%s %s", cvar, temp);
free(temp);
}
void C_IntegerCVAROutputNoRepeat(const char *cvar, const int value)
{
char buffer[CONSOLETEXTMAXLENGTH];
char *temp = commify(value);
M_snprintf(buffer, sizeof(buffer), "%s %s", cvar, temp);
if (numconsolestrings && M_StringStartsWith(console[numconsolestrings - 1].string, cvar))
M_StringCopy(console[numconsolestrings - 1].string, buffer, sizeof(console[0].string));
else
C_Input(buffer);
free(temp);
}
void C_PercentCVAROutput(const char *cvar, const int value)
{
char *temp = commify(value);
C_Input("%s %s%%", cvar, temp);
free(temp);
}
void C_StringCVAROutput(const char *cvar, const char *string)
{
C_Input("%s %s", cvar, string);
}
void C_Output(const char *string, ...)
{
va_list args;
char buffer[CONSOLETEXTMAXLENGTH];
if (!*string || togglingvanilla)
return;
va_start(args, string);
M_vsnprintf(buffer, CONSOLETEXTMAXLENGTH - 1, string, args);
va_end(args);
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringCopy(console[numconsolestrings].string, buffer, sizeof(console[0].string));
console[numconsolestrings].string[0] = toupper(console[numconsolestrings].string[0]);
console[numconsolestrings].indent = 0;
console[numconsolestrings].wrap = 0;
console[numconsolestrings++].stringtype = outputstring;
outputhistory = -1;
}
void C_TabbedOutput(const int tabs[MAXTABS], const char *string, ...)
{
va_list args;
char buffer[CONSOLETEXTMAXLENGTH];
va_start(args, string);
M_vsnprintf(buffer, CONSOLETEXTMAXLENGTH - 1, string, args);
va_end(args);
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringCopy(console[numconsolestrings].string, buffer, sizeof(console[0].string));
console[numconsolestrings].stringtype = outputstring;
memcpy(console[numconsolestrings].tabs, tabs, sizeof(console[0].tabs));
console[numconsolestrings].indent = (tabs[2] ? tabs[2] : (tabs[1] ? tabs[1] : tabs[0])) - 10;
console[numconsolestrings++].wrap = 0;
outputhistory = -1;
}
void C_Header(const int tabs[MAXTABS], patch_t *header, const char *string)
{
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
console[numconsolestrings].stringtype = headerstring;
memcpy(console[numconsolestrings].tabs, tabs, sizeof(console[0].tabs));
console[numconsolestrings].header = header;
console[numconsolestrings].wrap = 0;
M_StringCopy(console[numconsolestrings++].string, string, sizeof(console[0].string));
outputhistory = -1;
}
void C_Warning(const int minwarninglevel, const char *string, ...)
{
va_list args;
char buffer[CONSOLETEXTMAXLENGTH];
const int i = numconsolestrings - 1;
if (warninglevel < minwarninglevel && !devparm)
return;
va_start(args, string);
M_vsnprintf(buffer, CONSOLETEXTMAXLENGTH - 1, string, args);
va_end(args);
if (console[i].stringtype == warningstring && M_StringCompare(console[i].string, buffer))
console[i].count++;
else
{
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringCopy(console[numconsolestrings].string, buffer, sizeof(console[0].string));
console[numconsolestrings].indent = WARNINGWIDTH + 2;
console[numconsolestrings].wrap = 0;
console[numconsolestrings].stringtype = warningstring;
console[numconsolestrings++].count = 1;
}
outputhistory = -1;
}
void C_PlayerMessage(const char *string, ...)
{
va_list args;
char buffer[CONSOLETEXTMAXLENGTH];
const int i = numconsolestrings - 1;
va_start(args, string);
M_vsnprintf(buffer, CONSOLETEXTMAXLENGTH - 1, string, args);
va_end(args);
if (console[i].stringtype == playermessagestring && M_StringCompare(console[i].string, buffer) && groupmessages)
{
console[i].tics = gametime;
console[i].timestamp[0] = '\0';
console[i].count++;
}
else
{
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringReplaceAll(buffer, "\n", " ", false);
M_StringCopy(console[numconsolestrings].string, buffer, sizeof(console[0].string));
console[numconsolestrings].stringtype = playermessagestring;
console[numconsolestrings].tics = gametime;
console[numconsolestrings].timestamp[0] = '\0';
console[numconsolestrings].string[0] = toupper(console[numconsolestrings].string[0]);
console[numconsolestrings].indent = 0;
console[numconsolestrings].wrap = 0;
console[numconsolestrings++].count = 1;
}
outputhistory = -1;
}
void C_PlayerObituary(const char *string, ...)
{
va_list args;
char buffer[CONSOLETEXTMAXLENGTH];
va_start(args, string);
M_vsnprintf(buffer, CONSOLETEXTMAXLENGTH - 1, string, args);
va_end(args);
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringCopy(console[numconsolestrings].string, buffer, sizeof(console[0].string));
console[numconsolestrings].stringtype = playerwarningstring;
console[numconsolestrings].tics = gametime;
console[numconsolestrings].timestamp[0] = '\0';
console[numconsolestrings].string[0] = toupper(console[numconsolestrings].string[0]);
console[numconsolestrings].indent = WARNINGWIDTH + 2;
console[numconsolestrings].wrap = 0;
console[numconsolestrings++].count = 1;
outputhistory = -1;
if (obituaries)
{
HU_SetPlayerMessage(buffer, false, false);
message_warning = true;
}
}
void C_PlayerWarning(const char *string, ...)
{
va_list args;
char buffer[CONSOLETEXTMAXLENGTH];
va_start(args, string);
M_vsnprintf(buffer, CONSOLETEXTMAXLENGTH - 1, string, args);
va_end(args);
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringCopy(console[numconsolestrings].string, buffer, sizeof(console[0].string));
console[numconsolestrings].stringtype = playerwarningstring;
console[numconsolestrings].tics = gametime;
console[numconsolestrings].timestamp[0] = '\0';
console[numconsolestrings].string[0] = toupper(console[numconsolestrings].string[0]);
console[numconsolestrings].indent = WARNINGWIDTH + 2;
console[numconsolestrings].wrap = 0;
console[numconsolestrings++].count = 1;
outputhistory = -1;
}
void C_ResetWrappedLines(void)
{
for (int i = 0; i < numconsolestrings; i++)
console[i].wrap = 0;
}
static void C_AddToUndoHistory(void)
{
undohistory = I_Realloc(undohistory, (undolevels + 1) * sizeof(*undohistory));
undohistory[undolevels].input = M_StringDuplicate(consoleinput);
undohistory[undolevels].caretpos = caretpos;
undohistory[undolevels].selectstart = selectstart;
undohistory[undolevels].selectend = selectend;
undolevels++;
}
void C_AddConsoleDivider(void)
{
if (console[numconsolestrings - 1].stringtype != dividerstring || !numconsolestrings)
{
if (numconsolestrings >= (int)consolestringsmax)
console = I_Realloc(console, (consolestringsmax += CONSOLESTRINGSMAX) * sizeof(*console));
M_StringCopy(console[numconsolestrings].string, DIVIDERSTRING, sizeof(console[0].string));
console[numconsolestrings++].stringtype = dividerstring;
}
}
const kern_t altkern[] =
{
{ ' ', ' ', -1 }, { ' ', 'J', -1 }, { ' ', 'T', -1 }, { '!', ' ', 2 },
{ '"', '+', -1 }, { '"', ',', -2 }, { '"', '.', -2 }, { '"', '4', -1 },
{ '"', 'a', -1 }, { '"', 'c', -1 }, { '"', 'd', -1 }, { '"', 'e', -1 },
{ '"', 'g', -1 }, { '"', 'J', -2 }, { '"', 'j', -2 }, { '"', 'o', -1 },
{ '"', 'q', -1 }, { '"', 's', -1 }, { '(', '(', -1 }, { '(', '-', -1 },
{ '(', '4', -1 }, { '(', 't', -1 }, { ')', ')', -1 }, { '+', 'j', -2 },
{ ',', '-', -1 }, { ',', '4', -1 }, { ',', '7', -1 }, { '.', '"', -1 },
{ '.', '4', -1 }, { '.', '7', -1 }, { '.', '\\', -1 }, { '/', '/', -2 },
{ '/', '4', -1 }, { '/', 'a', -1 }, { '/', 'c', -1 }, { '/', 'd', -1 },
{ '/', 'e', -1 }, { '/', 'g', -1 }, { '/', 'q', -1 }, { '/', 's', -1 },
{ '0', ',', -1 }, { '0', '4', -1 }, { '0', ';', -1 }, { '0', 'j', -2 },
{ '1', '"', -1 }, { '1', ',', -1 }, { '1', '\'', -1 }, { '1', '\\', -1 },
{ '1', 'j', -2 }, { '2', ',', -1 }, { '2', '4', -1 }, { '2', 'j', -2 },
{ '3', ',', -1 }, { '3', '4', -1 }, { '3', ';', -1 }, { '3', 'j', -2 },
{ '4', '"', -1 }, { '4', ')', -1 }, { '4', ',', -1 }, { '4', '4', -1 },
{ '4', '7', -1 }, { '4', '\'', -1 }, { '4', '\\', -1 }, { '4', 'j', -2 },
{ '5', ',', -1 }, { '5', '4', -1 }, { '5', ';', -1 }, { '5', 'j', -2 },
{ '6', ',', -1 }, { '6', '4', -1 }, { '6', 'j', -2 }, { '7', ',', -2 },
{ '7', '.', -1 }, { '7', '4', -1 }, { '7', ';', -1 }, { '7', 'j', -2 },
{ '8', ',', -1 }, { '8', '4', -1 }, { '8', ';', -1 }, { '8', 'j', -2 },
{ '9', ',', -1 }, { '9', '4', -1 }, { '9', ';', -1 }, { '9', 'j', -2 },
{ '?', ' ', 2 }, { '\'', 'a', -1 }, { '\'', 'c', -1 }, { '\'', 'd', -1 },
{ '\'', 'e', -1 }, { '\'', 'g', -1 }, { '\'', 'J', -2 }, { '\'', 'j', -2 },
{ '\'', 'o', -1 }, { '\'', 's', -1 }, { '\'', 't', -1 }, { '\\', '\\', -2 },
{ '\\', 'T', -1 }, { '\\', 't', -1 }, { '\\', 'V', -1 }, { '\\', 'v', -1 },
{ '\t', '-', 1 }, { '\t', '4', -1 }, { '_', 'f', -1 }, { '_', 'T', -1 },
{ '_', 't', -1 }, { '_', 'V', -1 }, { '_', 'v', -1 }, { 'a', '"', -1 },
{ 'a', '\\', -1 }, { 'a', 'j', -2 }, { 'b', '"', -1 }, { 'b', ',', -1 },
{ 'b', ';', -1 }, { 'b', '\\', -1 }, { 'b', 'j', -2 }, { 'c', '"', -1 },
{ 'c', ',', -1 }, { 'c', ';', -1 }, { 'c', '\\', -1 }, { 'c', 'j', -2 },
{ 'd', 'j', -2 }, { 'e', '"', -1 }, { 'e', ')', -1 }, { 'e', ';', -1 },
{ 'e', '\\', -1 }, { 'e', '_', -1 }, { 'e', 'j', -2 }, { 'F', ' ', -1 },
{ 'f', ' ', -1 }, { 'F', ',', -1 }, { 'f', ',', -1 }, { 'F', '.', -1 },
{ 'f', '.', -1 }, { 'F', ';', -1 }, { 'f', ';', -1 }, { 'f', '_', -1 },
{ 'F', 'a', -1 }, { 'f', 'a', -1 }, { 'F', 'e', -1 }, { 'f', 'f', -1 },
{ 'F', 'J', -1 }, { 'f', 'j', -2 }, { 'F', 'o', -1 }, { 'f', 't', -1 },
{ 'h', '\\', -1 }, { 'h', 'j', -2 }, { 'i', 'j', -2 }, { 'k', 'j', -2 },
{ 'L', ' ', -1 }, { 'L', '"', -1 }, { 'L', '-', -1 }, { 'L', '\'', -1 },
{ 'L', '\\', -1 }, { 'l', 'j', -2 }, { 'L', 'Y', -1 }, { 'm', '"', -1 },
{ 'm', '\\', -1 }, { 'm', 'j', -2 }, { 'n', '"', -1 }, { 'n', '\\', -1 },
{ 'n', 'j', -2 }, { 'o', '"', -1 }, { 'o', ',', -1 }, { 'o', ';', -1 },
{ 'o', '\\', -1 }, { 'o', 'j', -2 }, { 'p', '"', -1 }, { 'P', ',', -1 },
{ 'p', ',', -1 }, { 'P', '.', -1 }, { 'P', ';', -1 }, { 'p', ';', -1 },
{ 'p', '\\', -1 }, { 'P', '_', -1 }, { 'P', 'J', -1 }, { 'p', 'j', -2 },
{ 'r', ' ', -1 }, { 'r', '"', -1 }, { 'r', ')', -1 }, { 'r', ',', -2 },
{ 'r', '.', -1 }, { 'r', '/', -1 }, { 'r', ';', -1 }, { 'r', '\\', -1 },
{ 'r', '_', -1 }, { 'r', 'a', -1 }, { 'r', 'j', -2 }, { 's', ',', -1 },
{ 's', ';', -1 }, { 's', 'j', -2 }, { 'T', ' ', -1 }, { 'T', ',', -1 },
{ 'T', '.', -1 }, { 'T', ';', -1 }, { 'T', 'a', -1 }, { 'T', 'e', -1 },
{ 't', 'j', -2 }, { 'T', 'o', -1 }, { 't', 't', -1 }, { 'u', 'j', -2 },
{ 'V', ',', -1 }, { 'v', ',', -1 }, { 'V', '.', -1 }, { 'v', '4', -1 },
{ 'V', ';', -1 }, { 'v', ';', -1 }, { 'v', '_', -1 }, { 'V', 'a', -1 },
{ 'v', 'a', -1 }, { 'v', 'j', -2 }, { 'w', 'j', -2 }, { 'x', '7', -1 },
{ 'x', 'j', -2 }, { 'Y', ',', -1 }, { 'Y', '.', -1 }, { 'Y', ';', -1 },
{ 'z', 'j', -2 }, { '\0', '\0', 0 }
};
int C_TextWidth(const char *text, const bool formatting, const bool kerning)
{
bool italics = false;
bool monospaced = false;
const int len = (int)strlen(text);
unsigned char prevletter = '\0';
int width = 0;
for (int i = 0; i < len; i++)
{
const unsigned char letter = text[i];
unsigned char nextletter = text[i + 1];
if (letter == ' ')
width += spacewidth;
else if (letter == BOLDONCHAR || letter == BOLDOFFCHAR)
continue;
else if (letter == ITALICSONCHAR)
{
italics = true;
continue;
}
else if (letter == ITALICSOFFCHAR)
{
italics = false;
continue;
}
else if (letter == MONOSPACEDONCHAR)
{
monospaced = true;
continue;
}
else if (letter == MONOSPACEDOFFCHAR)
{
monospaced = false;
continue;
}
else if (monospaced)
width += zerowidth;
else if (letter == '(' && i < len - 3 && tolower(text[i + 1]) == 't'
&& tolower(text[i + 2]) == 'm' && text[i + 3] == ')' && formatting)
{
width += SHORT(trademark->width);
i += 3;
}
else if (letter == '(' && i < len - 2 && tolower(text[i + 1]) == 'c' && text[i + 2] == ')' && formatting)
{
width += SHORT(copyright->width);
i += 2;
}
else if (letter == '(' && i < len - 2 && tolower(text[i + 1]) == 'r' && text[i + 2] == ')' && formatting)
{
width += SHORT(regomark->width);
i += 2;
}
else if (letter == 215 || (letter == 'x' && isdigit(prevletter) && (nextletter == '\0' || isdigit(nextletter))))
width += SHORT(multiply->width);
else if (letter == '-' && prevletter == ' ' && !isdigit(nextletter))
width += SHORT(endash->width);
else if (!i || prevletter == ' ' || prevletter == '(' || prevletter == '[' || prevletter == '\t')
{
if (letter == '\'')
width += SHORT(lsquote->width);
else if (letter == '"')
width += SHORT(ldquote->width);
else
{
const int c = letter - CONSOLEFONTSTART;
width += SHORT((c >= 0 && c < CONSOLEFONTSIZE ? consolefont[c] : unknownchar)->width);
}
}
else
{
const int c = letter - CONSOLEFONTSTART;
width += SHORT((c >= 0 && c < CONSOLEFONTSIZE ? consolefont[c] : unknownchar)->width);
if (letter == '-' && italics)
width++;
}
if (kerning)
{
for (int j = 0; altkern[j].char1; j++)
if (prevletter == altkern[j].char1 && letter == altkern[j].char2)
{
width += altkern[j].adjust;
break;
}
if (prevletter == '/' && italics)
width -= 2;
}
prevletter = letter;
}
return width;
}
static int C_OverlayWidth(const char *text, const bool monospaced)
{
const int len = (int)strlen(text);
int width = 0;
for (int i = 0; i < len; i++)
{
const unsigned char letter = text[i];
if (letter == ' ')
width += spacewidth;
else if (isdigit(letter))
width += (monospaced ? zerowidth : SHORT(consolefont[letter - CONSOLEFONTSTART]->width));
else if (letter >= CONSOLEFONTSTART)
width += (SHORT(consolefont[letter - CONSOLEFONTSTART]->width) - (letter == ','));
}
return width;
}
static void C_DrawScrollbar(void)
{
scrollbarfacestart = CONSOLESCROLLBARHEIGHT * MAX(0, (outputhistory == -1 ?
numconsolestrings - CONSOLEBLANKLINES - CONSOLELINES : outputhistory - CONSOLEBLANKLINES)) / numconsolestrings;
scrollbarfaceend = scrollbarfacestart + CONSOLESCROLLBARHEIGHT - CONSOLESCROLLBARHEIGHT
* MAX(0, numconsolestrings - CONSOLEBLANKLINES - CONSOLELINES) / numconsolestrings;
if (!scrollbarfacestart && scrollbarfaceend == CONSOLESCROLLBARHEIGHT)
scrollbardrawn = false;
else
{
const int offset = (CONSOLEHEIGHT - consoleheight) * SCREENWIDTH;
const int gripstart = (scrollbarfacestart + (scrollbarfaceend - scrollbarfacestart) / 2 - 2) * SCREENWIDTH - offset;
const int trackend = MAX(0, CONSOLESCROLLBARHEIGHT * SCREENWIDTH - offset);
// draw scrollbar track
for (int y = 0; y < trackend; y += SCREENWIDTH)
for (int x = CONSOLESCROLLBARX; x < CONSOLESCROLLBARX + CONSOLESCROLLBARWIDTH; x++)
{
byte *dot = *screens + y + x;
*dot = tinttab50[*dot + consolescrollbartrackcolor];
}
if (scrollbarfaceend - scrollbarfacestart > 8)
{
const int gripend = gripstart + 6 * SCREENWIDTH;
// init scrollbar grip
for (int y = gripstart; y < gripend; y += 2 * SCREENWIDTH)
if (y >= 0)
for (int x = CONSOLESCROLLBARX + 1; x < CONSOLESCROLLBARX + CONSOLESCROLLBARWIDTH - 1; x++)
tempscreen[y + x] = screens[0][y + x];
// draw scrollbar face
const int end = scrollbarfaceend * SCREENWIDTH - offset;
for (int y = scrollbarfacestart * SCREENWIDTH - offset; y < end; y += SCREENWIDTH)
if (y >= 0)
for (int x = CONSOLESCROLLBARX; x < CONSOLESCROLLBARX + CONSOLESCROLLBARWIDTH; x++)
screens[0][y + x] = consolescrollbarfacecolor;
// draw scrollbar grip
for (int y = gripstart; y < gripend; y += 2 * SCREENWIDTH)
if (y >= 0)
for (int x = CONSOLESCROLLBARX + 1; x < CONSOLESCROLLBARX + CONSOLESCROLLBARWIDTH - 1; x++)
screens[0][y + x] = tempscreen[y + x];
}
else
{
const int end = scrollbarfaceend * SCREENWIDTH - offset;
// draw scrollbar face
for (int y = scrollbarfacestart * SCREENWIDTH - offset; y < end; y += SCREENWIDTH)
if (y >= 0)
for (int x = CONSOLESCROLLBARX; x < CONSOLESCROLLBARX + CONSOLESCROLLBARWIDTH; x++)
screens[0][y + x] = consolescrollbarfacecolor;
}
// draw scrollbar face shadow
if (scrollbarfaceend >= 0)
for (int x = CONSOLESCROLLBARX; x < CONSOLESCROLLBARX + CONSOLESCROLLBARWIDTH; x++)
{
byte *dot = *screens + scrollbarfaceend + x;
*dot = tinttab10[*dot];
}
scrollbardrawn = true;
}
}
void C_ClearConsole(void)
{
numconsolestrings = 0;
consolestringsmax = CONSOLESTRINGSMAX;
console = I_Realloc(console, consolestringsmax * sizeof(*console));
memset(console, 0, consolestringsmax * sizeof(*console));
for (int i = 0; i < CONSOLEBLANKLINES; i++)
{
console[numconsolestrings].string[0] = '\0';
console[numconsolestrings].indent = 0;
console[numconsolestrings].wrap = 0;
console[numconsolestrings++].stringtype = outputstring;
}
}
static void C_InitBrandingColors(void)
{
consolebrandingcolor1 = FindBrightDominantColor(W_CacheLumpName("STTNUM0"));
if (W_GetNumLumps("STTNUM0") >= 2
&& !(consolebrandingcolor1 >= nearestcolors[80] && consolebrandingcolor1 <= nearestcolors[111]))
{
consolebrandingcolor2 = black25[consolebrandingcolor1] << 8;
consolebrandingcolor1 <<= 8;
}
else
{
consolebrandingcolor1 = FindBrightDominantColor(W_CacheLumpName("M_NGAME"));
if (W_GetNumLumps("M_NGAME") >= 2
&& !(consolebrandingcolor1 >= nearestcolors[80] && consolebrandingcolor1 <= nearestcolors[111]))
{
consolebrandingcolor2 = black25[consolebrandingcolor1] << 8;
consolebrandingcolor1 <<= 8;
}
else
{
consolebrandingcolor1 = nearestcolors[CONSOLEBRANDINGCOLOR1] << 8;
consolebrandingcolor2 = nearestcolors[CONSOLEBRANDINGCOLOR2] << 8;
}
}
}
void C_Init(void)
{
char *appdatafolder = M_GetAppDataFolder();
char consolefolder[MAX_PATH];
char buffer[9];
M_snprintf(consolefolder, sizeof(consolefolder), "%s" DIR_SEPARATOR_S DOOMRETRO_CONSOLEFOLDER, appdatafolder);
M_MakeDirectory(consolefolder);
free(appdatafolder);
for (int i = 0, j = CONSOLEFONTSTART; i < CONSOLEFONTSIZE; i++)
{
M_snprintf(buffer, sizeof(buffer), "DRFON%03i", j++);
consolefont[i] = W_CacheLastLumpName(W_CheckNumForName(buffer) >= 0 ? buffer : "DRFON000");
}
consoleautomapbevelcolor = &tinttab50[nearestcolors[CONSOLEAUTOMAPBEVELCOLOR] << 8];
consolebackcolor1 = &tinttab50[nearestcolors[CONSOLEBACKCOLOR] << 8];
consolebackcolor2 = &tinttab60[nearestblack << 8];
consolebevelcolor1 = &tinttab50[nearestcolors[CONSOLEBEVELCOLOR] << 8];
consolebevelcolor2 = &tinttab20[nearestcolors[CONSOLEBEVELCOLOR] << 8];
consoleboldcolor = nearestcolors[CONSOLEBOLDCOLOR];
consolebolditalicscolor = nearestcolors[CONSOLEBOLDITALICSCOLOR];
consolecaretcolor = nearestcolors[CONSOLECARETCOLOR];
consoledividercolor = nearestcolors[CONSOLEDIVIDERCOLOR] << 8;
consoleinputcolor = nearestcolors[CONSOLEINPUTCOLOR];
consoleoutputcolor = nearestcolors[CONSOLEOUTPUTCOLOR];
consoleplayermessagecolor = (harmony ? 226 : nearestcolors[CONSOLEPLAYERMESSAGECOLOR]);
consolescrollbarfacecolor = nearestcolors[CONSOLESCROLLBARFACECOLOR];
consolescrollbartrackcolor = nearestcolors[CONSOLESCROLLBARTRACKCOLOR] << 8;
consoleselectedinputbackgroundcolor = nearestcolors[CONSOLESELECTEDINPUTBACKGROUNDCOLOR];
consoleselectedinputcolor = nearestcolors[CONSOLESELECTEDINPUTCOLOR];
consolewarningboldcolor = nearestcolors[CONSOLEWARNINGBOLDCOLOR];
consolewarningcolor = nearestcolors[CONSOLEWARNINGCOLOR];
C_InitBrandingColors();
consolecolors[inputstring] = consoleinputcolor;
consolecolors[cheatstring] = consoleinputcolor;
consolecolors[outputstring] = consoleoutputcolor;
consolecolors[warningstring] = consolewarningcolor;
consolecolors[playermessagestring] = consoleplayermessagecolor;
consolecolors[playerwarningstring] = consolewarningcolor;
consoleboldcolors[inputstring] = consoleboldcolor;
consoleboldcolors[cheatstring] = consoleboldcolor;
consoleboldcolors[outputstring] = consoleboldcolor;
consoleboldcolors[warningstring] = consolewarningboldcolor;
consoleboldcolors[playermessagestring] = consoleplayermessagecolor;
consoleboldcolors[playerwarningstring] = consolewarningboldcolor;
brand = W_CacheLastLumpName("DRBRAND");
unknownchar = W_CacheLastLumpName("DRFON000");
lsquote = consolefont[0x91 - CONSOLEFONTSTART];
ldquote = consolefont[0x93 - CONSOLEFONTSTART];
endash = consolefont[0x96 - CONSOLEFONTSTART];
trademark = consolefont[0x99 - CONSOLEFONTSTART];
copyright = consolefont[0xA9 - CONSOLEFONTSTART];
regomark = consolefont[0xAE - CONSOLEFONTSTART];
degree = consolefont[0xB0 - CONSOLEFONTSTART];
multiply = consolefont[0xD7 - CONSOLEFONTSTART];
warning = W_CacheLastLumpName("DRFONWRN");
altunderscores = W_CacheLastLumpName("DRFONUND");
bindlist = W_CacheLastLumpName("DRBNDLST");
cmdlist = W_CacheLastLumpName("DRCMDLST");
cvarlist = W_CacheLastLumpName("DRCVRLST");
maplist = W_CacheLastLumpName("DRMAPLST");
mapstats = W_CacheLastLumpName("DRMAPST");
playerstats = W_CacheLastLumpName("DRPLYRST");
thinglist = W_CacheLastLumpName("DRTHNLST");
brandwidth = SHORT(brand->width);
brandheight = SHORT(brand->height);
degreewidth = SHORT(degree->width);
spacewidth = SHORT(consolefont[' ' - CONSOLEFONTSTART]->width);
zerowidth = SHORT(consolefont['0' - CONSOLEFONTSTART]->width);
suckswidth = C_OverlayWidth(s_STSTR_SUCKS, false);
timewidth = C_OverlayWidth("00:00", true);
M_TranslateAutocomplete();
}
void C_ShowConsole(bool reset)
{
consoleheight = MAX(1, consoleheight);
consoledirection = 1;
consoleanim = 0;
showcaret = true;
caretwait = 0;
if (reset)
{
consoleinput[0] = '\0';
caretpos = 0;
selectstart = 0;
selectend = 0;
undolevels = 0;
inputhistory = -1;
outputhistory = -1;
}
for (int i = 0; i < MAXMOUSEBUTTONS; i++)
mousebuttons[i] = false;
if (gamestate == GS_LEVEL)
I_RestoreMousePointerPosition();
if (keyboardalwaysrun == KEY_CAPSLOCK && alwaysrun && GetCapsLockState())
#if defined(_WIN32)
{
ToggleCapsLockState();
nokeyevent = true;
}
#elif defined(X11)
SetCapsLockState(false);
#endif
S_StopSounds();
S_LowerMusicVolume();
SDL_StartTextInput();
S_StartSound(NULL, sfx_consol);
}
void C_HideConsole(void)
{
if (!consoleactive)
return;
if (keyboardalwaysrun == KEY_CAPSLOCK && alwaysrun && !GetCapsLockState())
#if defined(_WIN32)
{
ToggleCapsLockState();
nokeyevent = true;
}
#elif defined(X11)
SetCapsLockState(true);
#endif
SDL_StopTextInput();
consoledirection = -1;
consoleanim = 0;
I_SaveMousePointerPosition();
S_StartSound(viewplayer->mo, sfx_consol);
S_RestoreMusicVolume();
}
void C_HideConsoleFast(void)
{
if (!consoleactive)
return;
if (keyboardalwaysrun == KEY_CAPSLOCK && alwaysrun && !GetCapsLockState())
#if defined(_WIN32)
{
ToggleCapsLockState();
nokeyevent = true;
}
#elif defined(X11)
SetCapsLockState(true);
#endif
SDL_StopTextInput();
consoledirection = -1;
consoleanim = 0;
consoleheight = 0;
consoleactive = false;
I_SaveMousePointerPosition();
S_RestoreMusicVolume();
}
static void C_DrawBackground(void)
{
const bool inverted = ((viewplayer->fixedcolormap == INVERSECOLORMAP) != !r_textures);
const int height = (consoleheight + 5) * SCREENWIDTH;
static byte blurscreen[MAXSCREENAREA];
// apply random noise to background
M_BigSeed(666);
for (int i = height; i >= 0; i--)
screens[0][i] = colormaps[0][M_BigRandomInt(0, 7) * 256 + screens[0][i]];
M_BigSeed((unsigned int)time(NULL));
// blur background
memcpy(blurscreen, screens[0], height);
for (int y = 0; y <= height - SCREENWIDTH; y += SCREENWIDTH)
for (int x = y; x <= y + SCREENWIDTH - 2; x++)
blurscreen[x] = tinttab50[(blurscreen[x + 1] << 8) + blurscreen[x]];
for (int y = 0; y <= height - SCREENWIDTH; y += SCREENWIDTH)
for (int x = y + SCREENWIDTH - 2; x > y; x--)
blurscreen[x] = tinttab50[(blurscreen[x - 1] << 8) + blurscreen[x]];
for (int y = height - SCREENWIDTH; y >= SCREENWIDTH; y -= SCREENWIDTH)
for (int x = y + SCREENWIDTH - 1; x >= y + 1; x--)
blurscreen[x] = tinttab50[(blurscreen[x - SCREENWIDTH - 1] << 8) + blurscreen[x]];
for (int y = 0; y <= height - 2 * SCREENWIDTH; y += SCREENWIDTH)
for (int x = y; x <= y + SCREENWIDTH - 1; x++)
blurscreen[x] = tinttab50[(blurscreen[x + SCREENWIDTH] << 8) + blurscreen[x]];
for (int y = height - SCREENWIDTH; y >= SCREENWIDTH; y -= SCREENWIDTH)
for (int x = y; x <= y + SCREENWIDTH - 1; x++)
blurscreen[x] = tinttab50[(blurscreen[x - SCREENWIDTH] << 8) + blurscreen[x]];
for (int y = 0; y <= height - 2 * SCREENWIDTH; y += SCREENWIDTH)
for (int x = y + SCREENWIDTH - 1; x >= y + 1; x--)
blurscreen[x] = tinttab50[(blurscreen[x + SCREENWIDTH - 1] << 8) + blurscreen[x]];
for (int y = height - SCREENWIDTH; y >= SCREENWIDTH; y -= SCREENWIDTH)
for (int x = y; x <= y + SCREENWIDTH - 2; x++)
blurscreen[x] = tinttab50[(blurscreen[x - SCREENWIDTH + 1] << 8) + blurscreen[x]];
// tint background
if (inverted)
for (int i = 0; i < height; i++)
screens[0][i] = consolebackcolor2[blurscreen[i]];
else
for (int i = 0; i < height; i++)
screens[0][i] = consolebackcolor1[blurscreen[i]];
// apply corrugated glass effect to background
for (int y = consoleheight % 3; y <= height - 3 * SCREENWIDTH; y += SCREENWIDTH)
{
for (int x = y + 2; x < y + SCREENWIDTH - 1; x += 3)
screens[0][x] = colormaps[0][6 * 256 + screens[0][x + ((x % SCREENWIDTH) ? -1 : 1)]];
for (int x = (y += SCREENWIDTH) + 1; x < y + SCREENWIDTH - 1; x += 3)
screens[0][x] = colormaps[0][6 * 256 + screens[0][x + ((x % SCREENWIDTH) ? -1 : 1)]];
for (int x = (y += SCREENWIDTH); x < y + SCREENWIDTH - 1; x += 3)
screens[0][x] = colormaps[0][6 * 256 + screens[0][x + ((x % SCREENWIDTH) ? -1 : 1)]];
}
// draw branding
V_DrawConsoleBrandingPatch(SCREENWIDTH - MAXWIDESCREENDELTA - brandwidth + (vid_widescreen ? 19 : 44),
consoleheight - brandheight + 2, brand);
// draw bottom edge
for (int i = height - 3 * SCREENWIDTH; i < height; i++)
screens[0][i] = tinttab60[consolebrandingcolor1 + screens[0][i]];
// bevel left and right edges