5 using System.Collections.Generic;
6 using System.Diagnostics;
8 using System.Reflection;
10 using SiliconStudio.Core;
11 using SiliconStudio.Core.Mathematics;
12 using SiliconStudio.Paradox.Games;
13 using SiliconStudio.Paradox.UI.Events;
15 namespace SiliconStudio.
Paradox.UI
20 [DebuggerDisplay(
"UIElement: {Name}")]
23 #region Dependency Properties
54 private static void DefaultSizeInvalidation(
object propertyOwner,
PropertyKey<float> propertyKey,
float propertyOldValue)
57 element.InvalidateMeasure();
66 RoutingStrategy.Tunnel,
71 RoutingStrategy.Tunnel,
76 RoutingStrategy.Tunnel,
81 RoutingStrategy.Bubble,
86 RoutingStrategy.Direct,
91 RoutingStrategy.Direct,
96 RoutingStrategy.Bubble,
101 RoutingStrategy.Bubble,
106 RoutingStrategy.Bubble,
111 RoutingStrategy.Bubble,
116 RoutingStrategy.Bubble,
121 private static uint uiElementCount;
122 private Visibility visibility = Visibility.Visible;
123 private float opacity = 1.0f;
124 private bool isEnabled =
true;
125 private bool isHierarchyEnabled =
true;
126 private float width = float.NaN;
127 private float height = float.NaN;
128 private float depth = float.NaN;
132 private float maximumWidth = float.PositiveInfinity;
133 private float maximumHeight = float.PositiveInfinity;
134 private float maximumDepth = float.PositiveInfinity;
135 private float minimumWidth;
136 private float minimumHeight;
137 private float minimumDepth;
138 private Matrix localMatrix = Matrix.Identity;
144 internal bool HierarchyDisablePicking;
145 internal Vector3 RenderSizeInternal;
146 internal Matrix WorldMatrixInternal;
147 internal protected Thickness MarginInternal = Thickness.UniformCuboid(0f);
152 private Vector3 previousProvidedMeasureSize =
new Vector3(-1,-1,-1);
153 private Vector3 previousProvidedArrangeSize =
new Vector3(-1,-1,-1);
154 private bool previousIsParentCollapsed;
156 private static Queue<List<RoutedEventHandlerInfo>> routedEventHandlerInfoListPool =
new Queue<List<RoutedEventHandlerInfo>>();
161 EventManager.RegisterClassHandler(typeof(
UIElement), previewTouchDownEvent, PreviewTouchDownClassHandler);
162 EventManager.RegisterClassHandler(typeof(
UIElement), previewTouchMoveEvent, PreviewTouchMoveClassHandler);
163 EventManager.RegisterClassHandler(typeof(
UIElement), previewTouchUpEvent, PreviewTouchUpClassHandler);
164 EventManager.RegisterClassHandler(typeof(
UIElement), touchDownEvent, TouchDownClassHandler);
165 EventManager.RegisterClassHandler(typeof(
UIElement), touchEnterEvent, TouchEnterClassHandler);
166 EventManager.RegisterClassHandler(typeof(
UIElement), touchLeaveEvent, TouchLeaveClassHandler);
167 EventManager.RegisterClassHandler(typeof(
UIElement), touchMoveEvent, TouchMoveClassHandler);
168 EventManager.RegisterClassHandler(typeof(
UIElement), touchUpEvent, TouchUpClassHandler);
169 EventManager.RegisterClassHandler(typeof(
UIElement), keyPressedEvent, KeyPressedClassHandler);
170 EventManager.RegisterClassHandler(typeof(
UIElement), keyDownEvent, KeyDownClassHandler);
171 EventManager.RegisterClassHandler(typeof(
UIElement), keyReleasedEvent, KeyReleasedClassHandler);
179 ID = ++uiElementCount;
188 internal static UIElement FocusedElement {
get; set; }
193 public uint ID {
get;
private set; }
204 public Vector3 DesiredSize {
get;
private set; }
210 public Vector3 DesiredSizeWithMargins {
get;
private set; }
215 public bool IsArrangeValid {
get;
private set; }
220 public bool IsMeasureValid {
get;
private set; }
225 public bool IsTouched {
get;
internal set; }
233 get {
return WorldMatrixInternal; }
234 private set { WorldMatrixInternal = value; }
240 internal int DepthBias {
get;
private set; }
245 internal int MaxChildrenDepthBias {
get;
private set; }
252 public int DrawLayerNumber {
get; set; }
259 internal bool ForceNextMeasure =
true;
260 internal bool ForceNextArrange =
true;
265 internal protected Vector2 RealSizeVirtualResolutionRatio
267 get {
return UISystem.BackBufferVirtualResolutionRatio; }
279 protected internal void InvalidateArrange()
283 PropagateArrangeInvalidationToChildren();
286 private void PropagateArrangeInvalidationToChildren()
288 foreach (var child
in VisualChildrenCollection)
290 if (child.IsArrangeValid)
292 child.IsArrangeValid =
false;
293 child.PropagateArrangeInvalidationToChildren();
298 private void ForceArrange()
303 IsArrangeValid =
false;
304 ForceNextArrange =
true;
306 if(VisualParent != null)
307 VisualParent.ForceArrange();
313 protected internal void InvalidateMeasure()
317 PropagateMeasureInvalidationToChildren();
320 private void PropagateMeasureInvalidationToChildren()
322 foreach (var child
in VisualChildrenCollection)
324 if (child.IsMeasureValid)
326 child.IsMeasureValid =
false;
327 child.IsArrangeValid =
false;
328 child.PropagateMeasureInvalidationToChildren();
333 private void ForceMeasure()
335 if (ForceNextMeasure && ForceNextArrange)
338 ForceNextMeasure =
true;
339 ForceNextArrange =
true;
341 IsMeasureValid =
false;
342 IsArrangeValid =
false;
344 if (VisualParent != null)
345 VisualParent.ForceMeasure();
348 private static void NameInvalidationCallback(
object propertyOwner,
PropertyKey<string> propertyKey,
string propertyOldValue)
350 var element = (UIElement)propertyOwner;
351 element.OnNameChanged();
366 public bool CanBeHitByUser {
get; set; }
371 public bool PreventChildrenFromBeingHit {
get; set; }
376 public virtual bool IsEnabled
378 get {
return isEnabled; }
390 public bool IsHierarchyEnabled
392 get {
return isHierarchyEnabled; }
398 public bool IsVisible
400 get {
return Visibility == Visibility.Visible; }
406 public bool IsCollapsed
408 get {
return Visibility == Visibility.Collapsed; }
417 get {
return opacity; }
418 set { opacity = Math.Max(0, Math.Min(1, value)); }
426 get {
return visibility; }
429 if(value == visibility)
444 get {
return mouseOverState; }
447 var oldValue = mouseOverState;
448 if(oldValue == value)
451 mouseOverState = value;
453 var handler = MouseOverStateChanged;
455 handler(
this,
new PropertyChangedArgs<MouseOverState> { NewValue = value, OldValue = oldValue });
463 public float DefaultHeight
465 get {
return DependencyProperties.Get(DefaultHeightPropertyKey); }
466 set { DependencyProperties.Set(DefaultHeightPropertyKey, value); }
473 public float DefaultWidth
475 get {
return DependencyProperties.Get(DefaultWidthPropertyKey); }
476 set { DependencyProperties.Set(DefaultWidthPropertyKey, value); }
483 public float DefaultDepth
485 get {
return DependencyProperties.Get(DefaultDepthPropertyKey); }
486 set { DependencyProperties.Set(DefaultDepthPropertyKey, value); }
489 private static void DefaultSizeValidator(ref
float size)
491 if (size < 0 ||
float.IsInfinity(size) ||
float.IsNaN(size))
492 throw new ArgumentOutOfRangeException(
"size");
501 get {
return height; }
504 if (value < 0 ||
float.IsInfinity(value))
505 throw new ArgumentOutOfRangeException(
"value");
518 get {
return width; }
521 if (value < 0 ||
float.IsInfinity(value))
522 throw new ArgumentOutOfRangeException(
"value");
535 get {
return depth; }
538 if (value < 0 ||
float.IsInfinity(value))
539 throw new ArgumentOutOfRangeException(
"value");
551 get {
return new Vector3(Width, Height, Depth); }
566 internal void SetSize(
int dimensionIndex,
float value)
568 if (dimensionIndex == 0)
570 else if (dimensionIndex == 1)
582 public float MinimumWidth
584 get {
return minimumWidth; }
587 if (value < 0 ||
float.IsNaN(value) ||
float.IsInfinity(value))
588 throw new ArgumentOutOfRangeException(
"value");
589 minimumWidth = value;
598 public float MinimumHeight
600 get {
return minimumHeight; }
603 if (value < 0 ||
float.IsNaN(value) ||
float.IsInfinity(value))
604 throw new ArgumentOutOfRangeException(
"value");
605 minimumHeight = value;
614 public float MinimumDepth
616 get {
return minimumDepth; }
619 if (value < 0 ||
float.IsNaN(value) ||
float.IsInfinity(value))
620 throw new ArgumentOutOfRangeException(
"value");
621 minimumDepth = value;
631 public bool ClipToBounds {
get; set; }
637 public float MaximumWidth
639 get {
return maximumWidth; }
642 if (value < 0 ||
float.IsNaN(value))
643 throw new ArgumentOutOfRangeException(
"value");
644 maximumWidth = value;
653 public float MaximumHeight
655 get {
return maximumHeight; }
658 if (value < 0 ||
float.IsNaN(value))
659 throw new ArgumentOutOfRangeException(
"value");
660 maximumHeight = value;
669 public float MaximumDepth
671 get {
return maximumDepth; }
674 if (value < 0 ||
float.IsNaN(value))
675 throw new ArgumentOutOfRangeException(
"value");
676 maximumDepth = value;
686 get {
return horizontalAlignment; }
689 horizontalAlignment = value;
699 get {
return verticalAlignment; }
702 verticalAlignment = value;
712 get {
return depthAlignment; }
715 depthAlignment = value;
725 get {
return DependencyProperties.Get(NamePropertyKey); }
726 set { DependencyProperties.Set(NamePropertyKey, value); }
734 get {
return DependencyProperties.Get(parentPropertyKey); }
735 protected set { DependencyProperties.Set(parentPropertyKey, value); }
743 get {
return DependencyProperties.Get(visualParentPropertyKey); }
744 protected set { DependencyProperties.Set(visualParentPropertyKey, value); }
753 get {
return VisualChildrenCollection; }
759 protected internal virtual List<UIElement> HitableChildren
761 get {
return VisualChildrenCollection.UnderlyingList; }
767 public Thickness Margin
769 get {
return MarginInternal; }
772 MarginInternal = value;
783 get {
return localMatrix; }
787 LocalMatrixChanged =
true;
794 public float RenderOpacity {
get;
private set; }
801 get {
return RenderSizeInternal; }
802 private set { RenderSizeInternal = value; }
808 public Vector3 RenderOffsets {
get;
private set; }
813 public float ActualWidth
815 get {
return RenderSize.X; }
821 public float ActualHeight
823 get {
return RenderSize.Y; }
828 public float ActualDepth
830 get {
return RenderSize.Z; }
836 public Color BackgroundColor
838 get {
return DependencyProperties.Get(backgroundColorPropertyKey); }
839 set { DependencyProperties.Set(backgroundColorPropertyKey, value); }
842 private unsafe
bool Vector3BinaryEqual(ref
Vector3 left, ref
Vector3 right)
844 fixed (
Vector3* pVector3Left = &left)
845 fixed (
Vector3* pVector3Right = &right)
847 var pLeft = (
int*)pVector3Left;
848 var pRight = (
int*)pVector3Right;
850 return pLeft[0] == pRight[0] && pLeft[1] == pRight[1] && pLeft[2] == pRight[2];
863 if (!ForceNextMeasure && Vector3BinaryEqual(ref availableSizeWithMargins, ref previousProvidedMeasureSize))
865 IsMeasureValid =
true;
866 ValidateChildrenMeasure();
870 ForceNextMeasure =
false;
871 IsMeasureValid =
true;
872 IsArrangeValid =
false;
873 previousProvidedMeasureSize = availableSizeWithMargins;
878 DesiredSize = DesiredSizeWithMargins = Vector3.Zero;
883 var desiredSize =
new Vector3(Width, Height, Depth);
886 if (
float.IsNaN(desiredSize.X) ||
float.IsNaN(desiredSize.Y) || float.IsNaN(desiredSize.Z))
892 var availableSizeWithoutMargins = CalculateSizeWithoutThickness(ref availableSizeWithMargins, ref MarginInternal);
895 availableSizeWithoutMargins =
new Vector3(
896 Math.Max(MinimumWidth, Math.Min(MaximumWidth, !
float.IsNaN(desiredSize.X)? desiredSize.X: availableSizeWithoutMargins.X)),
897 Math.Max(MinimumHeight, Math.Min(MaximumHeight, !float.IsNaN(desiredSize.Y) ? desiredSize.Y : availableSizeWithoutMargins.Y)),
898 Math.Max(MinimumDepth, Math.Min(MaximumDepth, !
float.IsNaN(desiredSize.Z) ? desiredSize.Z : availableSizeWithoutMargins.Z)));
901 var childrenDesiredSize = MeasureOverride(availableSizeWithoutMargins);
904 if (
float.IsNaN(desiredSize.X))
905 desiredSize.X = childrenDesiredSize.X;
906 if (
float.IsNaN(desiredSize.Y))
907 desiredSize.Y = childrenDesiredSize.Y;
908 if (
float.IsNaN(desiredSize.Z))
909 desiredSize.Z = childrenDesiredSize.Z;
912 if (
float.IsNaN(desiredSize.X))
913 desiredSize.X = DefaultWidth;
914 if (
float.IsNaN(desiredSize.Y))
915 desiredSize.Y = DefaultHeight;
916 if (
float.IsNaN(desiredSize.Z))
917 desiredSize.Z = DefaultDepth;
922 Math.Max(MinimumWidth, Math.Min(MaximumWidth, desiredSize.X)),
923 Math.Max(MinimumHeight, Math.Min(MaximumHeight, desiredSize.Y)),
924 Math.Max(MinimumDepth, Math.Min(MaximumDepth, desiredSize.Z)));
927 var desiredSizeWithMargins = CalculateSizeWithThickness(ref desiredSize, ref MarginInternal);
930 DesiredSize = desiredSize;
931 DesiredSizeWithMargins = desiredSizeWithMargins;
934 private void ValidateChildrenMeasure()
936 foreach (var child
in VisualChildrenCollection)
938 if (!child.IsMeasureValid)
940 child.IsMeasureValid =
true;
941 child.ValidateChildrenMeasure();
965 if (!ForceNextArrange && Vector3BinaryEqual(ref finalSizeWithMargins, ref previousProvidedArrangeSize) && isParentCollapsed == previousIsParentCollapsed)
967 IsArrangeValid =
true;
968 ValidateChildrenArrange();
972 ForceNextArrange =
false;
973 IsArrangeValid =
true;
974 ArrangeChanged =
true;
975 previousIsParentCollapsed = isParentCollapsed;
976 previousProvidedArrangeSize = finalSizeWithMargins;
979 if (IsCollapsed || isParentCollapsed)
986 var elementSize =
new Vector3(Width, Height, Depth);
989 var finalSizeWithoutMargins = CalculateSizeWithoutThickness(ref finalSizeWithMargins, ref MarginInternal);
991 elementSize.X = finalSizeWithoutMargins.X;
993 elementSize.Y = finalSizeWithoutMargins.Y;
995 elementSize.Z = finalSizeWithoutMargins.Z;
998 if (
float.IsNaN(elementSize.X))
999 elementSize.X = Math.Min(DesiredSize.X, finalSizeWithoutMargins.X);
1000 if (
float.IsNaN(elementSize.Y))
1001 elementSize.Y = Math.Min(DesiredSize.Y, finalSizeWithoutMargins.Y);
1002 if (
float.IsNaN(elementSize.Z))
1003 elementSize.Z = Math.Min(DesiredSize.Z, finalSizeWithoutMargins.Z);
1007 Math.Max(MinimumWidth, Math.Min(MaximumWidth, elementSize.X)),
1008 Math.Max(MinimumHeight, Math.Min(MaximumHeight, elementSize.Y)),
1009 Math.Max(MinimumDepth, Math.Min(MaximumDepth, elementSize.Z)));
1012 elementSize = ArrangeOverride(elementSize);
1015 var renderOffsets = CalculateAdjustmentOffsets(ref MarginInternal, ref finalSizeWithMargins, ref elementSize);
1018 RenderSize = elementSize;
1019 RenderOffsets = renderOffsets;
1022 private void ValidateChildrenArrange()
1024 foreach (var child
in VisualChildrenCollection)
1026 if (!child.IsArrangeValid)
1028 child.IsArrangeValid =
true;
1029 child.ValidateChildrenArrange();
1041 return finalSizeWithoutMargins;
1049 DesiredSize = Vector3.Zero;
1050 DesiredSizeWithMargins = Vector3.Zero;
1051 RenderSize = Vector3.Zero;
1052 RenderOffsets = Vector3.Zero;
1054 foreach (var child
in VisualChildrenCollection)
1055 PropagateCollapseToChild(child);
1066 throw new InvalidOperationException(
"Element is not a child of this element.");
1068 element.InvalidateMeasure();
1069 element.CollapseOverride();
1083 return VisualChildren.Select(child => child.FindName(name)).FirstOrDefault(elt => elt != null);
1093 throw new NotImplementedException();
1103 if (parent != null && child.
Parent != null && parent != child.
Parent)
1104 throw new InvalidOperationException(
"The UI element 'Name="+child.
Name+
"' has already as parent the element 'Name="+child.
Parent.
Name+
"'.");
1106 child.Parent = parent;
1116 if (child == null)
throw new ArgumentNullException(
"child");
1118 throw new InvalidOperationException(
"The UI element 'Name=" + child.
Name +
"' has already as visual parent the element 'Name=" + child.
VisualParent.
Name +
"'.");
1121 child.VisualParent.VisualChildrenCollection.Remove(child);
1123 child.VisualParent = parent;
1127 parent.VisualChildrenCollection.Add(child);
1141 var intersects = Collision.RayIntersectsRectangle(ref ray, ref WorldMatrixInternal, ref RenderSizeInternal, 2, out intersectionPoint);
1150 if (intersection.Z > intersectionPoint.Z)
1151 intersectionPoint = intersection;
1156 if (intersection.Z > intersectionPoint.Z)
1157 intersectionPoint = intersection;
1164 #region Implementation of the IUIElementUpdate interface
1166 void IUIElementUpdate.Update(
GameTime time)
1173 foreach (var child
in VisualChildrenCollection)
1177 void IUIElementUpdate.UpdateWorldMatrix(ref
Matrix parentWorldMatrix,
bool parentWorldChanged)
1179 UpdateWorldMatrix(ref parentWorldMatrix, parentWorldChanged);
1182 void IUIElementUpdate.UpdateElementState(
int elementBias)
1184 var parent = VisualParent;
1185 var parentRenderOpacity = 1f;
1186 var parentIsHierarchyEnabled =
true;
1187 var parentHierarchyDisablePicking =
false;
1191 parentRenderOpacity = parent.RenderOpacity;
1192 parentIsHierarchyEnabled = parent.IsHierarchyEnabled;
1193 parentHierarchyDisablePicking = parent.HierarchyDisablePicking;
1196 RenderOpacity = parentRenderOpacity * Opacity;
1197 isHierarchyEnabled = parentIsHierarchyEnabled && isEnabled;
1198 HierarchyDisablePicking = parentHierarchyDisablePicking || PreventChildrenFromBeingHit;
1199 DepthBias = elementBias;
1201 var currentElementDepthBias = DepthBias + DrawLayerNumber;
1203 foreach (var visualChild
in VisualChildrenCollection)
1205 ((IUIElementUpdate)visualChild).UpdateElementState(currentElementDepthBias);
1207 currentElementDepthBias = visualChild.MaxChildrenDepthBias + (visualChild.ClipToBounds ? visualChild.DrawLayerNumber : 0);
1210 MaxChildrenDepthBias = currentElementDepthBias;
1213 void IUIElementUpdate.UpdateUISystemReference(UISystem system)
1215 OnUISystemChanged(system);
1216 foreach (var children
in VisualChildrenCollection)
1217 ((IUIElementUpdate)children).UpdateUISystemReference(system);
1240 if (parentWorldChanged || LocalMatrixChanged || ArrangeChanged)
1242 var localMatrixCopy = localMatrix;
1245 localMatrixCopy.TranslationVector += RenderOffsets + RenderSize / 2;
1249 Matrix.Multiply(ref localMatrixCopy, ref parentWorldMatrix, out worldMatrix);
1250 WorldMatrix = worldMatrix;
1252 LocalMatrixChanged =
false;
1253 ArrangeChanged =
false;
1275 var negativeThickness = -thickness;
1276 return CalculateSizeWithoutThickness(ref sizeWithoutMargins, ref negativeThickness);
1288 Math.Max(0, sizeWithMargins.X - thickness.Left - thickness.Right),
1289 Math.Max(0, sizeWithMargins.Y - thickness.Top - thickness.Bottom),
1290 Math.Max(0, sizeWithMargins.Z - thickness.Front - thickness.Back));
1303 var usedSpaceWithThickness = CalculateSizeWithThickness(ref usedSpaceWithoutThickness, ref thickness);
1306 var offsets =
new Vector3(thickness.Left, thickness.Top, thickness.Back);
1311 case HorizontalAlignment.Center:
1312 offsets.X += (providedSpace.X - usedSpaceWithThickness.X) / 2;
1314 case HorizontalAlignment.Right:
1315 offsets.X += providedSpace.X - usedSpaceWithThickness.X;
1322 case VerticalAlignment.Center:
1323 offsets.Y += (providedSpace.Y - usedSpaceWithThickness.Y) / 2;
1325 case VerticalAlignment.Bottom:
1326 offsets.Y += providedSpace.Y - usedSpaceWithThickness.Y;
1333 case DepthAlignment.Center:
1334 offsets.Z += (providedSpace.Z - usedSpaceWithThickness.Z) / 2;
1336 case DepthAlignment.Front:
1337 offsets.Z += providedSpace.Z - usedSpaceWithThickness.Z;
1346 var routedEvent = e.RoutedEvent;
1349 if (routedEvent.RoutingStrategy ==
RoutingStrategy.Tunnel && VisualParent != null)
1350 VisualParent.PropagateRoutedEvent(e);
1353 var classHandler = EventManager.GetClassHandler(GetType(), routedEvent);
1354 if (classHandler != null && (classHandler.HandledEventToo || !e.
Handled))
1355 classHandler.Invoke(
this, e);
1358 if (eventsToHandlers.ContainsKey(routedEvent))
1361 if (routedEventHandlerInfoListPool.Count == 0)
1362 routedEventHandlerInfoListPool.Enqueue(
new List<RoutedEventHandlerInfo>());
1363 var pooledList = routedEventHandlerInfoListPool.Dequeue();
1366 pooledList.AddRange(eventsToHandlers[routedEvent]);
1369 foreach (var handlerInfo
in pooledList)
1371 if (handlerInfo.HandledEventToo || !e.
Handled)
1372 handlerInfo.Invoke(
this, e);
1377 routedEventHandlerInfoListPool.Enqueue(pooledList);
1381 if (routedEvent.RoutingStrategy ==
RoutingStrategy.Bubble && VisualParent != null)
1382 VisualParent.PropagateRoutedEvent(e);
1395 throw new ArgumentNullException(
"e");
1400 if(!e.
RoutedEvent.HandlerSecondArgumentType.GetTypeInfo().IsAssignableFrom(e.GetType().GetTypeInfo()))
1401 throw new InvalidOperationException(
"The type of second parameter of the handler (" + e.
RoutedEvent.HandlerSecondArgumentType
1402 +
") is not assignable from the parameter 'e' type (" + e.GetType() +
").");
1404 var sourceWasNull = e.Source == null;
1408 e.StartEventRouting();
1410 PropagateRoutedEvent(e);
1412 e.EndEventRouting();
1429 if (routedEvent == null)
throw new ArgumentNullException(
"routedEvent");
1430 if (handler == null)
throw new ArgumentNullException(
"handler");
1432 if(!eventsToHandlers.ContainsKey(routedEvent))
1433 eventsToHandlers[routedEvent] =
new List<RoutedEventHandlerInfo>();
1435 eventsToHandlers[routedEvent].Add(
new RoutedEventHandlerInfo<T>(handler, handledEventsToo));
1446 if (routedEvent == null)
throw new ArgumentNullException(
"routedEvent");
1447 if (handler == null)
throw new ArgumentNullException(
"handler");
1449 if(!eventsToHandlers.ContainsKey(routedEvent))
1452 eventsToHandlers[routedEvent].Remove(
new RoutedEventHandlerInfo<T>(handler));
1455 private readonly Dictionary<RoutedEvent, List<RoutedEventHandlerInfo>> eventsToHandlers =
new Dictionary<RoutedEvent, List<RoutedEventHandlerInfo>>();
1469 public event EventHandler<TouchEventArgs> PreviewTouchDown
1471 add { AddHandler(previewTouchDownEvent, value); }
1472 remove { RemoveHandler(previewTouchDownEvent, value); }
1480 public event EventHandler<TouchEventArgs> PreviewTouchMove
1482 add { AddHandler(previewTouchMoveEvent, value); }
1483 remove { RemoveHandler(previewTouchMoveEvent, value); }
1490 public event EventHandler<TouchEventArgs> PreviewTouchUp
1492 add { AddHandler(previewTouchUpEvent, value); }
1493 remove { RemoveHandler(previewTouchUpEvent, value); }
1500 public event EventHandler<TouchEventArgs> TouchDown
1502 add { AddHandler(touchDownEvent, value); }
1503 remove { RemoveHandler(touchDownEvent, value); }
1511 public event EventHandler<TouchEventArgs> TouchEnter
1513 add { AddHandler(touchEnterEvent, value); }
1514 remove { RemoveHandler(touchEnterEvent, value); }
1522 public event EventHandler<TouchEventArgs> TouchLeave
1524 add { AddHandler(touchLeaveEvent, value); }
1525 remove { RemoveHandler(touchLeaveEvent, value); }
1533 public event EventHandler<TouchEventArgs> TouchMove
1535 add { AddHandler(touchMoveEvent, value); }
1536 remove { RemoveHandler(touchMoveEvent, value); }
1543 public event EventHandler<TouchEventArgs> TouchUp
1545 add { AddHandler(touchUpEvent, value); }
1546 remove { RemoveHandler(touchUpEvent, value); }
1553 internal event EventHandler<KeyEventArgs> KeyPressed
1555 add { AddHandler(keyPressedEvent, value); }
1556 remove { RemoveHandler(keyPressedEvent, value); }
1563 internal event EventHandler<KeyEventArgs> KeyDown
1565 add { AddHandler(keyDownEvent, value); }
1566 remove { RemoveHandler(keyDownEvent, value); }
1573 internal event EventHandler<KeyEventArgs> KeyReleased
1575 add { AddHandler(keyReleasedEvent, value); }
1576 remove { RemoveHandler(keyReleasedEvent, value); }
1581 #region Internal Event Raiser
1583 internal void RaiseTouchDownEvent(TouchEventArgs touchArgs)
1585 touchArgs.RoutedEvent = previewTouchDownEvent;
1586 RaiseEvent(touchArgs);
1588 touchArgs.RoutedEvent = touchDownEvent;
1589 RaiseEvent(touchArgs);
1592 internal void RaiseTouchEnterEvent(TouchEventArgs touchArgs)
1594 touchArgs.RoutedEvent = touchEnterEvent;
1595 RaiseEvent(touchArgs);
1598 internal void RaiseTouchLeaveEvent(TouchEventArgs touchArgs)
1600 touchArgs.RoutedEvent = touchLeaveEvent;
1601 RaiseEvent(touchArgs);
1604 internal void RaiseTouchMoveEvent(TouchEventArgs touchArgs)
1606 touchArgs.RoutedEvent = previewTouchMoveEvent;
1607 RaiseEvent(touchArgs);
1609 touchArgs.RoutedEvent = touchMoveEvent;
1610 RaiseEvent(touchArgs);
1613 internal void RaiseTouchUpEvent(TouchEventArgs touchArgs)
1615 touchArgs.RoutedEvent = previewTouchUpEvent;
1616 RaiseEvent(touchArgs);
1618 touchArgs.RoutedEvent = touchUpEvent;
1619 RaiseEvent(touchArgs);
1622 internal void RaiseKeyPressedEvent(KeyEventArgs keyEventArgs)
1624 keyEventArgs.RoutedEvent = keyPressedEvent;
1625 RaiseEvent(keyEventArgs);
1628 internal void RaiseKeyDownEvent(KeyEventArgs keyEventArgs)
1630 keyEventArgs.RoutedEvent = keyDownEvent;
1631 RaiseEvent(keyEventArgs);
1634 internal void RaiseKeyReleasedEvent(KeyEventArgs keyEventArgs)
1636 keyEventArgs.RoutedEvent = keyReleasedEvent;
1637 RaiseEvent(keyEventArgs);
1642 #region Class Event Handlers
1644 private static void PreviewTouchDownClassHandler(
object sender, TouchEventArgs args)
1646 var uiElementSender = (UIElement)sender;
1647 if(uiElementSender.IsHierarchyEnabled)
1648 uiElementSender.OnPreviewTouchDown(args);
1661 private static void PreviewTouchMoveClassHandler(
object sender,
TouchEventArgs args)
1663 var uiElementSender = (
UIElement)sender;
1664 if (uiElementSender.IsHierarchyEnabled)
1665 uiElementSender.OnPreviewTouchMove(args);
1677 private static void PreviewTouchUpClassHandler(
object sender,
TouchEventArgs args)
1679 var uiElementSender = (
UIElement)sender;
1680 if (uiElementSender.IsHierarchyEnabled)
1681 uiElementSender.OnPreviewTouchUp(args);
1694 private static void TouchDownClassHandler(
object sender,
TouchEventArgs args)
1696 var uiElementSender = (
UIElement)sender;
1697 if (uiElementSender.IsHierarchyEnabled)
1698 uiElementSender.OnTouchDown(args);
1710 private static void TouchEnterClassHandler(
object sender,
TouchEventArgs args)
1712 var uiElementSender = (
UIElement)sender;
1713 if (uiElementSender.IsHierarchyEnabled)
1714 uiElementSender.OnTouchEnter(args);
1727 private static void TouchLeaveClassHandler(
object sender,
TouchEventArgs args)
1729 var uiElementSender = (
UIElement)sender;
1730 if (uiElementSender.IsHierarchyEnabled)
1731 uiElementSender.OnTouchLeave(args);
1744 private static void TouchMoveClassHandler(
object sender,
TouchEventArgs args)
1746 var uiElementSender = (
UIElement)sender;
1747 if (uiElementSender.IsHierarchyEnabled)
1748 uiElementSender.OnTouchMove(args);
1760 private static void TouchUpClassHandler(
object sender,
TouchEventArgs args)
1762 var uiElementSender = (
UIElement)sender;
1763 if (uiElementSender.IsHierarchyEnabled)
1764 uiElementSender.OnTouchUp(args);
1776 private static void KeyPressedClassHandler(
object sender, KeyEventArgs args)
1778 var uiElementSender = (
UIElement)sender;
1779 if (uiElementSender.IsHierarchyEnabled)
1780 uiElementSender.OnKeyPressed(args);
1788 internal virtual void OnKeyPressed(KeyEventArgs args)
1792 private static void KeyDownClassHandler(
object sender, KeyEventArgs args)
1794 var uiElementSender = (UIElement)sender;
1795 if (uiElementSender.IsHierarchyEnabled)
1796 uiElementSender.OnKeyDown(args);
1804 internal virtual void OnKeyDown(KeyEventArgs args)
1808 private static void KeyReleasedClassHandler(
object sender, KeyEventArgs args)
1810 var uiElementSender = (UIElement)sender;
1811 if (uiElementSender.IsHierarchyEnabled)
1812 uiElementSender.OnKeyReleased(args);
1820 internal virtual void OnKeyReleased(KeyEventArgs args)
MouseOverState
Describe the possible states of the mouse over an UI element.
Provides a base class for all the User Interface elements in Paradox applications.
static Vector3 CalculateSizeWithoutThickness(ref Vector3 sizeWithMargins, ref Thickness thickness)
Remove the thickness values into the size calculation of a UI element.
virtual void Update(GameTime time)
Method called by IUIElementUpdate.Update. This method can be overridden by inherited classes to perfo...
Represents a two dimensional mathematical vector.
static void SetVisualParent(UIElement child, UIElement parent)
Set the visual parent to a child.
bool Handled
Gets or sets a value that indicates the present state of the event handling for a routed event as it ...
void Arrange(Vector3 finalSizeWithMargins, bool isParentCollapsed)
Positions child elements and determines the size of the UIElement. This method constitutes the second...
static Vector3 CalculateSizeWithThickness(ref Vector3 sizeWithoutMargins, ref Thickness thickness)
Add the thickness values into the size calculation of a UI element.
VerticalAlignment
Describes how a child element is vertically positioned or stretched within a parent's layout slot...
Interface for the update of the UIElements.
virtual Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
When overridden in a derived class, positions possible child elements and determines a size for a UIE...
virtual void OnPreviewTouchUp(TouchEventArgs args)
The class handler of the event PreviewTouchUp. This method can be overridden in inherited classes to ...
virtual bool Intersects(ref Ray ray, out Vector3 intersectionPoint)
Calculate the intersection of the UI element and the ray.
UIElement VisualParent
Gets the visual parent of this element. This is a dependency property.
virtual void OnPreviewTouchMove(TouchEventArgs args)
The class handler of the event PreviewTouchMove. This method can be overridden in inherited classes t...
virtual void OnPreviewTouchDown(TouchEventArgs args)
The class handler of the event PreviewTouchDown. This method can be overridden in inherited classes t...
UIElement()
Create an instance of a UIElement
Represents a container that can hold properties, lightweight to embed (lazy initialized).
Contains state information and event data associated with a routed event.
const float ZeroTolerance
The value for which all absolute numbers smaller than are considered equal to zero.
Represents a three dimensional mathematical vector.
virtual Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
When overridden in a derived class, measures the size in layout required for possible child elements ...
Visibility
Specifies the display state of an element.
static bool RayIntersectsRectangle(ref Ray ray, ref Matrix rectangleWorldMatrix, ref Vector3 rectangleSize, int normalAxis, out Vector3 intersectionPoint)
Determines whether there is an intersection between a Ray and a rectangle (2D).
void RegisterName(string name, UIElement scopedElement)
Provides an accessor that simplifies access to the NameScope registration method. ...
PropertyChangedHandler< MouseOverState > MouseOverStateChanged
Occurs when the value of the MouseOverState property changed.
DepthAlignment
Describes how a child element is positioned in depth or stretched within a parent's layout slot...
Describes the thickness of a frame around a cuboid. Six float values describe the Left...
virtual void OnUISystemChanged(UISystem system)
Function called when the UISystem in charge of the UIElement changed. This function can be override i...
static void SetParent(UIElement child, UIElement parent)
Set the parent to a child.
HorizontalAlignment
Indicates where an element should be displayed on the horizontal axis relative to the allocated layou...
virtual void OnTouchDown(TouchEventArgs args)
The class handler of the event TouchDown. This method can be overridden in inherited classes to perfo...
RoutedEvent RoutedEvent
Gets or sets the RoutedEvent associated with this RoutedEventArgs instance.
string Name
Gets or sets the name of this element. This is a dependency property.
Contains static methods to help in determining intersections, containment, etc.
Base class for UI element renderers
virtual void OnNameChanged()
This method is call when the name of the UIElement changes. This method can be overridden in inherite...
UIElement Parent
Gets the logical parent of this element. This is a dependency property.
Current timing used for variable-step (real time) or fixed-step (game time) games.
SiliconStudio.Core.Mathematics.Color Color
virtual void UpdateWorldMatrix(ref Matrix parentWorldMatrix, bool parentWorldChanged)
Method called by IUIElementUpdate.UpdateWorldMatrix. Parents are in charge of recursively calling thi...
void PropagateCollapseToChild(UIElement element)
Propagate the collapsing to a child element element .
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Represents a three dimensional line based on a point in space and a direction.
virtual void OnTouchUp(TouchEventArgs args)
The class handler of the event TouchUp. This method can be overridden in inherited classes to perform...
virtual void OnTouchEnter(TouchEventArgs args)
The class handler of the event TouchEnter. This method can be overridden in inherited classes to perf...
Provides data for touch input events.
UIElement FindName(string name)
Finds an element that has the provided identifier name in the element children.
Interface of the UI system.
virtual void OnTouchLeave(TouchEventArgs args)
The class handler of the event TouchLeave. This method can be overridden in inherited classes to perf...
A collection of UIElements.
Represents and identifies a routed event and declares its characteristics.
void Measure(Vector3 availableSizeWithMargins)
Updates the DesiredSize of a UIElement. Parent elements call this method from their own implementatio...
SiliconStudio.Core.Mathematics.Vector3 Vector3
_In_ size_t _In_ size_t size
A class that represents a tag propety.
A routed event typed with the RoutedEventArgs it triggers.
Vector3 CalculateAdjustmentOffsets(ref Thickness thickness, ref Vector3 providedSpace, ref Vector3 usedSpaceWithoutThickness)
Computes the (X,Y,Z) offsets to position correctly the UI element given the total provided space to i...
virtual void OnTouchMove(TouchEventArgs args)
The class handler of the event TouchMove. This method can be overridden in inherited classes to perfo...
RoutingStrategy
Indicates the routing strategy of a routed event.
PropertyContainer DependencyProperties
List of the dependency properties attached to the object.
virtual void CollapseOverride()
When overridden in a derived class, collapse possible child elements and derived class.
void RaiseEvent(RoutedEventArgs e)
Raises a specific routed event. The RoutedEvent to be raised is identified within the RoutedEventArgs...
Represents a 4x4 mathematical matrix.