Пример #1
0
        protected override void DrawStyle(Style style, float opacity)
        {
            base.DrawStyle(style, opacity);

            int texture = Gui.Renderer.GetTexture(Texture);

            if (texture < 0)
            {
                return;
            }

            if (ColorByTint)
            {
                Color = style.Tint;
            }

            int color = Color;

            if (Tint != -1)
            {
                color = ColorInt.Blend(Tint, color);
            }

            color = ColorInt.FromArgb(opacity, color);

            if (TextureRect.IsEmpty())
            {
                Point texsize = Gui.Renderer.GetTextureSize(texture);
                TextureRect = new Rectangle(Point.Zero, texsize);
            }

            //bool atlas = SpriteBatch.AutoAtlas;

            //if (ExcludeFromAtlas)
            //    SpriteBatch.AutoAtlas = false;

            if (Tiling == TextureMode.Grid || Tiling == TextureMode.GridRepeat)
            {
                SliceTexture(texture, Tiling, TextureRect, Grid, opacity, color);
            }
            else if (Tiling == TextureMode.Stretch)
            {
                Gui.Renderer.DrawTexture(texture, Location.x + Inset.Left, Location.y + Inset.Top, Size.x - (Inset.Left + Inset.Right), Size.y - (Inset.Top + Inset.Bottom), TextureRect, color);
            }
            else if (Tiling == TextureMode.Center)
            {
                Point center   = Location + Size / 2;
                Point rectsize = new Point(TextureRect.Width, TextureRect.Height);
                Point pos      = center - rectsize / 2;

                Gui.Renderer.DrawTexture(texture, pos.x, pos.y, rectsize.x, rectsize.y, TextureRect, color);
            }
            else
            {
                RepeatTexture(texture, Location, TextureRect, Tiling, opacity, color);
            }

            //if (ExcludeFromAtlas)
            //    SpriteBatch.AutoAtlas = atlas;
        }
Пример #2
0
        protected override void DrawText(Style style, float opacity)
        {
            if (IsDirty)
            {
                UpdateText(style);
            }

            if (Lines.Count == 0)
            {
                return;
            }

            int   font;
            Point p1, p2, size;

            foreach (TextLine line in Lines)
            {
                foreach (TextElement element in line.Elements)
                {
                    if (element.Linebreak)
                    {
                        continue;
                    }

                    font = Gui.Renderer.GetFont(element.Font);
                    size = element.Size;
                    p2   = element.Position + Location;

                    element.Rectangle = new Rectangle(p2, size);

                    if (!element.Rectangle.Intersects(ClipRect))
                    {
                        continue;
                    }

                    if (element.IsControl)
                    {
                        continue;
                    }

                    if (element.IsLink)
                    {
                        Gui.Renderer.DrawBox(p2.x, p2.y + size.y, size.x - 1, 1, ColorInt.FromArgb(opacity, ColorInt.FromArgb(opacity, element.Color.HasValue ? (int)element.Color : style.TextColor)));
                    }

                    //if (element.IsLink && element.Href == ActiveHref)
                    //    Gui.Renderer.DrawBox(p2.x, p2.y, size.x - 1, size.y, ColorInt.FromArgb(opacity, LinkColor));

                    if (UseTextColor)
                    {
                        Gui.Renderer.DrawText(element.Text, p2.x, p2.y, font, ColorInt.FromArgb(opacity, TextColor));
                    }
                    else
                    {
                        Gui.Renderer.DrawText(element.Text, p2.x, p2.y, font, ColorInt.FromArgb(opacity, element.Color.HasValue ? (int)element.Color : style.TextColor));
                    }
                }
            }
        }
Пример #3
0
        protected override void DrawBefore()
        {
            if (Modal)
            {
                SetScissor(0, 0, Desktop.Size.x, Desktop.Size.y);
                Gui.Renderer.DrawBox(0, 0, Desktop.Size.x, Desktop.Size.y, ColorInt.FromArgb(GetOpacity(1), Desktop.ModalColor));
                ResetScissor();
            }

            base.DrawBefore();
        }
