public LabelStyle(LabelStyle style) : base(style) { TextColor = style.TextColor; DisabledTextColor = style.DisabledTextColor; OverTextColor = style.OverTextColor; PressedTextColor = style.PressedTextColor; Font = style.Font; }
public Stylesheet Load(AssetLoaderContext context, string assetName) { var xml = context.Load <string>(assetName); var xDoc = XDocument.Parse(xml); var attr = xDoc.Root.Attribute("TextureRegionAtlas"); if (attr == null) { throw new Exception("Mandatory attribute 'TextureRegionAtlas' doesnt exist"); } var textureRegionAtlas = context.Load <TextureRegionAtlas>(attr.Value); // Load fonts var fonts = new Dictionary <string, SpriteFontBase>(); var fontsNode = xDoc.Root.Element("Fonts"); foreach (var el in fontsNode.Elements()) { SpriteFontBase font = null; var fontFile = el.Attribute("File").Value; if (fontFile.EndsWith(".ttf")) { var parts = new List <string>(); parts.Add(fontFile); var typeAttribute = el.Attribute("Type"); if (typeAttribute != null) { parts.Add(typeAttribute.Value); var amountAttribute = el.Attribute("Amount"); parts.Add(amountAttribute.Value); } parts.Add(el.Attribute("Size").Value); font = context.Load <DynamicSpriteFont>(string.Join(":", parts)); } else if (fontFile.EndsWith(".fnt")) { font = context.Load <StaticSpriteFont>(fontFile); } else { throw new Exception(string.Format("Font '{0}' isn't supported", fontFile)); } fonts[el.Attribute(BaseContext.IdName).Value] = font; } return(Stylesheet.LoadFromSource(xml, textureRegionAtlas, fonts)); }
public TextChunk(SpriteFontBase font, string text, Point size, bool calculateGlyps) { if (font == null) { throw new ArgumentNullException("font"); } _font = font; _text = text; _size = size; if (calculateGlyps) { CalculateGlyphs(); } }
protected override void LoadContent() { base.LoadContent(); _spriteBatch = new SpriteBatch(GraphicsDevice); using (var stream = TitleContainer.OpenStream("image.png")) { _playerImage = Texture2D.FromStream(GraphicsDevice, stream); } MyraEnvironment.Game = this; _font = DefaultAssets.UIStylesheet.Fonts.Values.First(); var root = new Panel(); var showButton = new TextButton { Text = "Show", Toggleable = true }; showButton.PressedChanged += ShowButton_PressedChanged; root.Widgets.Add(showButton); _labelOverGui = new Label { VerticalAlignment = VerticalAlignment.Bottom }; root.Widgets.Add(_labelOverGui); _desktop = new Desktop { Root = root }; var propertyGrid = new PropertyGrid { Object = _player, Width = 350 }; _windowEditor = new Window { Title = "Object Editor", Content = propertyGrid }; _windowEditor.Closed += (s, a) => { showButton.IsPressed = false; }; // Force window show showButton.IsPressed = true; #if MONOGAME // Inform Myra that external text input is available // So it stops translating Keys to chars _desktop.HasExternalTextInput = true; // Provide that text input Window.TextInput += (s, a) => { _desktop.OnChar(a.Character); }; #endif _renderContext = new RenderContext(); }
/// <summary> /// Draws a text /// </summary> /// <param name="text">The text which will be drawn.</param> /// <param name="position">The drawing location on screen.</param> /// <param name="colors">Colors of glyphs.</param> /// <param name="rotation">A rotation of this text in radians.</param> /// <param name="origin">Center of the rotation.</param> /// <param name="scale">A scaling of this text.</param> /// <param name="layerDepth">A depth of the layer of this string.</param> public void DrawString(SpriteFontBase font, string text, Vector2 position, Color[] colors, Vector2 scale, float rotation, Vector2 origin, float layerDepth = 0.0f) { font.DrawText(_renderer, text, position, colors, scale, rotation, origin, layerDepth); }
/// <summary> /// Draws a text /// </summary> /// <param name="text">The text which will be drawn.</param> /// <param name="position">The drawing location on screen.</param> /// <param name="color">A color mask.</param> /// <param name="layerDepth">A depth of the layer of this string.</param> public void DrawString(SpriteFontBase font, string text, Vector2 position, Color color, float layerDepth = 0.0f) { font.DrawText(_renderer, text, position, CrossEngineStuff.MultiplyColor(color, Opacity), layerDepth); }
public void DrawString(SpriteFontBase font, string text, Vector2 position, Color color, float layerDepth = 0) { _spriteBatch.DrawString(font, text, position, color, layerDepth); }