Пример #1
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);
        }
Пример #2
0
        internal static bool OnProcess(string Title, ref int ItemIndex, string[] Items, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

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

            LGuiFrame.Begin(Title, Rect);

            var NewIndex  = ItemIndex;
            var ItemWidth = Rect.Width - LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingX) * 2.0f - LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize);

            for (var Index = 0; Index < Items.Length; ++Index)
            {
                if (LGuiSelectable.OnProcess(Items[Index], ItemIndex == Index, ItemWidth))
                {
                    NewIndex = Index;
                }
            }

            LGuiFrame.End();

            if (ItemIndex != NewIndex)
            {
                ItemIndex = NewIndex;
                return(true);
            }

            return(false);
        }
Пример #3
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);
        }
Пример #4
0
 internal static void End()
 {
     LGuiContext.EndGroup();
 }
Пример #5
0
        internal static void End()
        {
            var FrameContext = LGuiContext.GetCurrentFrame();

            FrameContext.Size = FrameContext.Rect.Size - LGuiStyle.GetFrameChildSpacing() * 2.0f;

            if (FrameContext.Visibled)
            {
                var LayoutContext = LGuiLayout.GetCurrentLayoutContext();
                var Width         = LayoutContext.ChildSize.X - FrameContext.Rect.Width + LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingX);
                var Height        = LayoutContext.ChildSize.Y - FrameContext.Rect.Height + LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingY);
                var SliderSize    = LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize);

                var Offset = LGuiContextCache.GetFrameOffset(FrameContext.Title);

                if (Width > 0)
                {
                    LGuiSlider.OnProcess(
                        $"{FrameContext.Title}_hsbar",
                        ref Offset.X,
                        0.0f,
                        Width,
                        LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingX),
                        true,
                        string.Empty,
                        new LGuiRect(FrameContext.Rect.X, FrameContext.Rect.Bottom - SliderSize,
                                     FrameContext.Rect.Width - SliderSize, SliderSize));
                    FrameContext.Size.Y -= SliderSize;
                }
                else
                {
                    Offset.X = 0;
                }

                if (Height > 0)
                {
                    LGuiSlider.OnProcess(
                        $"{FrameContext.Title}_vsbar",
                        ref Offset.Y,
                        0.0f,
                        Height,
                        LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingY),
                        false,
                        string.Empty,
                        new LGuiRect(FrameContext.Rect.Right - SliderSize,
                                     FrameContext.Rect.Y, SliderSize, FrameContext.Rect.Height));
                    FrameContext.Size.X -= SliderSize;

                    var ID = LGuiHash.CalculateID(FrameContext.Title);
                    LGuiMisc.CheckAndSetContextID(ref FrameContext.Rect, ID, true);
                    Offset.Y = LGuiMisc.DoMouseWheelEvent(ID, 0.0f, Height, Offset.Y);
                }
                else
                {
                    Offset.Y = 0;
                }

                LGuiContextCache.SetFrameOffset(FrameContext.Title, Offset);
            }

            LGuiContextCache.SetFrameContextSize(FrameContext.Title, FrameContext.Size);
            LGuiLayout.EndLayout();
            LGuiContext.EndFrame();
        }
Пример #6
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);
        }
Пример #7
0
        internal static bool OnProcess(string Title, ref int ItemIndex, string[] Items, LGuiRect Rect, float PopupHeight)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

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

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

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            LGuiGraphics.DrawRect(Rect, TitleBgColorIndex, true);
            LGuiGraphics.DrawText(Items[ItemIndex], Rect.Pos + new LGuiVec2(LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingX), 0), LGuiStyleColorIndex.Text);

            var GrabRect         = new LGuiRect(Rect.Right - LGuiContext.Font.FontHeight, Rect.Y, LGuiContext.Font.FontHeight, LGuiContext.Font.FontHeight);
            var GrabBgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.ButtonActived :
                                   LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.ButtonHovered : LGuiStyleColorIndex.Button;

            LGuiGraphics.DrawRect(GrabRect, GrabBgColorIndex, true);
            LGuiGraphics.DrawTriangle(
                new LGuiVec2(GrabRect.Left + 4, GrabRect.Top + 4),
                new LGuiVec2(GrabRect.Right - 4, GrabRect.Top + 4),
                new LGuiVec2(GrabRect.CenterX, GrabRect.Bottom - 4),
                LGuiStyle.GetColor(LGuiStyleColorIndex.Text), true);

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

            var PopupID = $"{Title}_ItemPopup";

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
                LGuiPopup.Open(PopupID);
            }

            var NewIndex = ItemIndex;

            if (LGuiPopup.Begin(PopupID, new LGuiRect(Rect.X, Rect.Bottom + 1, Rect.Width, PopupHeight)))
            {
                var ItemWidth = Rect.Width - LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingX) * 2.0f - LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize);
                for (var Index = 0; Index < Items.Length; ++Index)
                {
                    if (LGuiSelectable.OnProcess(Items[Index], ItemIndex == Index, ItemWidth))
                    {
                        NewIndex = Index;
                        LGuiPopup.Close(PopupID);
                    }
                }
                LGuiPopup.End();
            }

            if (ItemIndex != NewIndex)
            {
                ItemIndex = NewIndex;
                return(true);
            }

            return(false);
        }
Пример #8
0
 internal static int CalculateID <T>(T Value)
 {
     return(Combine(LGuiContext.GetCurrentID(), Value.GetHashCode(), Value.ToString().GetHashCode()));
 }