vid_menu.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "../client/client.h"
  16. #include "../client/qmenu.h"
  17. #define REF_SOFT 0
  18. #define REF_OPENGL 1
  19. #define REF_3DFX 2
  20. #define REF_POWERVR 3
  21. #define REF_VERITE 4
  22. extern cvar_t *vid_ref;
  23. extern cvar_t *vid_fullscreen;
  24. extern cvar_t *vid_gamma;
  25. extern cvar_t *scr_viewsize;
  26. static cvar_t *gl_mode;
  27. static cvar_t *gl_driver;
  28. static cvar_t *gl_picmip;
  29. static cvar_t *gl_ext_palettedtexture;
  30. static cvar_t *gl_finish;
  31. static cvar_t *sw_mode;
  32. static cvar_t *sw_stipplealpha;
  33. extern void M_ForceMenuOff( void );
  34. /*
  35. ====================================================================
  36. MENU INTERACTION
  37. ====================================================================
  38. */
  39. #define SOFTWARE_MENU 0
  40. #define OPENGL_MENU 1
  41. static menuframework_s s_software_menu;
  42. static menuframework_s s_opengl_menu;
  43. static menuframework_s *s_current_menu;
  44. static int s_current_menu_index;
  45. static menulist_s s_mode_list[2];
  46. static menulist_s s_ref_list[2];
  47. static menuslider_s s_tq_slider;
  48. static menuslider_s s_screensize_slider[2];
  49. static menuslider_s s_brightness_slider[2];
  50. static menulist_s s_fs_box[2];
  51. static menulist_s s_stipple_box;
  52. static menulist_s s_paletted_texture_box;
  53. static menulist_s s_finish_box;
  54. static menuaction_s s_cancel_action[2];
  55. static menuaction_s s_defaults_action[2];
  56. static void DriverCallback( void *unused )
  57. {
  58. s_ref_list[!s_current_menu_index].curvalue = s_ref_list[s_current_menu_index].curvalue;
  59. if ( s_ref_list[s_current_menu_index].curvalue == 0 )
  60. {
  61. s_current_menu = &s_software_menu;
  62. s_current_menu_index = 0;
  63. }
  64. else
  65. {
  66. s_current_menu = &s_opengl_menu;
  67. s_current_menu_index = 1;
  68. }
  69. }
  70. static void ScreenSizeCallback( void *s )
  71. {
  72. menuslider_s *slider = ( menuslider_s * ) s;
  73. Cvar_SetValue( "viewsize", slider->curvalue * 10 );
  74. }
  75. static void BrightnessCallback( void *s )
  76. {
  77. menuslider_s *slider = ( menuslider_s * ) s;
  78. if ( s_current_menu_index == SOFTWARE_MENU )
  79. s_brightness_slider[1].curvalue = s_brightness_slider[0].curvalue;
  80. else
  81. s_brightness_slider[0].curvalue = s_brightness_slider[1].curvalue;
  82. if ( stricmp( vid_ref->string, "soft" ) == 0 )
  83. {
  84. float gamma = ( 0.8 - ( slider->curvalue/10.0 - 0.5 ) ) + 0.5;
  85. Cvar_SetValue( "vid_gamma", gamma );
  86. }
  87. }
  88. static void ResetDefaults( void *unused )
  89. {
  90. VID_MenuInit();
  91. }
  92. static void ApplyChanges( void *unused )
  93. {
  94. float gamma;
  95. /*
  96. ** make values consistent
  97. */
  98. s_fs_box[!s_current_menu_index].curvalue = s_fs_box[s_current_menu_index].curvalue;
  99. s_brightness_slider[!s_current_menu_index].curvalue = s_brightness_slider[s_current_menu_index].curvalue;
  100. s_ref_list[!s_current_menu_index].curvalue = s_ref_list[s_current_menu_index].curvalue;
  101. /*
  102. ** invert sense so greater = brighter, and scale to a range of 0.5 to 1.3
  103. */
  104. gamma = ( 0.8 - ( s_brightness_slider[s_current_menu_index].curvalue/10.0 - 0.5 ) ) + 0.5;
  105. Cvar_SetValue( "vid_gamma", gamma );
  106. Cvar_SetValue( "sw_stipplealpha", s_stipple_box.curvalue );
  107. Cvar_SetValue( "gl_picmip", 3 - s_tq_slider.curvalue );
  108. Cvar_SetValue( "vid_fullscreen", s_fs_box[s_current_menu_index].curvalue );
  109. Cvar_SetValue( "gl_ext_palettedtexture", s_paletted_texture_box.curvalue );
  110. Cvar_SetValue( "gl_finish", s_finish_box.curvalue );
  111. Cvar_SetValue( "sw_mode", s_mode_list[SOFTWARE_MENU].curvalue );
  112. Cvar_SetValue( "gl_mode", s_mode_list[OPENGL_MENU].curvalue );
  113. switch ( s_ref_list[s_current_menu_index].curvalue )
  114. {
  115. case REF_SOFT:
  116. Cvar_Set( "vid_ref", "soft" );
  117. break;
  118. case REF_OPENGL:
  119. Cvar_Set( "vid_ref", "gl" );
  120. Cvar_Set( "gl_driver", "opengl32" );
  121. break;
  122. case REF_3DFX:
  123. Cvar_Set( "vid_ref", "gl" );
  124. Cvar_Set( "gl_driver", "3dfxgl" );
  125. break;
  126. case REF_POWERVR:
  127. Cvar_Set( "vid_ref", "gl" );
  128. Cvar_Set( "gl_driver", "pvrgl" );
  129. break;
  130. case REF_VERITE:
  131. Cvar_Set( "vid_ref", "gl" );
  132. Cvar_Set( "gl_driver", "veritegl" );
  133. break;
  134. }
  135. /*
  136. ** update appropriate stuff if we're running OpenGL and gamma
  137. ** has been modified
  138. */
  139. if ( stricmp( vid_ref->string, "gl" ) == 0 )
  140. {
  141. if ( vid_gamma->modified )
  142. {
  143. vid_ref->modified = true;
  144. if ( stricmp( gl_driver->string, "3dfxgl" ) == 0 )
  145. {
  146. char envbuffer[1024];
  147. float g;
  148. vid_ref->modified = true;
  149. g = 2.00 * ( 0.8 - ( vid_gamma->value - 0.5 ) ) + 1.0F;
  150. Com_sprintf( envbuffer, sizeof(envbuffer), "SSTV2_GAMMA=%f", g );
  151. putenv( envbuffer );
  152. Com_sprintf( envbuffer, sizeof(envbuffer), "SST_GAMMA=%f", g );
  153. putenv( envbuffer );
  154. vid_gamma->modified = false;
  155. }
  156. }
  157. if ( gl_driver->modified )
  158. vid_ref->modified = true;
  159. }
  160. M_ForceMenuOff();
  161. }
  162. static void CancelChanges( void *unused )
  163. {
  164. extern void M_PopMenu( void );
  165. M_PopMenu();
  166. }
  167. /*
  168. ** VID_MenuInit
  169. */
  170. void VID_MenuInit( void )
  171. {
  172. static const char *resolutions[] =
  173. {
  174. "[320 240 ]",
  175. "[400 300 ]",
  176. "[512 384 ]",
  177. "[640 480 ]",
  178. "[800 600 ]",
  179. "[960 720 ]",
  180. "[1024 768 ]",
  181. "[1152 864 ]",
  182. "[1280 960 ]",
  183. "[1600 1200]",
  184. 0
  185. };
  186. static const char *refs[] =
  187. {
  188. "[software ]",
  189. "[default OpenGL]",
  190. "[3Dfx OpenGL ]",
  191. "[PowerVR OpenGL]",
  192. // "[Rendition OpenGL]",
  193. 0
  194. };
  195. static const char *yesno_names[] =
  196. {
  197. "no",
  198. "yes",
  199. 0
  200. };
  201. int i;
  202. if ( !gl_driver )
  203. gl_driver = Cvar_Get( "gl_driver", "opengl32", 0 );
  204. if ( !gl_picmip )
  205. gl_picmip = Cvar_Get( "gl_picmip", "0", 0 );
  206. if ( !gl_mode )
  207. gl_mode = Cvar_Get( "gl_mode", "3", 0 );
  208. if ( !sw_mode )
  209. sw_mode = Cvar_Get( "sw_mode", "0", 0 );
  210. if ( !gl_ext_palettedtexture )
  211. gl_ext_palettedtexture = Cvar_Get( "gl_ext_palettedtexture", "1", CVAR_ARCHIVE );
  212. if ( !gl_finish )
  213. gl_finish = Cvar_Get( "gl_finish", "0", CVAR_ARCHIVE );
  214. if ( !sw_stipplealpha )
  215. sw_stipplealpha = Cvar_Get( "sw_stipplealpha", "0", CVAR_ARCHIVE );
  216. s_mode_list[SOFTWARE_MENU].curvalue = sw_mode->value;
  217. s_mode_list[OPENGL_MENU].curvalue = gl_mode->value;
  218. if ( !scr_viewsize )
  219. scr_viewsize = Cvar_Get ("viewsize", "100", CVAR_ARCHIVE);
  220. s_screensize_slider[SOFTWARE_MENU].curvalue = scr_viewsize->value/10;
  221. s_screensize_slider[OPENGL_MENU].curvalue = scr_viewsize->value/10;
  222. if ( strcmp( vid_ref->string, "soft" ) == 0 )
  223. {
  224. s_current_menu_index = SOFTWARE_MENU;
  225. s_ref_list[0].curvalue = s_ref_list[1].curvalue = REF_SOFT;
  226. }
  227. else if ( strcmp( vid_ref->string, "gl" ) == 0 )
  228. {
  229. s_current_menu_index = OPENGL_MENU;
  230. if ( strcmp( gl_driver->string, "3dfxgl" ) == 0 )
  231. s_ref_list[s_current_menu_index].curvalue = REF_3DFX;
  232. else if ( strcmp( gl_driver->string, "pvrgl" ) == 0 )
  233. s_ref_list[s_current_menu_index].curvalue = REF_POWERVR;
  234. else if ( strcmp( gl_driver->string, "opengl32" ) == 0 )
  235. s_ref_list[s_current_menu_index].curvalue = REF_OPENGL;
  236. else
  237. // s_ref_list[s_current_menu_index].curvalue = REF_VERITE;
  238. s_ref_list[s_current_menu_index].curvalue = REF_OPENGL;
  239. }
  240. s_software_menu.x = viddef.width * 0.50;
  241. s_software_menu.nitems = 0;
  242. s_opengl_menu.x = viddef.width * 0.50;
  243. s_opengl_menu.nitems = 0;
  244. for ( i = 0; i < 2; i++ )
  245. {
  246. s_ref_list[i].generic.type = MTYPE_SPINCONTROL;
  247. s_ref_list[i].generic.name = "driver";
  248. s_ref_list[i].generic.x = 0;
  249. s_ref_list[i].generic.y = 0;
  250. s_ref_list[i].generic.callback = DriverCallback;
  251. s_ref_list[i].itemnames = refs;
  252. s_mode_list[i].generic.type = MTYPE_SPINCONTROL;
  253. s_mode_list[i].generic.name = "video mode";
  254. s_mode_list[i].generic.x = 0;
  255. s_mode_list[i].generic.y = 10;
  256. s_mode_list[i].itemnames = resolutions;
  257. s_screensize_slider[i].generic.type = MTYPE_SLIDER;
  258. s_screensize_slider[i].generic.x = 0;
  259. s_screensize_slider[i].generic.y = 20;
  260. s_screensize_slider[i].generic.name = "screen size";
  261. s_screensize_slider[i].minvalue = 3;
  262. s_screensize_slider[i].maxvalue = 12;
  263. s_screensize_slider[i].generic.callback = ScreenSizeCallback;
  264. s_brightness_slider[i].generic.type = MTYPE_SLIDER;
  265. s_brightness_slider[i].generic.x = 0;
  266. s_brightness_slider[i].generic.y = 30;
  267. s_brightness_slider[i].generic.name = "brightness";
  268. s_brightness_slider[i].generic.callback = BrightnessCallback;
  269. s_brightness_slider[i].minvalue = 5;
  270. s_brightness_slider[i].maxvalue = 13;
  271. s_brightness_slider[i].curvalue = ( 1.3 - vid_gamma->value + 0.5 ) * 10;
  272. s_fs_box[i].generic.type = MTYPE_SPINCONTROL;
  273. s_fs_box[i].generic.x = 0;
  274. s_fs_box[i].generic.y = 40;
  275. s_fs_box[i].generic.name = "fullscreen";
  276. s_fs_box[i].itemnames = yesno_names;
  277. s_fs_box[i].curvalue = vid_fullscreen->value;
  278. s_defaults_action[i].generic.type = MTYPE_ACTION;
  279. s_defaults_action[i].generic.name = "reset to defaults";
  280. s_defaults_action[i].generic.x = 0;
  281. s_defaults_action[i].generic.y = 90;
  282. s_defaults_action[i].generic.callback = ResetDefaults;
  283. s_cancel_action[i].generic.type = MTYPE_ACTION;
  284. s_cancel_action[i].generic.name = "cancel";
  285. s_cancel_action[i].generic.x = 0;
  286. s_cancel_action[i].generic.y = 100;
  287. s_cancel_action[i].generic.callback = CancelChanges;
  288. }
  289. s_stipple_box.generic.type = MTYPE_SPINCONTROL;
  290. s_stipple_box.generic.x = 0;
  291. s_stipple_box.generic.y = 60;
  292. s_stipple_box.generic.name = "stipple alpha";
  293. s_stipple_box.curvalue = sw_stipplealpha->value;
  294. s_stipple_box.itemnames = yesno_names;
  295. s_tq_slider.generic.type = MTYPE_SLIDER;
  296. s_tq_slider.generic.x = 0;
  297. s_tq_slider.generic.y = 60;
  298. s_tq_slider.generic.name = "texture quality";
  299. s_tq_slider.minvalue = 0;
  300. s_tq_slider.maxvalue = 3;
  301. s_tq_slider.curvalue = 3-gl_picmip->value;
  302. s_paletted_texture_box.generic.type = MTYPE_SPINCONTROL;
  303. s_paletted_texture_box.generic.x = 0;
  304. s_paletted_texture_box.generic.y = 70;
  305. s_paletted_texture_box.generic.name = "8-bit textures";
  306. s_paletted_texture_box.itemnames = yesno_names;
  307. s_paletted_texture_box.curvalue = gl_ext_palettedtexture->value;
  308. s_finish_box.generic.type = MTYPE_SPINCONTROL;
  309. s_finish_box.generic.x = 0;
  310. s_finish_box.generic.y = 80;
  311. s_finish_box.generic.name = "sync every frame";
  312. s_finish_box.curvalue = gl_finish->value;
  313. s_finish_box.itemnames = yesno_names;
  314. Menu_AddItem( &s_software_menu, ( void * ) &s_ref_list[SOFTWARE_MENU] );
  315. Menu_AddItem( &s_software_menu, ( void * ) &s_mode_list[SOFTWARE_MENU] );
  316. Menu_AddItem( &s_software_menu, ( void * ) &s_screensize_slider[SOFTWARE_MENU] );
  317. Menu_AddItem( &s_software_menu, ( void * ) &s_brightness_slider[SOFTWARE_MENU] );
  318. Menu_AddItem( &s_software_menu, ( void * ) &s_fs_box[SOFTWARE_MENU] );
  319. Menu_AddItem( &s_software_menu, ( void * ) &s_stipple_box );
  320. Menu_AddItem( &s_opengl_menu, ( void * ) &s_ref_list[OPENGL_MENU] );
  321. Menu_AddItem( &s_opengl_menu, ( void * ) &s_mode_list[OPENGL_MENU] );
  322. Menu_AddItem( &s_opengl_menu, ( void * ) &s_screensize_slider[OPENGL_MENU] );
  323. Menu_AddItem( &s_opengl_menu, ( void * ) &s_brightness_slider[OPENGL_MENU] );
  324. Menu_AddItem( &s_opengl_menu, ( void * ) &s_fs_box[OPENGL_MENU] );
  325. Menu_AddItem( &s_opengl_menu, ( void * ) &s_tq_slider );
  326. Menu_AddItem( &s_opengl_menu, ( void * ) &s_paletted_texture_box );
  327. Menu_AddItem( &s_opengl_menu, ( void * ) &s_finish_box );
  328. Menu_AddItem( &s_software_menu, ( void * ) &s_defaults_action[SOFTWARE_MENU] );
  329. Menu_AddItem( &s_software_menu, ( void * ) &s_cancel_action[SOFTWARE_MENU] );
  330. Menu_AddItem( &s_opengl_menu, ( void * ) &s_defaults_action[OPENGL_MENU] );
  331. Menu_AddItem( &s_opengl_menu, ( void * ) &s_cancel_action[OPENGL_MENU] );
  332. Menu_Center( &s_software_menu );
  333. Menu_Center( &s_opengl_menu );
  334. s_opengl_menu.x -= 8;
  335. s_software_menu.x -= 8;
  336. }
  337. /*
  338. ================
  339. VID_MenuDraw
  340. ================
  341. */
  342. void VID_MenuDraw (void)
  343. {
  344. int w, h;
  345. if ( s_current_menu_index == 0 )
  346. s_current_menu = &s_software_menu;
  347. else
  348. s_current_menu = &s_opengl_menu;
  349. /*
  350. ** draw the banner
  351. */
  352. re.DrawGetPicSize( &w, &h, "m_banner_video" );
  353. re.DrawPic( viddef.width / 2 - w / 2, viddef.height /2 - 110, "m_banner_video" );
  354. /*
  355. ** move cursor to a reasonable starting position
  356. */
  357. Menu_AdjustCursor( s_current_menu, 1 );
  358. /*
  359. ** draw the menu
  360. */
  361. Menu_Draw( s_current_menu );
  362. }
  363. /*
  364. ================
  365. VID_MenuKey
  366. ================
  367. */
  368. const char *VID_MenuKey( int key )
  369. {
  370. menuframework_s *m = s_current_menu;
  371. static const char *sound = "misc/menu1.wav";
  372. switch ( key )
  373. {
  374. case K_ESCAPE:
  375. ApplyChanges( 0 );
  376. return NULL;
  377. case K_KP_UPARROW:
  378. case K_UPARROW:
  379. m->cursor--;
  380. Menu_AdjustCursor( m, -1 );
  381. break;
  382. case K_KP_DOWNARROW:
  383. case K_DOWNARROW:
  384. m->cursor++;
  385. Menu_AdjustCursor( m, 1 );
  386. break;
  387. case K_KP_LEFTARROW:
  388. case K_LEFTARROW:
  389. Menu_SlideItem( m, -1 );
  390. break;
  391. case K_KP_RIGHTARROW:
  392. case K_RIGHTARROW:
  393. Menu_SlideItem( m, 1 );
  394. break;
  395. case K_KP_ENTER:
  396. case K_ENTER:
  397. if ( !Menu_SelectItem( m ) )
  398. ApplyChanges( NULL );
  399. break;
  400. }
  401. return sound;
  402. }