yquake2remaster/src/client/menu/videomenu.c

568 lines
12 KiB
C
Raw Normal View History

/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This is the refresher dependend video menu. If you add a new
* refresher this menu must be altered.
*
* =======================================================================
*/
#include "../../client/header/client.h"
#include "../../client/menu/header/qmenu.h"
2013-04-21 16:44:50 +00:00
#define CUSTOM_MODE 24
extern void M_ForceMenuOff(void);
static cvar_t *gl_mode;
static cvar_t *gl_hudscale;
2014-05-04 18:47:52 +00:00
static cvar_t *fov;
extern cvar_t *scr_viewsize;
extern cvar_t *vid_gamma;
extern cvar_t *vid_fullscreen;
2014-04-12 13:03:40 +00:00
static cvar_t *gl_swapinterval;
static cvar_t *gl_anisotropic;
2014-05-04 18:47:52 +00:00
static cvar_t *gl_msaa_samples;
static menuframework_s s_opengl_menu;
static menulist_s s_mode_list;
static menulist_s s_aspect_list;
static menulist_s s_hudscale_list;
static menuslider_s s_screensize_slider;
static menuslider_s s_brightness_slider;
static menulist_s s_fs_box;
2014-04-12 13:03:40 +00:00
static menulist_s s_vsync_list;
static menulist_s s_af_list;
2014-04-16 20:47:23 +00:00
static menulist_s s_msaa_list;
static menuaction_s s_defaults_action;
2014-04-12 13:03:40 +00:00
static menuaction_s s_apply_action;
static void
2012-07-22 13:34:45 +00:00
ScreenSizeCallback(void *s)
{
2012-07-22 13:34:45 +00:00
menuslider_s *slider = (menuslider_s *)s;
2012-07-22 13:34:45 +00:00
Cvar_SetValue("viewsize", slider->curvalue * 10);
}
static void
2012-07-22 13:34:45 +00:00
BrightnessCallback(void *s)
{
2012-07-22 13:34:45 +00:00
menuslider_s *slider = (menuslider_s *)s;
2012-07-22 13:34:45 +00:00
float gamma = slider->curvalue / 10.0;
Cvar_SetValue("vid_gamma", gamma);
}
static void
AnisotropicCallback(void *s)
{
menulist_s *list = (menulist_s *)s;
if (list->curvalue == 0)
{
Cvar_SetValue("gl_anisotropic", 0);
}
else
{
Cvar_SetValue("gl_anisotropic", pow(2, list->curvalue));
}
}
static void
2012-07-22 13:34:45 +00:00
ResetDefaults(void *unused)
{
VID_MenuInit();
}
static void
2012-07-22 13:34:45 +00:00
ApplyChanges(void *unused)
{
qboolean restart = false;
2010-01-08 15:22:49 +00:00
/* custom mode */
if (s_mode_list.curvalue != CUSTOM_MODE)
2010-01-08 15:22:49 +00:00
{
/* Restarts automatically */
Cvar_SetValue("gl_mode", s_mode_list.curvalue);
2010-01-08 15:22:49 +00:00
}
else
{
/* Restarts automatically */
2012-07-22 13:34:45 +00:00
Cvar_SetValue("gl_mode", -1);
}
/* horplus */
if (s_aspect_list.curvalue == 0)
{
if (horplus->value != 1)
{
Cvar_SetValue("horplus", 1);
}
}
else
{
if (horplus->value != 0)
{
Cvar_SetValue("horplus", 0);
}
}
/* fov */
if (s_aspect_list.curvalue == 0 || s_aspect_list.curvalue == 1)
{
if (fov->value != 90)
{
/* Restarts automatically */
Cvar_SetValue("fov", 90);
}
}
else if (s_aspect_list.curvalue == 2)
{
if (fov->value != 86)
{
/* Restarts automatically */
Cvar_SetValue("fov", 86);
}
}
else if (s_aspect_list.curvalue == 3)
{
if (fov->value != 100)
{
/* Restarts automatically */
Cvar_SetValue("fov", 100);
}
}
else if (s_aspect_list.curvalue == 4)
{
if (fov->value != 106)
{
/* Restarts automatically */
Cvar_SetValue("fov", 106);
}
}
/* HUD scaling */
if (s_hudscale_list.curvalue == 0)
{
Cvar_SetValue("gl_hudscale", 1);
}
else if (s_hudscale_list.curvalue == 1)
{
Cvar_SetValue("gl_hudscale", -1);
}
else if (s_hudscale_list.curvalue == 2)
{
Cvar_SetValue("gl_hudscale", 1.5);
}
else if (s_hudscale_list.curvalue == 3)
{
Cvar_SetValue("gl_hudscale", 2);
}
else if (s_hudscale_list.curvalue == 4)
{
Cvar_SetValue("gl_hudscale", 2.5);
}
else if (s_hudscale_list.curvalue == 5)
{
Cvar_SetValue("gl_hudscale", 3);
}
/* Restarts automatically */
Cvar_SetValue("vid_fullscreen", s_fs_box.curvalue);
/* vertical sync */
if (gl_swapinterval->value != s_vsync_list.curvalue)
{
Cvar_SetValue("gl_swapinterval", s_vsync_list.curvalue);
restart = true;
}
/* multisample anti-aliasing */
if (s_msaa_list.curvalue == 0)
{
if (gl_msaa_samples->value != 0)
{
Cvar_SetValue("gl_msaa_samples", 0);
restart = true;
}
}
else
{
if (gl_msaa_samples->value != pow(2, s_msaa_list.curvalue))
{
Cvar_SetValue("gl_msaa_samples", pow(2, s_msaa_list.curvalue));
restart = true;
}
}
if (restart)
{
Cbuf_AddText("vid_restart\n");
}
2012-08-02 13:33:42 +00:00
M_ForceMenuOff();
}
void
2012-07-22 13:34:45 +00:00
VID_MenuInit(void)
{
int y = 0;
static const char *resolutions[] = {
"[320 240 ]",
"[400 300 ]",
"[512 384 ]",
"[640 400 ]",
"[640 480 ]",
"[800 500 ]",
"[800 600 ]",
"[960 720 ]",
"[1024 480 ]",
"[1024 640 ]",
"[1024 768 ]",
"[1152 768 ]",
"[1152 864 ]",
"[1280 800 ]",
"[1280 854 ]",
"[1280 960 ]",
"[1280 1024]",
"[1366 768 ]",
2011-10-10 08:37:35 +00:00
"[1440 900 ]",
"[1600 1200]",
"[1680 1050]",
2011-10-10 08:37:35 +00:00
"[1920 1080]",
"[1920 1200]",
"[2048 1536]",
"[custom ]",
0
};
static const char *aspect_names[] = {
"auto",
"4:3",
"5:4",
"16:10",
"16:9",
"custom",
2012-08-02 18:12:19 +00:00
0
};
static const char *hudscale_names[] = {
"no (1x)",
"auto",
"1.5x",
"2x",
"2.5x",
"3.0x",
"custom",
0
};
static const char *yesno_names[] = {
"no",
"yes",
0
};
static const char *pow2_names[] = {
2014-04-16 20:47:23 +00:00
"off",
"2x",
"4x",
"8x",
"16x",
2014-04-16 20:47:23 +00:00
0
};
if (!gl_mode)
{
gl_mode = Cvar_Get("gl_mode", "4", 0);
}
if (!gl_hudscale)
{
gl_hudscale = Cvar_Get("gl_hudscale", "-1", CVAR_ARCHIVE);
}
if (!horplus)
{
horplus = Cvar_Get("horplus", "1", CVAR_ARCHIVE);
}
if (!fov)
{
fov = Cvar_Get("fov", "90", CVAR_USERINFO | CVAR_ARCHIVE);
}
if (!scr_viewsize)
{
scr_viewsize = Cvar_Get("viewsize", "100", CVAR_ARCHIVE);
}
if (!vid_gamma)
{
vid_gamma = Cvar_Get("vid_gamma", "1.0", CVAR_ARCHIVE);
}
2014-04-12 13:03:40 +00:00
if (!gl_swapinterval)
{
gl_swapinterval = Cvar_Get("gl_swapinterval", "1", CVAR_ARCHIVE);
}
if (!gl_anisotropic)
{
gl_anisotropic = Cvar_Get("gl_anisotropic", "0", CVAR_ARCHIVE);
}
2014-04-16 20:47:23 +00:00
if (!gl_msaa_samples)
{
gl_msaa_samples = Cvar_Get("gl_msaa_samples", "0", CVAR_ARCHIVE);
}
s_opengl_menu.x = viddef.width * 0.50;
s_opengl_menu.nitems = 0;
s_mode_list.generic.type = MTYPE_SPINCONTROL;
s_mode_list.generic.name = "video mode";
s_mode_list.generic.x = 0;
s_mode_list.generic.y = (y = 0);
s_mode_list.itemnames = resolutions;
if (gl_mode->value >= 0)
{
s_mode_list.curvalue = gl_mode->value;
}
else
{
s_mode_list.curvalue = CUSTOM_MODE;
}
s_aspect_list.generic.type = MTYPE_SPINCONTROL;
s_aspect_list.generic.name = "aspect ratio";
s_aspect_list.generic.x = 0;
s_aspect_list.generic.y = (y += 10);
s_aspect_list.itemnames = aspect_names;
if (horplus->value == 1)
{
s_aspect_list.curvalue = 0;
}
else if (fov->value == 90)
{
s_aspect_list.curvalue = 1;
}
else if (fov->value == 86)
{
s_aspect_list.curvalue = 2;
}
else if (fov->value == 100)
{
s_aspect_list.curvalue = 3;
}
else if (fov->value == 106)
{
s_aspect_list.curvalue = 4;
}
else
{
s_aspect_list.curvalue = 5;
}
s_hudscale_list.generic.type = MTYPE_SPINCONTROL;
s_hudscale_list.generic.name = "hud scale";
s_hudscale_list.generic.x = 0;
s_hudscale_list.generic.y = (y += 10);
s_hudscale_list.itemnames = hudscale_names;
if (gl_hudscale->value == 1)
{
s_hudscale_list.curvalue = 0;
}
else if (gl_hudscale->value < 0)
{
s_hudscale_list.curvalue = 1;
}
else if (gl_hudscale->value == 1.5f)
{
s_hudscale_list.curvalue = 2;
}
else if (gl_hudscale->value == 2)
{
s_hudscale_list.curvalue = 3;
}
else if (gl_hudscale->value == 2.5f)
{
s_hudscale_list.curvalue = 4;
}
else if (gl_hudscale->value == 3)
{
s_hudscale_list.curvalue = 5;
}
else
{
s_hudscale_list.curvalue = 6;
}
s_screensize_slider.generic.type = MTYPE_SLIDER;
s_screensize_slider.generic.name = "screen size";
s_screensize_slider.generic.x = 0;
s_screensize_slider.generic.y = (y += 10);
s_screensize_slider.minvalue = 4;
s_screensize_slider.maxvalue = 10;
s_screensize_slider.generic.callback = ScreenSizeCallback;
2012-08-02 13:33:42 +00:00
s_screensize_slider.curvalue = scr_viewsize->value / 10;
s_brightness_slider.generic.type = MTYPE_SLIDER;
s_brightness_slider.generic.name = "brightness";
s_brightness_slider.generic.x = 0;
s_brightness_slider.generic.y = (y += 10);
s_brightness_slider.generic.callback = BrightnessCallback;
s_brightness_slider.minvalue = 1;
s_brightness_slider.maxvalue = 20;
s_brightness_slider.curvalue = vid_gamma->value * 10;
s_fs_box.generic.type = MTYPE_SPINCONTROL;
s_fs_box.generic.name = "fullscreen";
s_fs_box.generic.x = 0;
s_fs_box.generic.y = (y += 10);
s_fs_box.itemnames = yesno_names;
s_fs_box.curvalue = (vid_fullscreen->value != 0);
2014-04-12 13:03:40 +00:00
s_vsync_list.generic.type = MTYPE_SPINCONTROL;
s_vsync_list.generic.name = "vertical sync";
s_vsync_list.generic.x = 0;
s_vsync_list.generic.y = (y += 10);
2014-04-12 13:03:40 +00:00
s_vsync_list.itemnames = yesno_names;
s_vsync_list.curvalue = (gl_swapinterval->value != 0);
s_af_list.generic.type = MTYPE_SPINCONTROL;
s_af_list.generic.name = "aniso filtering";
s_af_list.generic.x = 0;
s_af_list.generic.y = (y += 20);
s_af_list.generic.callback = AnisotropicCallback;
s_af_list.itemnames = pow2_names;
s_af_list.curvalue = 0;
if (gl_anisotropic->value)
{
do
{
s_af_list.curvalue++;
} while (pow2_names[s_af_list.curvalue] &&
pow(2, s_af_list.curvalue) <= gl_anisotropic->value);
s_af_list.curvalue--;
}
2014-04-16 20:47:23 +00:00
s_msaa_list.generic.type = MTYPE_SPINCONTROL;
s_msaa_list.generic.name = "multisampling";
s_msaa_list.generic.x = 0;
s_msaa_list.generic.y = (y += 10);
s_msaa_list.itemnames = pow2_names;
2014-04-16 20:47:23 +00:00
s_msaa_list.curvalue = 0;
if (gl_msaa_samples->value)
2014-04-16 20:47:23 +00:00
{
do
{
s_msaa_list.curvalue++;
} while (pow2_names[s_msaa_list.curvalue] &&
pow(2, s_msaa_list.curvalue) <= gl_msaa_samples->value);
s_msaa_list.curvalue--;
2014-04-16 20:47:23 +00:00
}
s_defaults_action.generic.type = MTYPE_ACTION;
s_defaults_action.generic.name = "reset to default";
s_defaults_action.generic.x = 0;
s_defaults_action.generic.y = (y += 20);
s_defaults_action.generic.callback = ResetDefaults;
s_apply_action.generic.type = MTYPE_ACTION;
s_apply_action.generic.name = "apply";
s_apply_action.generic.x = 0;
s_apply_action.generic.y = (y += 10);
s_apply_action.generic.callback = ApplyChanges;
Menu_AddItem(&s_opengl_menu, (void *)&s_mode_list);
Menu_AddItem(&s_opengl_menu, (void *)&s_aspect_list);
Menu_AddItem(&s_opengl_menu, (void *)&s_hudscale_list);
Menu_AddItem(&s_opengl_menu, (void *)&s_screensize_slider);
Menu_AddItem(&s_opengl_menu, (void *)&s_brightness_slider);
Menu_AddItem(&s_opengl_menu, (void *)&s_fs_box);
2014-04-12 13:03:40 +00:00
Menu_AddItem(&s_opengl_menu, (void *)&s_vsync_list);
Menu_AddItem(&s_opengl_menu, (void *)&s_af_list);
2014-04-16 20:47:23 +00:00
Menu_AddItem(&s_opengl_menu, (void *)&s_msaa_list);
Menu_AddItem(&s_opengl_menu, (void *)&s_defaults_action);
Menu_AddItem(&s_opengl_menu, (void *)&s_apply_action);
2012-07-22 13:34:45 +00:00
Menu_Center(&s_opengl_menu);
s_opengl_menu.x -= 8;
}
void
2012-07-22 13:34:45 +00:00
VID_MenuDraw(void)
{
int w, h;
float scale = SCR_GetMenuScale();
/* draw the banner */
Draw_GetPicSize(&w, &h, "m_banner_video");
Draw_PicScaled(viddef.width / 2 - (w * scale) / 2, viddef.height / 2 - (110 * scale),
"m_banner_video", scale);
/* move cursor to a reasonable starting position */
Menu_AdjustCursor(&s_opengl_menu, 1);
/* draw the menu */
Menu_Draw(&s_opengl_menu);
}
const char *
2012-07-22 13:34:45 +00:00
VID_MenuKey(int key)
{
2012-07-22 13:34:45 +00:00
extern void M_PopMenu(void);
menuframework_s *m = &s_opengl_menu;
static const char *sound = "misc/menu1.wav";
2012-07-22 13:34:45 +00:00
switch (key)
{
case K_ESCAPE:
M_PopMenu();
2012-07-22 13:34:45 +00:00
return NULL;
case K_UPARROW:
m->cursor--;
2012-07-22 13:34:45 +00:00
Menu_AdjustCursor(m, -1);
break;
case K_DOWNARROW:
m->cursor++;
2012-07-22 13:34:45 +00:00
Menu_AdjustCursor(m, 1);
break;
case K_LEFTARROW:
2012-07-22 13:34:45 +00:00
Menu_SlideItem(m, -1);
break;
case K_RIGHTARROW:
2012-07-22 13:34:45 +00:00
Menu_SlideItem(m, 1);
break;
case K_ENTER:
2012-07-22 13:34:45 +00:00
Menu_SelectItem(m);
break;
}
2012-07-22 13:34:45 +00:00
return sound;
}
2012-07-22 13:34:45 +00:00