]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/item/inputbox.c
Merge branch 'master' into terencehill/clear_button
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / inputbox.c
index b44db7c42a23342207aeccb8bebf0fdc949c124a..614f6d557679a465861e400a8e3cb9e1deebee1a 100644 (file)
@@ -31,10 +31,12 @@ CLASS(InputBox) EXTENDS(Label)
 
        ATTRIB(InputBox, enableClearButton, float, 1)
        ATTRIB(InputBox, clearButton, entity, NULL)
-       ATTRIB(InputBox, cb_size, vector, '0 0 0')
+       ATTRIB(InputBox, cb_width, float, 0)
        ATTRIB(InputBox, cb_pressed, float, 0)
        ATTRIB(InputBox, cb_focused, float, 0)
-       ATTRIB(InputBox, cb_src, string, SKINGFX_CLEARBUTTON)
+       ATTRIB(InputBox, cb_color, vector, '1 1 1')
+       ATTRIB(InputBox, cb_colorF, vector, '1 1 1')
+       ATTRIB(InputBox, cb_colorC, vector, '1 1 1')
 ENDCLASS(InputBox)
 void InputBox_Clear_Click(entity btn, entity me);
 #endif
@@ -51,8 +53,9 @@ void InputBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector a
        SUPER(InputBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
        if (me.enableClearButton)
        {
-               me.cb_size = eX * (absSize_y / absSize_x) + eY;
-               me.keepspaceRight = me.keepspaceRight + me.cb_size_x;
+               me.cb_width = absSize_y / absSize_x;
+               me.cb_offset = bound(-1, me.cb_offset, 0) * me.cb_width; // bound to range -1, 0
+               me.keepspaceRight = me.keepspaceRight - me.cb_offset + me.cb_width;
        }
 }
 
@@ -70,10 +73,10 @@ void InputBox_Clear_Click(entity btn, entity me)
 
 float over_ClearButton(entity me, vector pos)
 {
-       if (pos_x >= 1 - me.cb_size_x)
-       if (pos_x < 1)
+       if (pos_x >= 1 + me.cb_offset - me.cb_width)
+       if (pos_x < 1 + me.cb_offset)
        if (pos_y >= 0)
-       if (pos_y < me.cb_size_y)
+       if (pos_y < 1)
                return 1;
        return 0;
 }
@@ -217,6 +220,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;
@@ -294,7 +300,6 @@ void InputBox_draw(entity me)
                                else if(ch2 == "x") // ^x found
                                {
                                        theColor = '1 1 1';
-                                       theTempColor = '0 0 0';
                                        
                                        component = HEXDIGIT_TO_DEC(substring(me.text, i+2, 1));
                                        if (component >= 0) // ^xr found
@@ -358,7 +363,7 @@ void InputBox_draw(entity me)
        }
        else
                draw_Text(me.realOrigin - eX * me.scrollPos, me.text, me.realFontSize, '1 1 1', 1, 0);
-               // skipping SUPER(InputBox).draw(me);
+
        if(!me.focused || (time - me.lastChangeTime) < floor(time - me.lastChangeTime) + 0.5)
                draw_Text(me.realOrigin + eX * (cursorPosInWidths - me.scrollPos), CURSOR, me.realFontSize, '1 1 1', 1, 0);
 
@@ -368,12 +373,15 @@ void InputBox_draw(entity me)
        if (me.text != "")
        {
                if(me.focused && me.cb_pressed)
-                       draw_Picture('1 1 0' - me.cb_size, strcat(me.cb_src, "_c"), me.cb_size, '1 1 1', 1);
+                       draw_Picture(eX * (1 + me.cb_offset - me.cb_width), strcat(me.cb_src, "_c"), eX * me.cb_width + eY, me.cb_colorC, 1);
                else if(me.focused && me.cb_focused)
-                       draw_Picture('1 1 0' - me.cb_size, strcat(me.cb_src, "_f"), me.cb_size, '1 1 1', 1);
+                       draw_Picture(eX * (1 + me.cb_offset - me.cb_width), strcat(me.cb_src, "_f"), eX * me.cb_width + eY, me.cb_colorF, 1);
                else
-                       draw_Picture('1 1 0' - me.cb_size, strcat(me.cb_src, "_n"), me.cb_size, '1 1 1', 1);
+                       draw_Picture(eX * (1 + me.cb_offset - me.cb_width), strcat(me.cb_src, "_n"), eX * me.cb_width + eY, me.cb_color, 1);
        }
+
+       // skipping SUPER(InputBox).draw(me);
+       Item_draw(me);
 }
 
 void InputBox_showNotify(entity me)