Beispiel #1
0
    public static Color ToColor(RagePixelHSBColor hsbColor)
    {
        float r = hsbColor.b;
        float g = hsbColor.b;
        float b = hsbColor.b;

        if (hsbColor.s != 0)
        {
            float max = hsbColor.b;
            float dif = hsbColor.b * hsbColor.s;
            float min = hsbColor.b - dif;

            float h = hsbColor.h * 360f;

            if (h < 60f)
            {
                r = max;
                g = h * dif / 60f + min;
                b = min;
            }
            else if (h < 120f)
            {
                r = -(h - 120f) * dif / 60f + min;
                g = max;
                b = min;
            }
            else if (h < 180f)
            {
                r = min;
                g = max;
                b = (h - 120f) * dif / 60f + min;
            }
            else if (h < 240f)
            {
                r = min;
                g = -(h - 240f) * dif / 60f + min;
                b = max;
            }
            else if (h < 300f)
            {
                r = (h - 240f) * dif / 60f + min;
                g = min;
                b = max;
            }
            else if (h <= 360f)
            {
                r = max;
                g = min;
                b = -(h - 360f) * dif / 60 + min;
            }
            else
            {
                r = 0;
                g = 0;
                b = 0;
            }
        }

        return(new Color(Mathf.Clamp01(r), Mathf.Clamp01(g), Mathf.Clamp01(b), hsbColor.a));
    }
Beispiel #2
0
    public RagePixelHSBColor(Color col)
    {
        RagePixelHSBColor temp = FromColor(col);

        h = temp.h;
        s = temp.s;
        b = temp.b;
        a = temp.a;
    }
Beispiel #3
0
    public static RagePixelHSBColor FromColor(Color color)
    {
        RagePixelHSBColor ret = new RagePixelHSBColor(0f, 0f, 0f, color.a);

        float r = color.r;
        float g = color.g;
        float b = color.b;

        float max = Mathf.Max(r, Mathf.Max(g, b));

        if (max <= 0)
        {
            return(ret);
        }

        float min = Mathf.Min(r, Mathf.Min(g, b));
        float dif = max - min;

        if (max > min)
        {
            if (g == max)
            {
                ret.h = (b - r) / dif * 60f + 120f;
            }
            else if (b == max)
            {
                ret.h = (r - g) / dif * 60f + 240f;
            }
            else if (b > g)
            {
                ret.h = (g - b) / dif * 60f + 360f;
            }
            else
            {
                ret.h = (g - b) / dif * 60f;
            }
            if (ret.h < 0)
            {
                ret.h = ret.h + 360f;
            }
        }
        else
        {
            ret.h = 0;
        }

        ret.h *= 1f / 360f;
        ret.s  = (dif / max) * 1f;
        ret.b  = max;

        return(ret);
    }
    public static RagePixelHSBColor FromColor(Color color)
    {
        RagePixelHSBColor ret = new RagePixelHSBColor(0f, 0f, 0f, color.a);

        float r = color.r;
        float g = color.g;
        float b = color.b;

        float max = Mathf.Max(r, Mathf.Max(g, b));

        if(max <= 0)
        {
            return ret;
        }

        float min = Mathf.Min(r, Mathf.Min(g, b));
        float dif = max - min;

        if(max > min)
        {
            if(g == max)
            {
                ret.h = (b - r) / dif * 60f + 120f;
            }
            else if(b == max)
            {
                ret.h = (r - g) / dif * 60f + 240f;
            }
            else if(b > g)
            {
                ret.h = (g - b) / dif * 60f + 360f;
            }
            else
            {
                ret.h = (g - b) / dif * 60f;
            }
            if(ret.h < 0)
            {
                ret.h = ret.h + 360f;
            }
        }
        else
        {
            ret.h = 0;
        }

        ret.h *= 1f / 360f;
        ret.s = (dif / max) * 1f;
        ret.b = max;

        return ret;
    }
