5 using SiliconStudio.Core;
6 using SiliconStudio.Core.Mathematics;
7 using SiliconStudio.Paradox.Games;
8 using SiliconStudio.Paradox.Graphics;
9 using SiliconStudio.Paradox.UI;
10 using SiliconStudio.Paradox.UI.Renderers;
12 namespace SiliconStudio.
Paradox.Effects
19 private readonly
IGame game;
28 private bool uiResolutionChanged;
33 game = (
IGame)services.GetService(typeof(
IGame));
36 batch = uiSystem.Batch;
38 rendererManager =
new RendererManager(
new DefaultRenderersFactory(services));
40 DebugName =
"UIRenderer";
43 public override void Load()
47 uiSystem.ResolutionChanged += UISystemOnResolutionChanged;
56 private void UISystemOnResolutionChanged(
object sender,
EventArgs eventArgs)
58 uiResolutionChanged =
true;
66 uiSystem.ResolutionChanged -= UISystemOnResolutionChanged;
71 if (uiSystem.RootElement == null)
74 var drawTime = game.DrawTime;
75 var rootElement = uiSystem.RootElement;
76 var virtualResolution = uiSystem.VirtualResolution;
80 updatableRootElement.Update(drawTime);
83 rootElement.Measure(virtualResolution);
84 rootElement.Arrange(virtualResolution,
false);
87 updatableRootElement.UpdateWorldMatrix(ref uiSystem.WorldMatrix, uiResolutionChanged);
88 updatableRootElement.UpdateElementState(0);
89 uiResolutionChanged =
false;
92 GraphicsDevice.SetRenderTarget(GraphicsDevice.DepthStencilBuffer, GraphicsDevice.BackBuffer);
93 GraphicsDevice.Clear(GraphicsDevice.DepthStencilBuffer, DepthStencilClearOptions.DepthBuffer | DepthStencilClearOptions.Stencil);
96 renderingContext.Time = game.DrawTime;
99 renderingContext.StencilTestReferenceValue = 0;
100 batch.Begin(ref uiSystem.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);
103 ReccursiveDrawWithClipping(rootElement);
109 private void ReccursiveDrawWithClipping(
UIElement element)
115 var renderer = rendererManager.GetRenderer(element);
116 renderingContext.DepthBias = element.DepthBias;
125 batch.Begin(ref uiSystem.ViewProjectionInternal, GraphicsDevice.BlendStates.ColorDisabled, uiSystem.IncreaseStencilValueState, renderingContext.StencilTestReferenceValue);
126 renderer.RenderClipping(element, renderingContext);
130 renderingContext.StencilTestReferenceValue += 1;
131 batch.Begin(ref uiSystem.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);
135 renderer.RenderColor(element, renderingContext);
138 foreach (var child
in element.VisualChildrenCollection)
139 ReccursiveDrawWithClipping(child);
142 if (element.ClipToBounds)
147 renderingContext.DepthBias = element.MaxChildrenDepthBias;
150 batch.Begin(ref uiSystem.ViewProjectionInternal, GraphicsDevice.BlendStates.ColorDisabled, uiSystem.DecreaseStencilValueState, renderingContext.StencilTestReferenceValue);
151 renderer.RenderClipping(element, renderingContext);
155 renderingContext.StencilTestReferenceValue -= 1;
156 batch.Begin(ref uiSystem.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);
162 return rendererManager.GetRenderer(element);
167 rendererManager.RegisterRendererFactory(uiElementType, factory);
172 rendererManager.RegisterRenderer(element, renderer);
Provides a base class for all the User Interface elements in Paradox applications.
override void OnRendering(RenderContext context)
The renderer in charge of drawing the UI.
A renderable texture view.
bool ClipToBounds
Gets or sets a value indicating whether to clip the content of this element (or content coming from t...
Interface for the update of the UIElements.
override void Unload()
Unloads this instance. This method is called when a RenderPass is de-attached (directly or indirectly...
Performs render pipeline transformations attached to a specific RenderPass.
A utility class to batch and draw UI images.
A service registry is a IServiceProvider that provides methods to register and unregister services...
A factory that can create ElementRenderers.
ElementRenderer GetRenderer(UIElement element)
Get the renderer of the corresponding UIElement.
Base class for UI element renderers
bool IsVisible
Gets a value indicating whether this element is visible in the user interface (UI).
Thread-local storage context used during rendering.
void RegisterRenderer(UIElement element, ElementRenderer renderer)
Associate a renderer to an UIElement.
The interface for managing UI element renderers.
Interface of the UI system.
void RegisterRendererFactory(Type uiElementType, IElementRendererFactory factory)
Associate a renderer factory to an UI element type.
override void Load()
Loads this instance. This method is called when a RenderPass is attached (directly or indirectly) to ...
The class in charge to manage the renderer of the different UIElement
UIRenderer(IServiceRegistry services)
The UI drawing context. It provides information about how to render UIElements for drawing...