From baf135eeed1ae5f3c8c1eaa2d42ae2140bde0216 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 18 Sep 2013 10:46:12 +0200 Subject: [PATCH] improve res handling --- qcsrc/menu/item/textslider.c | 5 ++ qcsrc/menu/xonotic/slider_resolution.c | 88 +++++++++++++++++++------- 2 files changed, 69 insertions(+), 24 deletions(-) diff --git a/qcsrc/menu/item/textslider.c b/qcsrc/menu/item/textslider.c index 028a1603a..1676c3bed 100644 --- a/qcsrc/menu/item/textslider.c +++ b/qcsrc/menu/item/textslider.c @@ -6,6 +6,7 @@ CLASS(TextSlider) EXTENDS(Slider) METHOD(TextSlider, valueToIdentifier, string(entity, float)) METHOD(TextSlider, setValueFromIdentifier, void(entity, string)) METHOD(TextSlider, getIdentifier, string(entity)) + METHOD(TextSlider, clearValues, void(entity)) METHOD(TextSlider, addValue, void(entity, string, string)) METHOD(TextSlider, configureTextSliderValues, void(entity, string)) ATTRIBARRAY(TextSlider, valueStrings, string, 256) @@ -46,6 +47,10 @@ string TextSlider_getIdentifier(entity me) { return me.valueToIdentifier(me, me.value); } +void TextSlider_clearValues(entity me) +{ + me.nValues = 0; +} void TextSlider_addValue(entity me, string theString, string theIdentifier) { me.(valueStrings[me.nValues]) = theString; diff --git a/qcsrc/menu/xonotic/slider_resolution.c b/qcsrc/menu/xonotic/slider_resolution.c index 24e9cb9b8..128ab0c6a 100644 --- a/qcsrc/menu/xonotic/slider_resolution.c +++ b/qcsrc/menu/xonotic/slider_resolution.c @@ -1,10 +1,12 @@ #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)) + ATTRIB(XonoticResolutionSlider, vid_fullscreen, float) ENDCLASS(XonoticResolutionSlider) entity makeXonoticResolutionSlider(); void updateConwidths(float width, float height, float pixelheight); @@ -71,7 +73,24 @@ entity makeXonoticResolutionSlider() } void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight) { - me.addValue(me, strzone(sprintf(_("%dx%d"), w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); + if (pixelheight != 1) + { + float aspect = w / (h * pixelheight); + float bestdenom = rint(aspect); + float bestnum = 1; + float denom; + for (denom = 2; i < 10; ++i) { + float num = rint(aspect * denom); + if (fabs(num / denom - aspect) < fabs(bestnum / bestdenom - aspect)) + { + bestnum = num; + bestdenom = denom; + } + } + me.addValue(me, strzone(sprintf(_("%dx%d (%d:%d)"), w, h, bestnum, bestdenom)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); + } + else + me.addValue(me, strzone(sprintf(_("%dx%d"), w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); // FIXME (in case you ever want to dynamically instantiate this): THIS IS NEVER FREED } float autocvar_menu_vid_allowdualscreenresolution; @@ -81,38 +100,54 @@ void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me) vector r0, r; me.configureXonoticTextSlider(me, "_menu_vid_width"); + me.loadResolutions(me, cvar("vid_fullscreen")); +} +void XonoticTextSlider_loadResolutions(entity me, float fullscreen) +{ + me.clearValues(); - r0 = '0 0 0'; - for(i = 0;; ++i) + if (fullscreen) { - r = getresolution(i); - if(r_x == 0 && r_y == 0) - break; - if(r_z == 0) - r_z = 1; // compat - if(r == r0) - continue; - r0 = r; - if(r_x < 640 || r_y < 480) - continue; - if(r_x > 2 * r_y) // likely dualscreen resolution, skip this one - if(autocvar_menu_vid_allowdualscreenresolution <= 0) + r0 = '0 0 0'; + for(i = 0;; ++i) + { + r = getresolution(i); + if(r_x == 0 && r_y == 0) + break; + if(r_z == 0) + r_z = 1; // compat + if(r == r0) continue; - - me.addResolution(me, r_x, r_y, r_z); + r0 = r; + if(r_x < 640 || r_y < 480) + continue; + 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); + } } if(me.nValues == 0) { - me.addResolution(me, 640, 480, 1); - me.addResolution(me, 800, 600, 1); - me.addResolution(me, 1024, 768, 1); - me.addResolution(me, 1280, 960, 1); - me.addResolution(me, 1280, 1024, 1); - me.addResolution(me, 1650, 1080, 1); - me.addResolution(me, 1920, 1080, 1); + me.addResolution(me, 640, 480, 1); // pc res + me.addResolution(me, 720, 480, 1.125); // DVD NTSC 4:3 + me.addResolution(me, 720, 576, 0.9375); // DVD PAL 4:3 + me.addResolution(me, 720, 480, 0.84375); // DVD NTSC 16:9 + me.addResolution(me, 720, 576, 0.703125); // DVD PAL 16:9 + me.addResolution(me, 800, 480, 1); // 480p at 1:1 pixel aspect + me.addResolution(me, 800, 600, 1); // pc res + me.addResolution(me, 1024, 600, 1); // notebook res + me.addResolution(me, 1024, 768, 1); // pc res + me.addResolution(me, 1280, 720, 1); // 720p + me.addResolution(me, 1280, 960, 1); // pc res + me.addResolution(me, 1280, 1024, 1); // pc res + me.addResolution(me, 1920, 1080, 1); // 1080p } + me.vid_fullscreen = fullscreen; + me.configureXonoticTextSliderValues(me); } void XonoticResolutionSlider_loadCvars(entity me) @@ -131,6 +166,11 @@ void XonoticResolutionSlider_saveCvars(entity me) } void XonoticResolutionSlider_draw(entity me) { + if (cvar("vid_fullscreen") != me.vid_fullscreen) + { + me.loadResolutions(me, cvar("vid_fullscreen")); + XonoticResolutionSlider_DataHasChanged = TRUE; + } if (XonoticResolutionSlider_DataHasChanged) { XonoticResolutionSlider_DataHasChanged = FALSE; -- 2.39.2