From: terencehill Date: Mon, 14 Feb 2011 21:09:01 +0000 (+0100) Subject: Incorporated Clear button inside inputboxes that shows up only when the input box... X-Git-Tag: xonotic-v0.7.0~55^2~13^2~12 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=66fe1bae0cc9858c7825f02a4f76719fa1486a94;p=xonotic%2Fxonotic-data.pk3dir.git Incorporated Clear button inside inputboxes that shows up only when the input box isn't empty --- diff --git a/gfx/menu/luminos/clearbutton_c.tga b/gfx/menu/luminos/clearbutton_c.tga new file mode 100644 index 0000000000..df5b64cb6c Binary files /dev/null and b/gfx/menu/luminos/clearbutton_c.tga differ diff --git a/gfx/menu/luminos/clearbutton_f.tga b/gfx/menu/luminos/clearbutton_f.tga new file mode 100644 index 0000000000..1ef420399e Binary files /dev/null and b/gfx/menu/luminos/clearbutton_f.tga differ diff --git a/gfx/menu/luminos/clearbutton_n.tga b/gfx/menu/luminos/clearbutton_n.tga new file mode 100644 index 0000000000..201645b976 Binary files /dev/null and b/gfx/menu/luminos/clearbutton_n.tga differ diff --git a/qcsrc/menu/item/inputbox.c b/qcsrc/menu/item/inputbox.c index 5b07afd4ee..dc532c0ca3 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,14 @@ 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_size, vector, '0 0 0') + ATTRIB(InputBox, cb_pressed, float, 0) + ATTRIB(InputBox, cb_focused, float, 0) + // ATTRIB(InputBox, cb_src, string, SKINGFX_CLEARBUTTON) + ATTRIB(InputBox, cb_src, string, "clearbutton") ENDCLASS(InputBox) void InputBox_Clear_Click(entity btn, entity me); #endif @@ -37,6 +47,15 @@ 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_size = eX * (absSize_y / absSize_x) + eY; + me.keepspaceRight = me.keepspaceRight + me.cb_size_x; + } +} void InputBox_setText(entity me, string txt) { @@ -50,18 +69,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_size_x) + if (pos_x < 1) + if (pos_y >= 0) + if (pos_y < me.cb_size_y) + 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 +130,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) @@ -292,6 +364,17 @@ void InputBox_draw(entity me) draw_Text(me.realOrigin + eX * (cursorPosInWidths - me.scrollPos), CURSOR, me.realFontSize, '1 1 1', 1, 0); draw_ClearClip(); + + if (me.enableClearButton) + 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); + 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); + else + draw_Picture('1 1 0' - me.cb_size, strcat(me.cb_src, "_n"), me.cb_size, '1 1 1', 1); + } } void InputBox_showNotify(entity me)