vid_menu.c 12 KB

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