]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/slider_resolution.c
Hide DVD resolutions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider_resolution.c
index 998a0010eb8572e21b0b9a8034944c37edc51592..5914e9aff068e812d7583ac813aa05a1266e1315 100644 (file)
@@ -61,8 +61,16 @@ void updateConwidths(float width, float height, float pixelheight)
                f = 1;
        c = c * f; // fteqcc fail
 
-       cvar_set("vid_conwidth", ftos(rint(c_x)));
-       cvar_set("vid_conheight", ftos(rint(c_y)));
+       c_x = rint(c_x);
+       c_y = rint(c_y);
+
+       if (c_x != cvar("vid_conwidth") || c_y != cvar("vid_conheight"))
+       {
+               cvar_set("vid_conwidth", ftos(c_x));
+               cvar_set("vid_conheight", ftos(c_y));
+               localcmd("\nr_restart\n");
+       }
+
        XonoticResolutionSlider_DataHasChanged = TRUE;
 }
 entity makeXonoticResolutionSlider()
@@ -74,6 +82,18 @@ entity makeXonoticResolutionSlider()
 }
 void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight)
 {
+       float i;
+       for (i = 0; i < me.nValues; ++i)
+       {
+               tokenize_console(me.valueToIdentifier(me, i));
+               if (w > stof(argv(0))) continue;
+               if (w < stof(argv(0))) break;
+               if (h > stof(argv(1))) continue;
+               if (h < stof(argv(1))) break;
+               if (pixelheight > stof(argv(2)) + 0.01) continue;
+               if (pixelheight < stof(argv(2)) - 0.01) break;
+               return;  // already there
+       }
        if (pixelheight != 1)
        {
                float aspect = w / (h * pixelheight);
@@ -88,11 +108,10 @@ void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pi
                                bestdenom = denom;
                        }
                }
-               me.addValue(me, 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.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
+               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)
@@ -103,47 +122,47 @@ void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me)
 void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
 {
        float i;
-       vector r0, r;
+       vector r;
 
+       // HACK: text slider assumes the strings are constants, so clearValues
+       // will not unzone them
+       for(i = 0; i < me.nValues; ++i)
+       {
+               strunzone(me.valueToIdentifier(me, i));
+               strunzone(me.valueToText(me, i));
+       }
+       // NOW we can safely clear.
        me.clearValues(me);
 
        if (fullscreen)
        {
-               r0 = '0 0 0';
                for(i = 0;; ++i)
                {
                        r = getresolution(i);
-                       if(r_x == 0 && r_y == 0)
-                       {
-                               i = -1;
-                               r = getresolution(i);
-                       }
                        if(r_x == 0 && r_y == 0)
                                break;
-                       if(r == r0)
-                               continue;
-                       r0 = r;
                        if(r_x < 640 || r_y < 480)
                                continue;
-                       if(i != -1)
-                               if(r_x > 2 * r_y) // likely dualscreen resolution, skip this one
-                                       if(autocvar_menu_vid_allowdualscreenresolution <= 0)
-                                               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 (i == -1)
-                               break;
                }
+               r = getresolution(-1);
+               if(r_x != 0 || r_y != 0)
+                       me.addResolution(me, r_x, r_y, r_z);
+               dprint("Added system resolutions.\n");
        }
 
        if(me.nValues == 0)
        {
                me.addResolution(me, 640, 480, 1); // pc res
+#if 0
                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
+#endif
                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
@@ -152,7 +171,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");
        }
+       dprint("Total number of resolutions detected: ", ftos(me.nValues), "\n");
 
        me.vid_fullscreen = fullscreen;