X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fitem%2Finputbox.c;h=1c1bf5189bc34a48a824a46f132e96e79e2f83cb;hb=5d84c659e4c2c51c996b5330fa19c8a24887e42d;hp=572d3a0710dd866bef056667cb2862165d80cf0b;hpb=30125332eda7a5e10bd535c63c3f689729155810;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/item/inputbox.c b/qcsrc/menu/item/inputbox.c index 572d3a071..1c1bf5189 100644 --- a/qcsrc/menu/item/inputbox.c +++ b/qcsrc/menu/item/inputbox.c @@ -5,10 +5,12 @@ CLASS(InputBox) EXTENDS(Label) METHOD(InputBox, setText, void(entity, string)) METHOD(InputBox, enterText, void(entity, string)) METHOD(InputBox, keyDown, float(entity, float, float, float)) + METHOD(InputBox, mouseMove, float(entity, vector)) METHOD(InputBox, mouseRelease, float(entity, vector)) METHOD(InputBox, mousePress, float(entity, vector)) METHOD(InputBox, mouseDrag, float(entity, vector)) METHOD(InputBox, showNotify, void(entity)) + METHOD(InputBox, resizeNotify, void(entity, vector, vector, vector, vector)) ATTRIB(InputBox, src, string, string_null) @@ -26,6 +28,15 @@ CLASS(InputBox) EXTENDS(Label) ATTRIB(InputBox, color, vector, '1 1 1') ATTRIB(InputBox, colorF, vector, '1 1 1') ATTRIB(InputBox, maxLength, float, 255) // if negative, it counts bytes, not chars + + ATTRIB(InputBox, enableClearButton, float, 1) + ATTRIB(InputBox, clearButton, entity, NULL) + ATTRIB(InputBox, cb_width, float, 0) + ATTRIB(InputBox, cb_pressed, float, 0) + ATTRIB(InputBox, cb_focused, float, 0) + 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 @@ -37,6 +48,16 @@ void InputBox_configureInputBox(entity me, string theText, float theCursorPos, f me.src = gfx; me.cursorPos = theCursorPos; } +void InputBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + SUPER(InputBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); + if (me.enableClearButton) + { + 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; + } +} void InputBox_setText(entity me, string txt) { @@ -50,18 +71,60 @@ 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) + return 1; + return 0; +} + +float InputBox_mouseMove(entity me, vector pos) +{ + if (me.enableClearButton) + { + if (over_ClearButton(me, pos)) + { + me.cb_focused = 1; + return 1; + } + me.cb_focused = 0; + } + return 1; +} + float InputBox_mouseDrag(entity me, vector pos) { float p; - me.dragScrollPos = pos; - p = me.scrollPos + pos_x - me.keepspaceLeft; - me.cursorPos = draw_TextLengthUpToWidth(me.text, p, 0, me.realFontSize); - me.lastChangeTime = time; + if(me.pressed) + { + me.dragScrollPos = pos; + p = me.scrollPos + pos_x - me.keepspaceLeft; + me.cursorPos = draw_TextLengthUpToWidth(me.text, p, 0, me.realFontSize); + me.lastChangeTime = time; + } + else if (me.enableClearButton) + { + if (over_ClearButton(me, pos)) + { + me.cb_pressed = 1; + return 1; + } + } + me.cb_pressed = 0; return 1; } float InputBox_mousePress(entity me, vector pos) { + if (me.enableClearButton) + if (over_ClearButton(me, pos)) + { + me.cb_pressed = 1; + return 1; + } me.dragScrollTimer = time; me.pressed = 1; return InputBox_mouseDrag(me, pos); @@ -69,8 +132,19 @@ float InputBox_mousePress(entity me, vector pos) float InputBox_mouseRelease(entity me, vector pos) { + if(me.cb_pressed) + if (over_ClearButton(me, pos)) + { + me.cb_pressed = 0; + InputBox_Clear_Click(world, me); + return 1; + } + float r = InputBox_mouseDrag(me, pos); + //reset cb_pressed after mouseDrag, mouseDrag could set cb_pressed in this case: + //mouse press out of the clear button, drag and then mouse release over the clear button + me.cb_pressed = 0; me.pressed = 0; - return InputBox_mouseDrag(me, pos); + return r; } void InputBox_enterText(entity me, string ch) @@ -186,11 +260,11 @@ void InputBox_draw(entity me) vector p; vector theTempColor; float component; - + p = me.realOrigin - eX * me.scrollPos; theColor = '1 1 1'; theAlpha = 1; //theVariableAlpha = 1; // changes when ^ax found - + n = strlen(me.text); for(i = 0; i < n; ++i) { @@ -226,24 +300,24 @@ void InputBox_draw(entity me) else if(ch2 == "x") // ^x found { theColor = '1 1 1'; - + component = HEXDIGIT_TO_DEC(substring(me.text, i+2, 1)); if (component >= 0) // ^xr found { theTempColor_x = component/15; - + component = HEXDIGIT_TO_DEC(substring(me.text, i+3, 1)); if (component >= 0) // ^xrg found { theTempColor_y = component/15; - + component = HEXDIGIT_TO_DEC(substring(me.text, i+4, 1)); if (component >= 0) // ^xrgb found { 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_Text(p, substring(me.text, i, 5), me.realFontSize, theColor, 1, 0); // theVariableAlpha instead of 1 using alpha tags ^ax i += 3; @@ -295,6 +369,17 @@ void InputBox_draw(entity me) draw_ClearClip(); + if (me.enableClearButton) + if (me.text != "") + { + if(me.focused && me.cb_pressed) + 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(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(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); }