forked from id-Software/Quake-III-Arena
-
-
Notifications
You must be signed in to change notification settings - Fork 536
/
Copy pathui_shared.c
6070 lines (5254 loc) · 153 KB
/
ui_shared.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
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code 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 2 of the License,
or (at your option) any later version.
Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
//
// string allocation/management
#include "ui_shared.h"
#define SCROLL_TIME_START 500
#define SCROLL_TIME_ADJUST 150
#define SCROLL_TIME_ADJUSTOFFSET 40
#define SCROLL_TIME_FLOOR 20
typedef struct scrollInfo_s {
int nextScrollTime;
int nextAdjustTime;
int adjustValue;
int scrollKey;
float xStart;
float yStart;
itemDef_t *item;
qboolean scrollDir;
} scrollInfo_t;
static scrollInfo_t scrollInfo;
static void (*captureFunc) (void *p) = 0;
static void *captureData = NULL;
static itemDef_t *itemCapture = NULL; // item that has the mouse captured ( if any )
displayContextDef_t *DC = NULL;
static qboolean g_waitingForKey = qfalse;
static qboolean g_editingField = qfalse;
static itemDef_t *g_bindItem = NULL;
static itemDef_t *g_editItem = NULL;
menuDef_t Menus[MAX_MENUS]; // defined menus
int menuCount = 0; // how many
menuDef_t *menuStack[MAX_OPEN_MENUS];
int openMenuCount = 0;
static qboolean debugMode = qfalse;
#define DOUBLE_CLICK_DELAY 300
static int lastListBoxClickTime = 0;
void Item_RunScript(itemDef_t *item, const char *s);
void Item_SetupKeywordHash(void);
void Menu_SetupKeywordHash(void);
int BindingIDFromName(const char *name);
qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down);
itemDef_t *Menu_SetPrevCursorItem(menuDef_t *menu);
itemDef_t *Menu_SetNextCursorItem(menuDef_t *menu);
static qboolean Menu_OverActiveItem(menuDef_t *menu, float x, float y);
#ifdef CGAME
#define MEM_POOL_SIZE 128 * 1024
#else
#define MEM_POOL_SIZE 1024 * 1024
#endif
static char memoryPool[MEM_POOL_SIZE];
static int allocPoint, outOfMemory;
/*
===============
UI_Alloc
===============
*/
void *UI_Alloc( int size ) {
char *p;
if ( allocPoint + size > MEM_POOL_SIZE ) {
outOfMemory = qtrue;
if (DC->Print) {
DC->Print("UI_Alloc: Failure. Out of memory!\n");
}
//DC->trap_Print(S_COLOR_YELLOW"WARNING: UI Out of Memory!\n");
return NULL;
}
p = &memoryPool[allocPoint];
allocPoint += ( size + 15 ) & ~15;
return p;
}
/*
===============
UI_InitMemory
===============
*/
void UI_InitMemory( void ) {
allocPoint = 0;
outOfMemory = qfalse;
}
qboolean UI_OutOfMemory( void ) {
return outOfMemory;
}
#define HASH_TABLE_SIZE 2048
/*
================
return a hash value for the string
================
*/
static unsigned hashForString(const char *str) {
int i;
unsigned hash;
char letter;
hash = 0;
i = 0;
while (str[i] != '\0') {
letter = tolower(str[i]);
hash+=(unsigned)(letter)*(i+119);
i++;
}
hash &= (HASH_TABLE_SIZE-1);
return hash;
}
typedef struct stringDef_s {
struct stringDef_s *next;
const char *str;
} stringDef_t;
static int strPoolIndex = 0;
static char strPool[STRING_POOL_SIZE];
static int strHandleCount = 0;
static stringDef_t *strHandle[HASH_TABLE_SIZE];
const char *String_Alloc(const char *p) {
int len;
unsigned hash;
stringDef_t *str, *last;
static const char *staticNULL = "";
if (p == NULL) {
return NULL;
}
if (*p == 0) {
return staticNULL;
}
hash = hashForString(p);
str = strHandle[hash];
while (str) {
if (strcmp(p, str->str) == 0) {
return str->str;
}
str = str->next;
}
len = strlen(p);
if (len + strPoolIndex + 1 < STRING_POOL_SIZE) {
int ph = strPoolIndex;
strcpy(&strPool[strPoolIndex], p);
strPoolIndex += len + 1;
str = strHandle[hash];
last = str;
while (str && str->next) {
last = str;
str = str->next;
}
str = UI_Alloc(sizeof(stringDef_t));
if (!str) {
return NULL;
}
str->next = NULL;
str->str = &strPool[ph];
if (last) {
last->next = str;
} else {
strHandle[hash] = str;
}
return &strPool[ph];
}
return NULL;
}
void String_Report(void) {
float f;
Com_Printf("Memory/String Pool Info\n");
Com_Printf("----------------\n");
f = strPoolIndex;
f /= STRING_POOL_SIZE;
f *= 100;
Com_Printf("String Pool is %.1f%% full, %i bytes out of %i used.\n", f, strPoolIndex, STRING_POOL_SIZE);
f = allocPoint;
f /= MEM_POOL_SIZE;
f *= 100;
Com_Printf("Memory Pool is %.1f%% full, %i bytes out of %i used.\n", f, allocPoint, MEM_POOL_SIZE);
}
/*
=================
String_Init
=================
*/
void String_Init(void) {
int i;
for (i = 0; i < HASH_TABLE_SIZE; i++) {
strHandle[i] = NULL;
}
strHandleCount = 0;
strPoolIndex = 0;
menuCount = 0;
openMenuCount = 0;
UI_InitMemory();
Item_SetupKeywordHash();
Menu_SetupKeywordHash();
if (DC && DC->getBindingBuf) {
Controls_GetConfig();
}
}
#if 0
/*
=================
PC_SourceWarning
=================
*/
static __attribute__ ((format (printf, 2, 3))) void PC_SourceWarning(int handle, char *format, ...) {
int line;
char filename[128];
va_list argptr;
static char string[4096];
va_start (argptr, format);
Q_vsnprintf (string, sizeof(string), format, argptr);
va_end (argptr);
filename[0] = '\0';
line = 0;
trap_PC_SourceFileAndLine(handle, filename, &line);
Com_Printf(S_COLOR_YELLOW "WARNING: %s, line %d: %s\n", filename, line, string);
}
#endif
/*
=================
PC_SourceError
=================
*/
static __attribute__ ((format (printf, 2, 3))) void PC_SourceError(int handle, char *format, ...) {
int line;
char filename[128];
va_list argptr;
static char string[4096];
va_start (argptr, format);
Q_vsnprintf (string, sizeof(string), format, argptr);
va_end (argptr);
filename[0] = '\0';
line = 0;
trap_PC_SourceFileAndLine(handle, filename, &line);
Com_Printf(S_COLOR_RED "ERROR: %s, line %d: %s\n", filename, line, string);
}
/*
=================
LerpColor
=================
*/
void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t)
{
int i;
// lerp and clamp each component
for (i=0; i<4; i++)
{
c[i] = a[i] + t*(b[i]-a[i]);
if (c[i] < 0)
c[i] = 0;
else if (c[i] > 1.0)
c[i] = 1.0;
}
}
/*
=================
Float_Parse
=================
*/
qboolean Float_Parse(char **p, float *f) {
char *token;
token = COM_ParseExt(p, qfalse);
if (token && token[0] != 0) {
*f = atof(token);
return qtrue;
} else {
return qfalse;
}
}
/*
=================
PC_Float_Parse
=================
*/
qboolean PC_Float_Parse(int handle, float *f) {
pc_token_t token;
int negative = qfalse;
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
if (token.string[0] == '-') {
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
negative = qtrue;
}
if (token.type != TT_NUMBER) {
PC_SourceError(handle, "expected float but found %s", token.string);
return qfalse;
}
if (negative)
*f = -token.floatvalue;
else
*f = token.floatvalue;
return qtrue;
}
/*
=================
Color_Parse
=================
*/
qboolean Color_Parse(char **p, vec4_t *c) {
int i;
float f;
for (i = 0; i < 4; i++) {
if (!Float_Parse(p, &f)) {
return qfalse;
}
(*c)[i] = f;
}
return qtrue;
}
/*
=================
PC_Color_Parse
=================
*/
qboolean PC_Color_Parse(int handle, vec4_t *c) {
int i;
float f;
for (i = 0; i < 4; i++) {
if (!PC_Float_Parse(handle, &f)) {
return qfalse;
}
(*c)[i] = f;
}
return qtrue;
}
/*
=================
Int_Parse
=================
*/
qboolean Int_Parse(char **p, int *i) {
char *token;
token = COM_ParseExt(p, qfalse);
if (token && token[0] != 0) {
*i = atoi(token);
return qtrue;
} else {
return qfalse;
}
}
/*
=================
PC_Int_Parse
=================
*/
qboolean PC_Int_Parse(int handle, int *i) {
pc_token_t token;
int negative = qfalse;
if (!i)
return qfalse;
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
if (token.string[0] == '-') {
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
negative = qtrue;
}
if (token.type != TT_NUMBER) {
PC_SourceError(handle, "expected integer but found %s", token.string);
return qfalse;
}
*i = token.intvalue;
if (negative)
*i = - *i;
return qtrue;
}
/*
=================
Rect_Parse
=================
*/
qboolean Rect_Parse(char **p, rectDef_t *r) {
if (Float_Parse(p, &r->x)) {
if (Float_Parse(p, &r->y)) {
if (Float_Parse(p, &r->w)) {
if (Float_Parse(p, &r->h)) {
return qtrue;
}
}
}
}
return qfalse;
}
/*
=================
PC_Rect_Parse
=================
*/
qboolean PC_Rect_Parse(int handle, rectDef_t *r) {
if (PC_Float_Parse(handle, &r->x)) {
if (PC_Float_Parse(handle, &r->y)) {
if (PC_Float_Parse(handle, &r->w)) {
if (PC_Float_Parse(handle, &r->h)) {
return qtrue;
}
}
}
}
return qfalse;
}
/*
=================
String_Parse
=================
*/
qboolean String_Parse(char **p, const char **out) {
char *token;
token = COM_ParseExt(p, qfalse);
if (token && token[0] != 0) {
*(out) = String_Alloc(token);
return qtrue;
}
return qfalse;
}
/*
=================
PC_String_Parse
=================
*/
qboolean PC_String_Parse(int handle, const char **out) {
pc_token_t token;
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
*(out) = String_Alloc(token.string);
return qtrue;
}
/*
=================
PC_Script_Parse
=================
*/
qboolean PC_Script_Parse(int handle, const char **out) {
char script[1024];
pc_token_t token;
memset(script, 0, sizeof(script));
// scripts start with { and have ; separated command lists.. commands are command, arg..
// basically we want everything between the { } as it will be interpreted at run time
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
if (Q_stricmp(token.string, "{") != 0) {
return qfalse;
}
while ( 1 ) {
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
if (Q_stricmp(token.string, "}") == 0) {
*out = String_Alloc(script);
return qtrue;
}
if (token.string[1] != '\0') {
Q_strcat(script, 1024, va("\"%s\"", token.string));
} else {
Q_strcat(script, 1024, token.string);
}
Q_strcat(script, 1024, " ");
}
return qfalse;
}
// display, window, menu, item code
//
/*
==================
Init_Display
Initializes the display with a structure to all the drawing routines
==================
*/
void Init_Display(displayContextDef_t *dc) {
DC = dc;
}
// type and style painting
void GradientBar_Paint(rectDef_t *rect, vec4_t color) {
// gradient bar takes two paints
DC->setColor( color );
DC->drawHandlePic(rect->x, rect->y, rect->w, rect->h, DC->Assets.gradientBar);
DC->setColor( NULL );
}
/*
==================
Window_Init
Initializes a window structure ( windowDef_t ) with defaults
==================
*/
void Window_Init(Window *w) {
memset(w, 0, sizeof(windowDef_t));
w->borderSize = 1;
w->foreColor[0] = w->foreColor[1] = w->foreColor[2] = w->foreColor[3] = 1.0;
w->cinematic = -1;
}
void Fade(int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboolean bFlags, float fadeAmount) {
if (*flags & (WINDOW_FADINGOUT | WINDOW_FADINGIN)) {
if (DC->realTime > *nextTime) {
*nextTime = DC->realTime + offsetTime;
if (*flags & WINDOW_FADINGOUT) {
*f -= fadeAmount;
if (bFlags && *f <= 0.0) {
*flags &= ~(WINDOW_FADINGOUT | WINDOW_VISIBLE);
}
} else {
*f += fadeAmount;
if (*f >= clamp) {
*f = clamp;
if (bFlags) {
*flags &= ~WINDOW_FADINGIN;
}
}
}
}
}
}
void Window_Paint(Window *w, float fadeAmount, float fadeClamp, float fadeCycle) {
//float bordersize = 0;
vec4_t color = {0};
rectDef_t fillRect;
if ( w == NULL ) {
return;
}
if (debugMode) {
color[0] = color[1] = color[2] = color[3] = 1;
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, 1, color);
}
if (w->style == 0 && w->border == 0) {
return;
}
fillRect = w->rect;
if (w->border != 0) {
fillRect.x += w->borderSize;
fillRect.y += w->borderSize;
fillRect.w -= w->borderSize + 1;
fillRect.h -= w->borderSize + 1;
}
if (w->style == WINDOW_STYLE_FILLED) {
// box, but possible a shader that needs filled
if (w->background) {
Fade(&w->flags, &w->backColor[3], fadeClamp, &w->nextTime, fadeCycle, qtrue, fadeAmount);
DC->setColor(w->backColor);
DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background);
DC->setColor(NULL);
} else {
DC->fillRect(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->backColor);
}
} else if (w->style == WINDOW_STYLE_GRADIENT) {
GradientBar_Paint(&fillRect, w->backColor);
// gradient bar
} else if (w->style == WINDOW_STYLE_SHADER) {
if (w->flags & WINDOW_FORECOLORSET) {
DC->setColor(w->foreColor);
}
DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background);
DC->setColor(NULL);
} else if (w->style == WINDOW_STYLE_TEAMCOLOR) {
if (DC->getTeamColor) {
DC->getTeamColor(&color);
DC->fillRect(fillRect.x, fillRect.y, fillRect.w, fillRect.h, color);
}
} else if (w->style == WINDOW_STYLE_CINEMATIC) {
if (w->cinematic == -1) {
w->cinematic = DC->playCinematic(w->cinematicName, fillRect.x, fillRect.y, fillRect.w, fillRect.h);
if (w->cinematic == -1) {
w->cinematic = -2;
}
}
if (w->cinematic >= 0) {
DC->runCinematicFrame(w->cinematic);
DC->drawCinematic(w->cinematic, fillRect.x, fillRect.y, fillRect.w, fillRect.h);
}
}
if (w->border == WINDOW_BORDER_FULL) {
// full
// HACK HACK HACK
if (w->style == WINDOW_STYLE_TEAMCOLOR) {
if (color[0] > 0) {
// red
color[0] = 1;
color[1] = color[2] = .5;
} else {
color[2] = 1;
color[0] = color[1] = .5;
}
color[3] = 1;
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, color);
} else {
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, w->borderColor);
}
} else if (w->border == WINDOW_BORDER_HORZ) {
// top/bottom
DC->setColor(w->borderColor);
DC->drawTopBottom(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize);
DC->setColor( NULL );
} else if (w->border == WINDOW_BORDER_VERT) {
// left right
DC->setColor(w->borderColor);
DC->drawSides(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize);
DC->setColor( NULL );
} else if (w->border == WINDOW_BORDER_KCGRADIENT) {
// this is just two gradient bars along each horz edge
rectDef_t r = w->rect;
r.h = w->borderSize;
GradientBar_Paint(&r, w->borderColor);
r.y = w->rect.y + w->rect.h - 1;
GradientBar_Paint(&r, w->borderColor);
}
}
void Item_SetScreenCoords(itemDef_t *item, float x, float y) {
if (item == NULL) {
return;
}
if (item->window.border != 0) {
x += item->window.borderSize;
y += item->window.borderSize;
}
item->window.rect.x = x + item->window.rectClient.x;
item->window.rect.y = y + item->window.rectClient.y;
item->window.rect.w = item->window.rectClient.w;
item->window.rect.h = item->window.rectClient.h;
// force the text rects to recompute
item->textRect.w = 0;
item->textRect.h = 0;
}
// FIXME: consolidate this with nearby stuff
void Item_UpdatePosition(itemDef_t *item) {
float x, y;
menuDef_t *menu;
if (item == NULL || item->parent == NULL) {
return;
}
menu = item->parent;
x = menu->window.rect.x;
y = menu->window.rect.y;
if (menu->window.border != 0) {
x += menu->window.borderSize;
y += menu->window.borderSize;
}
Item_SetScreenCoords(item, x, y);
}
// menus
void Menu_UpdatePosition(menuDef_t *menu) {
int i;
float x, y;
if (menu == NULL) {
return;
}
x = menu->window.rect.x;
y = menu->window.rect.y;
if (menu->window.border != 0) {
x += menu->window.borderSize;
y += menu->window.borderSize;
}
for (i = 0; i < menu->itemCount; i++) {
Item_SetScreenCoords(menu->items[i], x, y);
}
}
void Menu_PostParse(menuDef_t *menu) {
if (menu == NULL) {
return;
}
if (menu->fullScreen) {
menu->window.rect.x = 0;
menu->window.rect.y = 0;
menu->window.rect.w = 640;
menu->window.rect.h = 480;
}
Menu_UpdatePosition(menu);
}
itemDef_t *Menu_ClearFocus(menuDef_t *menu) {
int i;
itemDef_t *ret = NULL;
if (menu == NULL) {
return NULL;
}
for (i = 0; i < menu->itemCount; i++) {
if (menu->items[i]->window.flags & WINDOW_HASFOCUS) {
ret = menu->items[i];
}
menu->items[i]->window.flags &= ~WINDOW_HASFOCUS;
if (menu->items[i]->leaveFocus) {
Item_RunScript(menu->items[i], menu->items[i]->leaveFocus);
}
}
return ret;
}
qboolean IsVisible(int flags) {
return (flags & WINDOW_VISIBLE && !(flags & WINDOW_FADINGOUT));
}
qboolean Rect_ContainsPoint(rectDef_t *rect, float x, float y) {
if (rect) {
if (x > rect->x && x < rect->x + rect->w && y > rect->y && y < rect->y + rect->h) {
return qtrue;
}
}
return qfalse;
}
int Menu_ItemsMatchingGroup(menuDef_t *menu, const char *name) {
int i;
int count = 0;
for (i = 0; i < menu->itemCount; i++) {
if (Q_stricmp(menu->items[i]->window.name, name) == 0 || (menu->items[i]->window.group && Q_stricmp(menu->items[i]->window.group, name) == 0)) {
count++;
}
}
return count;
}
itemDef_t *Menu_GetMatchingItemByNumber(menuDef_t *menu, int index, const char *name) {
int i;
int count = 0;
for (i = 0; i < menu->itemCount; i++) {
if (Q_stricmp(menu->items[i]->window.name, name) == 0 || (menu->items[i]->window.group && Q_stricmp(menu->items[i]->window.group, name) == 0)) {
if (count == index) {
return menu->items[i];
}
count++;
}
}
return NULL;
}
void Script_SetColor(itemDef_t *item, char **args) {
const char *name;
int i;
float f;
vec4_t *out;
// expecting type of color to set and 4 args for the color
if (String_Parse(args, &name)) {
out = NULL;
if (Q_stricmp(name, "backcolor") == 0) {
out = &item->window.backColor;
item->window.flags |= WINDOW_BACKCOLORSET;
} else if (Q_stricmp(name, "forecolor") == 0) {
out = &item->window.foreColor;
item->window.flags |= WINDOW_FORECOLORSET;
} else if (Q_stricmp(name, "bordercolor") == 0) {
out = &item->window.borderColor;
}
if (out) {
for (i = 0; i < 4; i++) {
if (!Float_Parse(args, &f)) {
return;
}
(*out)[i] = f;
}
}
}
}
void Script_SetAsset(itemDef_t *item, char **args) {
const char *name;
// expecting name to set asset to
if (String_Parse(args, &name)) {
// check for a model
if (item->type == ITEM_TYPE_MODEL) {
}
}
}
void Script_SetBackground(itemDef_t *item, char **args) {
const char *name;
// expecting name to set asset to
if (String_Parse(args, &name)) {
item->window.background = DC->registerShaderNoMip(name);
}
}
itemDef_t *Menu_FindItemByName(menuDef_t *menu, const char *p) {
int i;
if (menu == NULL || p == NULL) {
return NULL;
}
for (i = 0; i < menu->itemCount; i++) {
if (Q_stricmp(p, menu->items[i]->window.name) == 0) {
return menu->items[i];
}
}
return NULL;
}
void Script_SetTeamColor(itemDef_t *item, char **args) {
if (DC->getTeamColor) {
int i;
vec4_t color;
DC->getTeamColor(&color);
for (i = 0; i < 4; i++) {
item->window.backColor[i] = color[i];
}
}
}
void Script_SetItemColor(itemDef_t *item, char **args) {
const char *itemname;
const char *name;
vec4_t color;
int i;
vec4_t *out;
// expecting type of color to set and 4 args for the color
if (String_Parse(args, &itemname) && String_Parse(args, &name)) {
itemDef_t *item2;
int j;
int count = Menu_ItemsMatchingGroup(item->parent, itemname);
if (!Color_Parse(args, &color)) {
return;
}
for (j = 0; j < count; j++) {
item2 = Menu_GetMatchingItemByNumber(item->parent, j, itemname);
if (item2 != NULL) {
out = NULL;
if (Q_stricmp(name, "backcolor") == 0) {
out = &item2->window.backColor;
} else if (Q_stricmp(name, "forecolor") == 0) {
out = &item2->window.foreColor;
item2->window.flags |= WINDOW_FORECOLORSET;
} else if (Q_stricmp(name, "bordercolor") == 0) {
out = &item2->window.borderColor;
}
if (out) {
for (i = 0; i < 4; i++) {
(*out)[i] = color[i];
}
}
}
}
}
}
void Menu_ShowItemByName(menuDef_t *menu, const char *p, qboolean bShow) {
itemDef_t *item;
int i;
int count = Menu_ItemsMatchingGroup(menu, p);
for (i = 0; i < count; i++) {
item = Menu_GetMatchingItemByNumber(menu, i, p);
if (item != NULL) {
if (bShow) {
item->window.flags |= WINDOW_VISIBLE;
} else {
item->window.flags &= ~WINDOW_VISIBLE;
// stop cinematics playing in the window
if (item->window.cinematic >= 0) {
DC->stopCinematic(item->window.cinematic);
item->window.cinematic = -1;
}
}
}
}
}
void Menu_FadeItemByName(menuDef_t *menu, const char *p, qboolean fadeOut) {
itemDef_t *item;
int i;
int count = Menu_ItemsMatchingGroup(menu, p);
for (i = 0; i < count; i++) {
item = Menu_GetMatchingItemByNumber(menu, i, p);
if (item != NULL) {
if (fadeOut) {
item->window.flags |= (WINDOW_FADINGOUT | WINDOW_VISIBLE);