Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GestureConfig.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 
4 using System;
5 
6 using SiliconStudio.Core;
7 
8 namespace SiliconStudio.Paradox.Input
9 {
10  /// <summary>
11  /// This represents the base class for all gesture configuration.
12  /// </summary>
13  /// <remarks>
14  /// <para>Gesture configurations cannot be modified after being added to the input system for gesture recognition. Doing so will throw an <see cref="InvalidOperationException"/>.</para>
15  /// <para>Gesture Recognizers work with normalized coordinates belonging to [0,1]x[0,1/screenRatio]
16  /// so distances, speeds and margin errors need to be expressed relatively to this coordinates system.</para>
17  /// </remarks>
18  public abstract class GestureConfig
19  {
20  /// <summary>
21  /// Specify the <see cref="GestureType"/> corresponding to this configuration.
22  /// </summary>
23  public GestureType AssociatedGestureType { get; protected set; }
24 
25  private readonly int restrictedNumberOfFinger;
26 
27  internal GestureConfig() : this(0)
28  {
29  }
30 
31  internal GestureConfig(int numberOfFinger)
32  {
33  AssociatedGestureType = (GestureType)(-1);
34 
35  restrictedNumberOfFinger = numberOfFinger;
36  }
37 
38  /// <summary>
39  /// This value represents the required number of simultaneous finger to tap to trigger the gesture. For example: 1 for single finger, and so on...
40  /// </summary>
41  /// <remarks>This value is strictly positive.</remarks>
42  /// <exception cref="ArgumentOutOfRangeException">The given value is not in the allowed range.</exception>
43  /// <exception cref="InvalidOperationException">Tried to modify the configuration after it has been frozen by the system.</exception>
44  public int RequiredNumberOfFingers
45  {
46  get { return requiredNumberOfFingers; }
47  set
48  {
49  CheckNotFrozen();
50 
51  if (value < 1)
52  throw new ArgumentOutOfRangeException("value");
53 
54  if (restrictedNumberOfFinger != 0 && value != restrictedNumberOfFinger)
55  throw new ArgumentOutOfRangeException("value");
56 
57  requiredNumberOfFingers = value;
58  }
59  }
60  private int requiredNumberOfFingers;
61 
62  /// <summary>
63  /// Indicate that the configuration is frozen and cannot be modified anymore by the user.
64  /// </summary>
65  private bool frozen;
66 
67  /// <summary>
68  /// Freeze the configuration so that the user cannot modify it anymore.
69  /// </summary>
70  private void Freeze()
71  {
72  frozen = true;
73  }
74 
75  internal void CheckNotFrozen()
76  {
77  if(frozen)
78  throw new InvalidOperationException("Tried to modify the configuration after is has been frozen.");
79  }
80 
81  /// <summary>
82  /// Create a recognizer for the current configuration.
83  /// </summary>
84  /// <returns></returns>
85  internal GestureRecognizer CreateRecognizer(float screenRatio)
86  {
87  // freeze the configuration so that the user cannot modify it from outside.
88  Freeze();
89 
90  return CreateRecognizerImpl(screenRatio);
91  }
92 
93  internal abstract GestureRecognizer CreateRecognizerImpl(float screenRatio);
94  }
95 }
GestureType
List all the available type of Gestures.
Definition: GestureType.cs:9
This represents the base class for all gesture configuration.