]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/slider_resolution.qc
Menu: don't allow customization of drag tolerance for slider and listbox in the skins...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider_resolution.qc
index 476c441ed1a96a40afc2e3fcb2d7ff9b70a17d75..9a55f884030e25732d23cad43de801e4e6c22c13 100644 (file)
@@ -1,18 +1,4 @@
-#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, -1)
-ENDCLASS(XonoticResolutionSlider)
-entity makeXonoticResolutionSlider();
-float updateConwidths(float width, float height, float pixelheight);
-#endif
-
-#ifdef IMPLEMENTATION
+#include "slider_resolution.qh"
 
 /* private static */ float XonoticResolutionSlider_DataHasChanged;
 
@@ -53,8 +39,8 @@ float updateConwidths(float width, float height, float pixelheight)
 
        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");
+       LOG_TRACE("min factor: ", ftos(minfactor));
+       LOG_TRACE("max factor: ", ftos(maxfactor));
 
        if(sz < 0)
                f = 1 - (maxfactor - 1) * sz;
@@ -81,12 +67,16 @@ float updateConwidths(float width, float height, float pixelheight)
 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)
        {
@@ -113,15 +103,16 @@ void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pi
                                bestdenom = denom;
                        }
                }
-               me.insertValue(me, i, strzone(sprintf(_("%dx%d (%d:%d)"), w, h, bestnum, bestdenom)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
+               me.insertValue(me, i, strzone(sprintf("%dx%d (%d:%d)", w, h, bestnum, bestdenom)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
        }
        else
-               me.insertValue(me, i, strzone(sprintf(_("%dx%d"), w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
+               me.insertValue(me, i, strzone(sprintf("%dx%d", w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight))));
 }
 float autocvar_menu_vid_allowdualscreenresolution;
 void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me)
 {
-       me.configureXonoticTextSlider(me, "_menu_vid_width");
+       me.configureXonoticTextSlider(me, "_menu_vid_width",
+               _("Screen resolution"));
        me.loadResolutions(me, cvar("vid_fullscreen"));
 }
 void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
@@ -138,6 +129,8 @@ void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
        }
        // NOW we can safely clear.
        me.clearValues(me);
+       me.maxAllowedWidth = 0;
+       me.maxAllowedHeight = 0;
 
        if (fullscreen)
        {
@@ -156,11 +149,26 @@ void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
                r = getresolution(-1);
                if(r.x != 0 || r.y != 0)
                        me.addResolution(me, r.x, r.y, r.z);
-               dprint("Added system resolutions.\n");
+               LOG_TRACE("Added system resolutions.");
        }
 
        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
@@ -176,9 +184,9 @@ void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
                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.");
        }
-       dprint("Total number of resolutions detected: ", ftos(me.nValues), "\n");
+       LOG_TRACE("Total number of resolutions detected: ", ftos(me.nValues));
 
        me.vid_fullscreen = fullscreen;
 
@@ -186,7 +194,7 @@ void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
 }
 void XonoticResolutionSlider_loadCvars(entity me)
 {
-       me.setValueFromIdentifier(me, strcat(cvar_string("_menu_vid_width"), " ", cvar_string("_menu_vid_height"), " ", cvar_string("_menu_vid_pixelheight")));
+       me.setValueFromIdentifier_noAnim(me, strcat(cvar_string("_menu_vid_width"), " ", cvar_string("_menu_vid_height"), " ", cvar_string("_menu_vid_pixelheight")));
 }
 void XonoticResolutionSlider_saveCvars(entity me)
 {
@@ -217,4 +225,3 @@ void XonoticResolutionSlider_draw(entity me)
        }
        SUPER(XonoticResolutionSlider).draw(me);
 }
-#endif