Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DefaultToggleButtonRenderer.cs
Go to the documentation of this file.
1 using System;
2 
3 using SiliconStudio.Core;
4 using SiliconStudio.Core.Mathematics;
5 using SiliconStudio.Paradox.UI.Controls;
6 
7 namespace SiliconStudio.Paradox.UI.Renderers
8 {
9  /// <summary>
10  /// The default renderer for <see cref="ToggleButton"/>.
11  /// </summary>
12  internal class DefaultToggleButtonRenderer : ElementRenderer
13  {
14  public DefaultToggleButtonRenderer(IServiceRegistry services)
15  : base(services)
16  {
17  }
18 
19  public override void RenderColor(UIElement element, UIRenderingContext context)
20  {
21  base.RenderColor(element, context);
22 
23  var toggleButton = (ToggleButton)element;
24  var color = toggleButton.RenderOpacity * Color.White;
25 
26  var image = GetToggleStateImage(toggleButton);
27  if (image == null || image.Texture == null)
28  return;
29 
30  Batch.DrawImage(image.Texture, image.TextureAlpha, ref toggleButton.WorldMatrixInternal, ref image.RegionInternal, ref toggleButton.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation);
31  }
32 
33  private UIImage GetToggleStateImage(ToggleButton toggleButton)
34  {
35  switch (toggleButton.State)
36  {
37  case ToggleState.Checked:
38  return toggleButton.CheckedImage;
39  case ToggleState.Indeterminate:
40  return toggleButton.IndeterminateImage;
41  case ToggleState.UnChecked:
42  return toggleButton.UncheckedImage;
43  default:
44  throw new ArgumentOutOfRangeException();
45  }
46  }
47  }
48 }
Represent a UI toggle button. A toggle but can have two or three states depending on the IsThreeState...
Definition: ToggleButton.cs:15
A service registry is a IServiceProvider that provides methods to register and unregister services...
Android.Widget.Orientation Orientation
Definition: Section.cs:9
ToggleState State
Gets or sets the state of the ToggleButton
Definition: ToggleButton.cs:89