Beispiel #5
0
    public static RagePixelHSBColor Lerp(RagePixelHSBColor a, RagePixelHSBColor b, float t)
    {
        float h, s;

        //check special case black (color.b==0): interpolate neither hue nor saturation!
        //check special case grey (color.s==0): don't interpolate hue!
        if (a.b == 0)
        {
            h = b.h;
            s = b.s;
        }
        else if (b.b == 0)
        {
            h = a.h;
            s = a.s;
        }
        else
        {
            if (a.s == 0)
            {
                h = b.h;
            }
            else if (b.s == 0)
            {
                h = a.h;
            }
            else
            {
                // works around bug with LerpAngle
                float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t);
                while (angle < 0f)
                {
                    angle += 360f;
                }
                while (angle > 360f)
                {
                    angle -= 360f;
                }
                h = angle / 360f;
            }
            s = Mathf.Lerp(a.s, b.s, t);
        }
        return(new RagePixelHSBColor(h, s, Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t)));
    }
Beispiel #6
0
    public static void Test()
    {
        RagePixelHSBColor color;

        color = new RagePixelHSBColor(Color.red);
        Debug.Log("red: " + color);

        color = new RagePixelHSBColor(Color.green);
        Debug.Log("green: " + color);

        color = new RagePixelHSBColor(Color.blue);
        Debug.Log("blue: " + color);

        color = new RagePixelHSBColor(Color.grey);
        Debug.Log("grey: " + color);

        color = new RagePixelHSBColor(Color.white);
        Debug.Log("white: " + color);

        color = new RagePixelHSBColor(new Color(0.4f, 1f, 0.84f, 1f));
        Debug.Log("0.4, 1f, 0.84: " + color);

        Debug.Log("164,82,84   .... 0.643137f, 0.321568f, 0.329411f  :" + ToColor(new RagePixelHSBColor(new Color(0.643137f, 0.321568f, 0.329411f))));
    }
