static void M_ServerList_Key (int key, int ascii);
static void M_ModList_Key (int key, int ascii);
-static qboolean m_entersound; // play after drawing a frame, so caching won't disrupt the sound
+static qboolean m_entersound; ///< play after drawing a frame, so caching won't disrupt the sound
void M_Update_Return_Reason(char *s)
{
//=============================================================================
/* LOAD/SAVE MENU */
-static int load_cursor; // 0 < load_cursor < MAX_SAVEGAMES
+static int load_cursor; ///< 0 < load_cursor < MAX_SAVEGAMES
#define MAX_SAVEGAMES 12
static char m_filenames[MAX_SAVEGAMES][SAVEGAME_COMMENT_LENGTH+1];
//=============================================================================
/* VIDEO MENU */
-// note: if modes are added to the beginning of this list, update VID_DEFAULT
-video_resolution_t video_resolutions[] =
+video_resolution_t video_resolutions_hardcoded[] =
{
{"Standard 4x3" , 320, 240, 320, 240, 1 },
{"Standard 4x3" , 400, 300, 400, 300, 1 },
{NULL, 0, 0, 0, 0, 0}
};
// this is the number of the default mode (640x480) in the list above
-#define VID_DEFAULT 3
-#define VID_RES_COUNT ((int)(sizeof(video_resolutions) / sizeof(video_resolutions[0])) - 1)
+int video_resolutions_hardcoded_count = sizeof(video_resolutions_hardcoded) / sizeof(*video_resolutions_hardcoded) - 1;
#define VIDEO_ITEMS 11
static int video_cursor = 0;
static int video_cursor_table[VIDEO_ITEMS] = {68, 88, 96, 104, 112, 120, 128, 136, 144, 152, 168};
-static int video_resolution;
+static int menu_video_resolution;
-void M_Menu_Video_f (void)
+video_resolution_t *video_resolutions;
+int video_resolutions_count;
+
+static video_resolution_t *menu_video_resolutions;
+static int menu_video_resolutions_count;
+static qboolean menu_video_resolutions_forfullscreen;
+
+static void M_Menu_Video_FindResolution(int w, int h, float a)
{
int i;
- key_dest = key_menu;
- m_state = m_video;
- m_entersound = true;
+ if(menu_video_resolutions_forfullscreen)
+ {
+ menu_video_resolutions = video_resolutions;
+ menu_video_resolutions_count = video_resolutions_count;
+ }
+ else
+ {
+ menu_video_resolutions = video_resolutions_hardcoded;
+ menu_video_resolutions_count = video_resolutions_hardcoded_count;
+ }
// Look for the closest match to the current resolution
- video_resolution = 0;
- for (i = 1;i < VID_RES_COUNT;i++)
+ menu_video_resolution = 0;
+ for (i = 1;i < menu_video_resolutions_count;i++)
{
// if the new mode would be a worse match in width, skip it
- if (fabs(video_resolutions[i].width - vid.width) > fabs(video_resolutions[video_resolution].width - vid.width))
+ if (fabs(menu_video_resolutions[i].width - w) > fabs(menu_video_resolutions[menu_video_resolution].width - w))
continue;
// if it is equal in width, check height
- if (video_resolutions[i].width == vid.width && video_resolutions[video_resolution].width == vid.width)
+ if (menu_video_resolutions[i].width == w && menu_video_resolutions[menu_video_resolution].width == w)
{
// if the new mode would be a worse match in height, skip it
- if (fabs(video_resolutions[i].height - vid.height) > fabs(video_resolutions[video_resolution].height - vid.height))
+ if (fabs(menu_video_resolutions[i].height - h) > fabs(menu_video_resolutions[menu_video_resolution].height - h))
continue;
// if it is equal in width and height, check pixel aspect
- if (video_resolutions[i].height == vid.height && video_resolutions[video_resolution].height == vid.height)
+ if (menu_video_resolutions[i].height == h && menu_video_resolutions[menu_video_resolution].height == h)
{
// if the new mode would be a worse match in pixel aspect, skip it
- if (fabs(video_resolutions[i].pixelheight - vid_pixelheight.value) > fabs(video_resolutions[video_resolution].pixelheight - vid_pixelheight.value))
+ if (fabs(menu_video_resolutions[i].pixelheight - a) > fabs(menu_video_resolutions[menu_video_resolution].pixelheight - a))
continue;
// if it is equal in everything, skip it (prefer earlier modes)
- if (video_resolutions[i].pixelheight == vid_pixelheight.value && video_resolutions[video_resolution].pixelheight == vid_pixelheight.value)
+ if (menu_video_resolutions[i].pixelheight == a && menu_video_resolutions[menu_video_resolution].pixelheight == a)
continue;
// better match for width, height, and pixel aspect
- video_resolution = i;
+ menu_video_resolution = i;
}
else // better match for width and height
- video_resolution = i;
+ menu_video_resolution = i;
}
else // better match for width
- video_resolution = i;
+ menu_video_resolution = i;
}
}
+void M_Menu_Video_f (void)
+{
+ key_dest = key_menu;
+ m_state = m_video;
+ m_entersound = true;
+
+ M_Menu_Video_FindResolution(vid.width, vid.height, vid_pixelheight.value);
+}
+
static void M_Video_Draw (void)
{
int t;
cachepic_t *p;
+ if(!!vid_fullscreen.integer != menu_video_resolutions_forfullscreen)
+ {
+ video_resolution_t *res = &menu_video_resolutions[menu_video_resolution];
+ menu_video_resolutions_forfullscreen = !!vid_fullscreen.integer;
+ M_Menu_Video_FindResolution(res->width, res->height, res->pixelheight);
+ }
+
M_Background(320, 200);
M_DrawPic(16, 4, "gfx/qplaque");
else
M_Print(220, video_cursor_table[t] - 12, va("%dx%d", vid.width, vid.height));
M_Print(16, video_cursor_table[t], " New Resolution");
- M_Print(220, video_cursor_table[t], va("%dx%d", video_resolutions[video_resolution].width, video_resolutions[video_resolution].height));
- M_Print(96, video_cursor_table[t] + 8, va("Type: %s", video_resolutions[video_resolution].type));
+ M_Print(220, video_cursor_table[t], va("%dx%d", menu_video_resolutions[menu_video_resolution].width, menu_video_resolutions[menu_video_resolution].height));
+ M_Print(96, video_cursor_table[t] + 8, va("Type: %s", menu_video_resolutions[menu_video_resolution].type));
t++;
// Bits per pixel
{
// Resolution
int r;
- for(r = 0;r < VID_RES_COUNT;r++)
+ for(r = 0;r < menu_video_resolutions_count;r++)
{
- video_resolution += dir;
- if (video_resolution >= VID_RES_COUNT)
- video_resolution = 0;
- if (video_resolution < 0)
- video_resolution = VID_RES_COUNT - 1;
- if (video_resolutions[video_resolution].width >= vid_minwidth.integer && video_resolutions[video_resolution].height >= vid_minheight.integer)
+ menu_video_resolution += dir;
+ if (menu_video_resolution >= menu_video_resolutions_count)
+ menu_video_resolution = 0;
+ if (menu_video_resolution < 0)
+ menu_video_resolution = menu_video_resolutions_count - 1;
+ if (menu_video_resolutions[menu_video_resolution].width >= vid_minwidth.integer && menu_video_resolutions[menu_video_resolution].height >= vid_minheight.integer)
break;
}
}
switch (video_cursor)
{
case (VIDEO_ITEMS - 1):
- Cvar_SetValueQuick (&vid_width, video_resolutions[video_resolution].width);
- Cvar_SetValueQuick (&vid_height, video_resolutions[video_resolution].height);
- Cvar_SetValueQuick (&vid_conwidth, video_resolutions[video_resolution].conwidth);
- Cvar_SetValueQuick (&vid_conheight, video_resolutions[video_resolution].conheight);
- Cvar_SetValueQuick (&vid_pixelheight, video_resolutions[video_resolution].pixelheight);
+ Cvar_SetValueQuick (&vid_width, menu_video_resolutions[menu_video_resolution].width);
+ Cvar_SetValueQuick (&vid_height, menu_video_resolutions[menu_video_resolution].height);
+ Cvar_SetValueQuick (&vid_conwidth, menu_video_resolutions[menu_video_resolution].conwidth);
+ Cvar_SetValueQuick (&vid_conheight, menu_video_resolutions[menu_video_resolution].conheight);
+ Cvar_SetValueQuick (&vid_pixelheight, menu_video_resolutions[menu_video_resolution].pixelheight);
Cbuf_AddText ("vid_restart\n");
M_Menu_Options_f ();
break;
break;
}
return 0;
-};
+}
void M_Menu_Quit_f (void)
{
void MR_Init(void)
{
+ vid_mode_t res[1024];
+ size_t res_count, i;
+
+ res_count = VID_ListModes(res, sizeof(res) / sizeof(*res));
+ res_count = VID_SortModes(res, res_count, false, false, true);
+ if(res_count)
+ {
+ video_resolutions_count = res_count;
+ video_resolutions = (video_resolution_t *) Mem_Alloc(cls.permanentmempool, sizeof(*video_resolutions) * (video_resolutions_count + 1));
+ memset(&video_resolutions[video_resolutions_count], 0, sizeof(video_resolutions[video_resolutions_count]));
+ for(i = 0; i < res_count; ++i)
+ {
+ int n, d, t;
+ video_resolutions[i].type = "Detected mode"; // FIXME make this more dynamic
+ video_resolutions[i].width = res[i].width;
+ video_resolutions[i].height = res[i].height;
+ video_resolutions[i].pixelheight = res[i].pixelheight_num / (double) res[i].pixelheight_denom;
+ n = res[i].pixelheight_denom * video_resolutions[i].width;
+ d = res[i].pixelheight_num * video_resolutions[i].height;
+ while(d)
+ {
+ t = n;
+ n = d;
+ d = t % d;
+ }
+ d = (res[i].pixelheight_num * video_resolutions[i].height) / n;
+ n = (res[i].pixelheight_denom * video_resolutions[i].width) / n;
+ switch(n * 0x10000 | d)
+ {
+ case 0x00040003:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 480;
+ video_resolutions[i].type = "Standard 4x3";
+ break;
+ case 0x00050004:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 512;
+ if(res[i].pixelheight_denom == res[i].pixelheight_num)
+ video_resolutions[i].type = "Square Pixel (LCD) 5x4";
+ else
+ video_resolutions[i].type = "Short Pixel (CRT) 5x4";
+ break;
+ case 0x00080005:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 400;
+ if(res[i].pixelheight_denom == res[i].pixelheight_num)
+ video_resolutions[i].type = "Widescreen 8x5";
+ else
+ video_resolutions[i].type = "Tall Pixel (CRT) 8x5";
+
+ break;
+ case 0x00050003:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 384;
+ video_resolutions[i].type = "Widescreen 5x3";
+ break;
+ case 0x000D0009:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 400;
+ video_resolutions[i].type = "Widescreen 14x9";
+ break;
+ case 0x00100009:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 480;
+ video_resolutions[i].type = "Widescreen 16x9";
+ break;
+ case 0x00030002:
+ video_resolutions[i].conwidth = 720;
+ video_resolutions[i].conheight = 480;
+ video_resolutions[i].type = "NTSC 3x2";
+ break;
+ case 0x000D000B:
+ video_resolutions[i].conwidth = 720;
+ video_resolutions[i].conheight = 566;
+ video_resolutions[i].type = "PAL 14x11";
+ break;
+ case 0x00080007:
+ if(video_resolutions[i].width >= 512)
+ {
+ video_resolutions[i].conwidth = 512;
+ video_resolutions[i].conheight = 448;
+ video_resolutions[i].type = "SNES 8x7";
+ }
+ else
+ {
+ video_resolutions[i].conwidth = 256;
+ video_resolutions[i].conheight = 224;
+ video_resolutions[i].type = "NES 8x7";
+ }
+ break;
+ default:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 640 * d / n;
+ video_resolutions[i].type = "Detected mode";
+ break;
+ }
+ if(video_resolutions[i].conwidth > video_resolutions[i].width || video_resolutions[i].conheight > video_resolutions[i].height)
+ {
+ double f1, f2;
+ f1 = video_resolutions[i].conwidth > video_resolutions[i].width;
+ f2 = video_resolutions[i].conheight > video_resolutions[i].height;
+ if(f1 > f2)
+ {
+ video_resolutions[i].conwidth = video_resolutions[i].width;
+ video_resolutions[i].conheight = video_resolutions[i].conheight / f1;
+ }
+ else
+ {
+ video_resolutions[i].conwidth = video_resolutions[i].conwidth / f2;
+ video_resolutions[i].conheight = video_resolutions[i].height;
+ }
+ }
+ }
+ }
+ else
+ {
+ video_resolutions = video_resolutions_hardcoded;
+ video_resolutions_count = sizeof(video_resolutions_hardcoded) / sizeof(*video_resolutions_hardcoded) - 1;
+ }
+
+ menu_video_resolutions_forfullscreen = !!vid_fullscreen.integer;
+ M_Menu_Video_FindResolution(vid.width, vid.height, vid_pixelheight.value);
+
// use -forceqmenu to use always the normal quake menu (it sets forceqmenu to 1)
// COMMANDLINEOPTION: Client: -forceqmenu disables menu.dat (same as +forceqmenu 1)
if(COM_CheckParm("-forceqmenu"))