示例#1
0
 /// <summary>
 /// Create a textobject, that formats and displays the text. See doc for Formatting commands.
 /// </summary>
 /// <param name="parent">The gameObject to attach the text to</param>
 /// <param name="fontName">the name of the font (can be altered with Formatting Commands)</param>
 /// <param name="text">The text incl. formatting commands to display</param>
 /// <param name="color">The color of the text (can be altered with Formatting Commands)</param>
 /// <param name="alignment">The textAlignment (Left, Right, Center)</param>
 /// <param name="scale">The Size of the text (can be altered with Formatting Commands)</param>
 /// <param name="cropText">Whether to crop the text to only show text that fits inside the drawfield</param>
 internal TextObject(GameObject parent, string fontName, string text, Color color, textAlignment alignment = textAlignment.Left, float scale = 1.0f, bool cropText = true) : base(parent)
 {
     this.font      = Game.fonts.Get(fontName);
     this.alignment = alignment;
     this.color     = color;
     this.scale     = scale;
     this.cropText  = cropText;
     isUI           = parent as UIObject != null;
     apply(text);
 }
示例#2
0
 /// <summary>
 /// Create a UIObject with text
 /// </summary>
 /// <param name="pos">the relative position and size.</param>
 /// <param name="anchorMode">the Anchor preset used.</param>
 /// <param name="parent">the parent to anchor to</param>
 /// <param name="text">The text to display (See TextObject doc for TextObject formatting Commands)</param>
 /// <param name="textColor">The colour of the text</param>
 /// <param name="fontName">The path to the font for the text</param>
 /// <param name="alignment">The TextAlingment (Left, right, or center)</param>
 /// <param name="textScale">The Scale of the text</param>
 /// <param name="cropText">Whether to crop the displayed text to fit in this Object when drawing</param>
 internal UITextObject(Rectangle pos, Anchor anchorMode, UIObject parent, string text, Color textColor, string fontName = "", textAlignment alignment = textAlignment.Left, float textScale = 1.0f, bool cropText = true) : base(pos, anchorMode, parent)
 {
     textObject = new TextObject(this, fontName, text, textColor, alignment, textScale, cropText);
 }
示例#3
0
        public TextBDUI(RutineBDUI.OperationBDUI.PinBDUI parent, string text, PointF position, textAlignment alignment)
        {
            this.parent    = parent;
            this.text      = text;
            this.alignment = alignment;
            this.position  = position;

            parent.Paint += (object sender, System.Windows.Forms.PaintEventArgs e) =>
            {
                if (Paint != null)
                {
                    this.Paint(sender, e);
                }
                float width, height;
                width  = graphics.MeasureString(text, parent.parent.parent.font).Width;
                height = graphics.MeasureString(text, parent.parent.parent.font).Height;
                switch (alignment)
                {
                case textAlignment.Center:
                    e.Graphics.DrawString(text, font, brush, position.X - width / 2, position.Y - width / 2);
                    break;

                case textAlignment.Left:
                    e.Graphics.DrawString(text, font, brush, position.X - width, position.Y - width / 2);
                    break;

                case textAlignment.Right:
                    e.Graphics.DrawString(text, font, brush, position.X, position.Y - height / 2);
                    break;

                case textAlignment.Top:
                    e.Graphics.DrawString(text, font, brush, position.X - width / 2, position.Y - height);
                    break;

                case textAlignment.Bottom:
                    e.Graphics.DrawString(text, font, brush, position.X - width, position.Y - height / 2);
                    break;

                case textAlignment.TopLeft:
                    e.Graphics.DrawString(text, font, brush, position.X - width, position.Y - height);
                    break;

                case textAlignment.TopRight:
                    e.Graphics.DrawString(text, font, brush, position.X, position.Y - height);
                    break;

                case textAlignment.BottomLeft:
                    e.Graphics.DrawString(text, font, brush, position.X - width, position.Y);
                    break;

                case textAlignment.BottomRight:
                    e.Graphics.DrawString(text, font, brush, position.X, position.Y);
                    break;

                default:
                    break;
                }
                e.Graphics.DrawString(text, font, brush, position);
            };
        }