X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fcolorpicker.qc;h=46e698c2e2a1d6a9497ab6c25ffc350b776948ad;hb=af2f0cb624aaf967708b22e1303d113668af5114;hp=f16ab0ebd45fd0a16a0f941e06cfb9766941fe69;hpb=77f03e6ce033bef39ac19e0e7cb6e606ffcb26db;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/colorpicker.qc b/qcsrc/menu/xonotic/colorpicker.qc index f16ab0ebd..46e698c2e 100644 --- a/qcsrc/menu/xonotic/colorpicker.qc +++ b/qcsrc/menu/xonotic/colorpicker.qc @@ -1,25 +1,11 @@ -#ifdef INTERFACE -CLASS(XonoticColorpicker) EXTENDS(Image) - METHOD(XonoticColorpicker, configureXonoticColorpicker, void(entity, entity)) - METHOD(XonoticColorpicker, mousePress, float(entity, vector)) - METHOD(XonoticColorpicker, mouseRelease, float(entity, vector)) - METHOD(XonoticColorpicker, mouseDrag, float(entity, vector)) - ATTRIB(XonoticColorpicker, controlledTextbox, entity, NULL) - ATTRIB(XonoticColorpicker, image, string, SKINGFX_COLORPICKER) - ATTRIB(XonoticColorpicker, imagemargin, vector, SKINMARGIN_COLORPICKER) - ATTRIB(XonoticColorpicker, focusable, float, 1) - METHOD(XonoticColorpicker, focusLeave, void(entity)) - METHOD(XonoticColorpicker, keyDown, float(entity, float, float, float)) - METHOD(XonoticColorpicker, draw, void(entity)) -ENDCLASS(XonoticColorpicker) -entity makeXonoticColorpicker(entity theTextbox); -#endif - -#ifdef IMPLEMENTATION +#include "colorpicker.qh" + +#include "inputbox.qh" + entity makeXonoticColorpicker(entity theTextbox) { entity me; - me = spawnXonoticColorpicker(); + me = NEW(XonoticColorpicker); me.configureXonoticColorpicker(me, theTextbox); return me; } @@ -30,10 +16,10 @@ void XonoticColorpicker_configureXonoticColorpicker(entity me, entity theTextbox me.configureImage(me, me.image); } -float XonoticColorpicker_mousePress(entity me, vector coords) +METHOD(XonoticColorpicker, mousePress, bool(XonoticColorpicker this, vector pos)) { - me.mouseDrag(me, coords); - return 1; + this.mouseDrag(this, pos); + return true; } // must match hslimage.c @@ -72,57 +58,25 @@ vector color_hslimage(vector v, vector margin) float XonoticColorpicker_mouseDrag(entity me, vector coords) { - float i, carets; + int i; for (;;) { i = me.controlledTextbox.cursorPos; - if(i >= 2) - { - if(substring(me.controlledTextbox.text, i-2, 1) == "^") - { - carets = 1; - while (i - 2 - carets >= 0 && substring(me.controlledTextbox.text, i - 2 - carets, 1) == "^") - ++carets; - if (carets & 1) - if(strstrofs("0123456789", substring(me.controlledTextbox.text, i-1, 1), 0) >= 0) - { - me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); - me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); - continue; - } - } - } - - if(i >= 5) - { - if(substring(me.controlledTextbox.text, i-5, 2) == "^x") - { - carets = 1; - while (i - 5 - carets >= 0 && substring(me.controlledTextbox.text, i - 5 - carets, 1) == "^") - ++carets; - if (carets & 1) - if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-3, 1), 0) >= 0) - if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-2, 1), 0) >= 0) - if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-1, 1), 0) >= 0) - { - me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); - me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); - me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); - me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); - me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); - continue; - } - } - } - break; + string theText = me.controlledTextbox.text; + vector res = checkColorCode(theText, strlen(theText), i, true); + if (!res.x) + break; + + int cc_len = res.x; + int new_pos = i - res.y; + theText = strcat(substring(theText, 0, new_pos), substring(theText, new_pos + cc_len, -1)); + me.controlledTextbox.setText(me.controlledTextbox, theText); + me.controlledTextbox.cursorPos = new_pos; } if(substring(me.controlledTextbox.text, i-1, 1) == "^") { - carets = 1; - while (i - 1 - carets >= 0 && substring(me.controlledTextbox.text, i - 1 - carets, 1) == "^") - ++carets; - if (carets & 1) + if(!isCaretEscaped(me.controlledTextbox.text, i-1)) me.controlledTextbox.enterText(me.controlledTextbox, "^"); // escape previous caret } @@ -172,4 +126,3 @@ void XonoticColorpicker_draw(entity me) draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, '0 0 0', aC); draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, me.color, B); } -#endif