Pyrogenesis  trunk
TouchInput.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_TOUCHINPUT
19 #define INCLUDED_TOUCHINPUT
20 
21 #include "lib/input.h"
22 #include "maths/Vector2D.h"
23 #include "maths/Vector3D.h"
24 
25 /**
26  * Maps touch events (e.g. on Android touchscreen devices) onto mouse events
27  * and camera movement.
28  */
30 {
31 public:
32  CTouchInput();
33  ~CTouchInput();
34 
35  /**
36  * Returns whether the touch input mode is enabled for this device.
37  */
38  bool IsEnabled();
39 
41 
42  /**
43  * Should be called once per frame to perform updates.
44  */
45  void Frame();
46 
47 private:
48  void OnFingerDown(int id, int x, int y);
49  void OnFingerUp(int id, int x, int y);
50  void OnFingerMotion(int id, int x, int y);
51 
52  // Mouse emulation state:
53  enum
54  {
59  };
60  static const size_t MAX_MOUSE = 2;
63 
64  // Current finger state:
65  static const size_t MAX_FINGERS = 2;
69 
70 
71  enum
72  {
77  };
78  int m_State;
79 
82 
84  float m_PanDist;
85 };
86 
88 
89 extern InReaction touch_input_handler(const SDL_Event_* ev);
90 
91 #endif // INCLUDED_TOUCHINPUT
Definition: TouchInput.h:74
InReaction HandleEvent(const SDL_Event_ *ev)
Definition: TouchInput.cpp:187
int m_MouseEmulateState[MAX_MOUSE]
Definition: TouchInput.h:61
bool IsEnabled()
Returns whether the touch input mode is enabled for this device.
Definition: TouchInput.cpp:56
CVector2D m_Prev[MAX_FINGERS]
Definition: TouchInput.h:68
static const size_t MAX_FINGERS
Definition: TouchInput.h:65
Definition: TouchInput.h:55
Definition: Vector3D.h:28
bool m_Down[MAX_FINGERS]
Definition: TouchInput.h:66
Maps touch events (e.g.
Definition: TouchInput.h:29
~CTouchInput()
Definition: TouchInput.cpp:52
static const size_t MAX_MOUSE
Definition: TouchInput.h:60
Definition: libsdl.h:51
void OnFingerDown(int id, int x, int y)
Definition: TouchInput.cpp:65
CVector2D m_FirstTouchPos
Definition: TouchInput.h:81
CTouchInput g_TouchInput
Definition: TouchInput.cpp:291
InReaction
Definition: input.h:34
Definition: TouchInput.h:73
void OnFingerUp(int id, int x, int y)
Definition: TouchInput.cpp:83
CVector2D m_Pos[MAX_FINGERS]
Definition: TouchInput.h:67
double m_FirstTouchTime
Definition: TouchInput.h:80
Definition: TouchInput.h:75
Definition: Vector2D.h:31
CVector3D m_PanFocus
Definition: TouchInput.h:83
Definition: TouchInput.h:58
Definition: TouchInput.h:56
Definition: TouchInput.h:76
Definition: TouchInput.h:57
CTouchInput()
Definition: TouchInput.cpp:42
void Frame()
Should be called once per frame to perform updates.
Definition: TouchInput.cpp:165
void OnFingerMotion(int id, int x, int y)
Definition: TouchInput.cpp:116
int m_State
Definition: TouchInput.h:78
CVector2D m_MouseEmulateDownPos[MAX_MOUSE]
Definition: TouchInput.h:62
InReaction touch_input_handler(const SDL_Event_ *ev)
Definition: TouchInput.cpp:293
float m_PanDist
Definition: TouchInput.h:84