Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DefaultScrollBarRenderer.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 
5 using SiliconStudio.Core;
6 using SiliconStudio.Paradox.UI.Controls;
7 
8 namespace SiliconStudio.Paradox.UI.Renderers
9 {
10  /// <summary>
11  /// The default renderer for <see cref="ScrollBar"/>.
12  /// </summary>
13  internal class DefaultScrollBarRenderer : ElementRenderer
14  {
15  public DefaultScrollBarRenderer(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 bar = (ScrollBar)element;
25 
26  // round the size of the bar to nearest pixel modulo to avoid to have a bar varying by one pixel length while scrolling
27  var barSize = bar.RenderSizeInternal;
28  for (int i = 0; i < 2; i++)
29  barSize[i] = (float)(Math.Ceiling(barSize[i] * bar.RealSizeVirtualResolutionRatio[i]) / bar.RealSizeVirtualResolutionRatio[i]);
30 
31  Batch.DrawRectangle(ref element.WorldMatrixInternal, ref barSize, ref bar.BarColorInternal, context.DepthBias);
32  }
33  }
34 }
A service registry is a IServiceProvider that provides methods to register and unregister services...