Exemple #1
0
 internal DrawTextCommand(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font)
 {
     this.Text  = Text;
     this.Pos   = Pos;
     this.Color = Color;
     this.Font  = Font;
 }
Exemple #2
0
        private static LGuiVec2 OnGetTextSize(string Text, LGuiFont GuiFont)
        {
            var Font = FontCache.GetOrCreate(GuiFont);
            var Size = Device_.MeasureString(Text, Font, 0, GdiCommandExecutor.FontStringFormat);

            return(new LGuiVec2(Size.Width, Font.Height));
        }
        private static void HandleMouseEvent(LGuiTextFieldState State, LGuiFont Font, LGuiVec2 RenderPos)
        {
            if (LGuiContext.IO.IsMouseClick(LGuiMouseButtons.Left))
            {
                var Pos = LGuiContext.IO.MousePos - RenderPos + new LGuiVec2(State.OffsetX * Font.FontWidth, State.OffsetY * Font.FontHeight);
                if (State.SingleLine)
                {
                    Pos.Y = 0;
                }

                var Cursor = LocateCoord(State, Font, Pos);
                State.OnClick(Cursor);
            }
            else if (LGuiContext.IO.IsMouseDown(LGuiMouseButtons.Left) && LGuiContext.IO.IsMouseMove())
            {
                var Pos = LGuiContext.IO.MousePos - RenderPos + new LGuiVec2(State.OffsetX * Font.FontWidth, State.OffsetY * Font.FontHeight);
                if (State.SingleLine)
                {
                    Pos.Y = 0;
                }

                var Cursor = LocateCoord(State, Font, Pos);
                State.OnDrag(Cursor);
            }
        }
Exemple #4
0
        internal static Font GetOrCreate(LGuiFont GuiFont)
        {
            var Hash = GuiFont.GetHashCode();

            if (!FontCache_.ContainsKey(Hash))
            {
                FontCache_.Add(Hash, new Font(GuiFont.FontName, GuiFont.FontSize, GuiFont.Bold ? FontStyle.Bold : FontStyle.Regular));
            }

            return(FontCache_[Hash]);
        }
        private static int LayoutRow(LGuiTextFieldState State, LGuiFont Font, int StartIndex, ref LGuiVec2 TextSize)
        {
            var Index     = StartIndex;
            var LineWidth = 0.0f;

            TextSize.X = 0;
            TextSize.Y = 0;

            while (Index < State.TextLength)
            {
                var Ch = State.GetCharacter(Index++);

                if (Ch == '\n')
                {
                    TextSize.X = LGuiMisc.Max(TextSize.X, LineWidth);
                    TextSize.Y = TextSize.Y + Font.FontHeight + State.Spacing.Y;
                    LineWidth  = 0.0f;
                    break;
                }

                if (Ch == '\r')
                {
                    continue;
                }

                LineWidth = LineWidth + Font.FontWidth + State.Spacing.X;
            }

            if (TextSize.X < LineWidth)
            {
                TextSize.X = LineWidth;
            }

            if (LineWidth > 0 || TextSize.Y == 0.0f)
            {
                TextSize.Y = TextSize.Y + Font.FontHeight + State.Spacing.Y;
            }

            return(Index - StartIndex);
        }
Exemple #6
0
 public abstract void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font);
Exemple #7
0
 internal static void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font)
 {
     GetCurrentList().DrawText(Text, Pos, Color, Font);
 }
Exemple #8
0
        public void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font)
        {
            var Cmd = new DrawTextCommand(Text, Pos, Color, Font);

            AddCommand(Cmd);
        }
 public override void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font)
 {
     Device_.DrawString(Text, FontCache.GetOrCreate(Font), BrushCache.GetOrCreate(Color), Pos.X, Pos.Y, FontStringFormat);
 }
        private static int LocateCoord(LGuiTextFieldState State, LGuiFont Font, LGuiVec2 Pos)
        {
            var Length   = State.TextLength;
            var Index    = 0;
            var BaseY    = 0.0f;
            var Size     = LGuiVec2.Zero;
            var NumChars = 0;

            while (Index < Length)
            {
                NumChars = LayoutRow(State, Font, Index, ref Size);
                if (NumChars <= 0)
                {
                    return(Length);
                }

                if (Index == 0 && Pos.Y < BaseY)
                {
                    return(0);
                }

                if (Pos.Y < BaseY + Size.Y)
                {
                    break;
                }

                Index += NumChars;
                BaseY += Size.Y;
            }

            if (Index >= Length)
            {
                return(Length);
            }

            if (Pos.X < 0)
            {
                return(Index);
            }

            if (Pos.X < Size.X)
            {
                var PrevX = 0.0f;
                for (var N = 0; N < NumChars; ++N)
                {
                    var Width = Font.FontWidth + State.Spacing.X;
                    if (Pos.X < PrevX + Width)
                    {
                        if (Pos.X < PrevX + Width / 2.0f)
                        {
                            return(Index + N);
                        }
                        else
                        {
                            return(Index + N + 1);
                        }
                    }

                    PrevX += Width;
                }
            }

            if (State.GetCharacter(Index + NumChars - 1) == '\n')
            {
                return(Index + NumChars - 1);
            }

            return(Index + NumChars);
        }