Debian Codegraph @

code/q3_ui/ui_qmenu.c

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