Ejemplo n.º 1
0
        internal static void RenderHueRect(LGuiRect Rect)
        {
            var Width  = (int)Rect.Width;
            var Height = (int)Rect.Height;

            var Vertices = new LGuiVec2[Width * Height];
            var Colors   = new LGuiColor[Width * Height];
            var Indices  = new int[Width * Height * 2];
            var Index    = 0;

            for (var Y = 0; Y < Height; ++Y)
            {
                for (var X = 0; X < Width; ++X)
                {
                    Colors[Index]   = LGuiColor.Hsv2Rgb(new LGuiColor(X / (float)(Width - 1), 1, 1));
                    Vertices[Index] = new LGuiVec2(X, Y);

                    Indices[Index * 2 + 0] = Index;
                    Indices[Index * 2 + 1] = Index;
                    Index++;
                }
            }

            LGuiGraphics.DrawPrimitive(Rect, Vertices, Colors, Indices);
        }
Ejemplo n.º 2
0
        internal static bool OnProcess(string Title, LGuiRect Rect, ref LGuiColor Color)
        {
            LGuiFrame.Begin(Title, Rect);

            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

            if (!LGuiMisc.CheckVisible(ref Rect))
            {
                return(false);
            }

            var Hsv          = LGuiContextCache.GetColorPickerHsv(Title);
            var FrameSpacing = LGuiStyle.GetFrameChildSpacing();
            var SpacingY     = LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingY);
            var SliderSize   = LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize);

            var ColorRect = new LGuiRect(Rect.Pos + FrameSpacing, new LGuiVec2(Rect.Width - FrameSpacing.X * 2.0f, Rect.Height - (SliderSize + SpacingY) * 4.0f - SpacingY * 3.0f - 20));

            RenderColorRect(ColorRect, Hsv.R);
            RenderColorCross(ColorRect, Hsv.G, Hsv.B);

            var IDColor = LGuiHash.CalculateID($"{Title}_ColorSelector");

            LGuiMisc.CheckAndSetContextID(ref ColorRect, IDColor);

            var HsvValueChanged = false;

            if (LGuiContext.ActiveID == IDColor)
            {
                var X = LGuiMisc.Lerp(0.0f, 1.0f, (LGuiContext.IO.MousePos.X - ColorRect.X) / ColorRect.Width);
                var Y = LGuiMisc.Lerp(0.0f, 1.0f, (ColorRect.Height - (LGuiContext.IO.MousePos.Y - ColorRect.Y)) / ColorRect.Height);

                if (X != Hsv.G || Y != Hsv.B)
                {
                    HsvValueChanged = true;
                    Hsv.G           = X;
                    Hsv.B           = Y;
                }
            }

            var HueRect = new LGuiRect(Rect.X + FrameSpacing.X, ColorRect.Bottom + FrameSpacing.Y, ColorRect.Width, 20);

            RenderHueRect(HueRect);
            RenderHueArrow(HueRect, Hsv.R);

            var IDHue = LGuiHash.CalculateID($"{Title}_HueSelector");

            LGuiMisc.CheckAndSetContextID(ref HueRect, IDHue);

            if (LGuiContext.ActiveID == IDHue)
            {
                var Hue = LGuiMisc.Lerp(0.0f, 1.0f, (LGuiContext.IO.MousePos.X - HueRect.X) / HueRect.Width);

                if (Hue != Hsv.R)
                {
                    HsvValueChanged = true;
                    Hsv.R           = Hue;
                }
            }

            HsvValueChanged |= HandleHsvSlider(Title, ref Hsv, new LGuiVec2(HueRect.X, HueRect.Bottom + SpacingY), HueRect.Width / 2.0f);

            if (HsvValueChanged)
            {
                Color = LGuiColor.Hsv2Rgb(Hsv);
                LGuiContextCache.SetColorPickerHsv(Title, Hsv);
            }

            var RgbValueChanged = false;

            if (HandleRgbSlider(Title, ref Color, new LGuiVec2(HueRect.X + HueRect.Width / 2.0f + 2.5f, HueRect.Bottom + SpacingY), HueRect.Width / 2.0f))
            {
                RgbValueChanged = true;
                LGuiContextCache.SetColorPickerHsv(Title, LGuiColor.Rgb2Hsv(Color));
            }

            var CurrentTitleWidth = LGuiContext.Font.FontWidth * 8.5f;

            LGuiGraphics.DrawText("Current:", new LGuiVec2(HueRect.X, HueRect.Bottom + SpacingY + (SliderSize + SpacingY) * 3.0f), LGuiStyleColorIndex.Text);
            LGuiGraphics.DrawRect(new LGuiRect(HueRect.X + CurrentTitleWidth, HueRect.Bottom + SpacingY + (SliderSize + SpacingY) * 3.0f, HueRect.Width / 2.0f - CurrentTitleWidth, SliderSize), Color, true, false);

            LGuiFrame.End();

            return(HsvValueChanged | RgbValueChanged);
        }