icculus quake2 doxygen  1.0 dev
vid_menu.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 #include "../client/client.h"
21 #include "../client/qmenu.h"
22 
23 #define REF_SOFT 0
24 #define REF_OPENGL 1
25 #define REF_3DFX 2
26 #define REF_POWERVR 3
27 #define REF_VERITE 4
28 
29 extern cvar_t *vid_ref;
30 extern cvar_t *vid_fullscreen;
31 extern cvar_t *vid_gamma;
32 extern cvar_t *scr_viewsize;
33 
34 static cvar_t *gl_mode;
35 static cvar_t *gl_driver;
36 static cvar_t *gl_picmip;
38 static cvar_t *gl_finish;
39 
40 static cvar_t *sw_mode;
42 
43 extern void M_ForceMenuOff( void );
44 
45 /*
46 ====================================================================
47 
48 MENU INTERACTION
49 
50 ====================================================================
51 */
52 #define SOFTWARE_MENU 0
53 #define OPENGL_MENU 1
54 
59 
65 static menulist_s s_fs_box[2];
71 
72 static void DriverCallback( void *unused )
73 {
75 
76  if ( s_ref_list[s_current_menu_index].curvalue == 0 )
77  {
80  }
81  else
82  {
85  }
86 
87 }
88 
89 static void ScreenSizeCallback( void *s )
90 {
91  menuslider_s *slider = ( menuslider_s * ) s;
92 
93  Cvar_SetValue( "viewsize", slider->curvalue * 10 );
94 }
95 
96 static void BrightnessCallback( void *s )
97 {
98  menuslider_s *slider = ( menuslider_s * ) s;
99 
102  else
104 
105  if ( stricmp( vid_ref->string, "soft" ) == 0 )
106  {
107  float gamma = ( 0.8 - ( slider->curvalue/10.0 - 0.5 ) ) + 0.5;
108 
109  Cvar_SetValue( "vid_gamma", gamma );
110  }
111 }
112 
113 static void ResetDefaults( void *unused )
114 {
115  VID_MenuInit();
116 }
117 
118 static void ApplyChanges( void *unused )
119 {
120  float gamma;
121 
122  /*
123  ** make values consistent
124  */
128 
129  /*
130  ** invert sense so greater = brighter, and scale to a range of 0.5 to 1.3
131  */
132  gamma = ( 0.8 - ( s_brightness_slider[s_current_menu_index].curvalue/10.0 - 0.5 ) ) + 0.5;
133 
134  Cvar_SetValue( "vid_gamma", gamma );
135  Cvar_SetValue( "sw_stipplealpha", s_stipple_box.curvalue );
136  Cvar_SetValue( "gl_picmip", 3 - s_tq_slider.curvalue );
137  Cvar_SetValue( "vid_fullscreen", s_fs_box[s_current_menu_index].curvalue );
138  Cvar_SetValue( "gl_ext_palettedtexture", s_paletted_texture_box.curvalue );
139  Cvar_SetValue( "gl_finish", s_finish_box.curvalue );
140  Cvar_SetValue( "sw_mode", s_mode_list[SOFTWARE_MENU].curvalue );
141  Cvar_SetValue( "gl_mode", s_mode_list[OPENGL_MENU].curvalue );
142 
143  switch ( s_ref_list[s_current_menu_index].curvalue )
144  {
145  case REF_SOFT:
146  Cvar_Set( "vid_ref", "soft" );
147  break;
148  case REF_OPENGL:
149  Cvar_Set( "vid_ref", "gl" );
150  Cvar_Set( "gl_driver", "opengl32" );
151  break;
152  case REF_3DFX:
153  Cvar_Set( "vid_ref", "gl" );
154  Cvar_Set( "gl_driver", "3dfxgl" );
155  break;
156  case REF_POWERVR:
157  Cvar_Set( "vid_ref", "gl" );
158  Cvar_Set( "gl_driver", "pvrgl" );
159  break;
160  case REF_VERITE:
161  Cvar_Set( "vid_ref", "gl" );
162  Cvar_Set( "gl_driver", "veritegl" );
163  break;
164  }
165 
166  /*
167  ** update appropriate stuff if we're running OpenGL and gamma
168  ** has been modified
169  */
170  if ( stricmp( vid_ref->string, "gl" ) == 0 )
171  {
172  if ( vid_gamma->modified )
173  {
174  vid_ref->modified = true;
175  if ( stricmp( gl_driver->string, "3dfxgl" ) == 0 )
176  {
177  char envbuffer[1024];
178  float g;
179 
180  vid_ref->modified = true;
181 
182  g = 2.00 * ( 0.8 - ( vid_gamma->value - 0.5 ) ) + 1.0F;
183  Com_sprintf( envbuffer, sizeof(envbuffer), "SSTV2_GAMMA=%f", g );
184  putenv( envbuffer );
185  Com_sprintf( envbuffer, sizeof(envbuffer), "SST_GAMMA=%f", g );
186  putenv( envbuffer );
187 
188  vid_gamma->modified = false;
189  }
190  }
191 
192  if ( gl_driver->modified )
193  vid_ref->modified = true;
194  }
195 
196  M_ForceMenuOff();
197 }
198 
199 static void CancelChanges( void *unused )
200 {
201  extern void M_PopMenu( void );
202 
203  M_PopMenu();
204 }
205 
206 /*
207 ** VID_MenuInit
208 */
209 void VID_MenuInit( void )
210 {
211  static const char *resolutions[] =
212  {
213  "[320 240 ]",
214  "[400 300 ]",
215  "[512 384 ]",
216  "[640 480 ]",
217  "[800 600 ]",
218  "[960 720 ]",
219  "[1024 768 ]",
220  "[1152 864 ]",
221  "[1280 960 ]",
222  "[1600 1200]",
223  "[2048 1536]",
224  0
225  };
226  static const char *refs[] =
227  {
228  "[software ]",
229  "[default OpenGL]",
230  "[3Dfx OpenGL ]",
231  "[PowerVR OpenGL]",
232 // "[Rendition OpenGL]",
233  0
234  };
235  static const char *yesno_names[] =
236  {
237  "no",
238  "yes",
239  0
240  };
241  int i;
242 
243  if ( !gl_driver )
244  gl_driver = Cvar_Get( "gl_driver", "opengl32", 0 );
245  if ( !gl_picmip )
246  gl_picmip = Cvar_Get( "gl_picmip", "0", 0 );
247  if ( !gl_mode )
248  gl_mode = Cvar_Get( "gl_mode", "3", 0 );
249  if ( !sw_mode )
250  sw_mode = Cvar_Get( "sw_mode", "0", 0 );
251  if ( !gl_ext_palettedtexture )
252  gl_ext_palettedtexture = Cvar_Get( "gl_ext_palettedtexture", "1", CVAR_ARCHIVE );
253  if ( !gl_finish )
254  gl_finish = Cvar_Get( "gl_finish", "0", CVAR_ARCHIVE );
255 
256  if ( !sw_stipplealpha )
257  sw_stipplealpha = Cvar_Get( "sw_stipplealpha", "0", CVAR_ARCHIVE );
258 
261 
262  if ( !scr_viewsize )
263  scr_viewsize = Cvar_Get ("viewsize", "100", CVAR_ARCHIVE);
264 
267 
268  if ( strcmp( vid_ref->string, "soft" ) == 0 )
269  {
272  }
273  else if ( strcmp( vid_ref->string, "gl" ) == 0 )
274  {
276  if ( strcmp( gl_driver->string, "3dfxgl" ) == 0 )
278  else if ( strcmp( gl_driver->string, "pvrgl" ) == 0 )
280  else if ( strcmp( gl_driver->string, "opengl32" ) == 0 )
282  else
283 // s_ref_list[s_current_menu_index].curvalue = REF_VERITE;
285  }
286 
287  s_software_menu.x = viddef.width * 0.50;
289  s_opengl_menu.x = viddef.width * 0.50;
290  s_opengl_menu.nitems = 0;
291 
292  for ( i = 0; i < 2; i++ )
293  {
295  s_ref_list[i].generic.name = "driver";
296  s_ref_list[i].generic.x = 0;
297  s_ref_list[i].generic.y = 0;
299  s_ref_list[i].itemnames = refs;
300 
302  s_mode_list[i].generic.name = "video mode";
303  s_mode_list[i].generic.x = 0;
304  s_mode_list[i].generic.y = 10;
305  s_mode_list[i].itemnames = resolutions;
306 
310  s_screensize_slider[i].generic.name = "screen size";
314 
318  s_brightness_slider[i].generic.name = "brightness";
322  s_brightness_slider[i].curvalue = ( 1.3 - vid_gamma->value + 0.5 ) * 10;
323 
325  s_fs_box[i].generic.x = 0;
326  s_fs_box[i].generic.y = 40;
327  s_fs_box[i].generic.name = "fullscreen";
328  s_fs_box[i].itemnames = yesno_names;
330 
332  s_defaults_action[i].generic.name = "reset to defaults";
336 
338  s_cancel_action[i].generic.name = "cancel";
339  s_cancel_action[i].generic.x = 0;
340  s_cancel_action[i].generic.y = 100;
342  }
343 
345  s_stipple_box.generic.x = 0;
346  s_stipple_box.generic.y = 60;
347  s_stipple_box.generic.name = "stipple alpha";
349  s_stipple_box.itemnames = yesno_names;
350 
352  s_tq_slider.generic.x = 0;
353  s_tq_slider.generic.y = 60;
354  s_tq_slider.generic.name = "texture quality";
355  s_tq_slider.minvalue = 0;
356  s_tq_slider.maxvalue = 3;
358 
362  s_paletted_texture_box.generic.name = "8-bit textures";
363  s_paletted_texture_box.itemnames = yesno_names;
365 
367  s_finish_box.generic.x = 0;
368  s_finish_box.generic.y = 80;
369  s_finish_box.generic.name = "sync every frame";
371  s_finish_box.itemnames = yesno_names;
372 
378  Menu_AddItem( &s_software_menu, ( void * ) &s_stipple_box );
379 
385  Menu_AddItem( &s_opengl_menu, ( void * ) &s_tq_slider );
387  Menu_AddItem( &s_opengl_menu, ( void * ) &s_finish_box );
388 
393 
396  s_opengl_menu.x -= 8;
397  s_software_menu.x -= 8;
398 }
399 
400 /*
401 ================
402 VID_MenuDraw
403 ================
404 */
405 void VID_MenuDraw (void)
406 {
407  int w, h;
408 
409  if ( s_current_menu_index == 0 )
411  else
413 
414  /*
415  ** draw the banner
416  */
417  re.DrawGetPicSize( &w, &h, "m_banner_video" );
418  re.DrawPic( viddef.width / 2 - w / 2, viddef.height /2 - 110, "m_banner_video" );
419 
420  /*
421  ** move cursor to a reasonable starting position
422  */
424 
425  /*
426  ** draw the menu
427  */
429 }
430 
431 /*
432 ================
433 VID_MenuKey
434 ================
435 */
436 const char *VID_MenuKey( int key )
437 {
439  static const char *sound = "misc/menu1.wav";
440 
441  switch ( key )
442  {
443  case K_ESCAPE:
444  ApplyChanges( 0 );
445  return NULL;
446  case K_KP_UPARROW:
447  case K_UPARROW:
448  m->cursor--;
449  Menu_AdjustCursor( m, -1 );
450  break;
451  case K_KP_DOWNARROW:
452  case K_DOWNARROW:
453  m->cursor++;
454  Menu_AdjustCursor( m, 1 );
455  break;
456  case K_KP_LEFTARROW:
457  case K_LEFTARROW:
458  Menu_SlideItem( m, -1 );
459  break;
460  case K_KP_RIGHTARROW:
461  case K_RIGHTARROW:
462  Menu_SlideItem( m, 1 );
463  break;
464  case K_KP_ENTER:
465  case K_ENTER:
466  if ( !Menu_SelectItem( m ) )
467  ApplyChanges( NULL );
468  break;
469  }
470 
471  return sound;
472 }
473 
474 
REF_SOFT
#define REF_SOFT
Definition: vid_menu.c:23
K_DOWNARROW
@ K_DOWNARROW
Definition: keys.h:34
REF_OPENGL
#define REF_OPENGL
Definition: vid_menu.c:24
K_KP_UPARROW
@ K_KP_UPARROW
Definition: keys.h:61
menucommon_s::type
int type
Definition: qmenu.h:66
gl_driver
static cvar_t * gl_driver
Definition: vid_menu.c:35
cvar_s::modified
qboolean modified
Definition: q_shared.h:323
menuslider_s::generic
menucommon_s generic
Definition: qmenu.h:95
s_fs_box
static menulist_s s_fs_box[2]
Definition: vid_menu.c:65
SOFTWARE_MENU
#define SOFTWARE_MENU
Definition: vid_menu.c:52
s_paletted_texture_box
static menulist_s s_paletted_texture_box
Definition: vid_menu.c:67
cvar_s::string
char * string
Definition: q_shared.h:320
viddef_t::width
int width
Definition: vid.h:29
i
int i
Definition: q_shared.c:305
K_KP_LEFTARROW
@ K_KP_LEFTARROW
Definition: keys.h:63
scr_viewsize
cvar_t * scr_viewsize
Definition: cl_scrn.c:47
menucommon_s::x
int x
Definition: qmenu.h:68
REF_VERITE
#define REF_VERITE
Definition: vid_menu.c:27
viddef_t::height
int height
Definition: vid.h:29
vid_gamma
cvar_t * vid_gamma
Definition: vid_dll.c:42
menuaction_s::generic
menucommon_s generic
Definition: qmenu.h:115
Cvar_Get
cvar_t * Cvar_Get(char *var_name, char *var_value, int flags)
Definition: cvar.c:127
Menu_Center
void Menu_Center(menuframework_s *menu)
Definition: qmenu.c:340
cvar_s
Definition: q_shared.h:317
K_ENTER
@ K_ENTER
Definition: keys.h:26
menuslider_s::minvalue
float minvalue
Definition: qmenu.h:97
viddef
viddef_t viddef
Definition: vid_dll.c:49
vid_fullscreen
cvar_t * vid_fullscreen
Definition: vid_dll.c:46
s_ref_list
static menulist_s s_ref_list[2]
Definition: vid_menu.c:61
DriverCallback
static void DriverCallback(void *unused)
Definition: vid_menu.c:72
K_LEFTARROW
@ K_LEFTARROW
Definition: keys.h:35
K_ESCAPE
@ K_ESCAPE
Definition: keys.h:27
Menu_Draw
void Menu_Draw(menuframework_s *menu)
Definition: qmenu.c:350
menucommon_s::y
int y
Definition: qmenu.h:68
menulist_s
Definition: qmenu.h:104
s_mode_list
static menulist_s s_mode_list[2]
Definition: vid_menu.c:60
Menu_SelectItem
qboolean Menu_SelectItem(menuframework_s *s)
Definition: qmenu.c:486
gl_mode
static cvar_t * gl_mode
Definition: vid_menu.c:34
M_PopMenu
void M_PopMenu(void)
Definition: menu.c:127
Menu_AdjustCursor
void Menu_AdjustCursor(menuframework_s *m, int dir)
Definition: qmenu.c:292
K_KP_RIGHTARROW
@ K_KP_RIGHTARROW
Definition: keys.h:65
menucommon_s::callback
void(* callback)(void *self)
Definition: qmenu.h:76
gl_picmip
static cvar_t * gl_picmip
Definition: vid_menu.c:36
s_stipple_box
static menulist_s s_stipple_box
Definition: vid_menu.c:66
menuslider_s::maxvalue
float maxvalue
Definition: qmenu.h:98
CVAR_ARCHIVE
#define CVAR_ARCHIVE
Definition: q_shared.h:309
_tag_menuframework::cursor
int cursor
Definition: qmenu.h:52
s_tq_slider
static menuslider_s s_tq_slider
Definition: vid_menu.c:62
cvar_s::value
float value
Definition: q_shared.h:324
VID_MenuDraw
void VID_MenuDraw(void)
Definition: vid_menu.c:405
Cvar_SetValue
void Cvar_SetValue(char *var_name, float value)
Definition: cvar.c:317
NULL
#define NULL
Definition: q_shared.h:60
refexport_t::DrawGetPicSize
void(* DrawGetPicSize)(int *w, int *h, char *name)
Definition: ref.h:195
s_current_menu_index
static int s_current_menu_index
Definition: vid_menu.c:58
s_brightness_slider
static menuslider_s s_brightness_slider[2]
Definition: vid_menu.c:64
BrightnessCallback
static void BrightnessCallback(void *s)
Definition: vid_menu.c:96
MTYPE_ACTION
#define MTYPE_ACTION
Definition: qmenu.h:27
CancelChanges
static void CancelChanges(void *unused)
Definition: vid_menu.c:199
menuaction_s
Definition: qmenu.h:113
refexport_t::DrawPic
void(* DrawPic)(int x, int y, char *name)
Definition: ref.h:196
K_KP_ENTER
@ K_KP_ENTER
Definition: keys.h:69
ApplyChanges
static void ApplyChanges(void *unused)
Definition: vid_menu.c:118
_tag_menuframework
Definition: qmenu.h:49
_tag_menuframework::nitems
int nitems
Definition: qmenu.h:54
menulist_s::curvalue
int curvalue
Definition: qmenu.h:108
REF_POWERVR
#define REF_POWERVR
Definition: vid_menu.c:26
gl_finish
static cvar_t * gl_finish
Definition: vid_menu.c:38
re
refexport_t re
Definition: vid_dll.c:31
VID_MenuInit
void VID_MenuInit(void)
Definition: vid_menu.c:209
s_finish_box
static menulist_s s_finish_box
Definition: vid_menu.c:68
MTYPE_SLIDER
#define MTYPE_SLIDER
Definition: qmenu.h:25
ResetDefaults
static void ResetDefaults(void *unused)
Definition: vid_menu.c:113
s_software_menu
static menuframework_s s_software_menu
Definition: vid_menu.c:55
_tag_menuframework::x
int x
Definition: qmenu.h:51
menuslider_s::curvalue
float curvalue
Definition: qmenu.h:99
menuslider_s
Definition: qmenu.h:93
s_opengl_menu
static menuframework_s s_opengl_menu
Definition: vid_menu.c:56
menucommon_s::name
const char * name
Definition: qmenu.h:67
K_UPARROW
@ K_UPARROW
Definition: keys.h:33
s_current_menu
static menuframework_s * s_current_menu
Definition: vid_menu.c:57
menulist_s::itemnames
const char ** itemnames
Definition: qmenu.h:110
MTYPE_SPINCONTROL
#define MTYPE_SPINCONTROL
Definition: qmenu.h:28
gl_ext_palettedtexture
static cvar_t * gl_ext_palettedtexture
Definition: vid_menu.c:37
Menu_SlideItem
void Menu_SlideItem(menuframework_s *s, int dir)
Definition: qmenu.c:515
Cvar_Set
cvar_t * Cvar_Set(char *var_name, char *value)
Definition: cvar.c:278
vid_ref
cvar_t * vid_ref
Definition: vid_dll.c:43
s_cancel_action
static menuaction_s s_cancel_action[2]
Definition: vid_menu.c:69
w
GLdouble GLdouble GLdouble w
Definition: qgl_win.c:291
sw_stipplealpha
static cvar_t * sw_stipplealpha
Definition: vid_menu.c:41
OPENGL_MENU
#define OPENGL_MENU
Definition: vid_menu.c:53
K_RIGHTARROW
@ K_RIGHTARROW
Definition: keys.h:36
REF_3DFX
#define REF_3DFX
Definition: vid_menu.c:25
s_defaults_action
static menuaction_s s_defaults_action[2]
Definition: vid_menu.c:70
s_screensize_slider
static menuslider_s s_screensize_slider[2]
Definition: vid_menu.c:63
menulist_s::generic
menucommon_s generic
Definition: qmenu.h:106
Menu_AddItem
void Menu_AddItem(menuframework_s *menu, void *item)
Definition: qmenu.c:270
M_ForceMenuOff
void M_ForceMenuOff(void)
Definition: menu.c:117
ScreenSizeCallback
static void ScreenSizeCallback(void *s)
Definition: vid_menu.c:89
K_KP_DOWNARROW
@ K_KP_DOWNARROW
Definition: keys.h:67
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236
sw_mode
static cvar_t * sw_mode
Definition: vid_menu.c:40
VID_MenuKey
const char * VID_MenuKey(int key)
Definition: vid_menu.c:436