Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DefaultTextBlockRenderer.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using SiliconStudio.Core;
4 using SiliconStudio.Core.Mathematics;
5 using SiliconStudio.Paradox.Graphics;
6 using SiliconStudio.Paradox.UI.Controls;
7 
8 namespace SiliconStudio.Paradox.UI.Renderers
9 {
10  /// <summary>
11  /// The default renderer for <see cref="TextBlock"/>.
12  /// </summary>
13  internal class DefaultTextBlockRenderer : ElementRenderer
14  {
15  public DefaultTextBlockRenderer(IServiceRegistry services)
16  : base(services)
17  {
18  }
19 
20  public override void RenderColor(UIElement element, UIRenderingContext context)
21  {
22  base.RenderColor(element, context);
23 
24  var textBlock = (TextBlock)element;
25 
26  if (textBlock.Font == null || textBlock.TextToDisplay == null)
27  return;
28 
29  var drawCommand = new SpriteFont.InternalUIDrawCommand
30  {
31  Color = textBlock.RenderOpacity * textBlock.TextColor,
32  DepthBias = context.DepthBias,
33  FontScale = element.RealSizeVirtualResolutionRatio,
34  FontSize = textBlock.TextSize,
35  Batch = Batch,
36  SnapText = textBlock.SnapText,
37  WorldMatrix = textBlock.WorldMatrixInternal,
38  Alignment = textBlock.TextAlignment,
39  Size = new Vector2(textBlock.ActualWidth, textBlock.ActualHeight)
40  };
41 
42  Batch.DrawString(textBlock.Font, textBlock.TextToDisplay, ref drawCommand);
43  }
44  }
45 }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
TextAlignment
Specify the available text alignment when rendering text.
Definition: TextAlignment.cs:8
A service registry is a IServiceProvider that provides methods to register and unregister services...
SharpDX.DirectWrite.Font Font
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
Provides a lightweight control for displaying small amounts of text.
Definition: TextBlock.cs:18