Пример #4
0
        protected override void DrawText(Style style, float opacity)
        {
            if (_text == null)
            {
                _text = string.Empty;
            }

            string masked = _text;

            if (IsPassword)
            {
                masked = new string(PasswordChar, masked.Length);
            }

            int font = Gui.Renderer.GetFont(style.Font);

            if (font < 0)
            {
                return;
            }

            Point p = AlignText(masked, Alignment.MiddleLeft, style.TextPadding, font);

            Rectangle clip = new Rectangle(Location, Size);

            clip.Left  += style.TextPadding.Left;
            clip.Right -= style.TextPadding.Right - 1;
            clip        = Clip(clip);

            if (clip.Width < 1 || clip.Height < 1)
            {
                return;
            }

            SetScissor(clip.Left, clip.Top, clip.Width, clip.Height);

            if (Caret > masked.Length)
            {
                Caret = masked.Length;
            }

            if (Desktop.FocusedControl == this)
            {
                Rectangle rect = new Rectangle(Location, Size);

                Point s1 = Gui.Renderer.GetTextSize(masked, font);
                Point s2 = Gui.Renderer.GetTextSize(masked.Substring(0, Caret), font);

                if (string.IsNullOrEmpty(masked))
                {
                    s2.y = Gui.Renderer.GetTextSize(" ", font).y;
                    p    = AlignText(" ", Alignment.MiddleLeft, style.TextPadding, font);
                }
                else if (s2.y == 0)
                {
                    s2.y = Gui.Renderer.GetTextSize(" ", font).y;
                }

                int carex = p.x + Offset + s2.x;

                int lim1 = rect.Left + style.TextPadding.Left;
                int lim2 = rect.Right - style.TextPadding.Right;

                if (carex < lim1)
                {
                    Offset += lim1 - carex;
                }

                if (carex > lim2)
                {
                    Offset += lim2 - carex;
                }

                if (Offset < 0)
                {
                    if (p.x + Offset + s1.x < lim2)
                    {
                        Offset += lim2 - (p.x + Offset + s1.x);
                    }
                }

                p.x += Offset;

                Gui.Renderer.DrawText(masked, p.x, p.y, font, ColorInt.FromArgb(opacity, UseTextColor ? TextColor : style.TextColor));

                if (!ReadOnly && DoBlink > 0)
                {
                    Gui.Renderer.DrawBox(p.x + s2.x, p.y, 1, s2.y, ColorInt.FromArgb(opacity, BlinkColor));
                }

                if (IsSelection)
                {
                    int    start = Math.Min(SelectStart, SelectEnd);
                    int    end   = Math.Max(SelectStart, SelectEnd);
                    int    color = ColorInt.FromArgb(0.5f, SelectionColor);
                    string text  = masked.Substring(0, start);
                    string text2 = masked.Substring(start, end - start);

                    Point size1 = Gui.Renderer.GetTextSize(text, font);
                    Point size2 = Gui.Renderer.GetTextSize(text2, font);

                    Gui.Renderer.DrawBox(p.x + size1.x, p.y, size2.x, size2.y, ColorInt.FromArgb(opacity, color));
                }
            }
            else
            {
                HasFocus = false;
                Offset   = 0;
                Gui.Renderer.DrawText(masked, p.x, p.y, font, ColorInt.FromArgb(opacity, style.TextColor));
            }

            ResetScissor();
        }
