Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Border.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.Mathematics;
4 
5 namespace SiliconStudio.Paradox.UI.Controls
6 {
7  /// <summary>
8  /// A border element adds an uniform color border around its content.
9  /// </summary>
10  public class Border : ContentControl
11  {
12  internal Color BorderColorInternal = Color.Black;
13  private Thickness borderThickness = Thickness.UniformCuboid(0);
14 
15  /// <summary>
16  /// Gets or sets the padding inside a control.
17  /// </summary>
18  public Thickness BorderThickness
19  {
20  get { return borderThickness; }
21  set
22  {
23  borderThickness = value;
24  InvalidateMeasure();
25  }
26  }
27 
28  /// <summary>
29  /// Gets or sets the color of the borders.
30  /// </summary>
31  public Color BorderColor
32  {
33  get { return BorderColorInternal; }
34  set { BorderColorInternal = value; }
35  }
36 
37  protected override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
38  {
39  var availableLessBorders = CalculateSizeWithoutThickness(ref availableSizeWithoutMargins, ref borderThickness);
40 
41  var neededSize = base.MeasureOverride(availableLessBorders);
42 
43  return CalculateSizeWithThickness(ref neededSize, ref borderThickness);
44  }
45 
46  protected override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
47  {
48  // arrange the content
49  if (VisualContent != null)
50  {
51  // calculate the remaining space for the child after having removed the padding and border space.
52  var availableLessBorders = CalculateSizeWithoutThickness(ref finalSizeWithoutMargins, ref borderThickness);
53  var childSizeWithoutPadding = CalculateSizeWithoutThickness(ref availableLessBorders, ref padding);
54 
55  // arrange the child
56  VisualContent.Arrange(childSizeWithoutPadding, IsCollapsed);
57 
58  // compute the rendering offsets of the child element wrt the parent origin (0,0,0)
59  var childOffsets = new Vector3(padding.Left + borderThickness.Left, padding.Top + borderThickness.Top, padding.Back + borderThickness.Back) - finalSizeWithoutMargins / 2;
60 
61  // set the arrange matrix of the child.
62  VisualContent.DependencyProperties.Set(ContentArrangeMatrixPropertyKey, Matrix.Translation(childOffsets));
63  }
64 
65  return finalSizeWithoutMargins;
66  }
67  }
68 }
A border element adds an uniform color border around its content.
Definition: Border.cs:10
override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
When overridden in a derived class, positions possible child elements and determines a size for a UIE...
Definition: Border.cs:46
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
Describes the thickness of a frame around a cuboid. Six float values describe the Left...
Definition: Thickness.cs:12
Represents a control with a single piece of content of any type.
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
SiliconStudio.Core.Mathematics.Vector3 Vector3
override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
When overridden in a derived class, measures the size in layout required for possible child elements ...
Definition: Border.cs:37