]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/item/inputbox.qc
Merge remote-tracking branch 'origin/master' into terencehill/listbox_item_highlight
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / inputbox.qc
index 7708a0d7f9d287270996b9ca7b96d2157c1ac640..5bcfd5f9c0491f4e2a8a36310f74e805ac5f4b72 100644 (file)
@@ -1,5 +1,7 @@
-#ifdef INTERFACE
-CLASS(InputBox) EXTENDS(Label)
+#ifndef ITEM_INPUTBOX_H
+#define ITEM_INPUTBOX_H
+#include "label.qc"
+CLASS(InputBox, Label)
        METHOD(InputBox, configureInputBox, void(entity, string, float, float, string))
        METHOD(InputBox, draw, void(entity))
        METHOD(InputBox, setText, void(entity, string))
@@ -18,6 +20,7 @@ CLASS(InputBox) EXTENDS(Label)
        ATTRIB(InputBox, scrollPos, float, 0) // widths
 
        ATTRIB(InputBox, focusable, float, 1)
+       ATTRIB(InputBox, allowFocusSound, float, 1)
        ATTRIB(InputBox, disabled, float, 0)
        ATTRIB(InputBox, lastChangeTime, float, 0)
        ATTRIB(InputBox, dragScrollTimer, float, 0)
@@ -38,7 +41,6 @@ CLASS(InputBox) EXTENDS(Label)
        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
 
 #ifdef IMPLEMENTATION
@@ -53,7 +55,7 @@ void InputBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector a
        SUPER(InputBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
        if (me.enableClearButton)
        {
-               me.cb_width = absSize_y / absSize_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;
        }
@@ -66,17 +68,12 @@ void InputBox_setText(entity me, string txt)
        SUPER(InputBox).setText(me, strzone(txt));
 }
 
-void InputBox_Clear_Click(entity btn, entity me)
-{
-       me.setText(me, "");
-}
-
 float over_ClearButton(entity me, vector pos)
 {
-       if (pos_x >= 1 + me.cb_offset - me.cb_width)
-       if (pos_x < 1 + me.cb_offset)
-       if (pos_y >= 0)
-       if (pos_y < 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 < 1)
                return 1;
        return 0;
 }
@@ -101,7 +98,7 @@ float InputBox_mouseDrag(entity me, vector pos)
        if(me.pressed)
        {
                me.dragScrollPos = pos;
-               p = me.scrollPos + pos_x - me.keepspaceLeft;
+               p = me.scrollPos + pos.x - me.keepspaceLeft;
                me.cursorPos = draw_TextLengthUpToWidth(me.text, p, 0, me.realFontSize);
                me.lastChangeTime = time;
        }
@@ -135,8 +132,9 @@ float InputBox_mouseRelease(entity me, vector pos)
        if(me.cb_pressed)
        if (over_ClearButton(me, pos))
        {
+               m_play_click_sound(MENU_SOUND_CLEAR);
+               me.setText(me, "");
                me.cb_pressed = 0;
-               InputBox_Clear_Click(world, me);
                return 1;
        }
        float r = InputBox_mouseDrag(me, pos);
@@ -204,7 +202,10 @@ float InputBox_keyDown(entity me, float key, float ascii, float shift)
                case K_KP_DEL:
                case K_DEL:
                        if(shift & S_CTRL)
+                       {
+                               m_play_click_sound(MENU_SOUND_CLEAR);
                                me.setText(me, "");
+                       }
                        else
                                me.setText(me, strcat(substring(me.text, 0, me.cursorPos), substring(me.text, me.cursorPos + 1, strlen(me.text) - me.cursorPos - 1)));
                        return 1;
@@ -276,7 +277,7 @@ void InputBox_draw(entity me)
                                w = draw_TextWidth(strcat(ch, ch2), 0, me.realFontSize);
                                if(ch2 == "^")
                                {
-                                       draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
+                                       draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5);
                                        draw_Text(p + eX * 0.25 * w, "^", me.realFontSize, theColor, theAlpha, 0);
                                }
                                else if(ch2 == "0" || stof(ch2)) // digit?
@@ -294,7 +295,7 @@ void InputBox_draw(entity me)
                                                case 8: theColor = '1 1 1'; theAlpha = 0.5; break;
                                                case 9: theColor = '0.5 0.5 0.5'; theAlpha = 1; break;
                                        }
-                                       draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
+                                       draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5);
                                        draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0);
                                }
                                else if(ch2 == "x") // ^x found
@@ -304,21 +305,21 @@ void InputBox_draw(entity me)
                                        component = HEXDIGIT_TO_DEC(substring(me.text, i+2, 1));
                                        if (component >= 0) // ^xr found
                                        {
-                                               theTempColor_x = component/15;
+                                               theTempColor.x = component/15;
 
                                                component = HEXDIGIT_TO_DEC(substring(me.text, i+3, 1));
                                                if (component >= 0) // ^xrg found
                                                {
-                                                       theTempColor_y = component/15;
+                                                       theTempColor.y = component/15;
 
                                                        component = HEXDIGIT_TO_DEC(substring(me.text, i+4, 1));
                                                        if (component >= 0) // ^xrgb found
                                                        {
-                                                               theTempColor_z = component/15;
+                                                               theTempColor.z = component/15;
                                                                theColor = theTempColor;
                                                                w = draw_TextWidth(substring(me.text, i, 5), 0, me.realFontSize);
 
-                                                               draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
+                                                               draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5);
                                                                draw_Text(p, substring(me.text, i, 5), me.realFontSize, theColor, 1, 0);    // theVariableAlpha instead of 1 using alpha tags ^ax
                                                                i += 3;
                                                        }
@@ -326,7 +327,7 @@ void InputBox_draw(entity me)
                                                        {
                                                                // blue missing
                                                                w = draw_TextWidth(substring(me.text, i, 4), 0, me.realFontSize);
-                                                               draw_Fill(p, eX * w + eY * me.realFontSize_y, eZ, 0.5);
+                                                               draw_Fill(p, eX * w + eY * me.realFontSize.y, eZ, 0.5);
                                                                draw_Text(p, substring(me.text, i, 4), me.realFontSize, '1 1 1', theAlpha, 0);
                                                                i += 2;
                                                        }
@@ -335,7 +336,7 @@ void InputBox_draw(entity me)
                                                {
                                                        // green missing
                                                        w = draw_TextWidth(substring(me.text, i, 3), 0, me.realFontSize);
-                                                       draw_Fill(p, eX * w + eY * me.realFontSize_y, eY, 0.5);
+                                                       draw_Fill(p, eX * w + eY * me.realFontSize.y, eY, 0.5);
                                                        draw_Text(p, substring(me.text, i, 3), me.realFontSize, '1 1 1', theAlpha, 0);
                                                        i += 1;
                                                }
@@ -344,13 +345,13 @@ void InputBox_draw(entity me)
                                        {
                                                // red missing
                                                //w = draw_TextWidth(substring(me.text, i, 2), 0) * me.realFontSize_x;
-                                               draw_Fill(p, eX * w + eY * me.realFontSize_y, eX, 0.5);
+                                               draw_Fill(p, eX * w + eY * me.realFontSize.y, eX, 0.5);
                                                draw_Text(p, substring(me.text, i, 2), me.realFontSize, '1 1 1', theAlpha, 0);
                                        }
                                }
                                else
                                {
-                                       draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
+                                       draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5);
                                        draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0);
                                }
                                p += w * eX;