Пример #1
0
 public static void End()
 {
     LGuiWindow.End();
     LGuiLayout.End();
     LGuiContext.End();
     LGuiGraphics.End();
 }
Пример #2
0
        internal static bool OnProcess(string Title, bool Value, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

            var BoxSize = LGuiStyle.GetValue(LGuiStyleValueIndex.CheckBoxSize);
            var BoxRect = new LGuiRect(new LGuiVec2(Rect.X, Rect.Y + (Rect.Height - BoxSize) / 2.0f), new LGuiVec2(BoxSize, BoxSize));

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.FrameActived :
                               LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.FrameHovered : LGuiStyleColorIndex.Frame;

            LGuiGraphics.DrawRect(BoxRect, BgColorIndex, true);
            LGuiGraphics.DrawRect(BoxRect, LGuiStyleColorIndex.Border, false);
            if (Value)
            {
                LGuiGraphics.DrawRect(new LGuiRect(BoxRect.X + 2, BoxRect.Y + 2, BoxRect.Width - 4, BoxRect.Height - 4), LGuiStyleColorIndex.CheckMask, true);
            }
            LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + BoxSize + 3, Rect.Y + 1), LGuiStyleColorIndex.Text);

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
                Value = !Value;
            }

            return(Value);
        }
Пример #3
0
        internal static void Begin(string Title, LGuiRect Rect, bool IsChild = true)
        {
            var FullTitle = $"{LGuiContext.GetCurrentFrame().Title}/{Title}";
            var ID        = LGuiHash.CalculateID(FullTitle);

            LGuiContext.SetPreviousControlID(ID);

            var Offset  = LGuiContextCache.GetFrameOffset(FullTitle);
            var Context = new LGuiFrameContext(FullTitle, Rect);

            Context.Size = LGuiContextCache.GetFrameContextSize(FullTitle);

            if (!LGuiMisc.CheckVisible(ref Context.Rect))
            {
                Context.Visibled = false;
            }
            else
            {
                LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false);
            }

            LGuiMisc.CheckAndSetContextID(ref Rect, ID, true);

            LGuiContext.BeginFrame(Context, IsChild);
            LGuiLayout.BeginLayout(LGuiLayout.GetCurrentLayoutMode(),
                                   new LGuiVec2(
                                       Rect.X + LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingX) - Offset.X,
                                       Rect.Y + LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingY) - Offset.Y),
                                   false);
        }
Пример #4
0
        internal static bool OnProcess(string Text, bool Selected, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Text);

            LGuiContext.SetPreviousControlID(ID);

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.HeaderActive :
                               LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.HeaderHovered :
                               Selected ? LGuiStyleColorIndex.Header : LGuiStyleColorIndex.Frame;

            LGuiGraphics.DrawRect(Rect, BgColorIndex, true, false);

            LGuiGraphics.DrawText(Text, new LGuiVec2(Rect.X, Rect.Y), LGuiStyleColorIndex.Text);

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
                return(true);
            }

            return(false);
        }
Пример #5
0
        internal static bool HandleHsvSlider(string Title, ref LGuiColor Hsv, LGuiVec2 Pos, float Length)
        {
            var TitleWidth      = LGuiContext.Font.FontWidth * 2.5f;
            var SpacingY        = LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingY);
            var SliderSize      = LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize);
            var HsvValueChanged = false;

            LGuiGraphics.DrawText("H:", new LGuiVec2(Pos.X, Pos.Y), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_HueSlider", ref Hsv.R, 0.0f, 1.0f, 0.005f, true, "{0:0.00}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y, Length - TitleWidth, SliderSize)))
            {
                HsvValueChanged = true;
            }

            LGuiGraphics.DrawText("S:", new LGuiVec2(Pos.X, Pos.Y + SliderSize + SpacingY), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_SaturationSlider", ref Hsv.G, 0.0f, 1.0f, 0.005f, true, "{0:0.00}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + SliderSize + SpacingY, Length - TitleWidth, SliderSize)))
            {
                HsvValueChanged = true;
            }

            LGuiGraphics.DrawText("V:", new LGuiVec2(Pos.X, Pos.Y + (SliderSize + SpacingY) * 2.0f), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_ValueSlider", ref Hsv.B, 0.0f, 1.0f, 0.005f, true, "{0:0.00}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + (SliderSize + SpacingY) * 2.0f, Length - TitleWidth, SliderSize)))
            {
                HsvValueChanged = true;
            }

            return(HsvValueChanged);
        }
