2 CLASS(XonoticResolutionSlider) EXTENDS(XonoticTextSlider)
3 METHOD(XonoticResolutionSlider, configureXonoticResolutionSlider, void(entity))
4 METHOD(XonoticResolutionSlider, addResolution, void(entity, float, float, float))
5 METHOD(XonoticResolutionSlider, loadCvars, void(entity))
6 METHOD(XonoticResolutionSlider, saveCvars, void(entity))
7 ENDCLASS(XonoticResolutionSlider)
8 entity makeXonoticResolutionSlider();
10 void updateConwidths();
16 cvar_set("_menu_vid_width", cvar_string("vid_width"));
17 cvar_set("_menu_vid_height", cvar_string("vid_height"));
18 cvar_set("_menu_vid_pixelheight", cvar_string("vid_pixelheight"));
20 void updateConwidths()
23 float minfactor, maxfactor;
25 r_x = cvar("_menu_vid_width");
26 r_y = cvar("_menu_vid_height");
27 r_z = cvar("_menu_vid_pixelheight");
28 sz = cvar("menu_vid_scale");
30 // calculate the base resolution
33 c_y = c_x * r_y * r_z / r_x;
37 c_x = c_y * r_x / (r_y * r_z);
40 f = min(r_x / c_x, r_y / c_y);
42 c = c * f; // ensures that c_x <= r_x and c_y <= r_y
44 minfactor = min(1, 640 / c_x); // can be > 1 only if c_x is <640
45 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
46 dprint("min factor: ", ftos(minfactor), "\n");
47 dprint("max factor: ", ftos(maxfactor), "\n");
50 f = 1 - (maxfactor - 1) * sz;
52 f = 1 + (minfactor - 1) * sz;
55 c = c * f; // fteqcc fail
57 cvar_set("vid_width", ftos(rint(r_x)));
58 cvar_set("vid_height", ftos(rint(r_y)));
59 cvar_set("vid_pixelheight", ftos(rint(r_z)));
60 cvar_set("vid_conwidth", ftos(rint(c_x)));
61 cvar_set("vid_conheight", ftos(rint(c_y)));
63 entity makeXonoticResolutionSlider()
66 me = spawnXonoticResolutionSlider();
67 me.configureXonoticResolutionSlider(me);
70 void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight)
72 me.addValue(me, strzone(sprintf(_("%dx%d"), w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
73 // FIXME (in case you ever want to dynamically instantiate this): THIS IS NEVER FREED
75 void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me)
80 me.configureXonoticTextSlider(me, "_menu_vid_width");
86 if(r_x == 0 && r_y == 0)
93 if(r_x < 640 || r_y < 480)
95 if(r_x > 2 * r_y) // likely dualscreen resolution, skip this one
97 me.addResolution(me, r_x, r_y, r_z);
102 me.addResolution(me, 640, 480, 1);
103 me.addResolution(me, 800, 600, 1);
104 me.addResolution(me, 1024, 768, 1);
105 me.addResolution(me, 1280, 960, 1);
106 me.addResolution(me, 1280, 1024, 1);
107 me.addResolution(me, 1650, 1080, 1);
108 me.addResolution(me, 1920, 1080, 1);
111 me.configureXonoticTextSliderValues(me);
113 void XonoticResolutionSlider_loadCvars(entity me)
115 me.setValueFromIdentifier(me, strcat(cvar_string("_menu_vid_width"), " ", cvar_string("_menu_vid_height"), " ", cvar_string("_menu_vid_pixelheight")));
117 void XonoticResolutionSlider_saveCvars(entity me)
119 if(me.value >= 0 || me.value < me.nValues)
121 tokenize_console(me.getIdentifier(me));
122 cvar_set("_menu_vid_width", argv(0));
123 cvar_set("_menu_vid_height", argv(1));
124 cvar_set("_menu_vid_pixelheight", argv(2));