4 using System.Collections.Generic;
5 using System.Collections.Specialized;
6 using System.Diagnostics;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Collections;
10 using SiliconStudio.Core.Mathematics;
11 using SiliconStudio.Paradox.UI.Controls;
13 namespace SiliconStudio.
Paradox.UI.Panels
18 [DebuggerDisplay(
"Panel - Name={Name}")]
31 private static void InvalidateArrangeMatrix(
object propertyOwner,
PropertyKey<Matrix> propertyKey,
Matrix propertyOldValue)
34 var parentPanel = element.VisualParent as
Panel;
37 parentPanel.childrenWithArrangeMatrixInvalidated.Add(element);
40 private readonly
bool[] shouldAnchor =
new bool[3];
66 private readonly HashSet<UIElement> childrenWithArrangeMatrixInvalidated =
new HashSet<UIElement>();
67 private Matrix[] childrenArrangeWorldMatrix =
new Matrix[2];
80 private static void PanelZSortedChildInvalidator(
object element,
PropertyKey<int> key,
int oldValue)
83 var parentAsPanel = uiElement.VisualParent as
Panel;
85 if(parentAsPanel == null)
88 parentAsPanel.VisualChildrenCollection.Sort(PanelChildrenSorter);
97 for (
int i = 0; i < shouldAnchor.Length; i++)
98 shouldAnchor[i] =
true;
101 Children.CollectionChanged += LogicalChildrenChanged;
111 var modifiedElement = (
UIElement)trackingCollectionChangedEventArgs.
Item;
112 var elementIndex = trackingCollectionChangedEventArgs.
Index;
115 case NotifyCollectionChangedAction.Add:
116 OnLogicalChildAdded(modifiedElement, elementIndex);
118 case NotifyCollectionChangedAction.Remove:
119 OnLogicalChildRemoved(modifiedElement, elementIndex);
122 throw new NotImplementedException();
134 if (oldElement.
Parent == null)
136 SetParent(oldElement, null);
137 SetVisualParent(oldElement, null);
147 if (newElement == null)
148 throw new InvalidOperationException(
"Cannot add a null UIElement to the children list.");
149 SetParent(newElement,
this);
150 SetVisualParent(newElement,
this);
151 VisualChildrenCollection.Sort(PanelChildrenSorter);
152 if(Children.Count > childrenArrangeWorldMatrix.Length)
153 childrenArrangeWorldMatrix =
new Matrix[2*Children.Count];
158 var shouldUpdateAllChridrenMatrix = parentWorldChanged || ArrangeChanged || LocalMatrixChanged;
160 base.UpdateWorldMatrix(ref parentWorldMatrix, parentWorldChanged);
163 foreach (var child
in VisualChildrenCollection)
165 var shouldUpdateChildWorldMatrix = shouldUpdateAllChridrenMatrix || childrenWithArrangeMatrixInvalidated.Contains(child);
167 var childMatrix = child.DependencyProperties.Get(PanelArrangeMatrixPropertyKey);
168 Matrix.Multiply(ref childMatrix, ref WorldMatrixInternal, out childrenArrangeWorldMatrix[childIndex]);
171 ((
IUIElementUpdate)child).UpdateWorldMatrix(ref childrenArrangeWorldMatrix[childIndex], shouldUpdateChildWorldMatrix);
175 childrenWithArrangeMatrixInvalidated.Clear();
185 shouldAnchor[(int)direction] = enable;
190 return shouldAnchor[(int)direction];
195 var maxPosition = RenderSize[(int)direction];
196 var validPosition = Math.Max(0, Math.Min(position, maxPosition));
198 return new Vector2(-validPosition, maxPosition - validPosition);
Provides a base class for all the User Interface elements in Paradox applications.
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
A comparer sorting the Panel children by increasing Z-Index.
Represents a two dimensional mathematical vector.
void LogicalChildrenChanged(object sender, TrackingCollectionChangedEventArgs trackingCollectionChangedEventArgs)
Action to take when the Children collection is modified.
The exception that is thrown when an internal error happened in the UI System. That is an error that ...
Orientation
Defines the different orientations that a control or layout can have.
Interface for the update of the UIElements.
Panel()
Creates a new empty Panel.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
virtual void OnLogicalChildAdded(UIElement newElement, int index)
Action to perform when a logical child is added.
virtual Vector2 GetSurroudingAnchorDistances(Orientation direction, float position)
Get the distances to the previous and next anchors in the provided direction and from given position...
void ActivateAnchoring(Orientation direction, bool enable)
Change the anchoring activation state of the given direction.
UIElement Parent
Gets the logical parent of this element. This is a dependency property.
object Item
Gets the added or removed item (if dictionary, value only).
override int Compare(UIElement x, UIElement y)
NotifyCollectionChangedAction Action
Gets the type of action performed. Allowed values are NotifyCollectionChangedAction.Add and NotifyCollectionChangedAction.Remove.
virtual bool ShouldAnchor(Orientation direction)
Indicate whether the ScrollViewer managing this element should snap scrolling to anchors in the provi...
A collection of UIElements.
int Index
Gets the index in the collection (if applicable).
virtual void OnLogicalChildRemoved(UIElement oldElement, int index)
Action to perform when a logical child is removed.
A class that represents a tag propety.
object Get(PropertyKey propertyKey)
Gets the specified tag value.
PropertyContainer DependencyProperties
List of the dependency properties attached to the object.
override void UpdateWorldMatrix(ref Matrix parentWorldMatrix, bool parentWorldChanged)
Method called by IUIElementUpdate.UpdateWorldMatrix. Parents are in charge of recursively calling thi...
Provides a base class for all Panel elements. Use Panel elements to position and arrange child object...
Represents a 4x4 mathematical matrix.