Пример #6
0
        internal static int OnProcess(string Title, int Index, int Value, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.FrameActived :
                               LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.FrameHovered : LGuiStyleColorIndex.Frame;

            var Radius      = LGuiStyle.GetValue(LGuiStyleValueIndex.RadioButtonRadius);
            var RadioCenter = new LGuiVec2(Rect.X + Radius, Rect.Y + Rect.Height / 2.0f);

            LGuiGraphics.DrawCircle(RadioCenter, Radius, BgColorIndex, true);
            LGuiGraphics.DrawCircle(RadioCenter, Radius, LGuiStyleColorIndex.Border, false);
            if (Index == Value)
            {
                LGuiGraphics.DrawCircle(RadioCenter, Radius - 3, LGuiStyleColorIndex.CheckMask, true);
            }
            LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + Radius * 2 + 3, Rect.Y + 1), LGuiStyleColorIndex.Text);

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
                Value = Index;
            }

            return(Value);
        }
Пример #7
0
        internal static void OnProcess(int TextureID, LGuiRect SrcRect, LGuiVec2 DstSize)
        {
            var ID = LGuiHash.CalculateID(LGuiSettings.DefaultTextureTitle + TextureID);

            LGuiContext.SetPreviousControlID(ID);

            if (SrcRect.Width == 0 || SrcRect.Height == 0)
            {
                SrcRect.Size = LGuiConvert.GetTextureIDSize(TextureID);
            }

            if (DstSize.X == 0 || DstSize.Y == 0)
            {
                DstSize = LGuiConvert.GetTextureIDSize(TextureID);
            }

            var DstRect = LGuiLayout.DoLayout(DstSize);

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

            LGuiMisc.CheckAndSetContextID(ref DstRect, ID, true);

            LGuiGraphics.DrawTexture(TextureID, SrcRect, DstRect);
        }
Пример #8
0
        internal static void OnProcess(string Title, float Value, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID, true);

            Value = LGuiMisc.Clamp01(Value);
            var MaskRect = new LGuiRect(Rect.X + 1, Rect.Y + 1, (Rect.Width - 2) * Value, Rect.Height - 2);

            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true, false);
            LGuiGraphics.DrawRect(MaskRect, LGuiStyleColorIndex.CheckMask, true, false);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false, false);

            var Text     = $"{(Value * 100):00}%";
            var TextSize = LGuiConvert.GetTextSize(Text, LGuiContext.Font);

            LGuiGraphics.DrawText(Text, new LGuiVec2(Rect.CenterX - TextSize.X / 2.0f, Rect.CenterY - TextSize.Y / 2.0f), LGuiStyleColorIndex.Text);
        }
Пример #9
0
        internal static void End()
        {
            LGuiGraphics.SetTargetCommandList(null);

            SortWindowList();
            if (SortedWindowID_.Count > 0)
            {
                SortedWindowID_.Sort((Left, Right) =>
                {
                    if (WindowList_[Left].Order < WindowList_[Right].Order)
                    {
                        return(-1);
                    }

                    if (WindowList_[Left].Order > WindowList_[Right].Order)
                    {
                        return(1);
                    }

                    return(0);
                });

                LGuiGraphics.SetCurrentLevel(LGuiCommandLevel.Window);

                foreach (var ID in SortedWindowID_)
                {
                    LGuiGraphics.AddCommandList(WindowList_[ID].DrawList);
                }

                LGuiGraphics.RestoreCurrentLevel();
            }
        }
Пример #10
0
        internal static bool OnProcess(string Title, ref string Value, LGuiRect Rect, uint MaxLength, LGuiInputTextFlags Flags)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false);

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
            }

            var ValueChanged = false;

            if (LGuiContext.FocusID == ID || LGuiContext.ActiveID == ID)
            {
                ValueChanged = LGuiTextFieldController.OnProcess(ID, ref Value, Rect, MaxLength, Flags, null);
            }
            else
            {
                LGuiTextFieldController.OnProcess(ID, ref Value, Rect, MaxLength, Flags | LGuiInputTextFlags.OnlyDisplay, null);
            }

            return(ValueChanged);
        }
