示例#1
0
 public GuiText(TextFunc textFunc, float x = 0, float y = 0, int options = 0)
     : base(options)
 {
     this.TextFunc = textFunc;
     this.Position = new Vector2(x, y);
 }
示例#2
0
 protected int GetGDIStyle()
 {
     return(TextFunc.GetGDIStyle(this));
 }
示例#3
0
 protected string TrimText(string val)
 {
     return(TextFunc.TrimText(val, this));
 }
示例#4
0
 protected StringFormat GetGDIStringFormat()
 {
     return(TextFunc.GetGDIStringFormat(this));
 }
示例#5
0
 protected FontFamily GetGDIFontFamily()
 {
     return(TextFunc.GetGDIFontFamily(this));
 }
示例#6
0
 protected float GetComputedFontSize()
 {
     return(TextFunc.GetComputedFontSize(this));
 }
示例#7
0
        public void Paint(float x, float y, float w, float h, HorizontalAlign align)
        {
            if (!Enabled)
            {
                return;
            }
            if (TextFont == null)
            {
                return;
            }

            var text = TextFunc != null?TextFunc.Invoke() : null;

            var hint = HintFunc != null?HintFunc.Invoke() : null;

            if (string.IsNullOrEmpty(text) && HideBackgroundWhenTextIsEmpty)
            {
                return;
            }

            if (Hud.Window.CursorInsideRect(x, y, w, h))
            {
                var expanded = false;
                if (ExpandUpLabels != null && ExpandUpLabels.Count > 0)
                {
                    var ly = y - h;
                    foreach (var label in ExpandUpLabels)
                    {
                        label.Paint(x, ly, w, h, align);
                        label.PaintExpandedHint(x + w, ly, w * label.ExpandedHintWidthMultiplier, h, HorizontalAlign.Center);
                        ly      -= h;
                        expanded = true;
                    }
                    this.PaintExpandedHint(x + w, y, w * 3, h, HorizontalAlign.Center);
                }
                if (ExpandDownLabels != null && ExpandDownLabels.Count > 0)
                {
                    var ly = y + h;
                    foreach (var label in ExpandDownLabels)
                    {
                        label.Paint(x, ly, w, h, align);
                        label.PaintExpandedHint(x + w, ly, w * label.ExpandedHintWidthMultiplier, h, HorizontalAlign.Center);
                        ly      += h;
                        expanded = true;
                    }
                    this.PaintExpandedHint(x + w, y, w * 3, h, HorizontalAlign.Center);
                }
                if (ExpandRightLabels != null && ExpandRightLabels.Count > 0)
                {
                    var lx = x + w;
                    foreach (var label in ExpandRightLabels)
                    {
                        label.Paint(lx, y, w, h, align);
                        lx      += h;
                        expanded = true;
                    }
                }
                if (ExpandLeftLabels != null && ExpandLeftLabels.Count > 0)
                {
                    var lx = x - w;
                    foreach (var label in ExpandLeftLabels)
                    {
                        label.Paint(lx, y, w, h, align);
                        lx      -= h;
                        expanded = true;
                    }
                }

                if (!expanded)
                {
                    if (!string.IsNullOrEmpty(hint))
                    {
                        Hud.Render.SetHint(hint);
                    }
                }
            }

            if (BackgroundTexture1 != null)
            {
                BackgroundTexture1.Draw(x, y, w, h, BackgroundTextureOpacity1);
            }

            if (BackgroundTexture2 != null)
            {
                BackgroundTexture2.Draw(x, y, w, h, BackgroundTextureOpacity2);
            }

            if (BackgroundBrush != null)
            {
                BackgroundBrush.DrawRectangle(x, y, w, h);
            }

            if (!string.IsNullOrEmpty(text))
            {
                var layout = TextFont.GetTextLayout(text);
                switch (align)
                {
                case HorizontalAlign.Left:
                    TextFont.DrawText(layout, x, y + (h - layout.Metrics.Height) / 2);
                    break;

                case HorizontalAlign.Center:
                    TextFont.DrawText(layout, x + (w - layout.Metrics.Width) / 2, y + (h - layout.Metrics.Height) / 2);
                    break;

                case HorizontalAlign.Right:
                    TextFont.DrawText(layout, x + w - layout.Metrics.Width, y + (h - layout.Metrics.Height) / 2);
                    break;
                }
            }

            if (BorderBrush != null)
            {
                BorderBrush.DrawRectangle(x, y, w, h);
            }
        }
示例#8
0
 public DynamicTextElement(TextFunc getText, int x, int y, bool centered = false, bool neverHighlight = false, ClickFunc onClick = null, int color = SpriteText.color_White) : base("", x, y, centered, neverHighlight, onClick, color)
 {
     this.getText = getText;
 }