Пример #5
0
        protected override void DrawText(Style style, float opacity)
        {
            if (IsDirty)
            {
                UpdateText(style);
            }

            int       font;
            int       total = 0;
            int       numLine = 0;
            Point     p1, p2, size;
            Alignment align     = TextAlign != Alignment.Inherit ? TextAlign : style.TextAlign;
            bool      drawCaret = HasFocus && DoBlink > 0;

            if (Lines.Count == 0)
            {
                if (drawCaret)
                {
                    p1   = Location;
                    font = Gui.Renderer.GetFont(style.Font);

                    if (align == Alignment.TopLeft || align == Alignment.TopCenter || align == Alignment.TopRight)
                    {
                        p1.y += style.TextPadding.Top;
                    }

                    if (align == Alignment.BottomLeft || align == Alignment.BottomCenter || align == Alignment.BottomRight)
                    {
                        p1.y += Size.y - TextSize.y;
                    }

                    if (align == Alignment.MiddleLeft || align == Alignment.MiddleCenter || align == Alignment.MiddleRight)
                    {
                        p1.y += (Size.y - (TextSize.y - (style.TextPadding.Top + style.TextPadding.Bottom))) / 2;
                    }

                    if (align == Alignment.TopLeft || align == Alignment.MiddleLeft || align == Alignment.BottomLeft)
                    {
                        p1.x += style.TextPadding.Left;
                    }

                    if (align == Alignment.TopRight || align == Alignment.MiddleRight || align == Alignment.BottomRight)
                    {
                        p1.x += Size.x - style.TextPadding.Right;
                    }

                    if (align == Alignment.TopCenter || align == Alignment.MiddleCenter || align == Alignment.BottomCenter)
                    {
                        p1.x += Size.x / 2;
                    }

                    Point subsize = Gui.Renderer.GetTextSize(" ", font);
                    Gui.Renderer.DrawBox(p1.x, p1.y, 2, subsize.y, ColorInt.FromArgb(opacity, BlinkColor));
                }

                return;
            }

            foreach (TextLine line in Lines)
            {
                int perline = 0;

                foreach (TextElement element in line.Elements)
                {
                    //if (element.Linebreak)
                    //    continue;

                    font = Gui.Renderer.GetFont(element.Font);

                    if (element.Linebreak)
                    {
                        total++;
                    }
                    else
                    {
                        total += element.Text.Length;
                    }

                    size = element.Size;
                    p1   = Location;

                    if (align == Alignment.TopLeft || align == Alignment.TopCenter || align == Alignment.TopRight)
                    {
                        p1.y += style.TextPadding.Top;
                    }

                    if (align == Alignment.BottomLeft || align == Alignment.BottomCenter || align == Alignment.BottomRight)
                    {
                        p1.y += Size.y - TextSize.y;
                    }

                    if (align == Alignment.MiddleLeft || align == Alignment.MiddleCenter || align == Alignment.MiddleRight)
                    {
                        p1.y += (Size.y - (TextSize.y - (style.TextPadding.Top + style.TextPadding.Bottom))) / 2;
                    }

                    if (align == Alignment.TopLeft || align == Alignment.MiddleLeft || align == Alignment.BottomLeft)
                    {
                        p1.x += style.TextPadding.Left;
                    }

                    if (align == Alignment.TopRight || align == Alignment.MiddleRight || align == Alignment.BottomRight)
                    {
                        p1.x += Size.x - line.Width - style.TextPadding.Right;
                    }

                    if (align == Alignment.TopCenter || align == Alignment.MiddleCenter || align == Alignment.BottomCenter)
                    {
                        p1.x += (Size.x - line.Width) / 2;
                    }

                    p2 = element.Position + p1;

                    element.Rectangle = new Rectangle(p2, size);

                    if (element.IsLink && element.Href == ActiveHref)
                    {
                        Gui.Renderer.DrawBox(p2.x, p2.y, size.x - 1, size.y, ColorInt.FromArgb(opacity, LinkColor));
                    }

                    if (drawCaret && total >= Caret)
                    {
                        drawCaret = false;

                        if (string.IsNullOrEmpty(element.Text))
                        {
                            Point subsize = Gui.Renderer.GetTextSize(" ", font);
                            Gui.Renderer.DrawBox(p2.x, p2.y, 2, subsize.y, ColorInt.FromArgb(opacity, BlinkColor));
                        }
                        else
                        {
                            string substr = element.Text.Substring(0, element.Text.Length - (total - Caret));

                            if (string.IsNullOrEmpty(substr))
                            {
                                Point subsize = Gui.Renderer.GetTextSize(" ", font);
                                Gui.Renderer.DrawBox(p2.x, p2.y, 2, subsize.y, ColorInt.FromArgb(opacity, BlinkColor));
                            }
                            else
                            {
                                Point subsize = Gui.Renderer.GetTextSize(substr, font);
                                Gui.Renderer.DrawBox(p2.x + subsize.x, p2.y, 2, subsize.y, ColorInt.FromArgb(opacity, BlinkColor));
                            }
                        }
                    }

                    if (UseTextColor)
                    {
                        Gui.Renderer.DrawText(element.Text, p2.x, p2.y, font, ColorInt.FromArgb(opacity, TextColor));
                    }
                    else
                    {
                        Gui.Renderer.DrawText(element.Text, p2.x, p2.y, font, ColorInt.FromArgb(opacity, element.Color.HasValue ? (int)element.Color : style.TextColor));
                    }

                    //    Gui.Renderer.DrawBox(element.Rectangle.Left, element.Rectangle.Top, element.Rectangle.Width, element.Rectangle.Height, -1);

                    if (IsSelection && total >= SelectionStart && perline < SelectionEnd && !element.Linebreak)
                    {
                        int start = SelectionStart;
                        int end   = SelectionEnd;
                        int color = ColorInt.FromArgb(0.5f, -1);

                        //int origin = perline - element.Text.Length;
                        //start = Math.Max(0, origin - start);

                        //if (string.IsNullOrEmpty(element.Text))
                        //{
                        //    Point subsize = Gui.Renderer.GetTextSize(" ", font);
                        //    Gui.Renderer.DrawBox(p2.x, p2.y, subsize.x, subsize.y, ColorInt.FromArgb(opacity, BlinkColor));
                        //}
                        //else
                        //{
                        int begin = element.Text.Length - (total - start);
                        if (begin < 0)
                        {
                            begin = 0;
                        }

                        int len = element.Text.Length - begin - (total - end);
                        if (len < 0)
                        {
                            len = 0;
                        }
                        if (len > element.Text.Length)
                        {
                            len = element.Text.Length;
                        }
                        if (begin + len > element.Text.Length)
                        {
                            len = element.Text.Length - begin;
                        }

                        string strOffset   = element.Text.Substring(0, begin);
                        string strSelected = element.Text.Substring(begin, len);

                        Point offset    = Gui.Renderer.GetTextSize(strOffset, font);
                        Point selection = Gui.Renderer.GetTextSize(strSelected, font);
                        Gui.Renderer.DrawBox(p2.x + offset.x, p2.y, selection.x, selection.y, ColorInt.FromArgb(opacity, SelectionColor));
                        //}
                    }

                    if (!string.IsNullOrEmpty(element.Text))
                    {
                        perline += element.Text.Length;
                    }
                    else
                    {
                        perline++;
                    }
                }

                numLine++;
            }
        }