Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PointerEvent.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.Collections.Generic;
5 using SiliconStudio.Core.Mathematics;
6 
7 namespace SiliconStudio.Paradox.Input
8 {
9  /// <summary>
10  /// A pointer event.
11  /// </summary>
12  public class PointerEvent : EventArgs
13  {
14  internal readonly static Queue<PointerEvent> Pool = new Queue<PointerEvent>();
15 
16  internal static PointerEvent GetOrCreatePointerEvent()
17  {
18  lock (Pool)
19  return Pool.Count > 0 ? Pool.Dequeue() : new PointerEvent();
20  }
21 
22  /// <summary>
23  /// Initializes a new instance of the <see cref="PointerEvent" /> class.
24  /// </summary>
25  internal PointerEvent()
26  {
27  }
28 
29  /// <summary>
30  /// Initializes a new instance of the <see cref="PointerEvent" /> class.
31  /// </summary>
32  /// <param name="pointerId">The pointer id.</param>
33  /// <param name="position">The position.</param>
34  /// <param name="deltaPosition">The delta position.</param>
35  /// <param name="deltaTime">The delta time.</param>
36  /// <param name="state">The state.</param>
37  /// <param name="pointerType">Type of the pointer.</param>
38  /// <param name="isPrimary">if set to <c>true</c> [is primary].</param>
39  internal PointerEvent(int pointerId, Vector2 position, Vector2 deltaPosition, TimeSpan deltaTime, PointerState state, PointerType pointerType, bool isPrimary)
40  {
41  PointerId = pointerId;
42  Position = position;
43  DeltaPosition = deltaPosition;
44  DeltaTime = deltaTime;
45  State = state;
46  PointerType = pointerType;
47  IsPrimary = isPrimary;
48  }
49 
50  /// <summary>
51  /// Gets a unique identifier of the pointer. See remarks.
52  /// </summary>
53  /// <value>The pointer id.</value>
54  /// <remarks>The default mouse pointer will always be affected to the PointerId 0. On a tablet, a pen or each fingers will get a unique identifier.</remarks>
55  public int PointerId { get; internal set; }
56 
57  /// <summary>
58  /// Gets the absolute screen position of the pointer.
59  /// </summary>
60  /// <value>The position.</value>
61  public Vector2 Position { get; internal set; }
62 
63  /// <summary>
64  /// Gets the delta position of the pointer since the previous frame.
65  /// </summary>
66  /// <value>The delta position.</value>
67  public Vector2 DeltaPosition { get; internal set; }
68 
69  /// <summary>
70  /// Gets the amount of time since the previous state.
71  /// </summary>
72  /// <value>The delta time.</value>
73  public TimeSpan DeltaTime { get; internal set; }
74 
75  /// <summary>
76  /// Gets the state of this pointer event (down, up, move... etc.)
77  /// </summary>
78  /// <value>The state.</value>
79  public PointerState State { get; internal set; }
80 
81  /// <summary>
82  /// Gets the type of the pointer.
83  /// </summary>
84  /// <value>The type of the pointer.</value>
85  public PointerType PointerType { get; internal set; }
86 
87  /// <summary>
88  /// Gets a boolean indicating whether this is the default primary pointer.
89  /// </summary>
90  /// <value><c>true</c> if this instance is primary; otherwise, <c>false</c>.</value>
91  public bool IsPrimary { get; internal set; }
92 
93  /// <summary>
94  /// Clones this instance.
95  /// </summary>
96  /// <returns>PointerEvent.</returns>
98  {
99  var clone = GetOrCreatePointerEvent();
100 
101  clone.PointerId = PointerId;
102  clone.Position = Position;
103  clone.DeltaPosition = DeltaPosition;
104  clone.DeltaTime = DeltaTime;
105  clone.State = State;
106  clone.PointerType = PointerType;
107  clone.IsPrimary = IsPrimary;
108 
109  return clone;
110  }
111 
112  public override string ToString()
113  {
114  return string.Format("PointerId: {0}, Position: {1:0.00}, DeltaPosition: {2:0.00}, DeltaTime: {3:0.000}, State: {4}, PointerType: {5}, IsPrimary: {6}", PointerId, Position, DeltaPosition, DeltaTime.TotalSeconds, State, PointerType, IsPrimary);
115  }
116  }
117 }
PointerType
Type of a pointer device.
Definition: PointerType.cs:8
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
PointerState
State of a pointer event.
Definition: PointerState.cs:8
PointerEvent Clone()
Clones this instance.
Definition: PointerEvent.cs:97