Beispiel #7
0
    private void renderColorPickerTexture(Texture2D texture)
    {
        for (int pY = 0; pY < texture.height; pY++)
        {
            for (int pX = 0; pX < texture.width; pX++)
            {
                texture.SetPixel(pX, pY, new Color(0f, 0f, 0f, 0f));
                if ((pY < marginSize && pX > marginSize + 5) || (pX > texture.width - marginSize && pY < texture.height - marginSize - 5))
                {
                    texture.SetPixel(pX, pY, new Color(0f, 0f, 0f, 0.1f));
                }
            }
        }

        for (int pY = splitSize + marginSize; pY < texture.height - marginSize; pY++)
        {
            for (int pX = marginSize; pX < texture.width - splitSize - marginSize; pX++)
            {
                RagePixelHSBColor hsb = new RagePixelHSBColor(new RagePixelHSBColor(selectedColor).h, (float)(pX - marginSize) / ((float)texture.width - splitSize - marginSize * 2f), (float)(pY - splitSize - marginSize) / (float)(texture.height - splitSize - marginSize * 2));
                texture.SetPixel(pX, pY, hsb.ToColor());
            }
        }

        for (int pY = splitSize + marginSize; pY < texture.height - marginSize; pY++)
        {
            for (int pX = texture.width - splitSize - marginSize; pX < texture.width - marginSize; pX++)
            {
                RagePixelHSBColor hsb = new RagePixelHSBColor((float)(pY - splitSize - marginSize) / (float)(texture.height - splitSize - marginSize * 2f), 1f, 1f);
                texture.SetPixel(pX, pY, hsb.ToColor());
            }
        }

        for (int pY = marginSize; pY < splitSize + marginSize; pY++)
        {
            for (int pX = marginSize; pX < texture.width - marginSize; pX++)
            {
                RagePixelHSBColor hsb = new RagePixelHSBColor(0f, 0f, (float)(pX - marginSize) / (float)(texture.width - marginSize * 2f));
                texture.SetPixel(pX, pY, hsb.ToColor());
            }
        }

        for (int pY = marginSize; pY < texture.height - marginSize; pY++)
        {
            for (int pX = marginSize; pX < texture.width - marginSize; pX++)
            {
                if (pX == marginSize || pX == texture.width - marginSize - 1 || pY == marginSize || pY == texture.height - marginSize - 1)
                {
                    texture.SetPixel(pX, pY, new Color(0.75f, 0.75f, 0.75f, 1f));
                }
            }
        }

        RagePixelHSBColor pColor = new RagePixelHSBColor(selectedColor);
        int hueY = marginSize + splitSize + Mathf.RoundToInt((texture.height - marginSize * 2 - splitSize) * (pColor.h));

        for (int pX = texture.width - marginSize; pX < texture.width; pX++)
        {
            texture.SetPixel(pX, hueY, new Color(1f, 1f, 1f, 0.33f));
        }
        for (int pX = texture.width - marginSize + 1; pX < texture.width; pX++)
        {
            texture.SetPixel(pX, hueY - 1, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(pX, hueY + 1, new Color(1f, 1f, 1f, 0.33f));
        }
        for (int pX = texture.width - marginSize + 2; pX < texture.width; pX++)
        {
            texture.SetPixel(pX, hueY - 2, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(pX, hueY + 2, new Color(1f, 1f, 1f, 0.33f));
        }
        for (int pX = texture.width - marginSize + 3; pX < texture.width; pX++)
        {
            texture.SetPixel(pX, hueY - 3, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(pX, hueY + 3, new Color(1f, 1f, 1f, 0.33f));
        }

        int alphaX = marginSize + Mathf.RoundToInt((texture.width - marginSize * 2f) * Mathf.Clamp01(pColor.a));

        for (int pY = 0; pY < marginSize; pY++)
        {
            texture.SetPixel(alphaX, pY, new Color(1f, 1f, 1f, 0.33f));
        }
        for (int pY = 0; pY < marginSize - 1; pY++)
        {
            texture.SetPixel(alphaX - 1, pY, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(alphaX + 1, pY, new Color(1f, 1f, 1f, 0.33f));
        }
        for (int pY = 0; pY < marginSize - 2; pY++)
        {
            texture.SetPixel(alphaX - 2, pY, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(alphaX + 2, pY, new Color(1f, 1f, 1f, 0.33f));
        }
        for (int pY = 0; pY < marginSize - 3; pY++)
        {
            texture.SetPixel(alphaX - 3, pY, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(alphaX + 3, pY, new Color(1f, 1f, 1f, 0.33f));
        }

        int pickerX = marginSize + Mathf.RoundToInt((texture.width - marginSize * 2f - splitSize) * (pColor.s));
        int pickerY = marginSize + splitSize + Mathf.RoundToInt((texture.height - marginSize * 2f - splitSize) * (pColor.b));

        texture.SetPixel(pickerX, pickerY + 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 1, pickerY + 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 2, pickerY + 2, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 3, pickerY + 1, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 3, pickerY, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 3, pickerY - 1, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 2, pickerY - 2, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 1, pickerY - 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX, pickerY - 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 1, pickerY - 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 2, pickerY - 2, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 3, pickerY - 1, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 3, pickerY, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 3, pickerY + 1, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 2, pickerY + 2, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 1, pickerY + 3, new Color(0.5f, 0.5f, 0.5f, 1f));

        texture.filterMode = FilterMode.Point;

        texture.Apply();
    }
Beispiel #8
0
    public bool HandleGUIEvent(Event ev)
    {
        bool used = false;

        if (visible)
        {
            Vector2 localMousePos = ev.mousePosition - new Vector2(bounds.xMin, bounds.yMin) - new Vector2(marginSize, marginSize);

            Rect sbBounds = new Rect(0, 0, pixelWidth - marginSize * 2 - splitSize, pixelHeight - marginSize * 2 - splitSize);
            Rect aBounds  = new Rect(0, pixelWidth - marginSize - splitSize, pixelHeight - marginSize * 2, splitSize);
            Rect hBounds  = new Rect(pixelWidth - marginSize * 2 - splitSize, 0, splitSize, pixelHeight - marginSize * 2 - splitSize);

            if (bounds.Contains(ev.mousePosition))
            {
                if (ev.type == EventType.mouseUp)
                {
                    activeArea = GUIArea.None;
                    used       = true;
                }
                else if (ev.type == EventType.mouseDown)
                {
                    if (sbBounds.Contains(localMousePos))
                    {
                        activeArea = GUIArea.Color;
                    }
                    else if (hBounds.Contains(localMousePos))
                    {
                        activeArea = GUIArea.Hue;
                    }
                    else if (aBounds.Contains(localMousePos))
                    {
                        activeArea = GUIArea.Alpha;
                    }
                    else
                    {
                        activeArea = GUIArea.None;
                    }
                    used = true;
                }
            }
            else
            {
                if (Event.current.type == EventType.mouseDown)
                {
                    activeArea = GUIArea.None;
                }
            }

            if ((Event.current.type == EventType.mouseDrag || Event.current.type == EventType.mouseDown) && activeArea != GUIArea.None)
            {
                RagePixelHSBColor hsbcolor = new RagePixelHSBColor(selectedColor);
                switch (activeArea)
                {
                case GUIArea.Color:
                    hsbcolor.s = Mathf.Clamp(localMousePos.x, 0.001f, sbBounds.width - 0.001f) / (sbBounds.width);
                    hsbcolor.b = 1f - Mathf.Clamp(localMousePos.y, 0.001f, sbBounds.height - 0.001f) / (sbBounds.height);
                    break;

                case GUIArea.Hue:
                    hsbcolor.h = 1f - Mathf.Clamp(localMousePos.y, 0.001f, hBounds.height - 0.001f) / (hBounds.height);
                    break;

                case GUIArea.Alpha:
                    hsbcolor.a = Mathf.Clamp(localMousePos.x, 0.001f, aBounds.width - 0.001f) / (aBounds.width);
                    break;
                }
                selectedColor = hsbcolor.ToColor();
                used          = true;
            }
        }

        return(used);
    }
    public static RagePixelHSBColor Lerp(RagePixelHSBColor a, RagePixelHSBColor b, float t)
    {
        float h, s;

        //check special case black (color.b==0): interpolate neither hue nor saturation!
        //check special case grey (color.s==0): don't interpolate hue!
        if(a.b == 0)
        {
            h = b.h;
            s = b.s;
        }
        else if(b.b == 0)
        {
            h = a.h;
            s = a.s;
        }
        else
        {
            if(a.s == 0)
            {
                h = b.h;
            }
            else if(b.s == 0)
            {
                h = a.h;
            }
            else
            {
                // works around bug with LerpAngle
                float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t);
                while(angle < 0f)
                    angle += 360f;
                while(angle > 360f)
                    angle -= 360f;
                h = angle / 360f;
            }
            s = Mathf.Lerp(a.s, b.s, t);
        }
        return new RagePixelHSBColor(h, s, Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t));
    }
    public static Color ToColor(RagePixelHSBColor hsbColor)
    {
        float r = hsbColor.b;
        float g = hsbColor.b;
        float b = hsbColor.b;
        if(hsbColor.s != 0)
        {
            float max = hsbColor.b;
            float dif = hsbColor.b * hsbColor.s;
            float min = hsbColor.b - dif;

            float h = hsbColor.h * 360f;

            if(h < 60f)
            {
                r = max;
                g = h * dif / 60f + min;
                b = min;
            }
            else if(h < 120f)
            {
                r = -(h - 120f) * dif / 60f + min;
                g = max;
                b = min;
            }
            else if(h < 180f)
            {
                r = min;
                g = max;
                b = (h - 120f) * dif / 60f + min;
            }
            else if(h < 240f)
            {
                r = min;
                g = -(h - 240f) * dif / 60f + min;
                b = max;
            }
            else if(h < 300f)
            {
                r = (h - 240f) * dif / 60f + min;
                g = min;
                b = max;
            }
            else if(h <= 360f)
            {
                r = max;
                g = min;
                b = -(h - 360f) * dif / 60 + min;
            }
            else
            {
                r = 0;
                g = 0;
                b = 0;
            }
        }

        return new Color(Mathf.Clamp01(r), Mathf.Clamp01(g), Mathf.Clamp01(b), hsbColor.a);
    }
    public static void Test()
    {
        RagePixelHSBColor color;

        color = new RagePixelHSBColor(Color.red);
        Debug.Log("red: " + color);

        color = new RagePixelHSBColor(Color.green);
        Debug.Log("green: " + color);

        color = new RagePixelHSBColor(Color.blue);
        Debug.Log("blue: " + color);

        color = new RagePixelHSBColor(Color.grey);
        Debug.Log("grey: " + color);

        color = new RagePixelHSBColor(Color.white);
        Debug.Log("white: " + color);

        color = new RagePixelHSBColor(new Color(0.4f, 1f, 0.84f, 1f));
        Debug.Log("0.4, 1f, 0.84: " + color);

        Debug.Log("164,82,84   .... 0.643137f, 0.321568f, 0.329411f  :" + ToColor(new RagePixelHSBColor(new Color(0.643137f, 0.321568f, 0.329411f))));
    }
    private void renderColorPickerTexture(Texture2D texture)
    {
        for(int pY = 0; pY < texture.height; pY++)
        {
            for(int pX = 0; pX < texture.width; pX++)
            {
                texture.SetPixel(pX, pY, new Color(0f, 0f, 0f, 0f));
                if((pY < marginSize && pX > marginSize + 5) || (pX > texture.width - marginSize && pY < texture.height - marginSize - 5))
                {
                    texture.SetPixel(pX, pY, new Color(0f, 0f, 0f, 0.1f));
                }
            }
        }

        for(int pY = splitSize + marginSize; pY < texture.height - marginSize; pY++)
        {
            for(int pX = marginSize; pX < texture.width - splitSize - marginSize; pX++)
            {
                RagePixelHSBColor hsb = new RagePixelHSBColor(new RagePixelHSBColor(selectedColor).h, (float)(pX - marginSize) / ((float)texture.width - splitSize - marginSize * 2f), (float)(pY - splitSize - marginSize) / (float)(texture.height - splitSize - marginSize * 2));
                texture.SetPixel(pX, pY, hsb.ToColor());
            }
        }

        for(int pY = splitSize + marginSize; pY < texture.height - marginSize; pY++)
        {
            for(int pX = texture.width - splitSize - marginSize; pX < texture.width - marginSize; pX++)
            {
                RagePixelHSBColor hsb = new RagePixelHSBColor((float)(pY - splitSize - marginSize) / (float)(texture.height - splitSize - marginSize * 2f), 1f, 1f);
                texture.SetPixel(pX, pY, hsb.ToColor());
            }
        }

        for(int pY = marginSize; pY < splitSize + marginSize; pY++)
        {
            for(int pX = marginSize; pX < texture.width - marginSize; pX++)
            {
                RagePixelHSBColor hsb = new RagePixelHSBColor(0f, 0f, (float)(pX - marginSize) / (float)(texture.width - marginSize * 2f));
                texture.SetPixel(pX, pY, hsb.ToColor());
            }
        }

        for(int pY = marginSize; pY < texture.height - marginSize; pY++)
        {
            for(int pX = marginSize; pX < texture.width - marginSize; pX++)
            {
                if(pX == marginSize || pX == texture.width - marginSize - 1 || pY == marginSize || pY == texture.height - marginSize - 1)
                {
                    texture.SetPixel(pX, pY, new Color(0.75f, 0.75f, 0.75f, 1f));
                }
            }
        }

        RagePixelHSBColor pColor = new RagePixelHSBColor(selectedColor);
        int hueY = marginSize + splitSize + Mathf.RoundToInt((texture.height - marginSize * 2 - splitSize) * (pColor.h));

        for(int pX = texture.width - marginSize; pX < texture.width; pX++)
        {
            texture.SetPixel(pX, hueY, new Color(1f, 1f, 1f, 0.33f));
        }
        for(int pX = texture.width - marginSize + 1; pX < texture.width; pX++)
        {
            texture.SetPixel(pX, hueY - 1, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(pX, hueY + 1, new Color(1f, 1f, 1f, 0.33f));
        }
        for(int pX = texture.width - marginSize + 2; pX < texture.width; pX++)
        {
            texture.SetPixel(pX, hueY - 2, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(pX, hueY + 2, new Color(1f, 1f, 1f, 0.33f));
        }
        for(int pX = texture.width - marginSize + 3; pX < texture.width; pX++)
        {
            texture.SetPixel(pX, hueY - 3, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(pX, hueY + 3, new Color(1f, 1f, 1f, 0.33f));
        }

        int alphaX = marginSize + Mathf.RoundToInt((texture.width - marginSize * 2f) * Mathf.Clamp01(pColor.a));
        for(int pY = 0; pY < marginSize; pY++)
        {
            texture.SetPixel(alphaX, pY, new Color(1f, 1f, 1f, 0.33f));
        }
        for(int pY = 0; pY < marginSize - 1; pY++)
        {
            texture.SetPixel(alphaX - 1, pY, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(alphaX + 1, pY, new Color(1f, 1f, 1f, 0.33f));
        }
        for(int pY = 0; pY < marginSize - 2; pY++)
        {
            texture.SetPixel(alphaX - 2, pY, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(alphaX + 2, pY, new Color(1f, 1f, 1f, 0.33f));
        }
        for(int pY = 0; pY < marginSize - 3; pY++)
        {
            texture.SetPixel(alphaX - 3, pY, new Color(1f, 1f, 1f, 0.33f));
            texture.SetPixel(alphaX + 3, pY, new Color(1f, 1f, 1f, 0.33f));
        }

        int pickerX = marginSize + Mathf.RoundToInt((texture.width - marginSize * 2f - splitSize) * (pColor.s));
        int pickerY = marginSize + splitSize + Mathf.RoundToInt((texture.height - marginSize * 2f - splitSize) * (pColor.b));

        texture.SetPixel(pickerX, pickerY + 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 1, pickerY + 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 2, pickerY + 2, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 3, pickerY + 1, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 3, pickerY, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 3, pickerY - 1, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 2, pickerY - 2, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX + 1, pickerY - 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX, pickerY - 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 1, pickerY - 3, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 2, pickerY - 2, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 3, pickerY - 1, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 3, pickerY, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 3, pickerY + 1, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 2, pickerY + 2, new Color(0.5f, 0.5f, 0.5f, 1f));
        texture.SetPixel(pickerX - 1, pickerY + 3, new Color(0.5f, 0.5f, 0.5f, 1f));

        texture.filterMode = FilterMode.Point;

        texture.Apply();
    }
    public bool HandleGUIEvent(Event ev)
    {
        bool used = false;
        if(visible)
        {
            Vector2 localMousePos = ev.mousePosition - new Vector2(bounds.xMin, bounds.yMin) - new Vector2(marginSize, marginSize);

            Rect sbBounds = new Rect(0, 0, pixelWidth - marginSize * 2 - splitSize, pixelHeight - marginSize * 2 - splitSize);
            Rect aBounds = new Rect(0, pixelWidth - marginSize - splitSize, pixelHeight - marginSize * 2, splitSize);
            Rect hBounds = new Rect(pixelWidth - marginSize * 2 - splitSize, 0, splitSize, pixelHeight - marginSize * 2 - splitSize);

            if(bounds.Contains(ev.mousePosition))
            {
                if(ev.type == EventType.mouseUp)
                {
                    activeArea = GUIArea.None;
                    used = true;
                }
                else if(ev.type == EventType.mouseDown)
                {
                    if(sbBounds.Contains(localMousePos))
                    {
                        activeArea = GUIArea.Color;
                    }
                    else if(hBounds.Contains(localMousePos))
                    {
                        activeArea = GUIArea.Hue;
                    }
                    else if(aBounds.Contains(localMousePos))
                    {
                        activeArea = GUIArea.Alpha;
                    }
                    else
                    {
                        activeArea = GUIArea.None;
                    }
                    used = true;
                }
            }
            else
            {
                if(Event.current.type == EventType.mouseDown)
                {
                    activeArea = GUIArea.None;
                }
            }

            if((Event.current.type == EventType.mouseDrag || Event.current.type == EventType.mouseDown) && activeArea != GUIArea.None)
            {
                RagePixelHSBColor hsbcolor = new RagePixelHSBColor(selectedColor);
                switch(activeArea)
                {
                case GUIArea.Color:
                    hsbcolor.s = Mathf.Clamp(localMousePos.x, 0.001f, sbBounds.width - 0.001f) / (sbBounds.width);
                    hsbcolor.b = 1f - Mathf.Clamp(localMousePos.y, 0.001f, sbBounds.height - 0.001f) / (sbBounds.height);
                    break;
                case GUIArea.Hue:
                    hsbcolor.h = 1f - Mathf.Clamp(localMousePos.y, 0.001f, hBounds.height - 0.001f) / (hBounds.height);
                    break;
                case GUIArea.Alpha:
                    hsbcolor.a = Mathf.Clamp(localMousePos.x, 0.001f, aBounds.width - 0.001f) / (aBounds.width);
                    break;
                }
                selectedColor = hsbcolor.ToColor();
                used = true;
            }
        }

        return used;
    }