Debian Codegraph @

code/q3_ui/ui_qmenu.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 /**********************************************************************
24 UI_QMENU.C
25
26 Quake's menu framework system.
27 **********************************************************************/
28 #include "ui_local.h"
29
30 sfxHandle_t menu_in_sound;
31 sfxHandle_t menu_move_sound;
32 sfxHandle_t menu_out_sound;
33 sfxHandle_t menu_buzz_sound;
34 sfxHandle_t menu_null_sound;
35 sfxHandle_t weaponChangeSound;
36
37 static qhandle_t sliderBar;
38 static qhandle_t sliderButton_0;
39 static qhandle_t sliderButton_1;
40
41 vec4_t menu_text_color = {1.0f, 1.0f, 1.0f, 1.0f};
42 vec4_t menu_dim_color = {0.0f, 0.0f, 0.0f, 0.75f};
43 vec4_t color_black = {0.00f, 0.00f, 0.00f, 1.00f};
44 vec4_t color_white = {1.00f, 1.00f, 1.00f, 1.00f};
45 vec4_t color_yellow = {1.00f, 1.00f, 0.00f, 1.00f};
46 vec4_t color_blue = {0.00f, 0.00f, 1.00f, 1.00f};
47 vec4_t color_lightOrange = {1.00f, 0.68f, 0.00f, 1.00f };
48 vec4_t color_orange = {1.00f, 0.43f, 0.00f, 1.00f};
49 vec4_t color_red = {1.00f, 0.00f, 0.00f, 1.00f};
50 vec4_t color_dim = {0.00f, 0.00f, 0.00f, 0.25f};
51
52 // current color scheme
53 vec4_t pulse_color = {1.00f, 1.00f, 1.00f, 1.00f};
54 vec4_t text_color_disabled = {0.50f, 0.50f, 0.50f, 1.00f}; // light gray
55 vec4_t text_color_normal = {1.00f, 0.43f, 0.00f, 1.00f}; // light orange
56 vec4_t text_color_highlight = {1.00f, 1.00f, 0.00f, 1.00f}; // bright yellow
57 vec4_t listbar_color = {1.00f, 0.43f, 0.00f, 0.30f}; // transluscent orange
58 vec4_t text_color_status = {1.00f, 1.00f, 1.00f, 1.00f}; // bright white
59
60 // action widget
61 static void Action_Init( menuaction_s *a );
62 static void Action_Draw( menuaction_s *a );
63
64 // radio button widget
65 static void RadioButton_Init( menuradiobutton_s *rb );
66 static void RadioButton_Draw( menuradiobutton_s *rb );
67 static sfxHandle_t RadioButton_Key( menuradiobutton_s *rb, int key );
68
69 // slider widget
70 static void Slider_Init( menuslider_s *s );
71 static sfxHandle_t Slider_Key( menuslider_s *s, int key );
72 static void Slider_Draw( menuslider_s *s );
73
74 // spin control widget
75 static void SpinControl_Init( menulist_s *s );
76 static void SpinControl_Draw( menulist_s *s );
77 static sfxHandle_t SpinControl_Key( menulist_s *l, int key );
78
79 // text widget
80 static void Text_Init( menutext_s *b );
81 static void Text_Draw( menutext_s *b );
82
83 // scrolllist widget
84 static void ScrollList_Init( menulist_s *l );
85 sfxHandle_t ScrollList_Key( menulist_s *l, int key );
86
87 // proportional text widget
88 static void PText_Init( menutext_s *b );
89 static void PText_Draw( menutext_s *b );
90
91 // proportional banner text widget
92 static void BText_Init( menutext_s *b );
93 static void BText_Draw( menutext_s *b );
94
95 /*
96 =================
97 Text_Init
98 =================
99 */
100 static void Text_Init( menutext_s *t )
101 {
102 t->generic.flags |= QMF_INACTIVE;
103 }
104
105 /*
106 =================
107 Text_Draw
108 =================
109 */
110 static void Text_Draw( menutext_s *t )
111 {
112 int x;
113 int y;
114 char buff[512];
115 float* color;
116
117 x = t->generic.x;
118 y = t->generic.y;
119
120 buff[0] = '\0';
121
122 // possible label
123 if (t->generic.name)
124 strcpy(buff,t->generic.name);
125
126 // possible value
127 if (t->string)
128 strcat(buff,t->string);
129
130 if (t->generic.flags & QMF_GRAYED)
131 color = text_color_disabled;
132 else
133 color = t->color;
134
135 UI_DrawString( x, y, buff, t->style, color );
136 }
137
138 /*
139 =================
140 BText_Init
141 =================
142 */
143 static void BText_Init( menutext_s *t )
144 {
145 t->generic.flags |= QMF_INACTIVE;
146 }
147
148 /*
149 =================
150 BText_Draw
151 =================
152 */
153 static void BText_Draw( menutext_s *t )
154 {
155 int x;
156 int y;
157 float* color;
158
159 x = t->generic.x;
160 y = t->generic.y;
161
162 if (t->generic.flags & QMF_GRAYED)
163 color = text_color_disabled;
164 else
165 color = t->color;
166
167 UI_DrawBannerString( x, y, t->string, t->style, color );
168 }
169
170 /*
171 =================
172 PText_Init
173 =================
174 */
175 static void PText_Init( menutext_s *t )
176 {
177 int x;
178 int y;
179 int w;
180 int h;
181 float sizeScale;
182
183 sizeScale = UI_ProportionalSizeScale( t->style );
184
185 x = t->generic.x;
186 y = t->generic.y;
187 w = UI_ProportionalStringWidth( t->string ) * sizeScale;
188 h = PROP_HEIGHT * sizeScale;
189
190 if( t->generic.flags & QMF_RIGHT_JUSTIFY ) {
191 x -= w;
192 }
193 else if( t->generic.flags & QMF_CENTER_JUSTIFY ) {
194 x -= w / 2;
195 }
196
197 t->generic.left = x - PROP_GAP_WIDTH * sizeScale;
198 t->generic.right = x + w + PROP_GAP_WIDTH * sizeScale;
199 t->generic.top = y;
200 t->generic.bottom = y + h;
201 }
202
203 /*
204 =================
205 PText_Draw
206 =================
207 */
208 static void PText_Draw( menutext_s *t )
209 {
210 int x;
211 int y;
212 float * color;
213 int style;
214
215 x = t->generic.x;
216 y = t->generic.y;
217
218 if (t->generic.flags & QMF_GRAYED)
219 color = text_color_disabled;
220 else
221 color = t->color;
222
223 style = t->style;
224 if( t->generic.flags & QMF_PULSEIFFOCUS ) {
225 if( Menu_ItemAtCursor( t->generic.parent ) == t ) {
226 style |= UI_PULSE;
227 }
228 else {
229 style |= UI_INVERSE;
230 }
231 }
232
233 UI_DrawProportionalString( x, y, t->string, style, color );
234 }
235
236 /*
237 =================
238 Bitmap_Init
239 =================
240 */
241 void Bitmap_Init( menubitmap_s *b )
242 {
243 int x;
244 int y;
245 int w;
246 int h;
247
248 x = b->generic.x;
249 y = b->generic.y;
250 w = b->width;
251 h = b->height;
252 if( w < 0 ) {
253 w = -w;
254 }
255 if( h < 0 ) {
256 h = -h;
257 }
258
259 if (b->generic.flags & QMF_RIGHT_JUSTIFY)
260 {
261 x = x - w;
262 }
263 else if (b->generic.flags & QMF_CENTER_JUSTIFY)
264 {
265 x = x - w/2;
266 }
267
268 b->generic.left = x;
269 b->generic.right = x + w;
270 b->generic.top = y;
271 b->generic.bottom = y + h;
272
273 b->shader = 0;
274 b->focusshader = 0;
275 }
276
277 /*
278 =================
279 Bitmap_Draw
280 =================
281 */
282 void Bitmap_Draw( menubitmap_s *b )
283 {
284 float x;
285 float y;
286 float w;
287 float h;
288 vec4_t tempcolor;
289 float* color;
290
291 x = b->generic.x;
292 y = b->generic.y;
293 w = b->width;
294 h = b->height;
295
296 if (b->generic.flags & QMF_RIGHT_JUSTIFY)
297 {
298 x = x - w;
299 }
300 else if (b->generic.flags & QMF_CENTER_JUSTIFY)
301 {
302 x = x - w/2;
303 }
304
305 // used to refresh shader
306 if (b->generic.name && !b->shader)
307 {
308 b->shader = trap_R_RegisterShaderNoMip( b->generic.name );
309 if (!b->shader && b->errorpic)
310 b->shader = trap_R_RegisterShaderNoMip( b->errorpic );
311 }
312
313 if (b->focuspic && !b->focusshader)
314 b->focusshader = trap_R_RegisterShaderNoMip( b->focuspic );
315
316 if (b->generic.flags & QMF_GRAYED)
317 {
318 if (b->shader)
319 {
320 trap_R_SetColor( colorMdGrey );
321 UI_DrawHandlePic( x, y, w, h, b->shader );
322 trap_R_SetColor( NULL );
323 }
324 }
325 else
326 {
327 if (b->shader)
328 UI_DrawHandlePic( x, y, w, h, b->shader );
329
330 if ( ( (b->generic.flags & QMF_PULSE)
331 || (b->generic.flags & QMF_PULSEIFFOCUS) )
332 && (Menu_ItemAtCursor( b->generic.parent ) == b))
333 {
334 if (b->focuscolor)
335 {
336 tempcolor[0] = b->focuscolor[0];
337 tempcolor[1] = b->focuscolor[1];
338 tempcolor[2] = b->focuscolor[2];
339 color = tempcolor;
340 }
341 else
342 color = pulse_color;
343 color[3] = 0.5+0.5*sin(uis.realtime/PULSE_DIVISOR);
344
345 trap_R_SetColor( color );
346 UI_DrawHandlePic( x, y, w, h, b->focusshader );
347 trap_R_SetColor( NULL );
348 }
349 else if ((b->generic.flags & QMF_HIGHLIGHT) || ((b->generic.flags & QMF_HIGHLIGHT_IF_FOCUS) && (Menu_ItemAtCursor( b->generic.parent ) == b)))
350 {
351 if (b->focuscolor)
352 {
353 trap_R_SetColor( b->focuscolor );
354 UI_DrawHandlePic( x, y, w, h, b->focusshader );
355 trap_R_SetColor( NULL );
356 }
357 else
358 UI_DrawHandlePic( x, y, w, h, b->focusshader );
359 }
360 }
361 }
362
363 /*
364 =================
365 Action_Init
366 =================
367 */
368 static void Action_Init( menuaction_s *a )
369 {
370 int len;
371
372 // calculate bounds
373 if (a->generic.name)
374 len = strlen(a->generic.name);
375 else
376 len = 0;
377
378 // left justify text
379 a->generic.left = a->generic.x;
380 a->generic.right = a->generic.x + len*BIGCHAR_WIDTH;
381 a->generic.top = a->generic.y;
382 a->generic.bottom = a->generic.y + BIGCHAR_HEIGHT;
383 }
384
385 /*
386 =================
387 Action_Draw
388 =================
389 */
390 static void Action_Draw( menuaction_s *a )
391 {
392 int x, y;
393 int style;
394 float* color;
395
396 style = 0;
397 color = menu_text_color;
398 if ( a->generic.flags & QMF_GRAYED )
399 {
400 color = text_color_disabled;
401 }
402 else if (( a->generic.flags & QMF_PULSEIFFOCUS ) && ( a->generic.parent->cursor == a->generic.menuPosition ))
403 {
404 color = text_color_highlight;
405 style = UI_PULSE;
406 }
407 else if (( a->generic.flags & QMF_HIGHLIGHT_IF_FOCUS ) && ( a->generic.parent->cursor == a->generic.menuPosition ))
408 {
409 color = text_color_highlight;
410 }
411 else if ( a->generic.flags & QMF_BLINK )
412 {
413 style = UI_BLINK;
414 color = text_color_highlight;
415 }
416
417 x = a->generic.x;
418 y = a->generic.y;
419
420 UI_DrawString( x, y, a->generic.name, UI_LEFT|style, color );
421
422 if ( a->generic.parent->cursor == a->generic.menuPosition )
423 {
424 // draw cursor
425 UI_DrawChar( x - BIGCHAR_WIDTH, y, 13, UI_LEFT|UI_BLINK, color);
426 }
427 }
428
429 /*
430 =================
431 RadioButton_Init
432 =================
433 */
434 static void RadioButton_Init( menuradiobutton_s *rb )
435 {
436 int len;
437
438 // calculate bounds
439 if (rb->generic.name)
440 len = strlen(rb->generic.name);
441 else
442 len = 0;
443
444 rb->generic.left = rb->generic.x - (len+1)*SMALLCHAR_WIDTH;
445 rb->generic.right = rb->generic.x + 6*SMALLCHAR_WIDTH;
446 rb->generic.top = rb->generic.y;
447 rb->generic.bottom = rb->generic.y + SMALLCHAR_HEIGHT;
448 }
449
450 /*
451 =================
452 RadioButton_Key
453 =================
454 */
455 static sfxHandle_t RadioButton_Key( menuradiobutton_s *rb, int key )
456 {
457 switch (key)
458 {
459 case K_MOUSE1:
460 if (!(rb->generic.flags & QMF_HASMOUSEFOCUS))
461 break;
462
463 case K_JOY1:
464 case K_JOY2:
465 case K_JOY3:
466 case K_JOY4:
467 case K_ENTER:
468 case K_KP_ENTER:
469 case K_KP_LEFTARROW:
470 case K_LEFTARROW:
471 case K_KP_RIGHTARROW:
472 case K_RIGHTARROW:
473 rb->curvalue = !rb->curvalue;
474 if ( rb->generic.callback )
475 rb->generic.callback( rb, QM_ACTIVATED );
476
477 return (menu_move_sound);
478 }
479
480 // key not handled
481 return 0;
482 }
483
484 /*
485 =================
486 RadioButton_Draw
487 =================
488 */
489 static void RadioButton_Draw( menuradiobutton_s *rb )
490 {
491 int x;
492 int y;
493 float *color;
494 int style;
495 qboolean focus;
496
497 x = rb->generic.x;
498 y = rb->generic.y;
499
500 focus = (rb->generic.parent->cursor == rb->generic.menuPosition);
501
502 if ( rb->generic.flags & QMF_GRAYED )
503 {
504 color = text_color_disabled;
505 style = UI_LEFT|UI_SMALLFONT;
506 }
507 else if ( focus )
508 {
509 color = text_color_highlight;
510 style = UI_LEFT|UI_PULSE|UI_SMALLFONT;
511 }
512 else
513 {
514 color = text_color_normal;
515 style = UI_LEFT|UI_SMALLFONT;
516 }
517
518 if ( focus )
519 {
520 // draw cursor
521 UI_FillRect( rb->generic.left, rb->generic.top, rb->generic.right-rb->generic.left+1, rb->generic.bottom-rb->generic.top+1, listbar_color );
522 UI_DrawChar( x, y, 13, UI_CENTER|UI_BLINK|UI_SMALLFONT, color);
523 }
524
525 if ( rb->generic.name )
526 UI_DrawString( x - SMALLCHAR_WIDTH, y, rb->generic.name, UI_RIGHT|UI_SMALLFONT, color );
527
528 if ( !rb->curvalue )
529 {
530 UI_DrawHandlePic( x + SMALLCHAR_WIDTH, y + 2, 16, 16, uis.rb_off);
531 UI_DrawString( x + SMALLCHAR_WIDTH + 16, y, "off", style, color );
532 }
533 else
534 {
535 UI_DrawHandlePic( x + SMALLCHAR_WIDTH, y + 2, 16, 16, uis.rb_on );
536 UI_DrawString( x + SMALLCHAR_WIDTH + 16, y, "on", style, color );
537 }
538 }
539
540 /*
541 =================
542 Slider_Init
543 =================
544 */
545 static void Slider_Init( menuslider_s *s )
546 {
547 int len;
548
549 // calculate bounds
550 if (s->generic.name)
551 len = strlen(s->generic.name);
552 else
553 len = 0;
554
555 s->generic.left = s->generic.x - (len+1)*SMALLCHAR_WIDTH;
556 s->generic.right = s->generic.x + (SLIDER_RANGE+2+1)*SMALLCHAR_WIDTH;
557 s->generic.top = s->generic.y;
558 s->generic.bottom = s->generic.y + SMALLCHAR_HEIGHT;
559 }
560
561 /*
562 =================
563 Slider_Key
564 =================
565 */
566 static sfxHandle_t Slider_Key( menuslider_s *s, int key )
567 {
568 sfxHandle_t sound;
569 int x;
570 int oldvalue;
571
572 switch (key)
573 {
574 case K_MOUSE1:
575 x = uis.cursorx - s->generic.x - 2*SMALLCHAR_WIDTH;
576 oldvalue = s->curvalue;
577 s->curvalue = (x/(float)(SLIDER_RANGE*SMALLCHAR_WIDTH)) * (s->maxvalue-s->minvalue) + s->minvalue;
578
579 if (s->curvalue < s->minvalue)
580 s->curvalue = s->minvalue;
581 else if (s->curvalue > s->maxvalue)
582 s->curvalue = s->maxvalue;
583 if (s->curvalue != oldvalue)
584 sound = menu_move_sound;
585 else
586 sound = 0;
587 break;
588
589 case K_KP_LEFTARROW:
590 case K_LEFTARROW:
591 if (s->curvalue > s->minvalue)
592 {
593 s->curvalue--;
594 sound = menu_move_sound;
595 }
596 else
597 sound = menu_buzz_sound;
598 break;
599
600 case K_KP_RIGHTARROW:
601 case K_RIGHTARROW:
602 if (s->curvalue < s->maxvalue)
603 {
604 s->curvalue++;
605 sound = menu_move_sound;
606 }
607 else
608 sound = menu_buzz_sound;
609 break;
610
611 default:
612 // key not handled
613 sound = 0;
614 break;
615 }
616
617 if ( sound && s->generic.callback )
618 s->generic.callback( s, QM_ACTIVATED );
619
620 return (sound);
621 }
622
623 #if 1
624 /*
625 =================
626 Slider_Draw
627 =================
628 */
629 static void Slider_Draw( menuslider_s *s ) {
630 int x;
631 int y;
632 int style;
633 float *color;
634 int button;
635 qboolean focus;
636
637 x = s->generic.x;
638 y = s->generic.y;
639 focus = (s->generic.parent->cursor == s->generic.menuPosition);
640
641 if( s->generic.flags & QMF_GRAYED ) {
642 color = text_color_disabled;
643 style = UI_SMALLFONT;
644 }
645 else if( focus ) {
646 color = text_color_highlight;
647 style = UI_SMALLFONT | UI_PULSE;
648 }
649 else {
650 color = text_color_normal;
651 style = UI_SMALLFONT;
652 }
653
654 // draw label
655 UI_DrawString( x - SMALLCHAR_WIDTH, y, s->generic.name, UI_RIGHT|style, color );
656
657 // draw slider
658 UI_SetColor( color );
659 UI_DrawHandlePic( x + SMALLCHAR_WIDTH, y, 96, 16, sliderBar );
660 UI_SetColor( NULL );
661
662 // clamp thumb
663 if( s->maxvalue > s->minvalue ) {
664 s->range = ( s->curvalue - s->minvalue ) / ( float ) ( s->maxvalue - s->minvalue );
665 if( s->range < 0 ) {
666 s->range = 0;
667 }
668 else if( s->range > 1) {
669 s->range = 1;
670 }
671 }
672 else {
673 s->range = 0;
674 }
675
676 // draw thumb
677 if( style & UI_PULSE) {
678 button = sliderButton_1;
679 }
680 else {
681 button = sliderButton_0;
682 }
683
684 UI_DrawHandlePic( (int)( x + 2*SMALLCHAR_WIDTH + (SLIDER_RANGE-1)*SMALLCHAR_WIDTH* s->range ) - 2, y - 2, 12, 20, button );
685 }
686 #else
687 /*
688 =================
689 Slider_Draw
690 =================
691 */
692 static void Slider_Draw( menuslider_s *s )
693 {
694 float *color;
695 int style;
696 int i;
697 int x;
698 int y;
699 qboolean focus;
700
701 x = s->generic.x;
702 y = s->generic.y;
703 focus = (s->generic.parent->cursor == s->generic.menuPosition);
704
705 style = UI_SMALLFONT;
706 if ( s->generic.flags & QMF_GRAYED )
707 {
708 color = text_color_disabled;
709 }
710 else if (focus)
711 {
712 color = text_color_highlight;
713 style |= UI_PULSE;
714 }
715 else
716 {
717 color = text_color_normal;
718 }
719
720 if ( focus )
721 {
722 // draw cursor
723 UI_FillRect( s->generic.left, s->generic.top, s->generic.right-s->generic.left+1, s->generic.bottom-s->generic.top+1, listbar_color );
724 UI_DrawChar( x, y, 13, UI_CENTER|UI_BLINK|UI_SMALLFONT, color);
725 }
726
727 // draw label
728 UI_DrawString( x - SMALLCHAR_WIDTH, y, s->generic.name, UI_RIGHT|style, color );
729
730 // draw slider
731 UI_DrawChar( x + SMALLCHAR_WIDTH, y, 128, UI_LEFT|style, color);
732 for ( i = 0; i < SLIDER_RANGE; i++ )
733 UI_DrawChar( x + (i+2)*SMALLCHAR_WIDTH, y, 129, UI_LEFT|style, color);
734 UI_DrawChar( x + (i+2)*SMALLCHAR_WIDTH, y, 130, UI_LEFT|style, color);
735
736 // clamp thumb
737 if (s->maxvalue > s->minvalue)
738 {
739 s->range = ( s->curvalue - s->minvalue ) / ( float ) ( s->maxvalue - s->minvalue );
740 if ( s->range < 0)
741 s->range = 0;
742 else if ( s->range > 1)
743 s->range = 1;
744 }
745 else
746 s->range = 0;
747
748 // draw thumb
749 if (style & UI_PULSE) {
750 style &= ~UI_PULSE;
751 style |= UI_BLINK;
752 }
753 UI_DrawChar( (int)( x + 2*SMALLCHAR_WIDTH + (SLIDER_RANGE-1)*SMALLCHAR_WIDTH* s->range ), y, 131, UI_LEFT|style, color);
754 }
755 #endif
756
757 /*
758 =================
759 SpinControl_Init
760 =================
761 */
762 static void SpinControl_Init( menulist_s *s ) {
763 int len;
764 int l;
765 const char* str;
766
767 if (s->generic.name)
768 len = strlen(s->generic.name) * SMALLCHAR_WIDTH;
769 else
770 len = 0;
771
772 s->generic.left = s->generic.x - SMALLCHAR_WIDTH - len;
773
774 len = s->numitems = 0;
775 while ( (str = s->itemnames[s->numitems]) != 0 )
776 {
777 l = strlen(str);
778 if (l > len)
779 len = l;
780
781 s->numitems++;
782 }
783
784 s->generic.top = s->generic.y;
785 s->generic.right = s->generic.x + (len+1)*SMALLCHAR_WIDTH;
786 s->generic.bottom = s->generic.y + SMALLCHAR_HEIGHT;
787 }
788
789 /*
790 =================
791 SpinControl_Key
792 =================
793 */
794 static sfxHandle_t SpinControl_Key( menulist_s *s, int key )
795 {
796 sfxHandle_t sound;
797
798 sound = 0;
799 switch (key)
800 {
801 case K_KP_RIGHTARROW:
802 case K_RIGHTARROW:
803 case K_MOUSE1:
804 s->curvalue++;
805 if (s->curvalue >= s->numitems)
806 s->curvalue = 0;
807 sound = menu_move_sound;
808 break;
809
810 case K_KP_LEFTARROW:
811 case K_LEFTARROW:
812 s->curvalue--;
813 if (s->curvalue < 0)
814 s->curvalue = s->numitems-1;
815 sound = menu_move_sound;
816 break;
817 }
818
819 if ( sound && s->generic.callback )
820 s->generic.callback( s, QM_ACTIVATED );
821
822 return (sound);
823 }
824
825 /*
826 =================
827 SpinControl_Draw
828 =================
829 */
830 static void SpinControl_Draw( menulist_s *s )
831 {
832 float *color;
833 int x,y;
834 int style;
835 qboolean focus;
836
837 x = s->generic.x;
838 y = s->generic.y;
839
840 style = UI_SMALLFONT;
841 focus = (s->generic.parent->cursor == s->generic.menuPosition);
842
843 if ( s->generic.flags & QMF_GRAYED )
844 color = text_color_disabled;
845 else if ( focus )
846 {
847 color = text_color_highlight;
848 style |= UI_PULSE;
849 }
850 else if ( s->generic.flags & QMF_BLINK )
851 {
852 color = text_color_highlight;
853 style |= UI_BLINK;
854 }
855 else
856 color = text_color_normal;
857
858 if ( focus )
859 {
860 // draw cursor
861 UI_FillRect( s->generic.left, s->generic.top, s->generic.right-s->generic.left+1, s->generic.bottom-s->generic.top+1, listbar_color );
862 UI_DrawChar( x, y, 13, UI_CENTER|UI_BLINK|UI_SMALLFONT, color);
863 }
864
865 UI_DrawString( x - SMALLCHAR_WIDTH, y, s->generic.name, style|UI_RIGHT, color );
866 UI_DrawString( x + SMALLCHAR_WIDTH, y, s->itemnames[s->curvalue], style|UI_LEFT, color );
867 }
868
869 /*
870 =================
871 ScrollList_Init
872 =================
873 */
874 static void ScrollList_Init( menulist_s *l )
875 {
876 int w;
877
878 l->oldvalue = 0;
879 l->curvalue = 0;
880 l->top = 0;
881
882 if( !l->columns ) {
883 l->columns = 1;
884 l->separation = 0;
885 }
886 else if( !l->separation ) {
887 l->separation = 3;
888 }
889
890 w = ( (l->width + l->separation) * l->columns - l->separation) * SMALLCHAR_WIDTH;
891
892 l->generic.left = l->generic.x;
893 l->generic.top = l->generic.y;
894 l->generic.right = l->generic.x + w;
895 l->generic.bottom = l->generic.y + l->height * SMALLCHAR_HEIGHT;
896
897 if( l->generic.flags & QMF_CENTER_JUSTIFY ) {
898 l->generic.left -= w / 2;
899 l->generic.right -= w / 2;
900 }
901 }
902
903 /*
904 =================
905 ScrollList_Key
906 =================
907 */
908 sfxHandle_t ScrollList_Key( menulist_s *l, int key )
909 {
910 int x;
911 int y;
912 int w;
913 int i;
914 int j;
915 int c;
916 int cursorx;
917 int cursory;
918 int column;
919 int index;
920
921 switch (key)
922 {
923 case K_MOUSE1:
924 if (l->generic.flags & QMF_HASMOUSEFOCUS)
925 {
926 // check scroll region
927 x = l->generic.x;
928 y = l->generic.y;
929 w = ( (l->width + l->separation) * l->columns - l->separation) * SMALLCHAR_WIDTH;
930 if( l->generic.flags & QMF_CENTER_JUSTIFY ) {
931 x -= w / 2;
932 }
933 if (UI_CursorInRect( x, y, w, l->height*SMALLCHAR_HEIGHT ))
934 {
935 cursorx = (uis.cursorx - x)/SMALLCHAR_WIDTH;
936 column = cursorx / (l->width + l->separation);
937 cursory = (uis.cursory - y)/SMALLCHAR_HEIGHT;
938 index = column * l->height + cursory;
939 if (l->top + index < l->numitems)
940 {
941 l->oldvalue = l->curvalue;
942 l->curvalue = l->top + index;
943
944 if (l->oldvalue != l->curvalue && l->generic.callback)
945 {
946 l->generic.callback( l, QM_GOTFOCUS );
947 return (menu_move_sound);
948 }
949 }
950 }
951
952 // absorbed, silent sound effect
953 return (menu_null_sound);
954 }
955 break;
956
957 case K_KP_HOME:
958 case K_HOME:
959 l->oldvalue = l->curvalue;
960 l->curvalue = 0;
961 l->top = 0;
962
963 if (l->oldvalue != l->curvalue && l->generic.callback)
964 {
965 l->generic.callback( l, QM_GOTFOCUS );
966 return (menu_move_sound);
967 }
968 return (menu_buzz_sound);
969
970 case K_KP_END:
971 case K_END:
972 l->oldvalue = l->curvalue;
973 l->curvalue = l->numitems-1;
974 if( l->columns > 1 ) {
975 c = (l->curvalue / l->height + 1) * l->height;
976 l->top = c - (l->columns * l->height);
977 }
978 else {
979 l->top = l->curvalue - (l->height - 1);
980 }
981 if (l->top < 0)
982 l->top = 0;
983
984 if (l->oldvalue != l->curvalue && l->generic.callback)
985 {
986 l->generic.callback( l, QM_GOTFOCUS );
987 return (menu_move_sound);
988 }
989 return (menu_buzz_sound);
990
991 case K_PGUP:
992 case K_KP_PGUP:
993 if( l->columns > 1 ) {
994 return menu_null_sound;
995 }
996
997 if (l->curvalue > 0)
998 {
999 l->oldvalue = l->curvalue;
1000 l->curvalue -= l->height-1;
1001 if (l->curvalue < 0)
1002 l->curvalue = 0;
1003 l->top = l->curvalue;
1004 if (l->top < 0)
1005 l->top = 0;
1006
1007 if (l->generic.callback)
1008 l->generic.callback( l, QM_GOTFOCUS );
1009
1010 return (menu_move_sound);
1011 }
1012 return (menu_buzz_sound);
1013
1014 case K_PGDN:
1015 case K_KP_PGDN:
1016 if( l->columns > 1 ) {
1017 return menu_null_sound;
1018 }
1019
1020 if (l->curvalue < l->numitems-1)
1021 {
1022 l->oldvalue = l->curvalue;
1023 l->curvalue += l->height-1;
1024 if (l->curvalue > l->numitems-1)
1025 l->curvalue = l->numitems-1;
1026 l->top = l->curvalue - (l->height-1);
1027 if (l->top < 0)
1028 l->top = 0;
1029
1030 if (l->generic.callback)
1031 l->generic.callback( l, QM_GOTFOCUS );
1032
1033 return (menu_move_sound);
1034 }
1035 return (menu_buzz_sound);
1036
1037 case K_MWHEELUP:
1038 if( l->columns > 1 ) {
1039 return menu_null_sound;
1040 }
1041
1042 if (l->top > 0)
1043 {
1044 // if scrolling 3 lines would replace over half of the
1045 // displayed items, only scroll 1 item at a time.
1046 int scroll = l->height < 6 ? 1 : 3;
1047 l->top -= scroll;
1048 if (l->top < 0)
1049 l->top = 0;
1050
1051 if (l->generic.callback)
1052 l->generic.callback( l, QM_GOTFOCUS );
1053
1054 // make scrolling silent
1055 return (menu_null_sound);
1056 }
1057 return (menu_buzz_sound);
1058
1059 case K_MWHEELDOWN:
1060 if( l->columns > 1 ) {
1061 return menu_null_sound;
1062 }
1063
1064 if (l->top < l->numitems-l->height)
1065 {
1066 // if scrolling 3 items would replace over half of the
1067 // displayed items, only scroll 1 item at a time.
1068 int scroll = l->height < 6 ? 1 : 3;
1069 l->top += scroll;
1070 if (l->top > l->numitems-l->height)
1071 l->top = l->numitems-l->height;
1072
1073 if (l->generic.callback)
1074 l->generic.callback( l, QM_GOTFOCUS );
1075
1076 // make scrolling silent
1077 return (menu_null_sound);
1078 }
1079 return (menu_buzz_sound);
1080
1081 case K_KP_UPARROW:
1082 case K_UPARROW:
1083 if( l->curvalue == 0 ) {
1084 return menu_buzz_sound;
1085 }
1086
1087 l->oldvalue = l->curvalue;
1088 l->curvalue--;
1089
1090 if( l->curvalue < l->top ) {
1091 if( l->columns == 1 ) {
1092 l->top--;
1093 }
1094 else {
1095 l->top -= l->height;
1096 }
1097 }
1098
1099 if( l->generic.callback ) {
1100 l->generic.callback( l, QM_GOTFOCUS );
1101 }
1102
1103 return (menu_move_sound);
1104
1105 case K_KP_DOWNARROW:
1106 case K_DOWNARROW:
1107 if( l->curvalue == l->numitems - 1 ) {
1108 return menu_buzz_sound;
1109 }
1110
1111 l->oldvalue = l->curvalue;
1112 l->curvalue++;
1113
1114 if( l->curvalue >= l->top + l->columns * l->height ) {
1115 if( l->columns == 1 ) {
1116 l->top++;
1117 }
1118 else {
1119 l->top += l->height;
1120 }
1121 }
1122
1123 if( l->generic.callback ) {
1124 l->generic.callback( l, QM_GOTFOCUS );
1125 }
1126
1127 return menu_move_sound;
1128
1129 case K_KP_LEFTARROW:
1130 case K_LEFTARROW:
1131 if( l->columns == 1 ) {
1132 return menu_null_sound;
1133 }
1134
1135 if( l->curvalue < l->height ) {
1136 return menu_buzz_sound;
1137 }
1138
1139 l->oldvalue = l->curvalue;
1140 l->curvalue -= l->height;
1141
1142 if( l->curvalue < l->top ) {
1143 l->top -= l->height;
1144 }
1145
1146 if( l->generic.callback ) {
1147 l->generic.callback( l, QM_GOTFOCUS );
1148 }
1149
1150 return menu_move_sound;
1151
1152 case K_KP_RIGHTARROW:
1153 case K_RIGHTARROW:
1154 if( l->columns == 1 ) {
1155 return menu_null_sound;
1156 }
1157
1158 c = l->curvalue + l->height;
1159
1160 if( c >= l->numitems ) {
1161 return menu_buzz_sound;
1162 }
1163
1164 l->oldvalue = l->curvalue;
1165 l->curvalue = c;
1166
1167 if( l->curvalue > l->top + l->columns * l->height - 1 ) {
1168 l->top += l->height;
1169 }
1170
1171 if( l->generic.callback ) {
1172 l->generic.callback( l, QM_GOTFOCUS );
1173 }
1174
1175 return menu_move_sound;
1176 }
1177
1178 // cycle look for ascii key inside list items
1179 if ( !Q_isprint( key ) )
1180 return (0);
1181
1182 // force to lower for case insensitive compare
1183 if ( Q_isupper( key ) )
1184 {
1185 key -= 'A' - 'a';
1186 }
1187
1188 // iterate list items
1189 for (i=1; i<=l->numitems; i++)
1190 {
1191 j = (l->curvalue + i) % l->numitems;
1192 c = l->itemnames[j][0];
1193 if ( Q_isupper( c ) )
1194 {
1195 c -= 'A' - 'a';
1196 }
1197
1198 if (c == key)
1199 {
1200 // set current item, mimic windows listbox scroll behavior
1201 if (j < l->top)
1202 {
1203 // behind top most item, set this as new top
1204 l->top = j;
1205 }
1206 else if (j > l->top+l->height-1)
1207 {
1208 // past end of list box, do page down
1209 l->top = (j+1) - l->height;
1210 }
1211
1212 if (l->curvalue != j)
1213 {
1214 l->oldvalue = l->curvalue;
1215 l->curvalue = j;
1216 if (l->generic.callback)
1217 l->generic.callback( l, QM_GOTFOCUS );
1218 return ( menu_move_sound );
1219 }
1220
1221 return (menu_buzz_sound);
1222 }
1223 }
1224
1225 return (menu_buzz_sound);
1226 }
1227
1228 /*
1229 =================
1230 ScrollList_Draw
1231 =================
1232 */
1233 void ScrollList_Draw( menulist_s *l )
1234 {
1235 int x;
1236 int u;
1237 int y;
1238 int i;
1239 int base;
1240 int column;
1241 float* color;
1242 qboolean hasfocus;
1243 int style;
1244
1245 hasfocus = (l->generic.parent->cursor == l->generic.menuPosition);
1246
1247 x = l->generic.x;
1248 for( column = 0; column < l->columns; column++ ) {
1249 y = l->generic.y;
1250 base = l->top + column * l->height;
1251 for( i = base; i < base + l->height; i++) {
1252 if (i >= l->numitems)
1253 break;
1254
1255 if (i == l->curvalue)
1256 {
1257 u = x - 2;
1258 if( l->generic.flags & QMF_CENTER_JUSTIFY ) {
1259 u -= (l->width * SMALLCHAR_WIDTH) / 2 + 1;
1260 }
1261
1262 UI_FillRect(u,y,l->width*SMALLCHAR_WIDTH,SMALLCHAR_HEIGHT+2,listbar_color);
1263 color = text_color_highlight;
1264
1265 if (hasfocus)
1266 style = UI_PULSE|UI_LEFT|UI_SMALLFONT;
1267 else
1268 style = UI_LEFT|UI_SMALLFONT;
1269 }
1270 else
1271 {
1272 color = text_color_normal;
1273 style = UI_LEFT|UI_SMALLFONT;
1274 }
1275 if( l->generic.flags & QMF_CENTER_JUSTIFY ) {
1276 style |= UI_CENTER;
1277 }
1278
1279 UI_DrawString(
1280 x,
1281 y,
1282 l->itemnames[i],
1283 style,
1284 color);
1285
1286 y += SMALLCHAR_HEIGHT;
1287 }
1288 x += (l->width + l->separation) * SMALLCHAR_WIDTH;
1289 }
1290 }
1291
1292 /*
1293 =================
1294 Menu_AddItem
1295 =================
1296 */
1297 void Menu_AddItem( menuframework_s *menu, void *item )
1298 {
1299 menucommon_s *itemptr;
1300
1301 if (menu->nitems >= MAX_MENUITEMS)
1302 trap_Error ("Menu_AddItem: excessive items");
1303
1304 menu->items[menu->nitems] = item;
1305 ((menucommon_s*)menu->items[menu->nitems])->parent = menu;
1306 ((menucommon_s*)menu->items[menu->nitems])->menuPosition = menu->nitems;
1307 ((menucommon_s*)menu->items[menu->nitems])->flags &= ~QMF_HASMOUSEFOCUS;
1308
1309 // perform any item specific initializations
1310 itemptr = (menucommon_s*)item;
1311 if (!(itemptr->flags & QMF_NODEFAULTINIT))
1312 {
1313 switch (itemptr->type)
1314 {
1315 case MTYPE_ACTION:
1316 Action_Init((menuaction_s*)item);
1317 break;
1318
1319 case MTYPE_FIELD:
1320 MenuField_Init((menufield_s*)item);
1321 break;
1322
1323 case MTYPE_SPINCONTROL:
1324 SpinControl_Init((menulist_s*)item);
1325 break;
1326
1327 case MTYPE_RADIOBUTTON:
1328 RadioButton_Init((menuradiobutton_s*)item);
1329 break;
1330
1331 case MTYPE_SLIDER:
1332 Slider_Init((menuslider_s*)item);
1333 break;
1334
1335 case MTYPE_BITMAP:
1336 Bitmap_Init((menubitmap_s*)item);
1337 break;
1338
1339 case MTYPE_TEXT:
1340 Text_Init((menutext_s*)item);
1341 break;
1342
1343 case MTYPE_SCROLLLIST:
1344 ScrollList_Init((menulist_s*)item);
1345 break;
1346
1347 case MTYPE_PTEXT:
1348 PText_Init((menutext_s*)item);
1349 break;
1350
1351 case MTYPE_BTEXT:
1352 BText_Init((menutext_s*)item);
1353 break;
1354
1355 default:
1356 trap_Error( va("Menu_Init: unknown type %d", itemptr->type) );
1357 }
1358 }
1359
1360 menu->nitems++;
1361 }
1362
1363 /*
1364 =================
1365 Menu_CursorMoved
1366 =================
1367 */
1368 void Menu_CursorMoved( menuframework_s *m )
1369 {
1370 void (*callback)( void *self, int notification );
1371
1372 if (m->cursor_prev == m->cursor)
1373 return;
1374
1375 if (m->cursor_prev >= 0 && m->cursor_prev < m->nitems)
1376 {
1377 callback = ((menucommon_s*)(m->items[m->cursor_prev]))->callback;
1378 if (callback)
1379 callback(m->items[m->cursor_prev],QM_LOSTFOCUS);
1380 }
1381
1382 if (m->cursor >= 0 && m->cursor < m->nitems)
1383 {
1384 callback = ((menucommon_s*)(m->items[m->cursor]))->callback;
1385 if (callback)
1386 callback(m->items[m->cursor],QM_GOTFOCUS);
1387 }
1388 }
1389
1390 /*
1391 =================
1392 Menu_SetCursor
1393 =================
1394 */
1395 void Menu_SetCursor( menuframework_s *m, int cursor )
1396 {
1397 if (((menucommon_s*)(m->items[cursor]))->flags & (QMF_GRAYED|QMF_INACTIVE))
1398 {
1399 // cursor can't go there
1400 return;
1401 }
1402
1403 m->cursor_prev = m->cursor;
1404 m->cursor = cursor;
1405
1406 Menu_CursorMoved( m );
1407 }
1408
1409 /*
1410 =================
1411 Menu_SetCursorToItem
1412 =================
1413 */
1414 void Menu_SetCursorToItem( menuframework_s *m, void* ptr )
1415 {
1416 int i;
1417
1418 for (i=0; i<m->nitems; i++)
1419 {
1420 if (m->items[i] == ptr)
1421 {
1422 Menu_SetCursor( m, i );
1423 return;
1424 }
1425 }
1426 }
1427
1428 /*
1429 ** Menu_AdjustCursor
1430 **
1431 ** This function takes the given menu, the direction, and attempts
1432 ** to adjust the menu's cursor so that it's at the next available
1433 ** slot.
1434 */
1435 void Menu_AdjustCursor( menuframework_s *m, int dir ) {
1436 menucommon_s *item = NULL;
1437 qboolean wrapped = qfalse;
1438
1439 wrap:
1440 while ( m->cursor >= 0 && m->cursor < m->nitems ) {
1441 item = ( menucommon_s * ) m->items[m->cursor];
1442 if (( item->flags & (QMF_GRAYED|QMF_MOUSEONLY|QMF_INACTIVE) ) ) {
1443 m->cursor += dir;
1444 }
1445 else {
1446 break;
1447 }
1448 }
1449
1450 if ( dir == 1 ) {
1451 if ( m->cursor >= m->nitems ) {
1452 if ( m->wrapAround ) {
1453 if ( wrapped ) {
1454 m->cursor = m->cursor_prev;
1455 return;
1456 }
1457 m->cursor = 0;
1458 wrapped = qtrue;
1459 goto wrap;
1460 }
1461 m->cursor = m->cursor_prev;
1462 }
1463 }
1464 else {
1465 if ( m->cursor < 0 ) {
1466 if ( m->wrapAround ) {
1467 if ( wrapped ) {
1468 m->cursor = m->cursor_prev;
1469 return;
1470 }
1471 m->cursor = m->nitems - 1;
1472 wrapped = qtrue;
1473 goto wrap;
1474 }
1475 m->cursor = m->cursor_prev;
1476 }
1477 }
1478 }
1479
1480 /*
1481 =================
1482 Menu_Draw
1483 =================
1484 */
1485 void Menu_Draw( menuframework_s *menu )
1486 {
1487 int i;
1488 menucommon_s *itemptr;
1489
1490 // draw menu
1491 for (i=0; i<menu->nitems; i++)
1492 {
1493 itemptr = (menucommon_s*)menu->items[i];
1494
1495 if (itemptr->flags & QMF_HIDDEN)
1496 continue;
1497
1498 if (itemptr->ownerdraw)
1499 {
1500 // total subclassing, owner draws everything
1501 itemptr->ownerdraw( itemptr );
1502 }
1503 else
1504 {
1505 switch (itemptr->type)
1506 {
1507 case MTYPE_RADIOBUTTON:
1508 RadioButton_Draw( (menuradiobutton_s*)itemptr );
1509 break;
1510
1511 case MTYPE_FIELD:
1512 MenuField_Draw( (menufield_s*)itemptr );
1513 break;
1514
1515 case MTYPE_SLIDER:
1516 Slider_Draw( (menuslider_s*)itemptr );
1517 break;
1518
1519 case MTYPE_SPINCONTROL:
1520 SpinControl_Draw( (menulist_s*)itemptr );
1521 break;
1522
1523 case MTYPE_ACTION:
1524 Action_Draw( (menuaction_s*)itemptr );
1525 break;
1526
1527 case MTYPE_BITMAP:
1528 Bitmap_Draw( (menubitmap_s*)itemptr );
1529 break;
1530
1531 case MTYPE_TEXT:
1532 Text_Draw( (menutext_s*)itemptr );
1533 break;
1534
1535 case MTYPE_SCROLLLIST:
1536 ScrollList_Draw( (menulist_s*)itemptr );
1537 break;
1538
1539 case MTYPE_PTEXT:
1540 PText_Draw( (menutext_s*)itemptr );
1541 break;
1542
1543 case MTYPE_BTEXT:
1544 BText_Draw( (menutext_s*)itemptr );
1545 break;
1546
1547 default:
1548 trap_Error( va("Menu_Draw: unknown type %d", itemptr->type) );
1549 }
1550 }
1551 #ifndef NDEBUG
1552 if( uis.debug ) {
1553 int x;
1554 int y;
1555 int w;
1556 int h;
1557
1558 if( !( itemptr->flags & QMF_INACTIVE ) ) {
1559 x = itemptr->left;
1560 y = itemptr->top;
1561 w = itemptr->right - itemptr->left + 1;
1562 h = itemptr->bottom - itemptr->top + 1;
1563
1564 if (itemptr->flags & QMF_HASMOUSEFOCUS) {
1565 UI_DrawRect(x, y, w, h, colorYellow );
1566 }
1567 else {
1568 UI_DrawRect(x, y, w, h, colorWhite );
1569 }
1570 }
1571 }
1572 #endif
1573 }
1574
1575 itemptr = Menu_ItemAtCursor( menu );
1576 if ( itemptr && itemptr->statusbar)
1577 itemptr->statusbar( ( void * ) itemptr );
1578 }
1579
1580 /*
1581 =================
1582 Menu_ItemAtCursor
1583 =================
1584 */
1585 void *Menu_ItemAtCursor( menuframework_s *m )
1586 {
1587 if ( m->cursor < 0 || m->cursor >= m->nitems )
1588 return NULL;
1589
1590 return m->items[m->cursor];
1591 }
1592
1593 /*
1594 =================
1595 Menu_ActivateItem
1596 =================
1597 */
1598 sfxHandle_t Menu_ActivateItem( menuframework_s *s, menucommon_s* item ) {
1599 if ( item->callback ) {
1600 item->callback( item, QM_ACTIVATED );
1601 if( !( item->flags & QMF_SILENT ) ) {
1602 return menu_move_sound;
1603 }
1604 }
1605
1606 return 0;
1607 }
1608
1609 /*
1610 =================
1611 Menu_DefaultKey
1612 =================
1613 */
1614 sfxHandle_t Menu_DefaultKey( menuframework_s *m, int key )
1615 {
1616 sfxHandle_t sound = 0;
1617 menucommon_s *item;
1618 int cursor_prev;
1619
1620 // menu system keys
1621 switch ( key )
1622 {
1623 case K_MOUSE2:
1624 case K_ESCAPE:
1625 UI_PopMenu();
1626 return menu_out_sound;
1627 }
1628
1629 if (!m || !m->nitems)
1630 return 0;
1631
1632 // route key stimulus to widget
1633 item = Menu_ItemAtCursor( m );
1634 if (item && !(item->flags & (QMF_GRAYED|QMF_INACTIVE)))
1635 {
1636 switch (item->type)
1637 {
1638 case MTYPE_SPINCONTROL:
1639 sound = SpinControl_Key( (menulist_s*)item, key );
1640 break;
1641
1642 case MTYPE_RADIOBUTTON:
1643 sound = RadioButton_Key( (menuradiobutton_s*)item, key );
1644 break;
1645
1646 case MTYPE_SLIDER:
1647 sound = Slider_Key( (menuslider_s*)item, key );
1648 break;
1649
1650 case MTYPE_SCROLLLIST:
1651 sound = ScrollList_Key( (menulist_s*)item, key );
1652 break;
1653
1654 case MTYPE_FIELD:
1655 sound = MenuField_Key( (menufield_s*)item, &key );
1656 break;
1657 }
1658
1659 if (sound) {
1660 // key was handled
1661 return sound;
1662 }
1663 }
1664
1665 // default handling
1666 switch ( key )
1667 {
1668 #ifndef NDEBUG
1669 case K_F11:
1670 uis.debug ^= 1;
1671 break;
1672
1673 case K_F12:
1674 trap_Cmd_ExecuteText(EXEC_APPEND, "screenshot\n");
1675 break;
1676 #endif
1677 case K_KP_UPARROW:
1678 case K_UPARROW:
1679 cursor_prev = m->cursor;
1680 m->cursor_prev = m->cursor;
1681 m->cursor--;
1682 Menu_AdjustCursor( m, -1 );
1683 if ( cursor_prev != m->cursor ) {
1684 Menu_CursorMoved( m );
1685 sound = menu_move_sound;
1686 }
1687 break;
1688
1689 case K_TAB:
1690 case K_KP_DOWNARROW:
1691 case K_DOWNARROW:
1692 cursor_prev = m->cursor;
1693 m->cursor_prev = m->cursor;
1694 m->cursor++;
1695 Menu_AdjustCursor( m, 1 );
1696 if ( cursor_prev != m->cursor ) {
1697 Menu_CursorMoved( m );
1698 sound = menu_move_sound;
1699 }
1700 break;
1701
1702 case K_MOUSE1:
1703 case K_MOUSE3:
1704 if (item)
1705 if ((item->flags & QMF_HASMOUSEFOCUS) && !(item->flags & (QMF_GRAYED|QMF_INACTIVE)))
1706 return (Menu_ActivateItem( m, item ));
1707 break;
1708
1709 case K_JOY1:
1710 case K_JOY2:
1711 case K_JOY3:
1712 case K_JOY4:
1713 case K_AUX1:
1714 case K_AUX2:
1715 case K_AUX3:
1716 case K_AUX4:
1717 case K_AUX5:
1718 case K_AUX6:
1719 case K_AUX7:
1720 case K_AUX8:
1721 case K_AUX9:
1722 case K_AUX10:
1723 case K_AUX11:
1724 case K_AUX12:
1725 case K_AUX13:
1726 case K_AUX14:
1727 case K_AUX15:
1728 case K_AUX16:
1729 case K_KP_ENTER:
1730 case K_ENTER:
1731 if (item)
1732 if (!(item->flags & (QMF_MOUSEONLY|QMF_GRAYED|QMF_INACTIVE)))
1733 return (Menu_ActivateItem( m, item ));
1734 break;
1735 }
1736
1737 return sound;
1738 }
1739
1740 /*
1741 =================
1742 Menu_Cache
1743 =================
1744 */
1745 void Menu_Cache( void )
1746 {
1747 uis.charset = trap_R_RegisterShaderNoMip( "gfx/2d/bigchars" );
1748 uis.charsetProp = trap_R_RegisterShaderNoMip( "menu/art/font1_prop.tga" );
1749 uis.charsetPropGlow = trap_R_RegisterShaderNoMip( "menu/art/font1_prop_glo.tga" );
1750 uis.charsetPropB = trap_R_RegisterShaderNoMip( "menu/art/font2_prop.tga" );
1751 uis.cursor = trap_R_RegisterShaderNoMip( "menu/art/3_cursor2" );
1752 uis.rb_on = trap_R_RegisterShaderNoMip( "menu/art/switch_on" );
1753 uis.rb_off = trap_R_RegisterShaderNoMip( "menu/art/switch_off" );
1754
1755 uis.whiteShader = trap_R_RegisterShaderNoMip( "white" );
1756 if ( uis.glconfig.hardwareType == GLHW_RAGEPRO ) {
1757 // the blend effect turns to shit with the normal
1758 uis.menuBackShader = trap_R_RegisterShaderNoMip( "menubackRagePro" );
1759 } else {
1760 uis.menuBackShader = trap_R_RegisterShaderNoMip( "menuback" );
1761 }
1762 uis.menuBackNoLogoShader = trap_R_RegisterShaderNoMip( "menubacknologo" );
1763
1764 menu_in_sound = trap_S_RegisterSound( "sound/misc/menu1.wav", qfalse );
1765 menu_move_sound = trap_S_RegisterSound( "sound/misc/menu2.wav", qfalse );
1766 menu_out_sound = trap_S_RegisterSound( "sound/misc/menu3.wav", qfalse );
1767 menu_buzz_sound = trap_S_RegisterSound( "sound/misc/menu4.wav", qfalse );
1768 weaponChangeSound = trap_S_RegisterSound( "sound/weapons/change.wav", qfalse );
1769
1770 // need a nonzero sound, make an empty sound for this
1771 menu_null_sound = -1;
1772
1773 sliderBar = trap_R_RegisterShaderNoMip( "menu/art/slider2" );
1774 sliderButton_0 = trap_R_RegisterShaderNoMip( "menu/art/sliderbutt_0" );
1775 sliderButton_1 = trap_R_RegisterShaderNoMip( "menu/art/sliderbutt_1" );
1776 }
1777