Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DefaultRenderersFactory.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 System;
4 using System.Collections.Generic;
5 using System.Reflection;
6 
7 using SiliconStudio.Core;
8 using SiliconStudio.Paradox.UI.Controls;
9 
10 namespace SiliconStudio.Paradox.UI.Renderers
11 {
12  /// <summary>
13  /// A factory that create the default renderer for each <see cref="UIElement"/> type.
14  /// </summary>
15  internal class DefaultRenderersFactory : IElementRendererFactory
16  {
17  private readonly ElementRenderer defaultRenderer;
18 
19  private readonly Dictionary<Type, ElementRenderer> typeToRenderers = new Dictionary<Type, ElementRenderer>();
20 
21  public DefaultRenderersFactory(IServiceRegistry services)
22  {
23  defaultRenderer = new ElementRenderer(services);
24  typeToRenderers[typeof(ImageElement)] = new DefaultImageRenderer(services);
25  typeToRenderers[typeof(Button)] = new DefaultButtonRenderer(services);
26  typeToRenderers[typeof(ImageButton)] = new ElementRenderer(services);
27  typeToRenderers[typeof(ToggleButton)] = new ElementRenderer(services);
28  typeToRenderers[typeof(TextBlock)] = new DefaultTextBlockRenderer(services);
29  typeToRenderers[typeof(ScrollingText)] = new DefaultScrollingTextRenderer(services);
30  typeToRenderers[typeof(ModalElement)] = new DefaultModalElementRenderer(services);
31  typeToRenderers[typeof(ScrollBar)] = new DefaultScrollBarRenderer(services);
32  typeToRenderers[typeof(EditText)] = new DefaultEditTextRenderer(services);
33  typeToRenderers[typeof(ContentDecorator)] = new DefaultContentDecoratorRenderer(services);
34  typeToRenderers[typeof(Border)] = new DefaultBorderRenderer(services);
35  typeToRenderers[typeof(ToggleButton)] = new DefaultToggleButtonRenderer(services);
36  typeToRenderers[typeof(Slider)] = new DefaultSliderRenderer(services);
37  }
38 
39  public ElementRenderer TryCreateRenderer(UIElement element)
40  {
41  // try to get the renderer from the registered default renderer
42  var currentType = element.GetType();
43  while (currentType != null)
44  {
45  if (typeToRenderers.ContainsKey(currentType))
46  return typeToRenderers[currentType];
47 
48  currentType = currentType.GetTypeInfo().BaseType;
49  }
50 
51  return defaultRenderer;
52  }
53  }
54 }
A border element adds an uniform color border around its content.
Definition: Border.cs:10
Represent a UI toggle button. A toggle but can have two or three states depending on the IsThreeState...
Definition: ToggleButton.cs:15
Represents a modal element that puts an overlay upon the underneath elements and freeze their input...
Definition: ModalElement.cs:16
Represents a Windows button control, which reacts to the Click event.
Definition: Button.cs:13
A service registry is a IServiceProvider that provides methods to register and unregister services...
A ContentControl decorating its ContentControl.Content with a background image.
Represents a slider element.
Definition: Slider.cs:16
A text viewer that scrolls automatically the text from right to left.
Represents a control that displays an image.
Definition: ImageElement.cs:14
Provides a lightweight control for displaying small amounts of text.
Definition: TextBlock.cs:18
A Button whose ContentControl.Content are the Button.PressedImage and Button.NotPressedImage.
Definition: ImageButton.cs:12
Represent an edit text where the user can enter text.
Definition: EditText.cs:20