2 CLASS(XonoticResolutionSlider) EXTENDS(XonoticTextSlider)
3 METHOD(XonoticResolutionSlider, configureXonoticResolutionSlider, void(entity))
4 METHOD(XonoticResolutionSlider, loadResolutions, void(entity, float))
5 METHOD(XonoticResolutionSlider, addResolution, void(entity, float, float, float))
6 METHOD(XonoticResolutionSlider, loadCvars, void(entity))
7 METHOD(XonoticResolutionSlider, saveCvars, void(entity))
8 METHOD(XonoticResolutionSlider, draw, void(entity))
9 ATTRIB(XonoticResolutionSlider, vid_fullscreen, float, -1)
10 ENDCLASS(XonoticResolutionSlider)
11 entity makeXonoticResolutionSlider();
12 void updateConwidths(float width, float height, float pixelheight);
17 /* private static */ float XonoticResolutionSlider_DataHasChanged;
19 // Updates cvars (to be called by menu.qc at startup or on detected res change)
20 void updateConwidths(float width, float height, float pixelheight)
23 float minfactor, maxfactor;
26 // Save off current settings.
27 cvar_set("_menu_vid_width", ftos(width));
28 cvar_set("_menu_vid_height", ftos(height));
29 cvar_set("_menu_vid_pixelheight", ftos(pixelheight));
30 cvar_set("_menu_vid_desktopfullscreen", cvar_string("vid_desktopfullscreen"));
35 sz = cvar("menu_vid_scale");
37 // calculate the base resolution
40 c_y = c_x * r_y * r_z / r_x;
44 c_x = c_y * r_x / (r_y * r_z);
47 f = min(r_x / c_x, r_y / c_y);
49 c = c * f; // ensures that c_x <= r_x and c_y <= r_y
51 minfactor = min(1, 640 / c_x); // can be > 1 only if c_x is <640
52 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
53 dprint("min factor: ", ftos(minfactor), "\n");
54 dprint("max factor: ", ftos(maxfactor), "\n");
57 f = 1 - (maxfactor - 1) * sz;
59 f = 1 + (minfactor - 1) * sz;
62 c = c * f; // fteqcc fail
64 cvar_set("vid_conwidth", ftos(rint(c_x)));
65 cvar_set("vid_conheight", ftos(rint(c_y)));
66 XonoticResolutionSlider_DataHasChanged = TRUE;
68 entity makeXonoticResolutionSlider()
71 me = spawnXonoticResolutionSlider();
72 me.configureXonoticResolutionSlider(me);
75 void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight)
78 for (i = 0; i < me.nValues; ++i)
80 tokenize_console(me.valueToIdentifier(me, i));
81 if (w > stof(argv(0))) continue;
82 if (w < stof(argv(0))) break;
83 if (h > stof(argv(1))) continue;
84 if (h < stof(argv(1))) break;
85 if (pixelheight > stof(argv(2)) + 0.01) continue;
86 if (pixelheight < stof(argv(2)) - 0.01) break;
87 return; // already there
91 float aspect = w / (h * pixelheight);
92 float bestdenom = rint(aspect);
95 for (denom = 2; denom < 10; ++denom) {
96 float num = rint(aspect * denom);
97 if (fabs(num / denom - aspect) < fabs(bestnum / bestdenom - aspect))
103 me.insertValue(me, i, strzone(sprintf(_("%dx%d (%d:%d)"), w, h, bestnum, bestdenom)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
106 me.insertValue(me, i, strzone(sprintf(_("%dx%d"), w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
107 // FIXME (in case you ever want to dynamically instantiate this): THIS IS NEVER FREED
109 float autocvar_menu_vid_allowdualscreenresolution;
110 void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me)
112 me.configureXonoticTextSlider(me, "_menu_vid_width");
113 me.loadResolutions(me, cvar("vid_fullscreen"));
115 void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
126 r = getresolution(i);
127 if(r_x == 0 && r_y == 0)
129 if(r_x < 640 || r_y < 480)
131 if(r_x > 2 * r_y) // likely dualscreen resolution, skip this one
132 if(autocvar_menu_vid_allowdualscreenresolution <= 0)
134 me.addResolution(me, r_x, r_y, r_z);
136 r = getresolution(-1);
137 if(r_x != 0 || r_y != 0)
138 me.addResolution(me, r_x, r_y, r_z);
143 me.addResolution(me, 640, 480, 1); // pc res
144 me.addResolution(me, 720, 480, 1.125); // DVD NTSC 4:3
145 me.addResolution(me, 720, 576, 0.9375); // DVD PAL 4:3
146 me.addResolution(me, 720, 480, 0.84375); // DVD NTSC 16:9
147 me.addResolution(me, 720, 576, 0.703125); // DVD PAL 16:9
148 me.addResolution(me, 800, 480, 1); // 480p at 1:1 pixel aspect
149 me.addResolution(me, 800, 600, 1); // pc res
150 me.addResolution(me, 1024, 600, 1); // notebook res
151 me.addResolution(me, 1024, 768, 1); // pc res
152 me.addResolution(me, 1280, 720, 1); // 720p
153 me.addResolution(me, 1280, 960, 1); // pc res
154 me.addResolution(me, 1280, 1024, 1); // pc res
155 me.addResolution(me, 1920, 1080, 1); // 1080p
158 me.vid_fullscreen = fullscreen;
160 me.configureXonoticTextSliderValues(me);
162 void XonoticResolutionSlider_loadCvars(entity me)
164 me.setValueFromIdentifier(me, strcat(cvar_string("_menu_vid_width"), " ", cvar_string("_menu_vid_height"), " ", cvar_string("_menu_vid_pixelheight")));
166 void XonoticResolutionSlider_saveCvars(entity me)
168 if(me.value >= 0 || me.value < me.nValues)
170 tokenize_console(me.getIdentifier(me));
171 cvar_set("_menu_vid_width", argv(0));
172 cvar_set("_menu_vid_height", argv(1));
173 cvar_set("_menu_vid_pixelheight", argv(2));
174 vector r = getresolution(-1);
175 if (stof(argv(0)) == r_x && stof(argv(1)) == r_y && fabs(stof(argv(2)) - r_z) < 0.01)
176 cvar_set("_menu_vid_desktopfullscreen", "1");
178 cvar_set("_menu_vid_desktopfullscreen", "0");
181 void XonoticResolutionSlider_draw(entity me)
183 if (cvar("vid_fullscreen") != me.vid_fullscreen)
185 me.loadResolutions(me, cvar("vid_fullscreen"));
186 XonoticResolutionSlider_DataHasChanged = TRUE;
188 if (XonoticResolutionSlider_DataHasChanged)
190 XonoticResolutionSlider_DataHasChanged = FALSE;
193 SUPER(XonoticResolutionSlider).draw(me);