]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/colorpicker.qc
Merge branch 'master' into develop
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / colorpicker.qc
index 450c5fb29e1d6cf9f8770e0a271a49244e0bad4f..46e698c2e2a1d6a9497ab6c25ffc350b776948ad 100644 (file)
@@ -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