]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into divVerent/desktopfullscreen
authorRudolf Polzer <divverent@xonotic.org>
Wed, 18 Sep 2013 09:43:20 +0000 (11:43 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Wed, 18 Sep 2013 09:43:20 +0000 (11:43 +0200)
defaultXonotic.cfg
qcsrc/dpdefs/menudefs.qc
qcsrc/menu/item/textslider.c
qcsrc/menu/menu.qc
qcsrc/menu/xonotic/dialog_settings_video.c
qcsrc/menu/xonotic/slider_resolution.c

index 28c1af69dadf7a009b3da3fe094d7116640ff7a9..2faa816de2f56df0097390ca559033132e499a92 100644 (file)
@@ -93,6 +93,8 @@ vid_fullscreen 1
 vid_width 1024
 vid_height 768
 vid_pixelheight 1
+vid_resizable 0 // cannot be turned on before it is sure it cannot cause a r_restart
+vid_desktopfullscreen 1
 prvm_language en
 set _menu_prvm_language ""
 set _menu_vid_width "$vid_width"
index 4885f2916c70641ca7488b9fedd016fa7e144551..af5b41aee04bb227b27088d7c280173fdc97a72a 100644 (file)
@@ -15,7 +15,7 @@ void          end_sys_fields;
 
 void() m_init;
 void(float keynr, float ascii) m_keydown;
-void() m_draw;
+void(float width, float height) m_draw;
 void(float mode) m_toggle;
 void() m_shutdown;
 
index 028a1603a16c35ef50e43577c587f2127e59b8d8..1676c3bedcc02710fe67d90996da248b5862c218 100644 (file)
@@ -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;
index 1afc9f85d935c3e5958a31ba9cdd206fbf56afc0..eb68729bad9bacc5d80e5d80b4602dea51c91192 100644 (file)
@@ -16,10 +16,13 @@ float menuInitialized;
 float menuNotTheFirstFrame;
 float menuMouseMode;
 
+float conwidth_s, conheight_s, vidwidth_s, vidheight_s, vidpixelheight_s,
+      realconwidth, realconheight, screenconwidth, screenconheight;
+
 void m_sync()
 {
        updateCompression();
-       updateConwidths();
+       vidwidth_s = vidheight_s = vidpixelheight_s = 0;  // Force updateConwidths on next draw.
 
        loadAllCvars(main);
 }
@@ -79,7 +82,6 @@ void m_init()
        updateCompression();
        if(ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression"))
                localcmd("\nr_restart\n");
-       initConwidths();
 
        if(!restarting)
        {
@@ -93,7 +95,7 @@ void m_init()
 
 const float MENU_ASPECT = 1.25; // 1280x1024
 const float MENU_MINHEIGHT = 600;
-float conwidth_s, conheight_s, realconwidth, realconheight, screenconwidth, screenconheight;
+
 void draw_reset_cropped()
 {
        draw_reset(screenconwidth, screenconheight, 0.5 * (realconwidth - screenconwidth), 0.5 * (realconheight - screenconheight));
@@ -102,8 +104,16 @@ void draw_reset_full()
 {
        draw_reset(realconwidth, realconheight, 0, 0);
 }
-void UpdateConWidthHeight()
+
+void UpdateConWidthHeight(float w, float h, float p)
 {
+       if (w != vidwidth_s || h != vidheight_s || p != vidpixelheight_s)
+       {
+               updateConwidths(w, h, p);
+               vidwidth_s = w;
+               vidheight_s = h;
+               vidpixelheight_s = p;
+       }
        conwidth_s = conwidth;
        conheight_s = conheight;
        realconwidth = cvar("vid_conwidth");
@@ -140,6 +150,10 @@ void UpdateConWidthHeight()
                        main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
                }
        }
+       else
+       {
+               vidwidth_s = vidheight_s = vidpixelheight_s = 0; // retry next frame
+       }
 }
 
 string m_goto_buffer;
@@ -148,8 +162,6 @@ void m_init_delayed()
        float fh, glob, n, i;
        string s;
 
-       conwidth = conheight = -1;
-       UpdateConWidthHeight();
        draw_reset_cropped();
 
        menuInitialized = 0;
@@ -671,7 +683,7 @@ void m_tooltip(vector pos)
        }
 }
 
