Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DefaultScrollingTextRenderer.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 DefaultScrollingTextRenderer : ElementRenderer
14  {
15  private static Color blackColor;
16 
17  public DefaultScrollingTextRenderer(IServiceRegistry services)
18  : base(services)
19  {
20  }
21 
22  public override void RenderColor(UIElement element, UIRenderingContext context)
23  {
24  base.RenderColor(element, context);
25 
26  var scrollingText = (ScrollingText)element;
27 
28  if (scrollingText.Font == null || scrollingText.TextToDisplay == null)
29  return;
30 
31  var offset = scrollingText.ScrollingOffset;
32  var textWorldMatrix = element.WorldMatrix;
33  textWorldMatrix.M41 += textWorldMatrix.M11 * offset;
34  textWorldMatrix.M42 += textWorldMatrix.M12 * offset;
35  textWorldMatrix.M43 += textWorldMatrix.M13 * offset;
36  textWorldMatrix.M44 += textWorldMatrix.M14 * offset;
37 
38  // create the scrolling text draw command
39  var drawCommand = new SpriteFont.InternalUIDrawCommand
40  {
41  Color = scrollingText.RenderOpacity * scrollingText.TextColor,
42  DepthBias = context.DepthBias + 1,
43  FontScale = element.RealSizeVirtualResolutionRatio,
44  FontSize = scrollingText.TextSize,
45  Batch = Batch,
46  SnapText = scrollingText.SnapText,
47  WorldMatrix = textWorldMatrix,
48  Alignment = TextAlignment.Left,
49  Size = new Vector2(scrollingText.ActualWidth, scrollingText.ActualHeight)
50  };
51 
52  // flush the current content of the UI image batch
53  Batch.End();
54 
55  // draw a clipping mask
56  Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.ColorDisabled, IncreaseStencilValueState, context.StencilTestReferenceValue);
57  Batch.DrawRectangle(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref blackColor, context.DepthBias);
58  Batch.End();
59 
60  // draw the element it-self with stencil test value of "Context.Value + 1"
61  Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue + 1);
62  Batch.DrawString(scrollingText.Font, scrollingText.TextToDisplay, ref drawCommand);
63  Batch.End();
64 
65  // undraw the clipping mask
66  Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.ColorDisabled, DecreaseStencilValueState, context.StencilTestReferenceValue + 1);
67  Batch.DrawRectangle(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref blackColor, context.DepthBias+2);
68  Batch.End();
69 
70  // restart the Batch session
71  Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue);
72  }
73  }
74 }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
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
A text viewer that scrolls automatically the text from right to left.