예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
        internal static void OnProcess(LGuiColor Color, string Format, params object[] Args)
        {
            var Text = string.Format(Format, Args);
            var Size = LGuiConvert.GetTextSize(Text, LGuiContext.Font);
            var Rect = LGuiLayout.DoLayout(Size);

            OnProcess(Color, Text, Rect);
        }
예제 #4
0
        internal static bool OnProcess(string Title, bool Value)
        {
            var Size = LGuiConvert.GetTextSize(Title, LGuiContext.Font).Add(LGuiStyle.GetValue(LGuiStyleValueIndex.CheckBoxSize) + 3, 2);

            Size.Y = LGuiMisc.Max(Size.Y, LGuiStyle.GetValue(LGuiStyleValueIndex.CheckBoxSize));
            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, Value, Rect));
        }
예제 #5
0
        internal static int OnProcess(string Title, int Index, int Value)
        {
            var Radius = LGuiStyle.GetValue(LGuiStyleValueIndex.RadioButtonRadius);
            var Size   = LGuiConvert.GetTextSize(Title, LGuiContext.Font).Add(Radius * 2 + 3, 2);

            Size.Y = LGuiMisc.Max(Size.Y, Radius);
            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, Index, Value, Rect));
        }
예제 #6
0
        internal static bool OnProcess(string Title, ref string Value, uint MaxLength, LGuiInputTextFlags Flags)
        {
            var TextSize = LGuiConvert.GetTextSize(Value, LGuiContext.Font);

            var Size = new LGuiVec2(LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength), TextSize.Y + 2);

            if ((Flags & LGuiInputTextFlags.Multiline) == LGuiInputTextFlags.Multiline)
            {
                Size.Y = LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength);
            }

            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, ref Value, Rect, MaxLength, Flags));
        }