Пример #11
0
        internal static bool Begin(string Title, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

            var IsOpen = LGuiContextCache.GetPopupOpen(Title);

            if (IsOpen)
            {
                if (LGuiContext.IO.IsMouseClick(LGuiMouseButtons.Left) && !LGuiMisc.Contains(ref Rect, ref LGuiContext.IO.MousePos))
                {
                    LGuiContextCache.SetPopupOpen(Title, false);
                    return(false);
                }

                LGuiGraphics.SetCurrentLevel(LGuiCommandLevel.Popup);
                LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true);
                LGuiFrame.Begin(Title, Rect, false);
            }

            return(IsOpen);
        }
Пример #12
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);
        }
Пример #13
0
        internal static void RenderColorCross(LGuiRect ColorRect, float Saturation, float Value)
        {
            var CrossX = ColorRect.X + ColorRect.Width * Saturation;
            var CrossY = ColorRect.Y + ColorRect.Height * (1 - Value);

            LGuiGraphics.DrawLine(new LGuiVec2(CrossX - 5, CrossY), new LGuiVec2(CrossX + 5, CrossY), LGuiColor.White);
            LGuiGraphics.DrawLine(new LGuiVec2(CrossX, CrossY - 5), new LGuiVec2(CrossX, CrossY + 5), LGuiColor.White);
        }
Пример #14
0
        public static void Begin()
        {
            LGuiGraphics.Begin();
            LGuiContext.Begin();
            LGuiLayout.Begin();
            LGuiWindow.Begin();

            LGuiGraphics.DrawRect(LGuiContext.GetCurrentFrame().Rect, new LGuiColor(0.06f, 0.06f, 0.06f, 0.94f), true, false);
        }
Пример #15
0
        internal static bool Begin(string Title)
        {
            var FullTitle = $"{LGuiContext.GetCurrentFrame().Title}/{Title}";
            var ID        = LGuiHash.CalculateID(FullTitle);

            LGuiContext.SetPreviousControlID(ID);

            var Rect = LGuiLayout.DoLayout(new LGuiVec2(LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength), LGuiStyle.GetValue(LGuiStyleValueIndex.HeaderSize)));

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.GroupActived :
                               LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.GroupHovered : LGuiStyleColorIndex.Group;

            LGuiGraphics.DrawRect(Rect, BgColorIndex, true);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false);
            LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + LGuiStyle.GetValue(LGuiStyleValueIndex.GroupChildSpacing), Rect.Y), LGuiStyleColorIndex.Text);

            var Expand = LGuiContextCache.GetGroupExpand(FullTitle);

            if (Expand)
            {
                LGuiGraphics.DrawTriangle(
                    new LGuiVec2(Rect.X + 5, Rect.Y + 3),
                    new LGuiVec2(Rect.X + 15, Rect.Y + 3),
                    new LGuiVec2(Rect.X + 10, Rect.Bottom - 3),
                    LGuiStyle.GetColor(LGuiStyleColorIndex.Text),
                    true);
            }
            else
            {
                LGuiGraphics.DrawTriangle(
                    new LGuiVec2(Rect.X + 5, Rect.Y + 3),
                    new LGuiVec2(Rect.X + 15, Rect.CenterY),
                    new LGuiVec2(Rect.X + 5, Rect.Bottom - 3),
                    LGuiStyle.GetColor(LGuiStyleColorIndex.Text),
                    true);
            }

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
                Expand = !Expand;
                LGuiContextCache.SetGroupExpand(FullTitle, Expand);
            }

            if (Expand)
            {
                LGuiContext.BeginGroup(FullTitle, Rect.X + LGuiStyle.GetValue(LGuiStyleValueIndex.GroupChildSpacing));
            }
            return(Expand);
        }
Пример #16
0
        internal static void BeginFrame(LGuiFrameContext Context, bool IsChild)
        {
            PushID(LGuiHash.CalculateID(Context.Title));
            var ClipRect = FrameContextStack.Count > 0 && IsChild
                ? LGuiMisc.CombineRect(ref GetCurrentFrame().Rect, ref Context.Rect)
                : Context.Rect;

            FrameContextStack.Push(Context);
            LGuiGraphics.SetClipRect(ClipRect);
        }
