Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ModalElement.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 using System.Diagnostics;
5 
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Mathematics;
8 using SiliconStudio.Paradox.UI.Events;
9 
10 namespace SiliconStudio.Paradox.UI.Controls
11 {
12  /// <summary>
13  /// Represents a modal element that puts an overlay upon the underneath elements and freeze their input.
14  /// </summary>
15  [DebuggerDisplay("ModalElement - Name={Name}")]
16  public class ModalElement : ButtonBase
17  {
18  internal Color OverlayColorInternal;
19 
20  /// <summary>
21  /// The key to the IsModal dependency property.
22  /// </summary>
23  protected readonly static PropertyKey<bool> IsModalPropertyKey = new PropertyKey<bool>("IsModalKey", typeof(ModalElement), DefaultValueMetadata.Static(true));
24 
25  /// <summary>
26  /// Occurs when the element is modal and the user click outside of the modal element.
27  /// </summary>
28  /// <remarks>A click event is bubbling</remarks>
29  public event EventHandler<RoutedEventArgs> OutsideClick
30  {
31  add { AddHandler(OutsideClickEvent, value); }
32  remove { RemoveHandler(OutsideClickEvent, value); }
33  }
34 
35  /// <summary>
36  /// Identifies the <see cref="OutsideClick"/> routed event.
37  /// </summary>
38  public static readonly RoutedEvent<RoutedEventArgs> OutsideClickEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>(
39  "OutsideClick",
40  RoutingStrategy.Bubble,
41  typeof(ModalElement));
42 
43  public ModalElement()
44  {
45  OverlayColorInternal = new Color(0, 0, 0, 0.4f);
46  DrawLayerNumber += 1; // (overlay)
47  VerticalAlignment = VerticalAlignment.Center;
48  HorizontalAlignment = HorizontalAlignment.Center;
49  }
50 
51  /// <summary>
52  /// The color of the overlay drawn upon underneath elements.
53  /// </summary>
54  public Color OverlayColor
55  {
56  get { return OverlayColorInternal; }
57  set { OverlayColorInternal = value; }
58  }
59 
60  /// <summary>
61  /// Determine if the control should block the input of underneath elements or not.
62  /// </summary>
63  public bool IsModal
64  {
65  get { return DependencyProperties.Get(IsModalPropertyKey); }
66  set { DependencyProperties.Set(IsModalPropertyKey, value); }
67  }
68 
69  protected override void OnTouchUp(TouchEventArgs args)
70  {
71  base.OnTouchUp(args);
72 
73  if(!IsModal || args.Source != this)
74  return;
75 
76  var position = args.WorldPosition - new Vector3(WorldMatrixInternal.M41, WorldMatrixInternal.M42, WorldMatrixInternal.M43);
77  if (position.X < 0 || position.X > RenderSize.X
78  || position.Y < 0 || position.Y > RenderSize.Y)
79  {
80  var eventArgs = new RoutedEventArgs(OutsideClickEvent);
81  RaiseEvent(eventArgs);
82  }
83  }
84 
85  protected internal override bool Intersects(ref Ray ray, out Vector3 intersectionPoint)
86  {
87  if (!IsModal)
88  return base.Intersects(ref ray, out intersectionPoint);
89 
90  var virtualResolution = UISystem.VirtualResolution;
91  var worldmatrix = Matrix.Identity;
92 
93  return Collision.RayIntersectsRectangle(ref ray, ref worldmatrix, ref virtualResolution, 2, out intersectionPoint);
94  }
95  }
96 }
UIElement Source
Gets or sets a reference to the object that raised the event.
VerticalAlignment
Describes how a child element is vertically positioned or stretched within a parent's layout slot...
Contains state information and event data associated with a routed event.
Represents the base primitive for all the button-like controls
Definition: ButtonBase.cs:15
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
Represents a modal element that puts an overlay upon the underneath elements and freeze their input...
Definition: ModalElement.cs:16
HorizontalAlignment
Indicates where an element should be displayed on the horizontal axis relative to the allocated layou...
override void OnTouchUp(TouchEventArgs args)
The class handler of the event TouchUp. This method can be overridden in inherited classes to perform...
Definition: ModalElement.cs:69
The two bounding volumes overlap.
SiliconStudio.Core.Mathematics.Color Color
Definition: ColorPicker.cs:14
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
Represents a three dimensional line based on a point in space and a direction.
Definition: Ray.cs:42
Provides data for touch input events.
Represents and identifies a routed event and declares its characteristics.
Definition: RoutedEvent.cs:10
SiliconStudio.Core.Mathematics.Vector3 Vector3
A class that represents a tag propety.
Definition: PropertyKey.cs:17