예제 #7
0
        internal void OnCmdKey(LGuiTextFieldCmdKey CmdKey, char Ch)
        {
            if ((CmdKey & LGuiTextFieldCmdKey.Character) == LGuiTextFieldCmdKey.Character)
            {
                if (Ch == (char)0 || (SingleLine && Ch == '\n'))
                {
                }
                else
                {
                    if (HasSelection())
                    {
                        SortSelection();
                        Cursor_ = SelectStart_;
                        Execute(new LGuiReplaceStringCommand(this, SelectStart_, SelectEnd_ - SelectStart_, Ch.ToString()));
                        ClearSelection();
                    }
                    else
                    {
                        if (InsertMode && Cursor_ < Buffer_.Length && GetCharacter(Cursor_) != '\n')
                        {
                            Execute(new LGuiReplaceCharacterCommand(this, Cursor_, Ch));
                        }
                        else if (Buffer_.Length + 1 <= MaxLength)
                        {
                            Execute(new LGuiInsertCharacterCommand(this, Cursor_, Ch));
                        }
                    }
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Backspace) == LGuiTextFieldCmdKey.Backspace)
            {
                if (HasSelection())
                {
                    DeleteSelection();
                }
                else
                {
                    if (Cursor_ > 0)
                    {
                        Execute(new LGuiRemoveCharacterCommand(this, Cursor_));
                    }
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Delete) == LGuiTextFieldCmdKey.Delete)
            {
                if (HasSelection())
                {
                    DeleteSelection();
                }
                else
                {
                    if (Cursor_ < Buffer_.Length)
                    {
                        Cursor_++;
                        Execute(new LGuiRemoveCharacterCommand(this, Cursor_));
                    }
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Left) == LGuiTextFieldCmdKey.Left)
            {
                if ((CmdKey & LGuiTextFieldCmdKey.Shift) == LGuiTextFieldCmdKey.Shift)
                {
                    if (SelectEnd_ > 0)
                    {
                        SelectEnd_--;
                    }

                    Cursor_ = SelectEnd_;
                }
                else
                {
                    if (HasSelection())
                    {
                        Cursor_ = SelectStart_;
                        ClearSelection();
                    }
                    else if (Cursor_ > 0)
                    {
                        Cursor_--;
                    }
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Right) == LGuiTextFieldCmdKey.Right)
            {
                if ((CmdKey & LGuiTextFieldCmdKey.Shift) == LGuiTextFieldCmdKey.Shift)
                {
                    if (SelectEnd_ < Buffer_.Length)
                    {
                        SelectEnd_++;
                    }

                    Cursor_ = SelectEnd_;
                }
                else
                {
                    if (HasSelection())
                    {
                        Cursor_ = SelectEnd_;
                        ClearSelection();
                    }
                    else if (Cursor_ < Buffer_.Length)
                    {
                        Cursor_++;
                    }
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Up) == LGuiTextFieldCmdKey.Up && !SingleLine)
            {
                Cursor_ = FindPrevLinePos(Cursor_);

                if ((CmdKey & LGuiTextFieldCmdKey.Shift) == LGuiTextFieldCmdKey.Shift)
                {
                    SelectEnd_ = Cursor_;
                }
                else
                {
                    ClearSelection();
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Down) == LGuiTextFieldCmdKey.Down && !SingleLine)
            {
                Cursor_ = FindNextLinePos(Cursor_);

                if ((CmdKey & LGuiTextFieldCmdKey.Shift) == LGuiTextFieldCmdKey.Shift)
                {
                    SelectEnd_ = Cursor_;
                }
                else
                {
                    ClearSelection();
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Home) == LGuiTextFieldCmdKey.Home)
            {
                Cursor_ = (CmdKey & LGuiTextFieldCmdKey.Ctrl) == LGuiTextFieldCmdKey.Ctrl ? 0 : GetLineStartPos(Cursor_ - 1);

                if ((CmdKey & LGuiTextFieldCmdKey.Shift) == LGuiTextFieldCmdKey.Shift)
                {
                    SelectEnd_ = Cursor_;
                }
                else
                {
                    ClearSelection();
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.End) == LGuiTextFieldCmdKey.End)
            {
                Cursor_ = (CmdKey & LGuiTextFieldCmdKey.Ctrl) == LGuiTextFieldCmdKey.Ctrl ? Buffer_.Length : GetLineEndPos(Cursor_);

                if ((CmdKey & LGuiTextFieldCmdKey.Shift) == LGuiTextFieldCmdKey.Shift)
                {
                    SelectEnd_ = Cursor_;
                }
                else
                {
                    ClearSelection();
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Undo) == LGuiTextFieldCmdKey.Undo)
            {
                Undo();
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Redo) == LGuiTextFieldCmdKey.Redo)
            {
                Redo();
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Copy) == LGuiTextFieldCmdKey.Copy)
            {
                if (HasSelection())
                {
                    var ClipboardText = GetSelectionString();
                    LGuiConvert.SetClipboardText(ClipboardText);
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Paste) == LGuiTextFieldCmdKey.Paste)
            {
                var ClipboardText = LGuiConvert.GetClipboardText();
                if (SingleLine)
                {
                    ClipboardText = ClipboardText.Trim('\n');
                }

                if (!string.IsNullOrEmpty(ClipboardText) && Buffer_.Length + ClipboardText.Length <= MaxLength)
                {
                    if (HasSelection())
                    {
                        SortSelection();
                        Cursor_ = SelectStart_;
                        Execute(new LGuiReplaceStringCommand(this, SelectStart_, SelectEnd_ - SelectStart_, ClipboardText));
                        ClearSelection();
                    }
                    else
                    {
                        Execute(new LGuiInsertStringCommand(this, Cursor_, ClipboardText));
                    }
                }
            }
            else if ((CmdKey & LGuiTextFieldCmdKey.Cut) == LGuiTextFieldCmdKey.Cut)
            {
                if (HasSelection())
                {
                    var ClipboardText = GetSelectionString();
                    LGuiConvert.SetClipboardText(ClipboardText);
                    DeleteSelection();
                }
            }
        }
예제 #8
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);
        }
예제 #9
0
        internal static bool OnProcess(string Text, bool Selected)
        {
            var Size = LGuiConvert.GetTextSize(Text, LGuiContext.Font);

            return(OnProcess(Text, Selected, Size));
        }
예제 #10
0
        internal static bool OnProcess(string Title, LGuiButtonFlags Flags)
        {
            var Size = LGuiConvert.GetTextSize(Title, LGuiContext.Font).Add(6, 4);

            return(OnProcess(Title, Size, Flags));
        }