Пример #17
0
        internal static void OnProcess(LGuiColor Color, string Text, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Text);

            LGuiContext.SetPreviousControlID(ID);

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);
            LGuiGraphics.DrawText(Text, Rect.Pos, Color, LGuiContext.Font);
        }
Пример #18
0
        internal static bool Begin(LGuiVec2 Size)
        {
            if (!LGuiMisc.PreviousControlIsHovered())
            {
                return(false);
            }

            var Pos  = LGuiContext.IO.MousePos + new LGuiVec2(20, 5);
            var Rect = new LGuiRect(Pos, Size);

            LGuiGraphics.SetCurrentLevel(LGuiCommandLevel.Tips);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true);
            LGuiFrame.Begin(LGuiSettings.DefaultToolTipsTitle, Rect, false);
            return(true);
        }
Пример #19
0
        internal static void EndWindow()
        {
            LGuiFrame.End();
            LGuiGraphics.SetTargetCommandList(null);

            if (!CurrentWindowCanHandleMouseMsg(false))
            {
                CurrentWindow_ = 0;
                return;
            }

            HandleMouseMsg(ref WindowList_[CurrentWindow_].Rect);

            CurrentWindow_ = 0;
        }
Пример #20
0
        internal static void EndFrame()
        {
            if (FrameContextStack.Count > 0)
            {
                PopID();
                FrameContextStack.Pop();

                if (FrameContextStack.Count > 0)
                {
                    LGuiGraphics.SetClipRect(GetCurrentFrame().Rect);
                }
                else
                {
                    LGuiGraphics.SetClipRect(new LGuiRect(LGuiVec2.Zero, IO.DisplaySize));
                }
            }
        }
Пример #21
0
        internal static bool HandleRgbSlider(string Title, ref LGuiColor Color, LGuiVec2 Pos, float Length)
        {
            var A               = (int)(Color.A * 255.0f);
            var R               = (int)(Color.R * 255.0f);
            var G               = (int)(Color.G * 255.0f);
            var B               = (int)(Color.B * 255.0f);
            var TitleWidth      = LGuiContext.Font.FontWidth * 2.5f;
            var SpacingY        = LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingY);
            var SliderSize      = LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize);
            var RgbValueChanged = false;

            LGuiGraphics.DrawText("R:", new LGuiVec2(Pos.X, Pos.Y), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_RedSlider", ref R, 0, 255, 1, true, "{0}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y, Length - TitleWidth, SliderSize)))
            {
                RgbValueChanged = true;
            }

            LGuiGraphics.DrawText("G:", new LGuiVec2(Pos.X, Pos.Y + SliderSize + SpacingY), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_GreenSlider", ref G, 0, 255, 1, true, "{0}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + SliderSize + SpacingY, Length - TitleWidth, SliderSize)))
            {
                RgbValueChanged = true;
            }

            LGuiGraphics.DrawText("B:", new LGuiVec2(Pos.X, Pos.Y + (SliderSize + SpacingY) * 2.0f), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_BlueSlider", ref B, 0, 255, 1, true, "{0}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + (SliderSize + SpacingY) * 2.0f, Length - TitleWidth, SliderSize)))
            {
                RgbValueChanged = true;
            }

            LGuiGraphics.DrawText("A:", new LGuiVec2(Pos.X, Pos.Y + (SliderSize + SpacingY) * 3.0f), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_AlphaSlider", ref A, 0, 255, 1, true, "{0}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + (SliderSize + SpacingY) * 3.0f, Length - TitleWidth, SliderSize)))
            {
                RgbValueChanged = true;
            }

            if (RgbValueChanged)
            {
                Color = new LGuiColor(R, G, B, A);
            }

            return(RgbValueChanged);
        }
