Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
slider_resolution.qc File Reference
Include dependency graph for slider_resolution.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

entity makeXonoticResolutionSlider ()
float updateConwidths (float width, float height, float pixelheight)
void XonoticResolutionSlider_addResolution (entity me, float w, float h, float pixelheight)
void XonoticResolutionSlider_configureXonoticResolutionSlider (entity me)
void XonoticResolutionSlider_draw (entity me)
void XonoticResolutionSlider_loadCvars (entity me)
void XonoticResolutionSlider_loadResolutions (entity me, float fullscreen)
void XonoticResolutionSlider_saveCvars (entity me)

Variables

float autocvar_menu_vid_allowdualscreenresolution
float vid_conheight
float vid_conwidth
float XonoticResolutionSlider_DataHasChanged

Function Documentation

◆ makeXonoticResolutionSlider()

entity makeXonoticResolutionSlider ( )

Definition at line 83 of file slider_resolution.qc.

84{
86 me.configureXonoticResolutionSlider(me);
87 return me;
88}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define NEW(cname,...)
Definition oo.qh:117

References entity(), and NEW.

Referenced by XonoticVideoSettingsTab_fill().

◆ updateConwidths()

float updateConwidths ( float width,
float height,
float pixelheight )

Definition at line 8 of file slider_resolution.qc.

9{
10 vector r, c;
11 float minfactor, maxfactor;
12 float sz, f;
13
14 sz = cvar("menu_vid_scale");
15 if (sz < -1)
16 return 0; // No recalculation.
17
18 // Save off current settings.
19 cvar_set("_menu_vid_width", ftos(width));
20 cvar_set("_menu_vid_height", ftos(height));
21 cvar_set("_menu_vid_pixelheight", ftos(pixelheight));
22 cvar_set("_menu_vid_desktopfullscreen", cvar_string("vid_desktopfullscreen"));
23
24 // engine is handling conwidth calculations!
25 if((cvar_type("vid_conwidthauto") & CVAR_TYPEFLAG_ENGINE) && cvar("vid_conwidthauto"))
26 {
27 if(vid_conwidth != cvar("vid_conwidth") || vid_conheight != cvar("vid_conheight"))
28 {
29 // Please reload resolutions list and such stuff.
31 vid_conwidth = cvar("vid_conwidth");
32 vid_conheight = cvar("vid_conheight");
33 return 1;
34 }
35 return 0; // No recalculation
36 }
37
38 r_x = width;
39 r_y = height;
40 r_z = pixelheight;
41
42 // calculate the base resolution
43 c_z = 0;
44 c_x = 800;
45 c_y = c.x * r.y * r.z / r.x;
46 if(c.y < 600)
47 {
48 c_y = 600;
49 c_x = c.y * r.x / (r.y * r.z);
50 }
51
52 f = min(r.x / c.x, r.y / c.y);
53 if(f < 1)
54 c *= f; // ensures that c_x <= r_x and c_y <= r_y
55
56 minfactor = min(1, 640 / c.x); // can be > 1 only if c_x is <640
57 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
58 LOG_TRACE("min factor: ", ftos(minfactor));
59 LOG_TRACE("max factor: ", ftos(maxfactor));
60
61 if(sz < 0)
62 f = 1 - (maxfactor - 1) * sz;
63 else if(sz > 0)
64 f = 1 + (minfactor - 1) * sz;
65 else
66 f = 1;
67 c *= f; // fteqcc fail
68
69 c_x = rint(c.x);
70 c_y = rint(c.y);
71
72 // Please reload resolutions list and such stuff.
74
75 if (c.x != cvar("vid_conwidth") || c.y != cvar("vid_conheight"))
76 {
77 cvar_set("vid_conwidth", ftos(c.x));
78 cvar_set("vid_conheight", ftos(c.y));
79 return 1;
80 }
81 return 0;
82}
float height
Definition bobbing.qc:3
float CVAR_TYPEFLAG_ENGINE
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
#define LOG_TRACE(...)
Definition log.qh:76
void cvar_set(string name, string value)
float cvar(string name)
const string cvar_string(string name)
float min(float f,...)
float rint(float f)
string ftos(float f)
float max(float f,...)
vector
Definition self.qh:92
float XonoticResolutionSlider_DataHasChanged

