]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/colorpicker.qc
Merge branch 'master' into martin-t/globals
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / colorpicker.qc
index e0727373c14b3a4795db1cde2f3caadaec45bfbc..d8aedf69512a7349910fb0a0c6ba06e0009b6059 100644 (file)
@@ -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,50 +16,50 @@ 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
 vector hslimage_color(vector v, vector margin)
 {
-    v_x = (v_x - margin_x) / (1 - 2 * margin_x);
-    v_y = (v_y - margin_y) / (1 - 2 * margin_y);
-    if(v_x < 0) v_x = 0;
-    if(v_y < 0) v_y = 0;
-    if(v_x > 1) v_x = 1;
-    if(v_y > 1) v_y = 1;
-    if(v_y > 0.875) // grey bar
-        return hsl_to_rgb(eZ * v_x);
+    v_x = (v.x - margin.x) / (1 - 2 * margin.x);
+    v_y = (v.y - margin.y) / (1 - 2 * margin.y);
+    if(v.x < 0) v_x = 0;
+    if(v.y < 0) v_y = 0;
+    if(v.x > 1) v_x = 1;
+    if(v.y > 1) v_y = 1;
+    if(v.y > 0.875) // grey bar
+        return hsl_to_rgb(eZ * v.x);
     else
-        return hsl_to_rgb(v_x * 6 * eX + eY + v_y / 0.875 * eZ);
+        return hsl_to_rgb(v.x * 6 * eX + eY + v.y / 0.875 * eZ);
 }
 
 vector color_hslimage(vector v, vector margin)
 {
        vector pos = '0 0 0';
        v = rgb_to_hsl(v);
-       if (v_y)
+       if (v.y)
        {
-               pos_x = v_x / 6;
-               pos_y = v_z * 0.875;
+               pos_x = v.x / 6;
+               pos_y = v.z * 0.875;
        }
        else // grey scale
        {
-               pos_x = v_z;
+               pos_x = v.z;
                pos_y = 0.875 + 0.07;
        }
-       pos_x = margin_x + pos_x * (1 - 2 * margin_x);
-       pos_y = margin_y + pos_y * (1 - 2 * margin_y);
+       pos_x = margin.x + pos.x * (1 - 2 * margin.x);
+       pos_y = margin.y + pos.y * (1 - 2 * margin.y);
        return pos;
 }
 
 float XonoticColorpicker_mouseDrag(entity me, vector coords)
 {
        float i, carets;
-       for(;;)
+       for (;;)
        {
                i = me.controlledTextbox.cursorPos;
                if(i >= 2)
@@ -84,7 +70,7 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords)
                                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)
+                                       if(IS_DIGIT(substring(me.controlledTextbox.text, i-1, 1)))
                                        {
                                                me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0);
                                                me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0);
@@ -101,9 +87,9 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords)
                                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)
+                                       if(IS_HEXDIGIT(substring(me.controlledTextbox.text, i - 3, 1)))
+                                               if(IS_HEXDIGIT(substring(me.controlledTextbox.text, i - 2, 1)))
+                                                       if(IS_HEXDIGIT(substring(me.controlledTextbox.text, i - 1, 1)))
                                                        {
                                                                me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0);
                                                                me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0);
@@ -128,10 +114,10 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords)
 
        vector margin;
        margin = me.imagemargin;
-       if(coords_x >= margin_x)
-       if(coords_y >= margin_y)
-       if(coords_x <= 1 - margin_x)
-       if(coords_y <= 1 - margin_y)
+       if(coords.x >= margin.x)
+       if(coords.y >= margin.y)
+       if(coords.x <= 1 - margin.x)
+       if(coords.y <= 1 - margin.y)
                me.controlledTextbox.enterText(me.controlledTextbox, rgb_to_hexcolor(hslimage_color(coords, margin)));
 
        return 1;
@@ -139,6 +125,7 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords)
 
 float XonoticColorpicker_mouseRelease(entity me, vector coords)
 {
+       m_play_click_sound(MENU_SOUND_SLIDE);
        me.mouseDrag(me, coords);
        return 1;
 }
@@ -171,4 +158,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