Example #1
0
    public static GameObject ShowText(string name, string text, float time, TextAlignment alignment, TextAnchor anchor, float x, float y)
    {
        LoadFonts();

        // Destroy old object if existent
        GameObject textObject = GameObject.Find(PREFIX + name);
        MonoBehaviour.Destroy(textObject);

        textObject = new GameObject(PREFIX + name);

        textObject.AddComponent<OutlineText>().thickness = 2;

        TutorialText textBehaviour = textObject.GetComponent<TutorialText>();

        if (textBehaviour == null)
            textBehaviour = textObject.AddComponent<TutorialText>();

        GUIScale textScaler = textObject.GetComponent<GUIScale>();
        GUIText guitext = textObject.guiText;
        guitext.enabled = true;

        textObject.transform.position = new Vector3(x, y, 0);

        guitext.text = text;
        guitext.anchor = anchor;
        guitext.alignment = alignment;
        //guitext.font = bigFont;
        //guitext.material = bigMat;
        //guitext.fontSize = 48;

        if (time > 0)
            textBehaviour.DestroyIn(time);

        return textObject;
    }
 public static void UpdateFromFormsControl(this TextView textView, string text, Color formsColor, Font formsFont, TextAlignment textAlignment)
 {
     textView.Text = text;
     textView.SetTextColor(formsColor.ToAndroid(Color.Default));
     textView.UpdateFont(formsFont);
     textView.Gravity = textAlignment.ToNative();
 }
        public FormattedTextImpl(string text, string fontFamilyName, double fontSize, FontStyle fontStyle,
                    TextAlignment textAlignment, FontWeight fontWeight, TextWrapping wrapping)
        {
            _text = text ?? string.Empty;

            // Replace 0 characters with zero-width spaces (200B)
            _text = _text.Replace((char)0, (char)0x200B);

            var typeface = TypefaceCache.GetTypeface(fontFamilyName, fontStyle, fontWeight);

            _paint = new SKPaint();

            //currently Skia does not measure properly with Utf8 !!!
            //Paint.TextEncoding = SKTextEncoding.Utf8;
            _paint.TextEncoding = SKTextEncoding.Utf16;
            _paint.IsStroke = false;
            _paint.IsAntialias = true;            
            _paint.LcdRenderText = true;            
            _paint.SubpixelText = true;
            _paint.Typeface = typeface;
            _paint.TextSize = (float)fontSize;
            _paint.TextAlign = textAlignment.ToSKTextAlign();

            _wrapping = wrapping;

            Rebuild();
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormattedText"/> class.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="fontFamilyName">The font family.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="fontStyle">The font style.</param>
        /// <param name="textAlignment">The text alignment.</param>
        /// <param name="fontWeight">The font weight.</param>
        public FormattedText(
            string text,
            string fontFamilyName,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight)
        {
            Contract.Requires<ArgumentNullException>(text != null);
            Contract.Requires<ArgumentNullException>(fontFamilyName != null);
            Contract.Requires<ArgumentException>(fontSize > 0);

            Text = text;
            FontFamilyName = fontFamilyName;
            FontSize = fontSize;
            FontStyle = fontStyle;
            FontWeight = fontWeight;
            TextAlignment = textAlignment;

            var platform = PerspexLocator.Current.GetService<IPlatformRenderInterface>();

            if (platform == null)
            {
                throw new Exception("Could not create FormattedText: IPlatformRenderInterface not registered.");
            }

            PlatformImpl = platform.CreateFormattedText(
                text,
                fontFamilyName,
                fontSize,
                fontStyle,
                textAlignment,
                fontWeight);
        }
 public FixedWidthColumn(string name, int width, TextAlignment align, char blankChar)
 {
     this._name = name;
     this._w = width;
     this._align = align;
     this._blank = blankChar;
 }
        public FormattedTextImpl(
            Pango.Context context,
            string text,
            string fontFamily,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight)
        {
            Contract.Requires<ArgumentNullException>(context != null);
            Contract.Requires<ArgumentNullException>(text != null);
            Layout = new Pango.Layout(context);
            _text = text;
            Layout.SetText(text);
            Layout.FontDescription = new Pango.FontDescription
            {
                Family = fontFamily,
                Size = Pango.Units.FromDouble(CorrectScale(fontSize)),
                Style = (Pango.Style)fontStyle,
                Weight = fontWeight.ToCairo()
            };

            Layout.Alignment = textAlignment.ToCairo();
            Layout.Attributes = new Pango.AttrList();
        }
Example #7
0
 public Text(string text, TextAlignment align, int x, int y)
 {
     Label = text;
     Align = align;
     X = x;
     Y = y;
 }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormattedText"/> class.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="fontFamilyName">The font family.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="fontStyle">The font style.</param>
        /// <param name="textAlignment">The text alignment.</param>
        /// <param name="fontWeight">The font weight.</param>
        public FormattedText(
            string text,
            string fontFamilyName,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight)
        {
            //TODO: Find out why it was null in the first place. Demo project - AvalonStudio
            //https://github.com/VitalElement/AvalonStudio/commit/787fb9396feb74e6ca6bd4e08436269a349df9c6
            text = text ?? "";
            Text = text;
            FontFamilyName = fontFamilyName;
            FontSize = fontSize;
            FontStyle = fontStyle;
            FontWeight = fontWeight;
            TextAlignment = textAlignment;

            var platform = PerspexLocator.Current.GetService<IPlatformRenderInterface>();

            PlatformImpl = platform.CreateFormattedText(
                text,
                fontFamilyName,
                fontSize,
                fontStyle,
                textAlignment,
                fontWeight);
        }
        public static FormattedText Create(string text, Font font, TextAlignment alignment, SizeConstraint constraint)
        {
            if (text == null)
            {
                return new FormattedText(null, new Box2(0, 0, 0, 0), text, font, alignment, constraint);
            }
            else
            {
                var instances = new List<GlyphInstance>(text.Length);
                var x = 0f;

                foreach (var c in text)
                {
                    var glyph = font.GetGlyph(c);

                    if (glyph != null)
                    {
                        instances.Add(new GlyphInstance(new Box2(x, 0, glyph.Size.X, glyph.Size.Y), glyph.Sprite));
                        x += glyph.Size.X;
                    }
                }

                return new FormattedText(instances, new Box2(0, 0, x, font.Height), text, font, alignment, constraint);
            }
        }
Example #10
0
        public FormattedText(
            string text,
            string fontFamilyName,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight)
        {
            this.Text = text;
            this.FontFamilyName = fontFamilyName;
            this.FontSize = fontSize;
            this.FontStyle = fontStyle;
            this.FontWeight = fontWeight;
            this.TextAlignment = textAlignment;

            var platform = Locator.Current.GetService<IPlatformRenderInterface>();

            this.PlatformImpl = platform.CreateFormattedText(
                text,
                fontFamilyName,
                fontSize,
                fontStyle,
                textAlignment,
                fontWeight);
        }
Example #11
0
        public FormattedTextImpl(
            string text,
            string fontFamily,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight,
            TextWrapping wrapping)
        {
            var factory = AvaloniaLocator.Current.GetService<DWrite.Factory>();

            using (var format = new DWrite.TextFormat(
                factory,
                fontFamily,
                (DWrite.FontWeight)fontWeight,
                (DWrite.FontStyle)fontStyle,
                (float)fontSize))
            {
                format.WordWrapping = wrapping == TextWrapping.Wrap ? 
                    DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap;

                TextLayout = new DWrite.TextLayout(
                    factory,
                    text ?? string.Empty,
                    format,
                    float.MaxValue,
                    float.MaxValue);
            }

            TextLayout.TextAlignment = textAlignment.ToDirect2D();
        }
Example #12
0
        //    http://stackoverflow.com/questions/14932063/convert-code-of-a-user-control-from-vb-net-to-c-sharp
        //https://mightycoco.wordpress.com/2009/09/22/getstringformatfromcontentallignment-converting-contentallignment-data-into-stringformat-data/
        public static StringFormat BuildStringFormat(StringTrimming stringTrimming,TextAlignment alignment)
        {
            StringFormat format = StringFormat.GenericTypographic;
            format.Trimming = stringTrimming;
            format.FormatFlags = StringFormatFlags.LineLimit;
            switch (alignment) {
                    case TextAlignment.Left:{
                        format.Alignment = StringAlignment.Near;
                        format.LineAlignment = StringAlignment.Near;
                        return format;
                    }
                    case TextAlignment.Center:{
                        format.Alignment = StringAlignment.Center;
                        format.LineAlignment = StringAlignment.Near;
                        return format;
                    }

                    case TextAlignment.Right:{
                        format.Alignment = StringAlignment.Far;
                        format.LineAlignment = StringAlignment.Near;
                        return format;
                    }

                    case TextAlignment.Justify:{
                        format.Alignment = StringAlignment.Center;
                        format.LineAlignment = StringAlignment.Near;
                        return format;
                    }
            }
            return format;
        }
 public TextComponent(string myText, TextAlignment myAlignment, Vector2 myPosition, SpriteFont myFont)
 {
     Destination = myPosition;
     textAlighment = myAlignment;
     font = myFont;
     text = myText;
 }
 public GestureOptionEntry(string text, Texture2D icon, Vector2 iconSize, Vector2 position, float scale, Color color, TextAlignment alignment, GestureTest test, GestureHandler callback)
     : base(text, icon, iconSize, position, scale, color, alignment)
 {
     unlockedColor = color;
     this.callback = callback;
     this.test = test;
 }
Example #15
0
 public LabelTextureButton(
     Screen screen,
     SpriteBatch spriteBatch,
     UIAlignment alignment,
     int x,
     int y,
     Texture2D selectedTexture,
     Texture2D deselectedTexture,
     Rectangle localHitBox,
     SpriteFont font,
     TextAlignment textAlignment,
     string text,
     int textXOffset,
     int textYOffset,
     int outline,
     Color selectedColor,
     Color deselectedColor,
     Action onActivate,
     Action onMouseOver,
     Action onMouseOut)
     : base(screen, spriteBatch, alignment, x, y, selectedTexture, deselectedTexture, localHitBox, onActivate, onMouseOver, onMouseOut)
 {
     _font = font;
     _textAlignment = textAlignment;
     _text = text;
     _textXOffset = textXOffset;
     _textYOffset = textYOffset;
     _outline = outline;
     _selectedColor = selectedColor;
     _deselectedColor = deselectedColor;
 }
Example #16
0
 public SignalChooser(INodeWrapper nodeItem, NodeSignalIn initialSignalIn, double maxWidth, TextAlignment textAlignment)
 {
     NodeItem = nodeItem;
     SignalIn = initialSignalIn;
     MaxWidth = maxWidth;
     TextAlignment = textAlignment;
 }
		public static void UpdateFromFormsControl (this UILabel uiLabel, string text, TextAlignment textAlignment, Color textColor, Font font)
		{
			uiLabel.Text = text;
			uiLabel.TextAlignment = textAlignment.ToUITextAlignment ();
			uiLabel.TextColor = textColor.ToUIColor ();
			uiLabel.Font = font.ToUIFont ();
		}
Example #18
0
        public FormattedTextImpl(
            string text,
            string fontFamily,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight)
        {
            var factory = Locator.Current.GetService<DWrite.Factory>();

            var format = new DWrite.TextFormat(
                factory,
                fontFamily,
                (DWrite.FontWeight)fontWeight,
                (DWrite.FontStyle)fontStyle,
                (float)fontSize);

            TextLayout = new DWrite.TextLayout(
                factory,
                text ?? string.Empty,
                format,
                float.MaxValue,
                float.MaxValue);

            TextLayout.TextAlignment = textAlignment.ToDirect2D();
        }
Example #19
0
 public GUIButton(int x, int y, int width, int height)
     : base(x, y, width, height)
 {
     _text = "New Button";
     _clickAction = GUIClickAction.RunScript;
     _textAlign = TextAlignment.TopMiddle;
 }
Example #20
0
 public SignalValue(INodeWrapper nodeItem, NodeSignal initialSignal, double maxWidth, TextAlignment textAlignment, string formatString)
 {
     Signal = initialSignal;
     NodeItem = nodeItem;
     MaxWidth = maxWidth;
     TextAlignment = textAlignment;
     FormatString = formatString;
 }
 public TableColumnDefinition(string title, string format, int width, TextAlignment textAlignment, OverflowBehavior overflowBehavior)
 {
     Title = title;
     Format = format;
     Width = width;
     TextAlignment = textAlignment;
     OverflowBehavior = overflowBehavior;
 }
Example #22
0
		public Text (string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
			: base (pen, brush)
		{
			Frame = frame;
			Font = font;
			Alignment = alignment;
			Spans = new List<TextSpan> { new TextSpan (text) };
		}
Example #23
0
		public Text (Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
			: base (pen, brush)
		{
			Frame = frame;
			Font = font;
			Alignment = alignment;
			Spans = new List<TextSpan> ();
		}
Example #24
0
 public Text(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null)
     : base(pen, brush)
 {
     String = text;
     Frame = frame;
     Font = font;
     Alignment = alignment;
 }
Example #25
0
 public Text(ComponentPoint location, TextAlignment alignment, double size, string text)
 {
     Location = location;
     Alignment = alignment;
     var textRun = new TextRun(text, new TextRunFormatting(TextRunFormattingType.Normal, size));
     TextRuns = new List<TextRun>();
     TextRuns.Add(textRun);
 }
Example #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextLine"/> class.
 /// </summary>
 /// <param name="font">The font used to display text in this textline.</param>
 public TextLine(FontInfo font)
     : base(Vector2D.Zero, Vector2D.Zero)
 {
     this.text = string.Empty;
     this.font = font;
     this.color = Color.Black;
     this.alignment = TextAlignment.Left;
 }
Example #27
0
 private FormattedText(List<GlyphInstance> instances, Box2 bounds, string text, Font font, TextAlignment alignment, SizeConstraint constraint)
 {
     m_instances = instances;
     Bounds = bounds;
     Text = text;
     Font = font;
     Alignment = alignment;
     Constraint = constraint;
 }
Example #28
0
 public FontRendering()
 {
     _fontSize = 12.0f;
     _alignment = TextAlignment.Left;
     _textDecorations = new TextDecorationCollection();
     _textColor = Brushes.Black;
     _typeface = new Typeface(new FontFamily("Arial"),
        FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
 }
Example #29
0
        public IconText(string t, Texture2D iconSprite, Vector2 iconSize, Vector2 position, float scale, Color color, TextAlignment alignment, TextEffect effect = TextEffect.None, float alpha = 1.0f)
            : base(position,new Vector2(0,-1),Vector2.Zero)
        {
            text = new Text(t,  position, scale, color, effect);
            icon = new DrawableAsset<Texture2D>(Vector2.Zero, new Vector2(0, -1), iconSize, iconSprite);

            this.alignment = alignment;
            UpdateAlignment();
        }
Example #30
0
 public void Reply(bool allowed, int code, string message, TextAlignment alignment = TextAlignment.Left)
 {
     var task = ReplyAsync(allowed, code, message, alignment);
     task.Wait();
     if (task.IsFaulted && task.Exception != null)
     {
         throw task.Exception;
     }
 }