-void m_draw()
+void m_draw(float width, float height)
 {
        float t;
        float realFrametime;
@@ -685,8 +697,7 @@ void m_draw()
        if (anim)
                anim.tickAll(anim);
 
-       if(main)
-               UpdateConWidthHeight();
+       UpdateConWidthHeight(width, height, cvar("vid_pixelheight"));
 
        if(!menuInitialized)
        {
index 57bbc3cd21ecb93def8f27455bc01636e7905a29..00bb7de5afa9a89e11338a18d3bc353b76373a59 100644 (file)
@@ -140,6 +140,6 @@ void XonoticVideoSettingsTab_fill(entity me)
        }
 
        me.gotoRC(me, me.rows - 1, 0);
-               me.TD(me, 1, me.columns, makeXonoticCommandButton(_("Apply immediately"), '0 0 0', "menu_cmd sync; vid_restart; menu_restart; menu_cmd videosettings", COMMANDBUTTON_APPLY));
+               me.TD(me, 1, me.columns, makeXonoticCommandButton(_("Apply immediately"), '0 0 0', "vid_width $_menu_vid_width; vid_height $_menu_vid_height; vid_pixelheight $_menu_vid_pixelheight; vid_restart; menu_restart; menu_cmd videosettings", COMMANDBUTTON_APPLY));
 }
 #endif
index 01fd64e1022eb5d74524db0184dd80830d605f55..bfd0e40232e2774fb67ac29814d7a5b78c1c2cb3 100644 (file)
@@ -1,30 +1,37 @@
 #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();
-void initConwidths();
-void updateConwidths();
+void updateConwidths(float width, float height, float pixelheight);
 #endif
 
 #ifdef IMPLEMENTATION
-void initConwidths()
-{
-       cvar_set("_menu_vid_width", cvar_string("vid_width"));
-       cvar_set("_menu_vid_height", cvar_string("vid_height"));
-       cvar_set("_menu_vid_pixelheight", cvar_string("vid_pixelheight"));
-}
-void updateConwidths()
+
+/* private static */ float XonoticResolutionSlider_DataHasChanged;
+
+// Updates cvars (to be called by menu.qc at startup or on detected res change)
+void updateConwidths(float width, float height, float pixelheight)
 {
        vector r, c;
        float minfactor, maxfactor;
        float sz, f;
-       r_x = cvar("_menu_vid_width");
-       r_y = cvar("_menu_vid_height");
-       r_z = cvar("_menu_vid_pixelheight");
+
+       // Save off current settings.
+       cvar_set("_menu_vid_width", ftos(width));
+       cvar_set("_menu_vid_height", ftos(height));
+       cvar_set("_menu_vid_pixelheight", ftos(pixelheight));
+       cvar_set("_menu_vid_desktopfullscreen", cvar_string("vid_desktopfullscreen"));
+
+       r_x = width;
+       r_y = height;
+       r_z = pixelheight;
        sz = cvar("menu_vid_scale");
 
        // calculate the base resolution
@@ -54,11 +61,9 @@ void updateConwidths()
                f = 1;
        c = c * f; // fteqcc fail
 
-       cvar_set("vid_width", ftos(rint(r_x)));
-       cvar_set("vid_height", ftos(rint(r_y)));
-       cvar_set("vid_pixelheight", ftos(rint(r_z)));
        cvar_set("vid_conwidth", ftos(rint(c_x)));
        cvar_set("vid_conheight", ftos(rint(c_y)));
+       XonoticResolutionSlider_DataHasChanged = TRUE;
 }
 entity makeXonoticResolutionSlider()
 {
@@ -67,50 +72,90 @@ entity makeXonoticResolutionSlider()
        me.configureXonoticResolutionSlider(me);
        return me;
 }
-void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight)
+void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight, float desktopfullscreen)
 {
-       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; denom < 10; ++denom) {
+                       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;
 void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me)
+{
+       me.configureXonoticTextSlider(me, "_menu_vid_width");
+       me.loadResolutions(me, cvar("vid_fullscreen"));
+}
+void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
 {
        float i;
        vector r0, r;
 
-       me.configureXonoticTextSlider(me, "_menu_vid_width");
+       me.clearValues(me);
 
-       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)
+                       {
+                               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;
-                       
-               me.addResolution(me, r_x, r_y, r_z);
+                       if(i != -1)
+                               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;
+               }
        }
 
        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)
@@ -125,6 +170,25 @@ void XonoticResolutionSlider_saveCvars(entity me)
                cvar_set("_menu_vid_width", argv(0));
                cvar_set("_menu_vid_height", argv(1));
                cvar_set("_menu_vid_pixelheight", argv(2));
+               vector r = getresolution(-1);
+               if (stof(argv(0)) == r_x && stof(argv(1)) == r_y && fabs(stof(argv(2)) - r_z) < 0.01)
+                       cvar_set("_menu_vid_desktopfullscreen", "1");
+               else
+                       cvar_set("_menu_vid_desktopfullscreen", "0");
+       }
+}
+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;
+               me.loadCvars(me);
        }
+       SUPER(XonoticResolutionSlider).draw(me);
 }
 #endif