]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
fix the Nexposee hacks in Item/Label
authorRudolf Polzer <divverent@xonotic.org>
Wed, 11 Apr 2012 14:48:55 +0000 (16:48 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Wed, 11 Apr 2012 14:48:55 +0000 (16:48 +0200)
qcsrc/menu/item/borderimage.c
qcsrc/menu/item/inputbox.c
qcsrc/menu/item/label.c

index b5dc52d05107eeacccec166b60cdd0c37f424bf8..1032e805a5017cabe92eba152d8a8f40ac4661fb 100644 (file)
@@ -2,6 +2,7 @@
 CLASS(BorderImage) EXTENDS(Label)
        METHOD(BorderImage, configureBorderImage, void(entity, string, float, vector, string, float))
        METHOD(BorderImage, resizeNotify, void(entity, vector, vector, vector, vector))
+       METHOD(BorderImage, recalcPositionWithText, void(entity, string))
        METHOD(BorderImage, draw, void(entity))
        ATTRIB(BorderImage, src, string, string_null)
        ATTRIB(BorderImage, borderHeight, float, 0)
@@ -13,27 +14,38 @@ CLASS(BorderImage) EXTENDS(Label)
        ATTRIB(BorderImage, isNexposeeTitleBar, float, 0)
        ATTRIB(BorderImage, zoomedOutTitleBarPosition, float, 0)
        ATTRIB(BorderImage, zoomedOutTitleBar, float, 0)
+       ATTRIB(BorderImage, overrideRealOrigin, vector, '0 1 0')
+       ATTRIB(BorderImage, saveRelOrigin, vector, '0 0 0')
+       ATTRIB(BorderImage, saveRelSize, vector, '0 0 0')
 ENDCLASS(BorderImage)
 #endif
 
 #ifdef IMPLEMENTATION
-void BorderImage_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
+void BorderImage_recalcPositionWithText(entity me, string t)
 {
-       me.isNexposeeTitleBar = 0;
-       if(me.zoomedOutTitleBar)
-               if(me.parent.parent.instanceOfNexposee)
-                       if(me.parent.instanceOfDialog)
-                               if(me == me.parent.frame)
-                                       me.isNexposeeTitleBar = 1;
        if(me.isNexposeeTitleBar)
        {
                vector scrs;
                scrs = eX * conwidth + eY * conheight;
-               SUPER(BorderImage).resizeNotify(me, relOrigin, relSize, boxToGlobal(me.parent.Nexposee_smallOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_smallSize, scrs));
+               me.resizeNotify(me, me.saveRelOrigin, me.saveRelSize, boxToGlobal(me.parent.Nexposee_smallOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_smallSize, scrs));
+               SUPER(BorderImage).recalcPositionWithText(me, t);
                me.realOrigin_y = me.realFontSize_y * me.zoomedOutTitleBarPosition;
                me.realOrigin_Nexposeed = me.realOrigin;
                me.realFontSize_Nexposeed = me.realFontSize;
+               me.resizeNotify(me, me.saveRelOrigin, me.saveRelSize, boxToGlobal(me.parent.Nexposee_initialOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_initialSize, scrs));
        }
+       SUPER(BorderImage).recalcPositionWithText(me, t);
+}
+void BorderImage_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
+{
+       me.isNexposeeTitleBar = 0;
+       if(me.zoomedOutTitleBar)
+               if(me.parent.parent.instanceOfNexposee)
+                       if(me.parent.instanceOfDialog)
+                               if(me == me.parent.frame)
+                                       me.isNexposeeTitleBar = 1;
+       me.saveRelOrigin = relOrigin;
+       me.saveRelSize = relSize;
        SUPER(BorderImage).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
        me.borderVec_x = me.borderHeight / absSize_x;
        me.borderVec_y = me.borderHeight / absSize_y;
@@ -62,6 +74,10 @@ void BorderImage_draw(entity me)
        if(me.fontSize > 0)
        {
                vector ro, rf, df;
+
+               if(me.recalcPos)
+                       me.recalcPositionWithText(me, me.text);
+
                if(me.isNexposeeTitleBar)
                {
                        // me.parent.Nexposee_animationFactor 0 (small) or 1 (full)
index 13351cfd32c8f2586a37157f2f0e4677c6a42818..af6587b5a67ebca90ecdb614524bd94923b5fdd0 100644 (file)
@@ -146,6 +146,9 @@ void InputBox_draw(entity me)
        if(me.pressed)
                me.mouseDrag(me, me.dragScrollPos); // simulate mouseDrag event
 
+       if(me.recalcPos)
+               me.recalcPositionWithText(me, me.text);
+
        me.focusable = !me.disabled;
        if(me.disabled)
                draw_alpha *= me.disabledAlpha;
index 8f4313d7b69cb18f7bfa25322494486858c8fb76..e1543ce2756f60579cf1eeb1b5c79be924bc5a7b 100644 (file)
@@ -25,6 +25,8 @@ CLASS(Label) EXTENDS(Item)
        ATTRIB(Label, allowWrap, float, 0)
        ATTRIB(Label, recalcPos, float, 0)
        ATTRIB(Label, condenseFactor, float, 1)
+       ATTRIB(Label, overrideRealOrigin, vector, '0 0 0')
+       ATTRIB(Label, overrideCondenseFactor, float, 0)
 ENDCLASS(Label)
 #endif
 
@@ -48,59 +50,69 @@ void Label_recalcPositionWithText(entity me, string t)
 
        if(spaceUsed <= spaceAvail)
        {
-               me.realOrigin_x = me.align * (spaceAvail - spaceUsed) + me.keepspaceLeft;
-               me.condenseFactor = 1;
+               if(!me.overrideRealOrigin_x)
+                       me.realOrigin_x = me.align * (spaceAvail - spaceUsed) + me.keepspaceLeft;
+               if(!me.overrideCondenseFactor)
+                       me.condenseFactor = 1;
        }
        else if(me.allowCut || me.allowWrap)
        {
-               me.realOrigin_x = me.keepspaceLeft;
-               me.condenseFactor = 1;
+               if(!me.overrideRealOrigin_x)
+                       me.realOrigin_x = me.keepspaceLeft;
+               if(!me.overrideCondenseFactor)
+                       me.condenseFactor = 1;
        }
        else
        {
-               me.realOrigin_x = me.keepspaceLeft;
-               me.condenseFactor = spaceAvail / spaceUsed;
+               if(!me.overrideRealOrigin_x)
+                       me.realOrigin_x = me.keepspaceLeft;
+               if(!me.overrideCondenseFactor)
+                       me.condenseFactor = spaceAvail / spaceUsed;
                dprint(sprintf(_("NOTE: label text %s too wide for label, condensed by factor %f\n"), t, me.condenseFactor));
        }
 
-       float lines;
-       vector dfs;
-       vector fs;
+       if(!me.overrideRealOrigin_y)
+       {
+               float lines;
+               vector dfs;
+               vector fs;
 
-       // set up variables to draw in condensed size, but use hinting for original size
-       fs = me.realFontSize;
-       fs_x *= me.condenseFactor;
+               // set up variables to draw in condensed size, but use hinting for original size
+               fs = me.realFontSize;
+               fs_x *= me.condenseFactor;
 
-       dfs = draw_fontscale;
-       draw_fontscale_x *= me.condenseFactor;
+               dfs = draw_fontscale;
+               draw_fontscale_x *= me.condenseFactor;
 
-       if(me.allowCut) // FIXME allowCut incompatible with align != 0
-               lines = 1;
-       else if(me.allowWrap) // FIXME allowWrap incompatible with align != 0
-       {
-               getWrappedLine_remaining = me.text;
-               lines = 0;
-               while(getWrappedLine_remaining)
+               if(me.allowCut) // FIXME allowCut incompatible with align != 0
+                       lines = 1;
+               else if(me.allowWrap) // FIXME allowWrap incompatible with align != 0
                {
-                       if (me.allowColors)
-                               getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
-                       else
-                               getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
-                       ++lines;
+                       getWrappedLine_remaining = me.text;
+                       lines = 0;
+                       while(getWrappedLine_remaining)
+                       {
+                               if (me.allowColors)
+                                       getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
+                               else
+                                       getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
+                               ++lines;
+                       }
                }
-       }
-       else
-               lines = 1;
+               else
+                       lines = 1;
 
-       draw_fontscale = dfs;
+               draw_fontscale = dfs;
 
-       me.realOrigin_y = 0.5 * (1 - lines * me.realFontSize_y);
+               me.realOrigin_y = 0.5 * (1 - lines * me.realFontSize_y);
+       }
 
        me.recalcPos = 0;
 }
 void Label_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 {
        SUPER(Label).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
+
        // absSize_y is height of label
        me.realFontSize_y = me.fontSize / absSize_y;
        me.realFontSize_x = me.fontSize / absSize_x;