References cvar(), cvar_set(), cvar_string(), CVAR_TYPEFLAG_ENGINE, ftos(), height, LOG_TRACE, max(), min(), rint(), vector, vid_conheight, vid_conwidth, and XonoticResolutionSlider_DataHasChanged.

Referenced by GameCommand(), and UpdateConWidthHeight().

◆ XonoticResolutionSlider_addResolution()

void XonoticResolutionSlider_addResolution ( entity me,
float w,
float h,
float pixelheight )

Definition at line 89 of file slider_resolution.qc.

90{
91 if (me.maxAllowedWidth && w > me.maxAllowedWidth)
92 return;
93 if (me.maxAllowedHeight && h > me.maxAllowedHeight)
94 return;
95 float i;
96 for (i = 0; i < me.nValues; ++i)
97 {
98 tokenize_console(me.valueToIdentifier(me, i));
99 if (w > stof(argv(0))) continue;
100 if (w < stof(argv(0))) break;
101 if (h > stof(argv(1))) continue;
102 if (h < stof(argv(1))) break;
103 if (pixelheight > stof(argv(2)) + 0.01) continue;
104 if (pixelheight < stof(argv(2)) - 0.01) break;
105 return; // already there
106 }
107 if (pixelheight != 1)
108 {
109 float aspect = w / (h * pixelheight);
110 float bestdenom = rint(aspect);
111 float bestnum = 1;
112 float denom;
113 for (denom = 2; denom < 10; ++denom) {
114 float num = rint(aspect * denom);
115 if (fabs(num / denom - aspect) < fabs(bestnum / bestdenom - aspect))
116 {
117 bestnum = num;
118 bestdenom = denom;
119 }
120 }
121 me.insertValue(me, i, strzone(sprintf("%dx%d (%d:%d)", w, h, bestnum, bestdenom)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
122 }
123 else
124 me.insertValue(me, i, strzone(sprintf("%dx%d", w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
125}
#define tokenize_console
float stof(string val,...)
float fabs(float f)
string strzone(string s)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

References argv(), entity(), fabs(), ftos(), rint(), stof(), strcat(), strzone(), and tokenize_console.

◆ XonoticResolutionSlider_configureXonoticResolutionSlider()

void XonoticResolutionSlider_configureXonoticResolutionSlider ( entity me)

Definition at line 127 of file slider_resolution.qc.

128{
129 me.configureXonoticTextSlider(me, "_menu_vid_width",
130 _("Screen resolution"));
131 me.loadResolutions(me, cvar("vid_fullscreen"));
132}

References cvar(), and entity().

◆ XonoticResolutionSlider_draw()

void XonoticResolutionSlider_draw ( entity me)

Definition at line 229 of file slider_resolution.qc.

230{
231 if (cvar("vid_fullscreen") != me.vid_fullscreen)
232 {
233 me.loadResolutions(me, cvar("vid_fullscreen"));
235 }
237 {
239 me.loadCvars(me);
240 }
242}
#define SUPER(cname)
Definition oo.qh:231

References cvar(), entity(), SUPER, and XonoticResolutionSlider_DataHasChanged.

◆ XonoticResolutionSlider_loadCvars()

void XonoticResolutionSlider_loadCvars ( entity me)

Definition at line 210 of file slider_resolution.qc.

211{
212 me.setValueFromIdentifier(me, strcat(cvar_string("_menu_vid_width"), " ", cvar_string("_menu_vid_height"), " ", cvar_string("_menu_vid_pixelheight")), false);
213}

References cvar_string(), entity(), and strcat().

◆ XonoticResolutionSlider_loadResolutions()

void XonoticResolutionSlider_loadResolutions ( entity me,
float fullscreen )

Definition at line 133 of file slider_resolution.qc.

134{
135 float i;
136 vector r;
137
138 // HACK: text slider assumes the strings are constants, so clearValues
139 // will not unzone them
140 for(i = 0; i < me.nValues; ++i)
141 {
142 strunzone(me.valueToIdentifier(me, i));
143 strunzone(me.valueToText(me, i));
144 }
145 // NOW we can safely clear.
146 me.clearValues(me);
147 me.maxAllowedWidth = 0;
148 me.maxAllowedHeight = 0;
149
150 if (fullscreen)
151 {
152 for(i = 0;; ++i)
153 {
154 r = getresolution(i);
155 if(r_x == 0 && r_y == 0)
156 break;
157 if(r.x < 640 || r.y < 480)
158 continue;
159 if(r.x > 2 * r.y) // likely dualscreen resolution, skip this one
161 continue;
162 me.addResolution(me, r.x, r.y, r.z);
163 }
164 r = getresolution(-1);
165 if(r.x != 0 || r.y != 0)
166 me.addResolution(me, r.x, r.y, r.z);
167 LOG_TRACE("Added system resolutions.");
168 }
169
170 if(me.nValues == 0)
171 {
172 // Get workarea.
173 r = getresolution(-2);
174 // If workarea is not supported, get desktop size.
175 if(r.x == 0 && r.y == 0)
176 r = getresolution(-1);
177
178 // Add it, and limit all other resolutions to the workarea/desktop size.
179 if(r.x != 0 || r.y != 0)
180 {
181 me.maxAllowedWidth = r.x;
182 me.maxAllowedHeight = r.y;
183 me.addResolution(me, r.x, r.y, r.z);
184 }
185
186 // Add nice hardcoded defaults.
187 me.addResolution(me, 640, 480, 1); // pc res
188#if 0
189 me.addResolution(me, 720, 480, 1.125); // DVD NTSC 4:3
190 me.addResolution(me, 720, 576, 0.9375); // DVD PAL 4:3
191 me.addResolution(me, 720, 480, 0.84375); // DVD NTSC 16:9
192 me.addResolution(me, 720, 576, 0.703125); // DVD PAL 16:9
193#endif
194 me.addResolution(me, 800, 480, 1); // 480p at 1:1 pixel aspect
195 me.addResolution(me, 800, 600, 1); // pc res
196 me.addResolution(me, 1024, 600, 1); // notebook res
197 me.addResolution(me, 1024, 768, 1); // pc res
198 me.addResolution(me, 1280, 720, 1); // 720p
199 me.addResolution(me, 1280, 960, 1); // pc res
200 me.addResolution(me, 1280, 1024, 1); // pc res
201 me.addResolution(me, 1920, 1080, 1); // 1080p
202 LOG_TRACE("Added default resolutions.");
203 }
204 LOG_TRACE("Total number of resolutions detected: ", ftos(me.nValues));
205
206 me.vid_fullscreen = fullscreen;
207
208 me.configureXonoticTextSliderValues(me);
209}
vector getresolution(float number)
void strunzone(string s)
float autocvar_menu_vid_allowdualscreenresolution

References autocvar_menu_vid_allowdualscreenresolution, entity(), ftos(), getresolution(), LOG_TRACE, strunzone(), and vector.

◆ XonoticResolutionSlider_saveCvars()

void XonoticResolutionSlider_saveCvars ( entity me)

Definition at line 214 of file slider_resolution.qc.

215{
216 if(me.value >= 0 || me.value < me.nValues)
217 {
218 tokenize_console(me.getIdentifier(me));
219 cvar_set("_menu_vid_width", argv(0));
220 cvar_set("_menu_vid_height", argv(1));
221 cvar_set("_menu_vid_pixelheight", argv(2));
222 vector r = getresolution(-1);
223 if (stof(argv(0)) == r.x && stof(argv(1)) == r.y && fabs(stof(argv(2)) - r.z) < 0.01)
224 cvar_set("_menu_vid_desktopfullscreen", "1");
225 else
226 cvar_set("_menu_vid_desktopfullscreen", "0");
227 }
228}

References argv(), cvar_set(), entity(), fabs(), getresolution(), stof(), tokenize_console, and vector.

Variable Documentation

◆ autocvar_menu_vid_allowdualscreenresolution

float autocvar_menu_vid_allowdualscreenresolution

Definition at line 126 of file slider_resolution.qc.

Referenced by XonoticResolutionSlider_loadResolutions().

◆ vid_conheight

float vid_conheight

Definition at line 5 of file slider_resolution.qc.

◆ vid_conwidth

float vid_conwidth

Definition at line 4 of file slider_resolution.qc.

◆ XonoticResolutionSlider_DataHasChanged

float XonoticResolutionSlider_DataHasChanged

Definition at line 3 of file slider_resolution.qc.

Referenced by updateConwidths(), and XonoticResolutionSlider_draw().