Orxonox  0.0.5 Codename: Arcturus
OISMultiTouch.h
Go to the documentation of this file.
1 /*
2 The zlib/libpng License
3 
4 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
5 
6 This software is provided 'as-is', without any express or implied warranty. In no event will
7 the authors be held liable for any damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any purpose, including commercial
10 applications, and to alter it and redistribute it freely, subject to the following
11 restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not claim that
14  you wrote the original software. If you use this software in a product,
15  an acknowledgment in the product documentation would be appreciated but is
16  not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source distribution.
22 */
23 #ifndef OIS_MultiTouch_H
24 #define OIS_MultiTouch_H
25 #include "OISObject.h"
26 #include "OISEvents.h"
27 
28 #include <set>
29 #include <vector>
30 
31 #define OIS_MAX_NUM_TOUCHES 4 // 4 finger touches are probably the highest we'll ever get
32 
33 namespace OIS
34 {
42  {
44  };
45 
47  {
48  public:
49  MultiTouchState() : width(50), height(50), touchType(MT_None) {};
50 
54  mutable int width, height;
55 
58 
61 
64 
65  int touchType;
66 
67  inline bool touchIsType( MultiTypeEventTypeID touch ) const
68  {
69  return ((touchType & ( 1L << touch )) == 0) ? false : true;
70  }
71 
73  void clear()
74  {
75  X.clear();
76  Y.clear();
77  Z.clear();
78  touchType = MT_None;
79  }
80  };
81 
84  {
85  public:
86  MultiTouchEvent( Object *obj, const MultiTouchState &ms ) : EventArg(obj), state(ms) {}
87  virtual ~MultiTouchEvent() {}
88 
91  };
92 
98  {
99  public:
100  virtual ~MultiTouchListener() {}
101  virtual bool touchMoved( const MultiTouchEvent &arg ) = 0;
102  virtual bool touchPressed( const MultiTouchEvent &arg ) = 0;
103  virtual bool touchReleased( const MultiTouchEvent &arg ) = 0;
104  virtual bool touchCancelled( const MultiTouchEvent &arg ) = 0;
105  };
106 
111  class _OISExport MultiTouch : public Object
112  {
113  public:
114  virtual ~MultiTouch() {}
115 
123  virtual void setEventCallback( MultiTouchListener *touchListener ) {mListener = touchListener;}
124 
126  MultiTouchListener* getEventCallback() {return mListener;}
127 
129  void clearStates(void) { mStates.clear(); }
130 
132  std::vector<MultiTouchState> getMultiTouchStates() const { return mStates; }
133 
136  const std::vector<MultiTouchState> getFirstNTouchStates(int n) {
137  std::vector<MultiTouchState> states;
138  for( unsigned int i = 0; i < mStates.size(); i++ ) {
139  if(!(mStates[i].touchIsType(MT_None))) {
140  states.push_back(mStates[i]);
141  }
142  }
143  return states;
144  }
145 
148  const std::vector<MultiTouchState> getMultiTouchStatesOfType(MultiTypeEventTypeID type) {
149  std::vector<MultiTouchState> states;
150  for( unsigned int i = 0; i < mStates.size(); i++ ) {
151  if(mStates[i].touchIsType(type)) {
152  states.push_back(mStates[i]);
153  }
154  }
155  return states;
156  }
157 
158  protected:
159  MultiTouch(const std::string &vendor, bool buffered, int devID, InputManager* creator)
160  : Object(vendor, OISMultiTouch, buffered, devID, creator), mListener(0) {}
161 
163  std::vector<MultiTouchState> mStates;
164 
167  };
168 }
169 #endif
Base class of all events.
Definition: OISEvents.h:32
MultiTouch(const std::string &vendor, bool buffered, int devID, InputManager *creator)
Definition: OISMultiTouch.h:159
#define _OISExport
Definition: OISPrereqs.h:40
Definition: OISMultiTouch.h:43
virtual ~MultiTouch()
Definition: OISMultiTouch.h:114
virtual ~MultiTouchListener()
Definition: OISMultiTouch.h:100
Axis Y
Y Axis Component.
Definition: OISMultiTouch.h:60
const std::vector< MultiTouchState > getMultiTouchStatesOfType(MultiTypeEventTypeID type)
Definition: OISMultiTouch.h:148
const std::vector< MultiTouchState > getFirstNTouchStates(int n)
Definition: OISMultiTouch.h:136
::std::string string
Definition: gtest-port.h:756
MultiTouchListener * getEventCallback()
Definition: OISMultiTouch.h:126
int width
Represents the height/width of your display area.
Definition: OISMultiTouch.h:49
Definition: OISPrereqs.h:145
Definition: OISMultiTouch.h:43
Axis Z
Z Axis Component.
Definition: OISMultiTouch.h:63
std::vector< MultiTouchState > mStates
The state of the touch device, implemented in a vector to store the state from each finger touch...
Definition: OISMultiTouch.h:163
Specialised for multi-touch events.
Definition: OISMultiTouch.h:83
int touchType
Definition: OISMultiTouch.h:65
const MultiTouchState & state
The state of the touch - including axes.
Definition: OISMultiTouch.h:90
MultiTouchListener * mListener
Used for buffered/actionmapping callback.
Definition: OISMultiTouch.h:166
MultiTypeEventTypeID
Represents the state of the multi-touch device All members are valid for both buffered and non buffer...
Definition: OISMultiTouch.h:41
virtual void setEventCallback(MultiTouchListener *touchListener)
Definition: OISMultiTouch.h:123
bool touchIsType(MultiTypeEventTypeID touch) const
Definition: OISMultiTouch.h:67
To receive buffered touch input, derive a class from this, and implement the methods here...
Definition: OISMultiTouch.h:97
MultiTouchEvent(Object *obj, const MultiTouchState &ms)
Definition: OISMultiTouch.h:86
Definition: InputPrereqs.h:96
Definition: OISMultiTouch.h:43
virtual ~MultiTouchEvent()
Definition: OISMultiTouch.h:87
The base class of all input types.
Definition: OISObject.h:32
Definition: OISMultiTouch.h:46
Base Manager class.
Definition: OISInputManager.h:38
std::vector< MultiTouchState > getMultiTouchStates() const
Definition: OISMultiTouch.h:132
Axis component.
Definition: OISPrereqs.h:185
void clearStates(void)
Definition: OISMultiTouch.h:129
Definition: EventHelpers.h:31
Definition: OISMultiTouch.h:43
void clear()
Used internally by OIS.
Definition: OISPrereqs.h:197
Definition: OISMultiTouch.h:43
MultiTouch base class.
Definition: OISMultiTouch.h:111
void clear()
Clear all the values.
Definition: OISMultiTouch.h:73
Axis X
X Axis component.
Definition: OISMultiTouch.h:57