/
ui_main.c
10496 lines (9395 loc) · 295 KB
/
ui_main.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
/*
* Wolfenstein: Enemy Territory GPL Source Code
* Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
*
* ET: Legacy
* Copyright (C) 2012 Jan Simek <mail@etlegacy.com>
*
* This file is part of ET: Legacy - http://www.etlegacy.com
*
* ET: Legacy 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.
*
* ET: Legacy 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 ET: Legacy. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, Wolfenstein: Enemy Territory GPL Source Code is also
* subject to certain additional terms. You should have received a copy
* of these additional terms immediately following the terms and conditions
* of the GNU General Public License which accompanied the source code.
* If not, please request a copy in writing from id Software at the address below.
*
* id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
*
* @file ui_main.c
*/
#include "ui_local.h"
// NERVE - SMF
#define AXIS_TEAM 0
#define ALLIES_TEAM 1
#define SPECT_TEAM 2
// -NERVE - SMF
extern qboolean g_waitingForKey;
extern qboolean g_editingField;
extern itemDef_t *g_editItem;
uiInfo_t uiInfo;
static const char *MonthAbbrev[] =
{
"Jan", "Feb", "Mar",
"Apr", "May", "Jun",
"Jul", "Aug", "Sep",
"Oct", "Nov", "Dec"
};
static const serverFilter_t serverFilters[] =
{
{ "All", "" }
};
// For server browser
/*static const char *ETGameTypes[] = {
"Single Player",
"Cooperative",
"Objective",
"Stopwatch",
"Campaign",
"Last Man Standing"
};
static const char *shortETGameTypes[] = {
"SP",
"Coop",
"Obj",
"SW",
"Cmpgn",
"LMS"
};
static int const numETGameTypes = sizeof(ETGameTypes) / sizeof(const char*);*/
static const int numServerFilters = sizeof(serverFilters) / sizeof(serverFilter_t);
static char *netnames[] =
{
"???",
"UDP",
"IPX",
NULL
};
static int gamecodetoui[] = { 4, 2, 3, 0, 5, 1, 6 };
static int uitogamecode[] = { 4, 6, 2, 3, 1, 5, 7 };
// NERVE - SMF - enabled for multiplayer
static void UI_StartServerRefresh(qboolean full);
static void UI_StopServerRefresh(void);
static void UI_DoServerRefresh(void);
static void UI_FeederSelection(float feederID, int index);
qboolean UI_FeederSelectionClick(itemDef_t *item);
static void UI_BuildServerDisplayList(qboolean force);
static void UI_BuildServerStatus(qboolean force);
static void UI_BuildFindPlayerList(qboolean force);
static int QDECL UI_ServersQsortCompare(const void *arg1, const void *arg2);
static int UI_MapCountByGameType(qboolean singlePlayer);
static const char *UI_SelectedMap(qboolean singlePlayer, int index, int *actual);
static int UI_GetIndexFromSelection(int actual);
static const char *UI_SelectedCampaign(int index, int *actual);
static int UI_CampaignCount(qboolean singlePlayer);
qboolean UI_CheckExecKey(int key);
// -NERVE - SMF - enabled for multiplayer
static void UI_ParseGameInfo(const char *teamFile);
//static void UI_ParseTeamInfo(const char *teamFile); // TTimo: unused
//int ProcessNewUI( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6 );
itemDef_t *Menu_FindItemByName(menuDef_t *menu, const char *p);
void Menu_ShowItemByName(menuDef_t *menu, const char *p, qboolean bShow);
#define ITEM_GRENADES 1
#define ITEM_MEDKIT 2
#define ITEM_PISTOL 1
#define DEFAULT_PISTOL
#define PT_KNIFE (1)
#define PT_PISTOL (1 << 2)
#define PT_RIFLE (1 << 3)
#define PT_LIGHTONLY (1 << 4)
#define PT_GRENADES (1 << 5)
#define PT_EXPLOSIVES (1 << 6)
#define PT_MEDKIT (1 << 7)
// TTimo
static char translated_yes[4], translated_no[4];
typedef struct
{
const char *name;
int items;
} playerType_t;
static playerType_t playerTypes[] =
{
{ "player_window_soldier", PT_KNIFE | PT_PISTOL | PT_RIFLE | PT_GRENADES },
{ "player_window_medic", PT_KNIFE | PT_PISTOL | PT_MEDKIT },
{ "player_window_engineer", PT_KNIFE | PT_PISTOL | PT_LIGHTONLY | PT_GRENADES },
{ "player_window_lieutenant", PT_KNIFE | PT_PISTOL | PT_RIFLE | PT_EXPLOSIVES },
{ "player_window_covertops", PT_KNIFE | PT_PISTOL | PT_GRENADES }
};
int numPlayerTypes = sizeof(playerTypes) / sizeof(playerTypes[0]);
/*typedef struct {
int weapindex;
const char *desc;
// int flags;
const char *cvar;
int value;
const char *shadername;
const char *torso_anim;
const char *legs_anim;
// const char *large_shader;
} weaponType_t;*/
#define ENG_WEAPMASK_1 (0 | 1 | 2)
#define ENG_WEAPMASK_2 (4 | 8)
// NERVE - SMF - this is the weapon info list [what can and can't be used by character classes]
// - This list is seperate from the actual text names in the listboxes for localization purposes.
// - The list boxes look up this list by the cvar value.
// Gordon: stripped out some useless stuff, and moved some other stuff to generic class stuff
/*static weaponType_t weaponTypes[] = {
{ 0, "NULL", "none", -1, "none", "", "" },
{ WP_COLT, "1911 pistol", "mp_weapon", -1, "ui/assets/weapon_colt1911.tga", "firing_pistolB_1", "stand_pistolB" },
{ WP_LUGER, "Luger pistol", "mp_weapon", -1, "ui/assets/weapon_luger.tga", "firing_pistolB_1", "stand_pistolB" },
{ WP_MP40, "MP 40", "mp_weapon", 0, "ui/assets/weapon_mp40.tga", "relaxed_idle_2h_1", "relaxed_idle_2h_1" },
{ WP_THOMPSON, "Thompson", "mp_weapon", 1, "ui/assets/weapon_thompson.tga", "relaxed_idle_2h_1", "relaxed_idle_2h_1" },
{ WP_STEN, "Sten", "mp_weapon", 2, "ui/assets/weapon_sten.tga", "relaxed_idle_2h_1", "relaxed_idle_2h_1" },
{ WP_PANZERFAUST, "Panzerfaust", "mp_weapon", 4, "ui/assets/weapon_panzerfaust.tga", "stand_panzer", "stand_panzer" },
{ WP_FLAMETHROWER, "Flamethrower", "mp_weapon", 6, "ui/assets/weapon_flamethrower.tga", "stand_machinegun", "stand_machinegun" },
{ WP_GRENADE_PINEAPPLE, "Pineapple grenade", "mp_weapon_2", 8, "ui/assets/weapon_grenade.tga", "firing_pistolB_1", "stand_pistolB" },
{ WP_GRENADE_LAUNCHER, "Stick grenade", "mp_weapon_2", 8, "ui/assets/weapon_grenade_ger.tga", "firing_pistolB_1", "stand_pistolB" },
{ WP_DYNAMITE, "Explosives", "mp_item2", -1, "ui/assets/weapon_dynamite.tga", "firing_pistolB_1", "stand_pistolB" },
{ WP_KAR98, "Kar98", "mp_weapon", 2, "ui/assets/weapon_kar98.tga", "stand_rifle", "stand_rifle" },
{ WP_CARBINE, "M1 Garand", "mp_weapon", 2, "ui/assets/weapon_carbine.tga", "stand_rifle", "stand_rifle" },
{ WP_FG42, "FG42", "mp_weapon", 7, "ui/assets/weapon_fg42.tga", "stand_rifle", "stand_rifle" },
{ WP_GARAND, "M1 Garand", "mp_weapon", 8, "ui/assets/weapon_carbine.tga", "stand_rifle", "stand_rifle" },
{ WP_MOBILE_MG42, "Mobile MG42", "mp_weapon", 9, "ui/assets/weapon_mg42.tga", "stand_rifle", "stand_rifle" },
{ WP_LANDMINE, "Land Mines", "mp_weapon_2", 4, "ui/assets/weapon_landmine.tga", "firing_pistolB_1", "stand_pistolB" },
{ WP_K43, "K43", "mp_weapon", 8, "ui/assets/weapon_kar98.tga", "stand_rifle", "stand_rifle" },
// { WP_SATCHEL, "Satchel Charges", "mp_weapon", 10, "ui/assets/weapon_satchel.tga", "firing_pistolB_1", "stand_pistolB" },
{ WP_TRIPMINE, "Trip Mines", "mp_weapon", 9, "ui/assets/weapon_tripmine.tga", "firing_pistolB_1", "stand_pistolB" },
{ 0, NULL, NULL, -1, NULL, NULL },
};*/
typedef struct
{
char *name;
int flags;
char *shader;
} uiitemType_t;
#define UI_KNIFE_PIC "window_knife_pic"
#define UI_PISTOL_PIC "window_pistol_pic"
#define UI_WEAPON_PIC "window_weapon_pic"
#define UI_ITEM1_PIC "window_item1_pic"
#define UI_ITEM2_PIC "window_item2_pic"
#if 0 // rain - not used
static uiitemType_t itemTypes[] =
{
{ UI_KNIFE_PIC, PT_KNIFE, "ui/assets/weapon_knife.tga" },
{ UI_PISTOL_PIC, PT_PISTOL, "ui/assets/weapon_colt1911.tga" },
{ UI_WEAPON_PIC, PT_RIFLE, "ui/assets/weapon_mauser.tga" },
{ UI_ITEM1_PIC, PT_MEDKIT, "ui/assets/item_medkit.tga" },
{ UI_ITEM1_PIC, PT_GRENADES, "ui/assets/weapon_grenade.tga" },
{ UI_ITEM2_PIC, PT_EXPLOSIVES, "ui/assets/weapon_dynamite.tga" },
{ NULL, 0, NULL }
};
#endif
extern displayContextDef_t *DC;
/*
================
vmMain
This is the only way control passes into the module.
This must be the very first function compiled into the .qvm file
================
*/
vmCvar_t ui_new;
vmCvar_t ui_debug;
vmCvar_t ui_initialized;
vmCvar_t ui_teamArenaFirstRun;
extern itemDef_t *g_bindItem;
void _UI_Init(qboolean);
void _UI_Shutdown(void);
void _UI_KeyEvent(int key, qboolean down);
void _UI_MouseEvent(int dx, int dy);
void _UI_Refresh(int realtime);
qboolean _UI_IsFullscreen(void);
Q_EXPORT intptr_t vmMain(intptr_t command, intptr_t arg0, intptr_t arg1, intptr_t arg2, intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6, intptr_t arg7, intptr_t arg8, intptr_t arg9, intptr_t arg10, intptr_t arg11)
{
switch (command)
{
case UI_GETAPIVERSION:
return UI_API_VERSION;
case UI_INIT:
_UI_Init(arg0);
return 0;
case UI_SHUTDOWN:
_UI_Shutdown();
return 0;
case UI_KEY_EVENT:
_UI_KeyEvent(arg0, arg1);
return 0;
case UI_MOUSE_EVENT:
_UI_MouseEvent(arg0, arg1);
return 0;
case UI_REFRESH:
_UI_Refresh(arg0);
return 0;
case UI_IS_FULLSCREEN:
return _UI_IsFullscreen();
case UI_SET_ACTIVE_MENU:
_UI_SetActiveMenu(arg0);
return 0;
case UI_GET_ACTIVE_MENU:
return _UI_GetActiveMenu();
case UI_CONSOLE_COMMAND:
return UI_ConsoleCommand(arg0);
case UI_DRAW_CONNECT_SCREEN:
UI_DrawConnectScreen(arg0);
return 0;
// NERVE - SMF
case UI_CHECKEXECKEY:
return UI_CheckExecKey(arg0);
case UI_WANTSBINDKEYS:
return (g_waitingForKey && g_bindItem) ? qtrue : qfalse;
}
return -1;
}
void AssetCache(void)
{
int n;
//if (Assets.textFont == NULL) {
//}
//Assets.background = trap_R_RegisterShaderNoMip( ASSET_BACKGROUND );
//Com_Printf("Menu Size: %i bytes\n", sizeof(Menus));
uiInfo.uiDC.Assets.gradientBar = trap_R_RegisterShaderNoMip(ASSET_GRADIENTBAR);
uiInfo.uiDC.Assets.fxBasePic = trap_R_RegisterShaderNoMip(ART_FX_BASE);
uiInfo.uiDC.Assets.fxPic[0] = trap_R_RegisterShaderNoMip(ART_FX_RED);
uiInfo.uiDC.Assets.fxPic[1] = trap_R_RegisterShaderNoMip(ART_FX_YELLOW);
uiInfo.uiDC.Assets.fxPic[2] = trap_R_RegisterShaderNoMip(ART_FX_GREEN);
uiInfo.uiDC.Assets.fxPic[3] = trap_R_RegisterShaderNoMip(ART_FX_TEAL);
uiInfo.uiDC.Assets.fxPic[4] = trap_R_RegisterShaderNoMip(ART_FX_BLUE);
uiInfo.uiDC.Assets.fxPic[5] = trap_R_RegisterShaderNoMip(ART_FX_CYAN);
uiInfo.uiDC.Assets.fxPic[6] = trap_R_RegisterShaderNoMip(ART_FX_WHITE);
uiInfo.uiDC.Assets.scrollBar = trap_R_RegisterShaderNoMip(ASSET_SCROLLBAR);
uiInfo.uiDC.Assets.scrollBarArrowDown = trap_R_RegisterShaderNoMip(ASSET_SCROLLBAR_ARROWDOWN);
uiInfo.uiDC.Assets.scrollBarArrowUp = trap_R_RegisterShaderNoMip(ASSET_SCROLLBAR_ARROWUP);
uiInfo.uiDC.Assets.scrollBarArrowLeft = trap_R_RegisterShaderNoMip(ASSET_SCROLLBAR_ARROWLEFT);
uiInfo.uiDC.Assets.scrollBarArrowRight = trap_R_RegisterShaderNoMip(ASSET_SCROLLBAR_ARROWRIGHT);
uiInfo.uiDC.Assets.scrollBarThumb = trap_R_RegisterShaderNoMip(ASSET_SCROLL_THUMB);
uiInfo.uiDC.Assets.sliderBar = trap_R_RegisterShaderNoMip(ASSET_SLIDER_BAR);
uiInfo.uiDC.Assets.sliderThumb = trap_R_RegisterShaderNoMip(ASSET_SLIDER_THUMB);
uiInfo.uiDC.Assets.checkboxCheck = trap_R_RegisterShaderNoMip(ASSET_CHECKBOX_CHECK);
uiInfo.uiDC.Assets.checkboxCheckNot = trap_R_RegisterShaderNoMip(ASSET_CHECKBOX_CHECK_NOT);
uiInfo.uiDC.Assets.checkboxCheckNo = trap_R_RegisterShaderNoMip(ASSET_CHECKBOX_CHECK_NO);
for (n = 0; n < NUM_CROSSHAIRS; n++)
{
uiInfo.uiDC.Assets.crosshairShader[n] = trap_R_RegisterShaderNoMip(va("gfx/2d/crosshair%c", 'a' + n));
uiInfo.uiDC.Assets.crosshairAltShader[n] = trap_R_RegisterShaderNoMip(va("gfx/2d/crosshair%c_alt", 'a' + n));
}
//uiInfo.newHighScoreSound = trap_S_RegisterSound("sound/feedback/voc_newhighscore.wav");
/* for ( n = 1; weaponTypes[n].shadername; n++ ) {
if ( weaponTypes[n].shadername )
trap_R_RegisterShaderNoMip( weaponTypes[n].shadername );
}*/
// -NERVE - SMF
}
void _UI_DrawSides(float x, float y, float w, float h, float size)
{
UI_AdjustFrom640(&x, &y, &w, &h);
size *= uiInfo.uiDC.xscale;
trap_R_DrawStretchPic(x, y, size, h, 0, 0, 0, 0, uiInfo.uiDC.whiteShader);
trap_R_DrawStretchPic(x + w - size, y, size, h, 0, 0, 0, 0, uiInfo.uiDC.whiteShader);
}
void _UI_DrawTopBottom(float x, float y, float w, float h, float size)
{
UI_AdjustFrom640(&x, &y, &w, &h);
size *= uiInfo.uiDC.yscale;
trap_R_DrawStretchPic(x, y, w, size, 0, 0, 0, 0, uiInfo.uiDC.whiteShader);
trap_R_DrawStretchPic(x, y + h - size, w, size, 0, 0, 0, 0, uiInfo.uiDC.whiteShader);
}
/*
================
UI_DrawRect
Coordinates are 640*480 virtual values
=================
*/
void _UI_DrawRect(float x, float y, float width, float height, float size, const float *color)
{
trap_R_SetColor(color);
_UI_DrawTopBottom(x, y, width, height, size);
_UI_DrawSides(x, y, width, height, size);
trap_R_SetColor(NULL);
}
// NERVE - SMF
void Text_SetActiveFont(int font)
{
uiInfo.activeFont = font;
}
int Text_Width_Ext(const char *text, float scale, int limit, fontInfo_t *font)
{
int count, len;
float out = 0;
glyphInfo_t *glyph;
const char *s = text;
if (text)
{
len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
count = 0;
while (s && *s && count < len)
{
if (Q_IsColorString(s))
{
s += 2;
continue;
}
else
{
glyph = &font->glyphs[(unsigned char)*s];
out += glyph->xSkip;
s++;
count++;
}
}
}
return out * scale * font->glyphScale;
}
int Text_Width(const char *text, float scale, int limit)
{
fontInfo_t *font = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont];
return Text_Width_Ext(text, scale, limit, font);
}
int Multiline_Text_Width(const char *text, float scale, int limit)
{
int count, len;
float out = 0;
float width, widest = 0;
glyphInfo_t *glyph;
const char *s = text;
fontInfo_t *font = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont];
if (text)
{
len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
count = 0;
while (s && *s && count < len)
{
if (Q_IsColorString(s))
{
s += 2;
continue;
}
else
{
if (*s == '\n')
{
width = out * scale * font->glyphScale;
if (width > widest)
{
widest = width;
}
out = 0;
}
else
{
glyph = &font->glyphs[(unsigned char)*s];
out += glyph->xSkip;
}
s++;
count++;
}
}
}
if (widest > 0)
{
width = out * scale * font->glyphScale;
if (width > widest)
{
widest = width;
}
return widest;
}
else
{
return out * scale * font->glyphScale;
}
}
int Text_Height_Ext(const char *text, float scale, int limit, fontInfo_t *font)
{
int len, count;
float max;
glyphInfo_t *glyph;
const char *s = text;
max = 0;
if (text)
{
len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
count = 0;
while (s && *s && count < len)
{
if (Q_IsColorString(s))
{
s += 2;
continue;
}
else
{
glyph = &font->glyphs[(unsigned char)*s]; // NERVE - SMF - this needs to be an unsigned cast for localization
if (max < glyph->height)
{
max = glyph->height;
}
s++;
count++;
}
}
}
return max * scale * font->glyphScale;
}
int Text_Height(const char *text, float scale, int limit)
{
fontInfo_t *font = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont];
return Text_Height_Ext(text, scale, limit, font);
}
int Multiline_Text_Height(const char *text, float scale, int limit)
{
int len, count;
float max;
float totalheight = 0;
glyphInfo_t *glyph;
const char *s = text;
fontInfo_t *font = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont];
max = 0;
if (text)
{
len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
count = 0;
while (s && *s && count < len)
{
if (Q_IsColorString(s))
{
s += 2;
continue;
}
else
{
if (*s == '\n')
{
if (!totalheight)
{
totalheight += 5; // 5 is the vertical spacing that autowrap painting uses
}
totalheight += max;
max = 0;
}
else
{
glyph = &font->glyphs[(unsigned char)*s]; // NERVE - SMF - this needs to be an unsigned cast for localization
if (max < glyph->height)
{
max = glyph->height;
}
}
s++;
count++;
}
}
}
if (totalheight > 0)
{
if (!totalheight)
{
totalheight += 5; // 5 is the vertical spacing that autowrap painting uses
}
totalheight += max;
return totalheight * scale * font->glyphScale;
}
else
{
return max * scale * font->glyphScale;
}
}
void Text_PaintCharExt(float x, float y, float w, float h, float scalex, float scaley, float s, float t, float s2, float t2, qhandle_t hShader)
{
w *= scalex;
h *= scaley;
UI_AdjustFrom640(&x, &y, &w, &h);
trap_R_DrawStretchPic(x, y, w, h, s, t, s2, t2, hShader);
}
void Text_PaintChar(float x, float y, float w, float h, float scale, float s, float t, float s2, float t2, qhandle_t hShader)
{
w *= scale;
h *= scale;
UI_AdjustFrom640(&x, &y, &w, &h);
trap_R_DrawStretchPic(x, y, w, h, s, t, s2, t2, hShader);
}
void Text_Paint_Ext(float x, float y, float scalex, float scaley, vec4_t color, const char *text, float adjust, int limit, int style, fontInfo_t *font)
{
int len, count;
vec4_t newColor;
glyphInfo_t *glyph;
int index;
scalex *= font->glyphScale;
scaley *= font->glyphScale;
if (text)
{
const char *s = text;
trap_R_SetColor(color);
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
count = 0;
while (s && *s && count < len)
{
index = (unsigned char)*s;
// NERVE - SMF - don't draw tabs and newlines
if (index < 20)
{
s++;
count++;
continue;
}
glyph = &font->glyphs[index];
if (Q_IsColorString(s))
{
if (*(s + 1) == COLOR_NULL)
{
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
}
else
{
memcpy(newColor, g_color_table[ColorIndex(*(s + 1))], sizeof(newColor));
newColor[3] = color[3];
}
trap_R_SetColor(newColor);
s += 2;
continue;
}
else
{
float yadj = scaley * glyph->top;
if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE)
{
int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2;
colorBlack[3] = newColor[3];
trap_R_SetColor(colorBlack);
Text_PaintCharExt(x + (glyph->pitch * scalex) + ofs, y - yadj + ofs, glyph->imageWidth, glyph->imageHeight, scalex, scaley, glyph->s, glyph->t, glyph->s2, glyph->t2, glyph->glyph);
trap_R_SetColor(newColor);
colorBlack[3] = 1.0;
}
Text_PaintCharExt(x + (glyph->pitch * scalex), y - yadj, glyph->imageWidth, glyph->imageHeight, scalex, scaley, glyph->s, glyph->t, glyph->s2, glyph->t2, glyph->glyph);
x += (glyph->xSkip * scalex) + adjust;
s++;
count++;
}
}
trap_R_SetColor(NULL);
}
}
void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style)
{
fontInfo_t *font = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont];
Text_Paint_Ext(x, y, scale, scale, color, text, adjust, limit, style, font);
}
// copied over from Text_Paint
// we use the bulk of Text_Paint to determine were we will hit the max width
// can be used for actual text printing, or dummy run to get the number of lines
// returns the next char to be printed after wrap, or the ending \0 of the string
// NOTE: this is clearly non-optimal implementation, see Item_Text_AutoWrap_Paint for one
// if color_save != NULL, use to keep track of the current color between wraps
char *Text_AutoWrap_Paint_Chunk(float x, float y, int width, float scale, vec4_t color, char *text, float adjust, int limit, int style, qboolean dummy, vec4_t color_save)
{
int len, count;
vec4_t newColor;
glyphInfo_t *glyph;
float useScale;
fontInfo_t *font = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont];
int index;
char *wrap_point = NULL;
float wrap_x = x + width;
useScale = scale * font->glyphScale;
if (text)
{
char *s = text;
trap_R_SetColor(color);
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
count = 0;
while (s && *s && count < len)
{
index = (unsigned char)*s;
if (*s == ' ' || *s == '\t' || *s == '\n')
{
wrap_point = s;
}
// NERVE - SMF - don't draw tabs and newlines
if (index < 20)
{
s++;
count++;
continue;
}
glyph = &font->glyphs[index]; // NERVE - SMF - this needs to be an unsigned cast for localization
if (Q_IsColorString(s))
{
if (*(s + 1) == COLOR_NULL)
{
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
}
else
{
memcpy(newColor, g_color_table[ColorIndex(*(s + 1))], sizeof(newColor));
newColor[3] = color[3];
}
if (!dummy)
{
trap_R_SetColor(newColor);
}
if (color_save)
{
memcpy(&color_save[0], &newColor[0], sizeof(vec4_t));
}
s += 2;
continue;
}
else
{
float yadj = useScale * glyph->top;
if (x + (glyph->xSkip * useScale) + adjust > wrap_x)
{
if (wrap_point)
{
return wrap_point + 1; // the next char to be printed after line wrap
}
// we haven't found the wrap point .. cut
return s;
}
if (!dummy)
{
if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE)
{
int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2;
colorBlack[3] = newColor[3];
trap_R_SetColor(colorBlack);
Text_PaintChar(x + ofs, y - yadj + ofs,
glyph->imageWidth,
glyph->imageHeight,
useScale,
glyph->s,
glyph->t,
glyph->s2,
glyph->t2,
glyph->glyph);
trap_R_SetColor(newColor);
colorBlack[3] = 1.0;
}
Text_PaintChar(x, y - yadj,
glyph->imageWidth,
glyph->imageHeight,
useScale,
glyph->s,
glyph->t,
glyph->s2,
glyph->t2,
glyph->glyph);
}
x += (glyph->xSkip * useScale) + adjust;
s++;
count++;
}
}
if (!dummy)
{
trap_R_SetColor(NULL);
}
}
return text + strlen(text);
}
// count the lines that we will need to have to print with the given wrap parameters
int Count_Text_AutoWrap_Paint(float x, float y, int width, float scale, vec4_t color, const char *text, float adjust, int style)
{
const char *ret, *end;
int i = 0;
ret = text;
end = text + strlen(text);
do
{
ret = Text_AutoWrap_Paint_Chunk(x, y, width, scale, color, (char *)ret, adjust, 0, style, qtrue, NULL);
i++;
}
while (ret < end);
return i;
}
void Text_AutoWrap_Paint(float x, float y, int width, int height, float scale, vec4_t color, const char *l_text, float adjust, int style)
{
char text[1024];
char *ret, *end, *next;
char s;
vec4_t aux_color, next_color;
Q_strncpyz(text, l_text, sizeof(text) - 1);
ret = text;
end = text + strlen(text);
memcpy(&aux_color[0], &color[0], sizeof(vec4_t));
do
{
// one run to get the word wrap
next = Text_AutoWrap_Paint_Chunk(x, y, width, scale, aux_color, ret, adjust, 0, style, qtrue, next_color);
// now print - hack around a bit to avoid the word wrapped chars
s = *next;
*next = '\0';
Text_Paint(x, y, scale, aux_color, ret, adjust, 0, style);
*next = s;
ret = next;
memcpy(&aux_color[0], &next_color[0], sizeof(vec4_t));
y += height;
}
while (ret < end);
}
void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style)
{
int len, count;
vec4_t newColor;
glyphInfo_t *glyph, *glyph2;
float yadj;
float useScale;
fontInfo_t *font = &uiInfo.uiDC.Assets.fonts[uiInfo.activeFont];
useScale = scale * font->glyphScale;
if (text)
{
const char *s = text;
trap_R_SetColor(color);
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
len = strlen(text);
if (limit > 0 && len > limit)
{
len = limit;
}
count = 0;
glyph2 = &font->glyphs[(unsigned char)cursor];
while (s && *s && count < len)
{
glyph = &font->glyphs[(unsigned char)*s]; // NERVE - SMF - this needs to be an unsigned cast for localization
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
/*if ( Q_IsColorString( s ) ) {
memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
newColor[3] = color[3];
trap_R_SetColor( newColor );
s += 2;
continue;
} else*/{
yadj = useScale * glyph->top;
if (style == ITEM_TEXTSTYLE_SHADOWED || style == ITEM_TEXTSTYLE_SHADOWEDMORE)
{
int ofs = style == ITEM_TEXTSTYLE_SHADOWED ? 1 : 2;
colorBlack[3] = newColor[3];
trap_R_SetColor(colorBlack);
Text_PaintChar(x + (glyph->pitch * useScale) + ofs, y - yadj + ofs,
glyph->imageWidth,
glyph->imageHeight,
useScale,
glyph->s,
glyph->t,
glyph->s2,
glyph->t2,
glyph->glyph);
colorBlack[3] = 1.0;
trap_R_SetColor(newColor);
}
Text_PaintChar(x + (glyph->pitch * useScale), y - yadj,
glyph->imageWidth,
glyph->imageHeight,
useScale,
glyph->s,
glyph->t,
glyph->s2,
glyph->t2,
glyph->glyph);
// CG_DrawPic(x, y - yadj, scale * uiDC.Assets.textFont.glyphs[text[i]].imageWidth, scale * uiDC.Assets.textFont.glyphs[text[i]].imageHeight, uiDC.Assets.textFont.glyphs[text[i]].glyph);
yadj = useScale * glyph2->top;
if (count == cursorPos && !((uiInfo.uiDC.realTime / BLINK_DIVISOR) & 1))
{
Text_PaintChar(x + (glyph->pitch * useScale), y - yadj,
glyph2->imageWidth,
glyph2->imageHeight,
useScale,
glyph2->s,
glyph2->t,
glyph2->s2,
glyph2->t2,
glyph2->glyph);
}
x += (glyph->xSkip * useScale);
s++;
count++;
}
}
// need to paint cursor at end of text
if (cursorPos == len && !((uiInfo.uiDC.realTime / BLINK_DIVISOR) & 1))
{
yadj = useScale * glyph2->top;
Text_PaintChar(x + (glyph2->pitch * useScale), y - yadj,
glyph2->imageWidth,
glyph2->imageHeight,
useScale,
glyph2->s,
glyph2->t,
glyph2->s2,
glyph2->t2,
glyph2->glyph);
}
trap_R_SetColor(NULL);
}
}
static void Text_Paint_Limit(float *maxX, float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit)
{
int len, count;
vec4_t newColor;