Пример #22
0
        internal static void RenderHueArrow(LGuiRect HueRect, float Hue)
        {
            var ArrowX  = HueRect.X + HueRect.Width * Hue;
            var ArrowY1 = HueRect.Y;
            var ArrowY2 = HueRect.Bottom;

            LGuiGraphics.DrawTriangle(
                new LGuiVec2(ArrowX, ArrowY1 + 5),
                new LGuiVec2(ArrowX - 5, ArrowY1),
                new LGuiVec2(ArrowX + 5, ArrowY1),
                LGuiColor.White, true);
            LGuiGraphics.DrawTriangle(
                new LGuiVec2(ArrowX, ArrowY2 - 5),
                new LGuiVec2(ArrowX - 5, ArrowY2),
                new LGuiVec2(ArrowX + 5, ArrowY2),
                LGuiColor.White, true);
        }
Пример #23
0
        internal static bool OnProcess(string Title, LGuiRect Rect, LGuiButtonFlags Flags)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            if ((Flags & LGuiButtonFlags.Invisible) == LGuiButtonFlags.Invisible)
            {
            }
            else
            {
                var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.ButtonActived :
                                   LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.ButtonHovered : LGuiStyleColorIndex.Button;

                LGuiGraphics.DrawRect(Rect, BgColorIndex, true);
                LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false);
                LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + 3, Rect.Y + 2), LGuiStyleColorIndex.Text);
            }

            if ((Flags & LGuiButtonFlags.Repeat) == LGuiButtonFlags.Repeat)
            {
                if (LGuiContext.ActiveID == ID)
                {
                    return(true);
                }
            }
            else if (LGuiMisc.CheckAndSetFocusID(ID))
            {
                return(true);
            }

            return(false);
        }
Пример #24
0
        internal static bool OnProcess(string Title, LGuiColor Color, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            LGuiGraphics.DrawRect(Rect, Color, true);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false);

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
                return(true);
            }

            return(false);
        }
Пример #25
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);
        }
Пример #26
0
        internal static bool OnProcess(string Title, ref int Value, int Min, int Max, int Step, bool IsHorizontal, string Format, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

            var NewValue = LGuiMisc.Clamp(Min, Max, Value);

            Step = LGuiMisc.Min(Max - Min, Step);

            var GrabRect = CalculateGrabRect(ref Rect,
                                             new LGuiVec2((float)Step / (float)(Max - Min) * Rect.Width, (float)Step / (float)(Max - Min) * Rect.Height),
                                             LGuiStyle.GetGrabMinSize(),
                                             (float)(NewValue - Min) / (float)(Max - Min),
                                             IsHorizontal);

            LGuiMisc.CheckAndSetContextID(ref GrabRect, ID, true);

            var GrabColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.SliderGrabActived :
                                 LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.SliderGrabHovered : LGuiStyleColorIndex.SliderGrab;

            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false);
            LGuiGraphics.DrawRect(GrabRect, GrabColorIndex, true);
            if (!string.IsNullOrWhiteSpace(Format))
            {
                var Text     = string.Format(Format, NewValue);
                var TextSize = LGuiConvert.GetTextSize(Text, LGuiContext.Font);
                LGuiGraphics.DrawText(Text, new LGuiVec2(Rect.X + (Rect.Width - TextSize.X) / 2.0f, Rect.Y + (Rect.Height - TextSize.Y) / 2.0f), LGuiStyleColorIndex.Text);
            }

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            if (LGuiContext.ActiveID == ID)
            {
                NewValue = CalculateCurrentValue(ref Rect, ref GrabRect, Min, Max, Step, IsHorizontal);
            }
            else if (!IsHorizontal)
            {
                NewValue = LGuiMisc.DoMouseWheelEvent(ID, Min, Max, NewValue);
            }

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
            }

            var ValueChanged = false;

            if (NewValue != Value)
            {
                ValueChanged = true;
                Value        = NewValue;
            }

            return(ValueChanged);
        }
Пример #27
0
 public static int GetDrawCall()
 {
     return(LGuiGraphics.GetDrawCall());
 }
Пример #28
0
 public static void SetCommandExecutor(LGuiCommandExecutor Executor)
 {
     LGuiGraphics.SetExecutor(Executor);
 }
Пример #29
0
 public static ILGuiCommandList CreateCommandList()
 {
     return(LGuiGraphics.CreateCommandList());
 }
Пример #30
0
 public static void AddCommandList(ILGuiCommandList CommandList)
 {
     LGuiGraphics.AddCommandList(CommandList);
 }