X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fcolorpicker.qc;h=46e698c2e2a1d6a9497ab6c25ffc350b776948ad;hb=a3e71389992c582ccf77ca5b11d1f0ceee50eb9f;hp=f7d72439db5f2011dba96eb14aeab8269159abfd;hpb=785232fc90ed7bd7038c79f65534a7e79efd7f45;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/colorpicker.qc b/qcsrc/menu/xonotic/colorpicker.qc index f7d72439d..46e698c2e 100644 --- a/qcsrc/menu/xonotic/colorpicker.qc +++ b/qcsrc/menu/xonotic/colorpicker.qc @@ -1,23 +1,7 @@ -#ifndef COLORPICKER_H -#define COLORPICKER_H -#include "../item/image.qc" -CLASS(XonoticColorpicker, 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; @@ -32,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 @@ -74,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 } @@ -174,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