Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
InputManagerBase.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 System.Collections.Specialized;
6 using System.Diagnostics;
7 using System.Linq;
8 
9 using SiliconStudio.Core;
10 using SiliconStudio.Core.Collections;
11 using SiliconStudio.Core.Diagnostics;
12 using SiliconStudio.Paradox.Games;
13 using SiliconStudio.Core.Mathematics;
14 
15 namespace SiliconStudio.Paradox.Input
16 {
17  /// <summary>
18  /// Interface for input management system, including keyboard, mouse, gamepads and touch.
19  /// </summary>
20  public abstract class InputManagerBase : GameSystemBase
21  {
22  #region Constants and Fields
23 
24  public static Logger Logger = GlobalLogger.GetLogger("Input");
25 
26  internal const float GamePadAxisDeadZone = 0.01f;
27 
28  internal readonly List<GamePadFactory> GamePadFactories = new List<GamePadFactory>();
29 
30  private const int MaximumGamePadCount = 8;
31 
32  private readonly GamePadState[] gamePadStates;
33 
34  private readonly GamePad[] gamePads;
35 
36  private int gamePadCount;
37 
38  private readonly List<Keys> downKeysList = new List<Keys>();
39 
40  private readonly HashSet<Keys> pressedKeysSet = new HashSet<Keys>();
41 
42  private readonly HashSet<Keys> releasedKeysSet = new HashSet<Keys>();
43 
44  internal List<KeyboardInputEvent> KeyboardInputEvents = new List<KeyboardInputEvent>();
45 
46  internal bool LostFocus;
47 
48  internal List<MouseInputEvent> MouseInputEvents = new List<MouseInputEvent>();
49 
50  internal Vector2 CurrentMousePosition;
51 
52  private readonly Dictionary<Keys, bool> activeKeys = new Dictionary<Keys, bool>();
53 
54  private const int NumberOfMouseButtons = 5;
55 
56  private readonly bool[] mouseButtons = new bool[NumberOfMouseButtons];
57 
58  private readonly bool[] mouseButtonsPrevious = new bool[NumberOfMouseButtons];
59 
60  /// <summary>
61  /// The exact current down/up state of the mouse button (not synchronized with the update cycles).
62  /// </summary>
63  internal readonly bool[] MouseButtonCurrentlyDown = new bool[NumberOfMouseButtons];
64 
65  private readonly List<Dictionary<object, float>> virtualButtonValues = new List<Dictionary<object, float>>();
66 
67  private readonly List<PointerEvent> pointerEvents = new List<PointerEvent>();
68 
69  private readonly List<PointerEvent> currentPointerEvents = new List<PointerEvent>();
70 
71  private readonly List<GestureEvent> currentGestureEvents = new List<GestureEvent>();
72 
73  private readonly Dictionary<GestureConfig, GestureRecognizer> gestureConfigToRecognizer = new Dictionary<GestureConfig, GestureRecognizer>();
74 
75  /// <summary>
76  /// List of the gestures to recognize.
77  /// </summary>
78  /// <remarks>To detect a new gesture add its configuration to the list.
79  /// To stop detecting a gesture remove its configuration from the list.
80  /// To all gestures detection clear the list.
81  /// Note that once added to the list the <see cref="GestureConfig"/>s are frozen by the system and cannot be modified anymore.</remarks>
82  /// <seealso cref="GestureConfig"/>
83  public GestureConfigCollection ActivatedGestures { get; private set; }
84 
85  internal readonly Dictionary<int, PointerInfo> PointerInfos = new Dictionary<int, PointerInfo>();
86 
87  /// <summary>
88  /// Gets the delta value of the mouse wheel button since last frame.
89  /// </summary>
90  public float MouseWheelDelta { get; private set; }
91 
92  /// <summary>
93  /// The width in pixel of the control
94  /// </summary>
95  internal float ControlWidth
96  {
97  get { return controlWidth; }
98  set
99  {
100  controlWidth = Math.Max(0, value);
101 
102  if (controlHeight > 0)
103  ScreenAspectRatio = ControlWidth / ControlHeight;
104  }
105  }
106 
107  private float controlWidth;
108 
109  /// <summary>
110  /// The height in pixel of the control
111  /// </summary>
112  internal float ControlHeight
113  {
114  get { return controlHeight; }
115  set
116  {
117  controlHeight = Math.Max(0, value);
118 
119  if (controlHeight > 0)
120  ScreenAspectRatio = ControlWidth / ControlHeight;
121  }
122  }
123  private float controlHeight;
124 
125  internal float ScreenAspectRatio
126  {
127  get { return screenAspectRatio; }
128  private set
129  {
130  screenAspectRatio = value;
131 
132  foreach (var recognizer in gestureConfigToRecognizer.Values)
133  recognizer.ScreenRatio = ScreenAspectRatio;
134  }
135  }
136 
137  private float screenAspectRatio;
138 
139  #endregion
140 
141  internal class PointerInfo
142  {
143  public readonly Stopwatch PointerClock = new Stopwatch();
144  public Vector2 LastPosition;
145  }
146 
147  internal InputManagerBase(IServiceRegistry registry) : base(registry)
148  {
149  Enabled = true;
150  gamePads = new GamePad[MaximumGamePadCount];
151  gamePadStates = new GamePadState[MaximumGamePadCount];
152 
153  KeyDown = downKeysList;
154  KeyEvents = new List<KeyEvent>();
155  PointerEvents = currentPointerEvents;
156  GestureEvents = currentGestureEvents;
157 
158  ActivatedGestures = new GestureConfigCollection();
159  ActivatedGestures.CollectionChanged += ActivatedGesturesChanged;
160 
161  Services.AddService(typeof(InputManager), this);
162  }
163 
164  private void ActivatedGesturesChanged(object sender, TrackingCollectionChangedEventArgs trackingCollectionChangedEventArgs)
165  {
166  switch (trackingCollectionChangedEventArgs.Action)
167  {
168  case NotifyCollectionChangedAction.Add:
169  StartGestureRecognition((GestureConfig)trackingCollectionChangedEventArgs.Item);
170  break;
171  case NotifyCollectionChangedAction.Remove:
172  StopGestureRecognition((GestureConfig)trackingCollectionChangedEventArgs.Item);
173  break;
174  case NotifyCollectionChangedAction.Replace:
175  case NotifyCollectionChangedAction.Reset:
176  throw new NotSupportedException("ActivatedGestures collection was modified but the action was not supported by the system.");
177  case NotifyCollectionChangedAction.Move:
178  break;
179  default:
180  throw new ArgumentOutOfRangeException();
181  }
182  }
183 
184  private void StartGestureRecognition(GestureConfig config)
185  {
186  gestureConfigToRecognizer.Add(config, config.CreateRecognizer(ScreenAspectRatio));
187  }
188 
189  private void StopGestureRecognition(GestureConfig config)
190  {
191  gestureConfigToRecognizer.Remove(config);
192  }
193 
194  internal Vector2 NormalizeScreenPosition(Vector2 pixelPosition)
195  {
196  return new Vector2(pixelPosition.X / ControlWidth, pixelPosition.Y / ControlHeight);
197  }
198 
199  internal void HandlePointerEvents(int pointerId, Vector2 newPosition, PointerState pState, PointerType pointerType = PointerType.Touch)
200  {
201  lock (pointerEvents)
202  {
203  if (!PointerInfos.ContainsKey(pointerId))
204  PointerInfos[pointerId] = new PointerInfo();
205 
206  var pointerInfo = PointerInfos[pointerId];
207 
208  if (pState == PointerState.Down)
209  {
210  pointerInfo.LastPosition = newPosition;
211  pointerInfo.PointerClock.Restart();
212  }
213 
214  var pointerEvent = PointerEvent.GetOrCreatePointerEvent();
215 
216  pointerEvent.PointerId = pointerId;
217  pointerEvent.Position = newPosition;
218  pointerEvent.DeltaPosition = newPosition - pointerInfo.LastPosition;
219  pointerEvent.DeltaTime = pointerInfo.PointerClock.Elapsed;
220  pointerEvent.State = pState;
221  pointerEvent.PointerType = pointerType;
222  pointerEvent.IsPrimary = pointerId == 0;
223 
224  lock (pointerEvents)
225  pointerEvents.Add(pointerEvent);
226 
227  pointerInfo.LastPosition = newPosition;
228  pointerInfo.PointerClock.Restart();
229  }
230  }
231 
232  internal enum InputEventType
233  {
234  Up,
235 
236  Down,
237 
238  Wheel,
239  }
240 
241  /// <summary>
242  /// Gets or sets the configuration for virtual buttons.
243  /// </summary>
244  /// <value>The current binding.</value>
246 
247  /// <summary>
248  /// Gets a collection of pointer events since the previous updates.
249  /// </summary>
250  /// <value>The pointer events.</value>
251  public List<PointerEvent> PointerEvents { get; private set; }
252 
253  /// <summary>
254  /// Gets the collection of gesture events since the previous updates.
255  /// </summary>
256  /// <value>The gesture events.</value>
257  public List<GestureEvent> GestureEvents { get; private set; }
258 
259  /// <summary>
260  /// Gets a value indicating whether gamepads are available.
261  /// </summary>
262  /// <value><c>true</c> if gamepads are available; otherwise, <c>false</c>.</value>
263  public bool HasGamePad
264  {
265  get
266  {
267  return gamePadCount > 0;
268  }
269  }
270 
271  /// <summary>
272  /// Gets the number of gamepad connected.
273  /// </summary>
274  /// <value>The number of gamepad connected.</value>
275  public int GamePadCount
276  {
277  get
278  {
279  return gamePadCount;
280  }
281  }
282 
283  /// <summary>
284  /// Gets a value indicating whether the keyboard is available.
285  /// </summary>
286  /// <value><c>true</c> if the keyboard is available; otherwise, <c>false</c>.</value>
287  public bool HasKeyboard { get; internal set; }
288 
289  /// <summary>
290  /// Gets a value indicating whether the mouse is available.
291  /// </summary>
292  /// <value><c>true</c> if the mouse is available; otherwise, <c>false</c>.</value>
293  public bool HasMouse { get; internal set; }
294 
295  /// <summary>
296  /// Gets a value indicating whether pointer device is available.
297  /// </summary>
298  /// <value><c>true</c> if pointer devices are available; otherwise, <c>false</c>.</value>
299  public bool HasPointer { get; internal set; }
300 
301  /// <summary>
302  /// Gets the list of keys being pressed down.
303  /// </summary>
304  /// <value>The key pressed.</value>
305  public List<Keys> KeyDown { get; private set; }
306 
307  /// <summary>
308  /// Gets the list of key events (pressed or released) since the previous update.
309  /// </summary>
310  /// <value>The key events.</value>
311  public List<KeyEvent> KeyEvents { get; private set; }
312 
313  /// <summary>
314  /// Gets the mouse position.
315  /// </summary>
316  /// <value>The mouse position.</value>
317  public Vector2 MousePosition { get; private set; }
318 
319  /// <summary>
320  /// Gets a binding value for the specified name and the specified config extract from the current <see cref="VirtualButtonConfigSet"/>.
321  /// </summary>
322  /// <param name="configIndex">An index to a <see cref="VirtualButtonConfig"/> stored in the <see cref="VirtualButtonConfigSet"/></param>
323  /// <param name="bindingName">Name of the binding.</param>
324  /// <returns>The value of the binding.</returns>
325  public virtual float GetVirtualButton(int configIndex, object bindingName)
326  {
327  if (VirtualButtonConfigSet == null || configIndex < 0 || configIndex >= virtualButtonValues.Count)
328  {
329  return 0.0f;
330  }
331 
332  float value;
333  virtualButtonValues[configIndex].TryGetValue(bindingName, out value);
334  return value;
335  }
336 
337  /// <summary>
338  /// Gets the state of the specified gamepad.
339  /// </summary>
340  /// <param name="gamepadIndex">Index of the gamepad. -1 to return the first connected gamepad</param>
341  /// <returns>The state of the gamepad.</returns>
342  public virtual GamePadState GetGamePad(int gamepadIndex)
343  {
344  // If the game pad index is negative or larger, take the first connected gamepad
345  if (gamepadIndex < 0)
346  {
347  gamepadIndex = 0;
348  for(int i = 0; i < gamePadStates.Length; i++)
349  {
350  if (gamePadStates[i].IsConnected)
351  {
352  gamepadIndex = i;
353  break;
354  }
355  }
356  }
357  else if (gamepadIndex >= gamePadStates.Length)
358  {
359  for (gamepadIndex = gamePadStates.Length - 1; gamepadIndex >= 0; gamepadIndex--)
360  {
361  if (gamePadStates[gamepadIndex].IsConnected)
362  {
363  break;
364  }
365  }
366  }
367 
368  return gamePadStates[gamepadIndex];
369  }
370 
371  /// <summary>
372  /// Determines whether the specified key is being pressed down.
373  /// </summary>
374  /// <param name="key">The key.</param>
375  /// <returns><c>true</c> if the specified key is being pressed down; otherwise, <c>false</c>.</returns>
376  public bool IsKeyDown(Keys key)
377  {
378  bool pressed;
379  activeKeys.TryGetValue(key, out pressed);
380  return pressed;
381  }
382 
383  /// <summary>
384  /// Determines whether the specified key is pressed since the previous update.
385  /// </summary>
386  /// <param name="key">The key.</param>
387  /// <returns><c>true</c> if the specified key is pressed; otherwise, <c>false</c>.</returns>
388  public bool IsKeyPressed(Keys key)
389  {
390  return pressedKeysSet.Contains(key);
391  }
392 
393  /// <summary>
394  /// Determines whether the specified key is released since the previous update.
395  /// </summary>
396  /// <param name="key">The key.</param>
397  /// <returns><c>true</c> if the specified key is released; otherwise, <c>false</c>.</returns>
398  public bool IsKeyReleased(Keys key)
399  {
400  return releasedKeysSet.Contains(key);
401  }
402 
403  /// <summary>
404  /// Determines whether one or more of the mouse buttons are down
405  /// </summary>
406  /// <returns><c>true</c> if one or more of the mouse buttons are down; otherwise, <c>false</c>.</returns>
407  public bool HasDownMouseButtons()
408  {
409  for (int i = 0; i < mouseButtons.Length; ++i)
410  if (IsMouseButtonDown((MouseButton)i))
411  return true;
412 
413  return false;
414  }
415 
416  /// <summary>
417  /// Determines whether one or more of the mouse buttons are released
418  /// </summary>
419  /// <returns><c>true</c> if one or more of the mouse buttons are released; otherwise, <c>false</c>.</returns>
421  {
422  for (int i = 0; i < mouseButtons.Length; ++i)
423  if (IsMouseButtonReleased((MouseButton)i))
424  return true;
425 
426  return false;
427  }
428 
429  /// <summary>
430  /// Determines whether one or more of the mouse buttons are pressed
431  /// </summary>
432  /// <returns><c>true</c> if one or more of the mouse buttons are pressed; otherwise, <c>false</c>.</returns>
434  {
435  for (int i = 0; i < mouseButtons.Length; ++i)
436  if (IsMouseButtonPressed((MouseButton)i))
437  return true;
438 
439  return false;
440  }
441 
442  /// <summary>
443  /// Determines whether the specified mouse button is being pressed down.
444  /// </summary>
445  /// <param name="mouseButton">The mouse button.</param>
446  /// <returns><c>true</c> if the specified mouse button is being pressed down; otherwise, <c>false</c>.</returns>
447  public bool IsMouseButtonDown(MouseButton mouseButton)
448  {
449  return mouseButtons[(int)mouseButton];
450  }
451 
452  /// <summary>
453  /// Determines whether the specified mouse button is pressed since the previous update.
454  /// </summary>
455  /// <param name="mouseButton">The mouse button.</param>
456  /// <returns><c>true</c> if the specified mouse button is pressed since the previous update; otherwise, <c>false</c>.</returns>
457  public bool IsMouseButtonPressed(MouseButton mouseButton)
458  {
459  return !mouseButtonsPrevious[(int)mouseButton] && mouseButtons[(int)mouseButton];
460  }
461 
462  /// <summary>
463  /// Determines whether the specified mouse button is released.
464  /// </summary>
465  /// <param name="mouseButton">The mouse button.</param>
466  /// <returns><c>true</c> if the specified mouse button is released; otherwise, <c>false</c>.</returns>
467  public bool IsMouseButtonReleased(MouseButton mouseButton)
468  {
469  return mouseButtonsPrevious[(int)mouseButton] && !mouseButtons[(int)mouseButton];
470  }
471 
472  /// <summary>
473  /// Rescans all input devices in order to query new device connected. See remarks.
474  /// </summary>
475  /// <remarks>
476  /// This method could take several milliseconds and should be used at specific time in a game where performance is not crucial (pause, configuration screen...etc.)
477  /// </remarks>
478  public virtual void Scan()
479  {
480  lock (gamePads)
481  {
482  List<GamePadKey> gamePadKeys = GamePadFactories.SelectMany(gamePadFactory => gamePadFactory.GetConnectedPads()).ToList();
483 
484  int nextAvailable = -1;
485  for (int i = 0; i < gamePads.Length; i++)
486  {
487  GamePad gamePad = gamePads[i];
488  if (gamePad == null)
489  {
490  if (nextAvailable < 0)
491  {
492  nextAvailable = i;
493  }
494  continue;
495  }
496 
497  if (gamePadKeys.Contains(gamePad.Key))
498  {
499  gamePadKeys.Remove(gamePad.Key);
500  }
501  else
502  {
503  gamePad.Dispose();
504  gamePads[i] = null;
505 
506  if (nextAvailable < 0)
507  {
508  nextAvailable = i;
509  }
510  }
511  }
512 
513  foreach (GamePadKey gamePadKey in gamePadKeys)
514  {
515  int gamePadIndex = -1;
516  for (int i = nextAvailable; i < gamePads.Length; i++)
517  {
518  if (gamePads[i] == null)
519  {
520  gamePadIndex = i;
521  break;
522  }
523  }
524 
525  if (gamePadIndex >= 0)
526  {
527  GamePad gamePad = gamePadKey.Factory.GetGamePad(gamePadKey.Guid);
528  gamePads[gamePadIndex] = gamePad;
529  nextAvailable = gamePadIndex + 1;
530  }
531  }
532 
533  gamePadCount = 0;
534  foreach (GamePad internalGamePad in gamePads)
535  {
536  if (internalGamePad != null)
537  {
538  gamePadCount++;
539  }
540  }
541  }
542  }
543 
544  public override void Update(GameTime gameTime)
545  {
546  UpdateKeyboard();
547  UpdateMouse();
548  UpdateGamePads();
549  UpdatePointerEvents();
550  UpdateVirtualButtonValues();
551  UpdateGestureEvents(gameTime.Elapsed);
552  }
553 
554  private void UpdateGestureEvents(TimeSpan elapsedGameTime)
555  {
556  currentGestureEvents.Clear();
557 
558  foreach (var gestureRecognizer in gestureConfigToRecognizer.Values)
559  currentGestureEvents.AddRange(gestureRecognizer.ProcessPointerEvents(elapsedGameTime, currentPointerEvents));
560  }
561 
562  private void UpdatePointerEvents()
563  {
564  lock (PointerEvent.Pool)
565  {
566  foreach (var pointerEvent in currentPointerEvents)
567  PointerEvent.Pool.Enqueue(pointerEvent);
568  }
569  currentPointerEvents.Clear();
570 
571  lock (pointerEvents)
572  {
573  currentPointerEvents.AddRange(pointerEvents);
574  pointerEvents.Clear();
575  }
576  }
577 
578  private void UpdateVirtualButtonValues()
579  {
580  if (VirtualButtonConfigSet != null)
581  {
582  for (int i = 0; i < VirtualButtonConfigSet.Count; i++)
583  {
584  var config = VirtualButtonConfigSet[i];
585 
586  Dictionary<object, float> mapNameToValue;
587  if (i == virtualButtonValues.Count)
588  {
589  mapNameToValue = new Dictionary<object, float>();
590  virtualButtonValues.Add(mapNameToValue);
591  }
592  else
593  {
594  mapNameToValue = virtualButtonValues[i];
595  }
596 
597  mapNameToValue.Clear();
598 
599  if (config != null)
600  {
601  foreach (var name in config.BindingNames)
602  {
603  mapNameToValue[name] = config.GetValue(this, name);
604  }
605  }
606  }
607  }
608  }
609 
610  private void UpdateGamePads()
611  {
612  lock (gamePads)
613  {
614  for (int i = 0, j = gamePadCount; i < gamePads.Length && j > 0; i++, j--)
615  {
616  if (gamePads[i] != null)
617  {
618  // Get the state of the gamepad
619  gamePadStates[i] = gamePads[i].GetState();
620  }
621  }
622  }
623  }
624 
625  private void UpdateMouse()
626  {
627  MouseWheelDelta = 0;
628 
629  for (int i = 0; i < mouseButtons.Length; ++i)
630  mouseButtonsPrevious[i] = mouseButtons[i];
631 
632  lock (MouseInputEvents)
633  {
634  foreach (MouseInputEvent mouseInputEvent in MouseInputEvents)
635  {
636  var mouseButton = (int)mouseInputEvent.MouseButton;
637  if (mouseButton < 0 || mouseButton >= mouseButtons.Length)
638  continue;
639 
640  switch (mouseInputEvent.Type)
641  {
642  case InputEventType.Down:
643  mouseButtons[mouseButton] = true;
644  break;
645  case InputEventType.Up:
646  mouseButtons[mouseButton] = false;
647  break;
648  case InputEventType.Wheel:
649  if (mouseInputEvent.MouseButton != MouseButton.Middle)
650  {
651  throw new NotImplementedException();
652  }
653  MouseWheelDelta += mouseInputEvent.Value;
654  break;
655  default:
656  throw new NotSupportedException();
657  }
658  }
659  MouseInputEvents.Clear();
660  }
661 
662  MousePosition = CurrentMousePosition;
663 
664  if (LostFocus)
665  {
666  for (int i = 0; i < mouseButtons.Length; ++i)
667  mouseButtons[i] = false;
668  }
669 
670  LostFocus = false;
671  }
672 
673  private void UpdateKeyboard()
674  {
675  pressedKeysSet.Clear();
676  releasedKeysSet.Clear();
677  KeyEvents.Clear();
678 
679  lock (KeyboardInputEvents)
680  {
681  foreach (KeyboardInputEvent keyboardInputEvent in KeyboardInputEvents)
682  {
683  var key = keyboardInputEvent.Key;
684 
685  if (key == Keys.None)
686  continue;
687 
688  switch (keyboardInputEvent.Type)
689  {
690  case InputEventType.Down:
691  if (!IsKeyDown(key)) // prevent from several inconsistent pressed key due to OS repeat key
692  {
693  activeKeys[key] = true;
694  pressedKeysSet.Add(key);
695 
696  KeyEvents.Add(new KeyEvent(key, KeyEventType.Pressed));
697  downKeysList.Add(key);
698  }
699  break;
700  case InputEventType.Up:
701  activeKeys[key] = false;
702  releasedKeysSet.Add(key);
703  KeyEvents.Add(new KeyEvent(key, KeyEventType.Released));
704  downKeysList.Remove(key);
705  break;
706  default:
707  throw new NotSupportedException();
708  }
709  }
710 
711  KeyboardInputEvents.Clear();
712  }
713 
714  if (LostFocus)
715  {
716  activeKeys.Clear();
717  downKeysList.Clear();
718  }
719  }
720 
721  internal static float ClampDeadZone(float value, float deadZone)
722  {
723  if (value > 0.0f)
724  {
725  value -= deadZone;
726  if (value < 0.0f)
727  {
728  value = 0.0f;
729  }
730  }
731  else
732  {
733  value += deadZone;
734  if (value > 0.0f)
735  {
736  value = 0.0f;
737  }
738  }
739 
740  // Renormalize the value according to the dead zone
741  value = value / (1.0f - deadZone);
742  return value < -1.0f ? -1.0f : value > 1.0f ? 1.0f : value;
743  }
744 
745  internal struct GamePadKey : IEquatable<GamePadKey>
746  {
747  #region Constants and Fields
748 
749  public readonly GamePadFactory Factory;
750 
751  public readonly Guid Guid;
752 
753  #endregion
754 
755  public GamePadKey(Guid guid, GamePadFactory factory)
756  {
757  Guid = guid;
758  Factory = factory;
759  }
760 
761  public bool Equals(GamePadKey other)
762  {
763  return Guid.Equals(other.Guid) && Factory.Equals(other.Factory);
764  }
765 
766  public override bool Equals(object obj)
767  {
768  if (ReferenceEquals(null, obj)) return false;
769  return obj is GamePadKey && Equals((GamePadKey)obj);
770  }
771 
772  public override int GetHashCode()
773  {
774  unchecked
775  {
776  return (Guid.GetHashCode() * 397) ^ Factory.GetHashCode();
777  }
778  }
779 
780  public static bool operator ==(GamePadKey left, GamePadKey right)
781  {
782  return left.Equals(right);
783  }
784 
785  public static bool operator !=(GamePadKey left, GamePadKey right)
786  {
787  return !left.Equals(right);
788  }
789  }
790 
791  internal struct KeyboardInputEvent
792  {
793  #region Constants and Fields
794 
795  public Keys Key;
796 
797  public InputEventType Type;
798 
799  #endregion
800  }
801 
802  internal struct MouseInputEvent
803  {
804  #region Constants and Fields
805 
806  public MouseButton MouseButton;
807 
808  public InputEventType Type;
809 
810  public float Value;
811 
812  #endregion
813  }
814 
815  /// <summary>
816  /// Gets or sets the value indicating if simultaneous multiple finger touches are enabled or not.
817  /// If not enabled only the events of one finger at a time are triggered.
818  /// </summary>
819  public abstract bool MultiTouchEnabled { get; set; }
820 
821  /// <summary>
822  /// Base class used to track the state of a gamepad (XInput or DirectInput).
823  /// </summary>
824  internal abstract class GamePad : IDisposable
825  {
826  #region Constants and Fields
827 
828  /// <summary>
829  /// Unique identifier of the gamepad.
830  /// </summary>
831  public GamePadKey Key;
832 
833  #endregion
834 
835  protected GamePad(GamePadKey key)
836  {
837  Key = key;
838  }
839 
840  public virtual void Dispose()
841  {
842  }
843 
844  public abstract GamePadState GetState();
845  }
846 
847  /// <summary>
848  /// Base class used to track the state of a gamepad (XInput or DirectInput).
849  /// </summary>
850  internal abstract class GamePadFactory
851  {
852  public abstract IEnumerable<GamePadKey> GetConnectedPads();
853 
854  public abstract GamePad GetGamePad(Guid guid);
855  }
856  }
857 }
bool HasReleasedMouseButtons()
Determines whether one or more of the mouse buttons are released
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
bool HasDownMouseButtons()
Determines whether one or more of the mouse buttons are down
PointerType
Type of a pointer device.
Definition: PointerType.cs:8
bool IsMouseButtonReleased(MouseButton mouseButton)
Determines whether the specified mouse button is released.
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
SharpDX.DirectWrite.Factory Factory
MouseButton
Mouse buttons.
Definition: MouseButton.cs:10
Keys
Enumeration for keys.
Definition: Keys.cs:8
bool IsKeyDown(Keys key)
Determines whether the specified key is being pressed down.
Searchg files going upward in the directory hierarchy.
Search files in all sub-directories.
SiliconStudio.Paradox.Input.Keys Keys
bool IsKeyPressed(Keys key)
Determines whether the specified key is pressed since the previous update.
A service registry is a IServiceProvider that provides methods to register and unregister services...
PointerState
State of a pointer event.
Definition: PointerState.cs:8
bool IsMouseButtonDown(MouseButton mouseButton)
Determines whether the specified mouse button is being pressed down.
Base class for a GameSystemBase component.
Base implementation for ILogger.
Definition: Logger.cs:10
virtual GamePadState GetGamePad(int gamepadIndex)
Gets the state of the specified gamepad.
Describes the state of a gamepad.
Definition: GamePadState.cs:15
override void Update(GameTime gameTime)
This method is called when this game component is updated.
virtual void Scan()
Rescans all input devices in order to query new device connected. See remarks.
Current timing used for variable-step (real time) or fixed-step (game time) games.
Definition: GameTime.cs:31
The type of the serialized type will be passed as a generic arguments of the serializer. Example: serializer of A becomes instantiated as Serializer{A}.
float Y
The Y component of the vector.
Definition: Vector2.cs:79
object Item
Gets the added or removed item (if dictionary, value only).
virtual float GetVirtualButton(int configIndex, object bindingName)
Gets a binding value for the specified name and the specified config extract from the current Virtual...
Interface for input management system, including keyboard, mouse, gamepads and touch.
NotifyCollectionChangedAction Action
Gets the type of action performed. Allowed values are NotifyCollectionChangedAction.Add and NotifyCollectionChangedAction.Remove.
float X
The X component of the vector.
Definition: Vector2.cs:73
bool IsKeyReleased(Keys key)
Determines whether the specified key is released since the previous update.
TimeSpan Elapsed
Gets the elapsed game time since the last update
Definition: GameTime.cs:80
A gamepad virtual button.
bool HasPressedMouseButtons()
Determines whether one or more of the mouse buttons are pressed
KeyEventType
Used by KeyEvent
Definition: KeyEventType.cs:8
bool IsMouseButtonPressed(MouseButton mouseButton)
Determines whether the specified mouse button is pressed since the previous update.