-#ifdef INTERFACE
-CLASS(XonoticResolutionSlider) EXTENDS(XonoticTextSlider)
- METHOD(XonoticResolutionSlider, configureXonoticResolutionSlider, void(entity))
- METHOD(XonoticResolutionSlider, loadResolutions, void(entity, float))
- METHOD(XonoticResolutionSlider, addResolution, void(entity, float, float, float))
- METHOD(XonoticResolutionSlider, loadCvars, void(entity))
- METHOD(XonoticResolutionSlider, saveCvars, void(entity))
- METHOD(XonoticResolutionSlider, draw, void(entity))
+#ifndef SLIDER_RESOLUTION_H
+#define SLIDER_RESOLUTION_H
+#include "textslider.qc"
+CLASS(XonoticResolutionSlider, XonoticTextSlider)
+ METHOD(XonoticResolutionSlider, configureXonoticResolutionSlider, void(entity));
+ METHOD(XonoticResolutionSlider, loadResolutions, void(entity, float));
+ METHOD(XonoticResolutionSlider, addResolution, void(entity, float, float, float));
+ METHOD(XonoticResolutionSlider, loadCvars, void(entity));
+ METHOD(XonoticResolutionSlider, saveCvars, void(entity));
+ METHOD(XonoticResolutionSlider, draw, void(entity));
ATTRIB(XonoticResolutionSlider, vid_fullscreen, float, -1)
+ ATTRIB(XonoticResolutionSlider, maxAllowedWidth, float, 0)
+ ATTRIB(XonoticResolutionSlider, maxAllowedHeight, float, 0)
ENDCLASS(XonoticResolutionSlider)
entity makeXonoticResolutionSlider();
float updateConwidths(float width, float height, float pixelheight);
// calculate the base resolution
c_z = 0;
c_x = 800;
- c_y = c_x * r_y * r_z / r_x;
- if(c_y < 600)
+ c_y = c.x * r.y * r.z / r.x;
+ if(c.y < 600)
{
c_y = 600;
- c_x = c_y * r_x / (r_y * r_z);
+ c_x = c.y * r.x / (r.y * r.z);
}
- f = min(r_x / c_x, r_y / c_y);
+ f = min(r.x / c.x, r.y / c.y);
if(f < 1)
c = c * f; // ensures that c_x <= r_x and c_y <= r_y
- minfactor = min(1, 640 / c_x); // can be > 1 only if c_x is <640
- maxfactor = max(1, r_x / c_x, r_y / c_y); // can be < 1 only if r_x < c_x and r_y < c_y
- dprint("min factor: ", ftos(minfactor), "\n");
- dprint("max factor: ", ftos(maxfactor), "\n");
+ minfactor = min(1, 640 / c.x); // can be > 1 only if c_x is <640
+ maxfactor = max(1, r.x / c.x, r.y / c.y); // can be < 1 only if r_x < c_x and r_y < c_y
+ LOG_TRACE("min factor: ", ftos(minfactor), "\n");
+ LOG_TRACE("max factor: ", ftos(maxfactor), "\n");
if(sz < 0)
f = 1 - (maxfactor - 1) * sz;
f = 1;
c = c * f; // fteqcc fail
- c_x = rint(c_x);
- c_y = rint(c_y);
+ c_x = rint(c.x);
+ c_y = rint(c.y);
// Please reload resolutions list and such stuff.
- XonoticResolutionSlider_DataHasChanged = TRUE;
+ XonoticResolutionSlider_DataHasChanged = true;
- if (c_x != cvar("vid_conwidth") || c_y != cvar("vid_conheight"))
+ if (c.x != cvar("vid_conwidth") || c.y != cvar("vid_conheight"))
{
- cvar_set("vid_conwidth", ftos(c_x));
- cvar_set("vid_conheight", ftos(c_y));
+ cvar_set("vid_conwidth", ftos(c.x));
+ cvar_set("vid_conheight", ftos(c.y));
return 1;
}
return 0;
entity makeXonoticResolutionSlider()
{
entity me;
- me = spawnXonoticResolutionSlider();
+ me = NEW(XonoticResolutionSlider);
me.configureXonoticResolutionSlider(me);
return me;
}
void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight)
{
+ if (me.maxAllowedWidth && w > me.maxAllowedWidth)
+ return;
+ if (me.maxAllowedHeight && h > me.maxAllowedHeight)
+ return;
float i;
for (i = 0; i < me.nValues; ++i)
{
}
// NOW we can safely clear.
me.clearValues(me);
+ me.maxAllowedWidth = 0;
+ me.maxAllowedHeight = 0;
if (fullscreen)
{
r = getresolution(i);
if(r_x == 0 && r_y == 0)
break;
- if(r_x < 640 || r_y < 480)
+ if(r.x < 640 || r.y < 480)
continue;
- if(r_x > 2 * r_y) // likely dualscreen resolution, skip this one
+ if(r.x > 2 * r.y) // likely dualscreen resolution, skip this one
if(autocvar_menu_vid_allowdualscreenresolution <= 0)
continue;
- me.addResolution(me, r_x, r_y, r_z);
+ me.addResolution(me, r.x, r.y, r.z);
}
r = getresolution(-1);
- if(r_x != 0 || r_y != 0)
- me.addResolution(me, r_x, r_y, r_z);
- dprint("Added system resolutions.\n");
+ if(r.x != 0 || r.y != 0)
+ me.addResolution(me, r.x, r.y, r.z);
+ LOG_TRACE("Added system resolutions.\n");
}
if(me.nValues == 0)
{
+ // Get workarea.
+ r = getresolution(-2);
+ // If workarea is not supported, get desktop size.
+ if(r.x == 0 && r.y == 0)
+ r = getresolution(-1);
+
+ // Add it, and limit all other resolutions to the workarea/desktop size.
+ if(r.x != 0 || r.y != 0)
+ {
+ me.maxAllowedWidth = r.x;
+ me.maxAllowedHeight = r.y;
+ me.addResolution(me, r.x, r.y, r.z);
+ }
+
+ // Add nice hardcoded defaults.
me.addResolution(me, 640, 480, 1); // pc res
#if 0
me.addResolution(me, 720, 480, 1.125); // DVD NTSC 4:3
me.addResolution(me, 1280, 960, 1); // pc res
me.addResolution(me, 1280, 1024, 1); // pc res
me.addResolution(me, 1920, 1080, 1); // 1080p
- dprint("Added default resolutions.\n");
+ LOG_TRACE("Added default resolutions.\n");
}
- dprint("Total number of resolutions detected: ", ftos(me.nValues), "\n");
+ LOG_TRACE("Total number of resolutions detected: ", ftos(me.nValues), "\n");
me.vid_fullscreen = fullscreen;
cvar_set("_menu_vid_height", argv(1));
cvar_set("_menu_vid_pixelheight", argv(2));
vector r = getresolution(-1);
- if (stof(argv(0)) == r_x && stof(argv(1)) == r_y && fabs(stof(argv(2)) - r_z) < 0.01)
+ if (stof(argv(0)) == r.x && stof(argv(1)) == r.y && fabs(stof(argv(2)) - r.z) < 0.01)
cvar_set("_menu_vid_desktopfullscreen", "1");
else
cvar_set("_menu_vid_desktopfullscreen", "0");
if (cvar("vid_fullscreen") != me.vid_fullscreen)
{
me.loadResolutions(me, cvar("vid_fullscreen"));
- XonoticResolutionSlider_DataHasChanged = TRUE;
+ XonoticResolutionSlider_DataHasChanged = true;
}
if (XonoticResolutionSlider_DataHasChanged)
{
- XonoticResolutionSlider_DataHasChanged = FALSE;
+ XonoticResolutionSlider_DataHasChanged = false;
me.loadCvars(me);
}
SUPER(XonoticResolutionSlider).draw(me);