Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ContentPresenter.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 
4 using SiliconStudio.Core;
5 using System.Diagnostics;
6 using SiliconStudio.Core.Mathematics;
7 
8 namespace SiliconStudio.Paradox.UI.Controls
9 {
10  /// <summary>
11  /// A class aiming at presenting another <see cref="UIElement"/>.
12  /// </summary>
13  [DebuggerDisplay("ContentPresenter - Name={Name}")]
14  public class ContentPresenter : UIElement
15  {
16  private static void ContentInvalidationCallback(object propertyOwner, PropertyKey<UIElement> propertyKey, UIElement oldContent)
17  {
18  var presenter = (ContentPresenter)propertyOwner;
19 
20  if(oldContent == presenter.Content)
21  return;
22 
23  if (oldContent != null)
24  SetVisualParent(oldContent, null);
25 
26  if (presenter.Content != null)
27  SetVisualParent(presenter.Content, presenter);
28 
29  presenter.InvalidateMeasure();
30  }
31 
32  /// <summary>
33  /// The key to the Content dependency property.
34  /// </summary>
35  public readonly static PropertyKey<UIElement> ContentPropertyKey = new PropertyKey<UIElement>("ContentKey", typeof(ContentPresenter), DefaultValueMetadata.Static<UIElement>(null), ObjectInvalidationMetadata.New<UIElement>(ContentInvalidationCallback));
36 
37  private Matrix contentWorldMatrix;
38 
40  {
41  DepthAlignment = DepthAlignment.Stretch;
42  }
43 
44  /// <summary>
45  /// Gets or sets content of the presenter.
46  /// </summary>
47  public UIElement Content
48  {
49  get { return DependencyProperties.Get(ContentPropertyKey); }
50  set { DependencyProperties.Set(ContentPropertyKey, value); }
51  }
52 
53  protected override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
54  {
55  // measure size desired by the children
56  var childDesiredSizeWithMargins = Vector3.Zero;
57  if (Content != null)
58  {
59  Content.Measure(availableSizeWithoutMargins);
60  childDesiredSizeWithMargins = Content.DesiredSizeWithMargins;
61  }
62 
63  return childDesiredSizeWithMargins;
64  }
65 
66  protected override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
67  {
68  // arrange the content
69  if (Content != null)
70  {
71  // arrange the child
72  Content.Arrange(finalSizeWithoutMargins, IsCollapsed);
73  }
74 
75  return finalSizeWithoutMargins;
76  }
77 
78  protected override void UpdateWorldMatrix(ref Matrix parentWorldMatrix, bool parentWorldChanged)
79  {
80  var contentWorldMatrixChanged = parentWorldChanged || ArrangeChanged || LocalMatrixChanged;
81 
82  base.UpdateWorldMatrix(ref parentWorldMatrix, parentWorldChanged);
83 
84  if (Content != null)
85  {
86  if (contentWorldMatrixChanged)
87  {
88  contentWorldMatrix = WorldMatrixInternal;
89  var contentMatrix = Matrix.Translation(-RenderSize / 2);
90  Matrix.Multiply(ref contentMatrix, ref WorldMatrixInternal, out contentWorldMatrix);
91  }
92 
93  ((IUIElementUpdate)Content).UpdateWorldMatrix(ref contentWorldMatrix, contentWorldMatrixChanged);
94  }
95  }
96  }
97 }
Provides a base class for all the User Interface elements in Paradox applications.
Definition: UIElement.cs:21
Interface for the update of the UIElements.
override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
When overridden in a derived class, positions possible child elements and determines a size for a UIE...
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
DepthAlignment
Describes how a child element is positioned in depth or stretched within a parent's layout slot...
override void UpdateWorldMatrix(ref Matrix parentWorldMatrix, bool parentWorldChanged)
Method called by IUIElementUpdate.UpdateWorldMatrix. Parents are in charge of recursively calling thi...
override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
When overridden in a derived class, measures the size in layout required for possible child elements ...
A class aiming at presenting another UIElement.
Only valid for a property / field that has a class or struct type. When restored, instead of recreati...
A class that represents a tag propety.
Definition: PropertyKey.cs:17
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47