X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fitem%2Finputbox.qc;h=30c325ca415cacf0c806b81e9dac4806f7545644;hb=4da0b1d48eaa7e046fed22cba4709dea8dd5616e;hp=43ef41f817d20303f668c4b2ae2177fe2d982195;hpb=826222f84e886d85179a032b07edc71d99982040;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/item/inputbox.qc b/qcsrc/menu/item/inputbox.qc index 43ef41f81..30c325ca4 100644 --- a/qcsrc/menu/item/inputbox.qc +++ b/qcsrc/menu/item/inputbox.qc @@ -1,51 +1,8 @@ #include "inputbox.qh" -#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)); - 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) +.float cb_offset; +.string cb_src; - ATTRIB(InputBox, cursorPos, float, 0) // characters - 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) - ATTRIB(InputBox, dragScrollPos, vector, '0 0 0') - ATTRIB(InputBox, pressed, float, 0) - ATTRIB(InputBox, editColorCodes, float, 1) - ATTRIB(InputBox, forbiddenCharacters, string, "") - 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, applyButton, entity, NULL) - - 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) -#endif - -#ifdef IMPLEMENTATION void InputBox_configureInputBox(entity me, string theText, float theCursorPos, float theFontSize, string gfx) { SUPER(InputBox).configureLabel(me, theText, theFontSize, 0.0); @@ -65,12 +22,14 @@ void InputBox_setText(entity me, string txt) { - if (me.text) strunzone(me.text); + strfree(me.text); SUPER(InputBox).setText(me, strzone(txt)); } float over_ClearButton(entity me, vector pos) { + if (me.text == "") + return 0; if (pos.x >= 1 + me.cb_offset - me.cb_width) if (pos.x < 1 + me.cb_offset) if (pos.y >= 0) @@ -114,17 +73,17 @@ return 1; } - float InputBox_mousePress(entity me, vector pos) + METHOD(InputBox, mousePress, bool(InputBox this, vector pos)) { - if (me.enableClearButton) - if (over_ClearButton(me, pos)) + if (this.enableClearButton) + if (over_ClearButton(this, pos)) { - me.cb_pressed = 1; - return 1; + this.cb_pressed = 1; + return true; } - me.dragScrollTimer = time; - me.pressed = 1; - return InputBox_mouseDrag(me, pos); + this.dragScrollTimer = time; + this.pressed = 1; + return InputBox_mouseDrag(this, pos); } float InputBox_mouseRelease(entity me, vector pos) @@ -149,19 +108,19 @@ void InputBox_enterText(entity me, string ch) { - float i; - for (i = 0; i < strlen(ch); ++i) + int len = strlen(ch); + for (int i = 0; i < len; ++i) if (strstrofs(me.forbiddenCharacters, substring(ch, i, 1), 0) > -1) return; if (me.maxLength > 0) { - if (strlen(ch) + strlen(me.text) > me.maxLength) return; + if (len + strlen(me.text) > me.maxLength) return; } else if (me.maxLength < 0) { if (u8_strsize(ch) + u8_strsize(me.text) > -me.maxLength) return; } me.setText(me, strcat(substring(me.text, 0, me.cursorPos), ch, substring(me.text, me.cursorPos, strlen(me.text) - me.cursorPos))); - me.cursorPos += strlen(ch); + me.cursorPos += len; } float InputBox_keyDown(entity me, float key, float ascii, float shift) @@ -253,75 +212,52 @@ draw_SetClipRect(eX * me.keepspaceLeft, eX * (1 - me.keepspaceLeft - me.keepspaceRight) + eY); if (me.editColorCodes) { - string ch, ch2; - float i, n; - vector theColor; - float theAlpha; // float theVariableAlpha; - vector p; - vector theTempColor; - float component; + vector p = me.realOrigin - eX * me.scrollPos; + vector theColor = '1 1 1'; + float theAlpha = 1; - 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) + for (int i = 0, n = strlen(me.text); i < n; ++i) { - ch = substring(me.text, i, 1); + string ch = substring(me.text, i, 1); if (ch == "^") { float w; - ch2 = substring(me.text, i + 1, 1); + string ch2 = substring(me.text, i + 1, 1); w = draw_TextWidth(strcat(ch, ch2), 0, me.realFontSize); + float fill_alpha = 0.4; if (ch2 == "^") { - draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5); + if (me.cursorPos > i && me.cursorPos <= i + 2) + fill_alpha = 0.6; + draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', fill_alpha); draw_Text(p + eX * 0.25 * w, "^", me.realFontSize, theColor, theAlpha, 0); } - else if (ch2 == "0" || stof(ch2)) // digit? + else if (IS_DIGIT(ch2)) { + theAlpha = 1; switch (stof(ch2)) { - case 0: theColor = '0 0 0'; - theAlpha = 1; - break; - case 1: theColor = '1 0 0'; - theAlpha = 1; - break; - case 2: theColor = '0 1 0'; - theAlpha = 1; - break; - case 3: theColor = '1 1 0'; - theAlpha = 1; - break; - case 4: theColor = '0 0 1'; - theAlpha = 1; - break; - case 5: theColor = '0 1 1'; - theAlpha = 1; - break; - case 6: theColor = '1 0 1'; - theAlpha = 1; - break; - case 7: theColor = '1 1 1'; - theAlpha = 1; - break; - case 8: theColor = '1 1 1'; - theAlpha = 0.5; - break; - case 9: theColor = '0.5 0.5 0.5'; - theAlpha = 1; - break; + case 0: theColor = '0 0 0'; break; + case 1: theColor = '1 0 0'; break; + case 2: theColor = '0 1 0'; break; + case 3: theColor = '1 1 0'; break; + case 4: theColor = '0 0 1'; break; + case 5: theColor = '0 1 1'; break; + case 6: theColor = '1 0 1'; break; + case 7: theColor = '1 1 1'; break; + case 8: theColor = '1 1 1'; theAlpha = 0.5; break; + case 9: theColor = '0.5 0.5 0.5'; break; } - draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', 0.5); + if (me.cursorPos > i && me.cursorPos <= i + 2) + fill_alpha = 0.6; + draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', fill_alpha); draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0); } else if (ch2 == "x") // ^x found { + vector theTempColor; theColor = '1 1 1'; - - component = HEXDIGIT_TO_DEC(substring(me.text, i + 2, 1)); + float component = HEXDIGIT_TO_DEC(substring(me.text, i + 2, 1)); if (component >= 0) // ^xr found { theTempColor.x = component / 15; @@ -338,15 +274,17 @@ 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 + if (me.cursorPos > i && me.cursorPos <= i + 5) + fill_alpha = 0.8; + draw_Fill(p, eX * w + eY * me.realFontSize.y, '1 1 1', fill_alpha); + draw_Text(p, substring(me.text, i, 5), me.realFontSize, theColor, 1, 0); i += 3; } else { // 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, fill_alpha); draw_Text(p, substring(me.text, i, 4), me.realFontSize, '1 1 1', theAlpha, 0); i += 2; } @@ -355,7 +293,7 @@ { // 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, fill_alpha); draw_Text(p, substring(me.text, i, 3), me.realFontSize, '1 1 1', theAlpha, 0); i += 1; } @@ -364,20 +302,20 @@ { // 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, fill_alpha); 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', fill_alpha); draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0); } p += w * eX; ++i; continue; } - draw_Text(p, ch, me.realFontSize, theColor, theAlpha, 0); // TODO theVariableAlpha + draw_Text(p, ch, me.realFontSize, theColor, theAlpha, 0); p += eX * draw_TextWidth(ch, 0, me.realFontSize); } } @@ -386,24 +324,26 @@ draw_Text(me.realOrigin - eX * me.scrollPos, me.text, me.realFontSize, '1 1 1', 1, 0); } - 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); + 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); 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); - } + if (me.enableClearButton && 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); + MenuItem_draw(me); } void InputBox_showNotify(entity me) { me.focusable = !me.disabled; } -#endif