OIS  1.5
Object-oriented Input System
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  MT_None = 0,
47  };
48 
50  {
51  public:
53  width(50), height(50), touchType(MT_None){};
54 
58  mutable int width, height;
59 
62 
65 
68 
69  int touchType;
70 
71  inline bool touchIsType(MultiTypeEventTypeID touch) const
72  {
73  return ((touchType & (1L << touch)) == 0) ? false : true;
74  }
75 
77  void clear()
78  {
79  X.clear();
80  Y.clear();
81  Z.clear();
82  touchType = MT_None;
83  }
84  };
85 
88  {
89  public:
91  EventArg(obj), state(ms) {}
92  virtual ~MultiTouchEvent() {}
93 
96  };
97 
103  {
104  public:
105  virtual ~MultiTouchListener() {}
106  virtual bool touchMoved(const MultiTouchEvent& arg) = 0;
107  virtual bool touchPressed(const MultiTouchEvent& arg) = 0;
108  virtual bool touchReleased(const MultiTouchEvent& arg) = 0;
109  virtual bool touchCancelled(const MultiTouchEvent& arg) = 0;
110  };
111 
116  class _OISExport MultiTouch : public Object
117  {
118  public:
119  virtual ~MultiTouch() {}
120 
128  virtual void setEventCallback(MultiTouchListener* touchListener) { mListener = touchListener; }
129 
131  MultiTouchListener* getEventCallback() { return mListener; }
132 
134  void clearStates(void) { mStates.clear(); }
135 
137  std::vector<MultiTouchState> getMultiTouchStates() const { return mStates; }
138 
141  const std::vector<MultiTouchState> getFirstNTouchStates(int n)
142  {
143  std::vector<MultiTouchState> states;
144  for(unsigned int i = 0; i < mStates.size(); i++)
145  {
146  if(!(mStates[i].touchIsType(MT_None)))
147  {
148  states.push_back(mStates[i]);
149  }
150  }
151  return states;
152  }
153 
156  const std::vector<MultiTouchState> getMultiTouchStatesOfType(MultiTypeEventTypeID type)
157  {
158  std::vector<MultiTouchState> states;
159  for(unsigned int i = 0; i < mStates.size(); i++)
160  {
161  if(mStates[i].touchIsType(type))
162  {
163  states.push_back(mStates[i]);
164  }
165  }
166  return states;
167  }
168 
169  protected:
170  MultiTouch(const std::string& vendor, bool buffered, int devID, InputManager* creator) :
171  Object(vendor, OISMultiTouch, buffered, devID, creator), mListener(0) {}
172 
174  std::vector<MultiTouchState> mStates;
175 
178  };
179 }
180 #endif
std::vector< MultiTouchState > getMultiTouchStates() const
Definition: OISMultiTouch.h:137
Definition: OISEvents.h:32
MultiTouch(const std::string &vendor, bool buffered, int devID, InputManager *creator)
Definition: OISMultiTouch.h:170
#define _OISExport
Definition: OISPrereqs.h:40
Definition: OISMultiTouch.h:46
virtual ~MultiTouch()
Definition: OISMultiTouch.h:119
virtual ~MultiTouchListener()
Definition: OISMultiTouch.h:105
Axis Y
Y Axis Component.
Definition: OISMultiTouch.h:64
const std::vector< MultiTouchState > getMultiTouchStatesOfType(MultiTypeEventTypeID type)
Definition: OISMultiTouch.h:156
const std::vector< MultiTouchState > getFirstNTouchStates(int n)
Definition: OISMultiTouch.h:141
MultiTouchListener * getEventCallback()
Definition: OISMultiTouch.h:131
bool touchIsType(MultiTypeEventTypeID touch) const
Definition: OISMultiTouch.h:71
Definition: OISPrereqs.h:166
Definition: OISMultiTouch.h:45
Axis Z
Z Axis Component.
Definition: OISMultiTouch.h:67
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:174
Definition: OISMultiTouch.h:87
int touchType
Definition: OISMultiTouch.h:69
const MultiTouchState & state
The state of the touch - including axes.
Definition: OISMultiTouch.h:95
MultiTouchListener * mListener
Used for buffered/actionmapping callback.
Definition: OISMultiTouch.h:177
MultiTouchState()
Definition: OISMultiTouch.h:52
MultiTypeEventTypeID
Touch Event type.
Definition: OISMultiTouch.h:41
virtual void setEventCallback(MultiTouchListener *touchListener)
Definition: OISMultiTouch.h:128
Definition: OISMultiTouch.h:102
MultiTouchEvent(Object *obj, const MultiTouchState &ms)
Definition: OISMultiTouch.h:90
Definition: OISMultiTouch.h:42
virtual ~MultiTouchEvent()
Definition: OISMultiTouch.h:92
Definition: OISObject.h:32
Definition: OISMultiTouch.h:49
Definition: OISInputManager.h:38
Axis component.
Definition: OISPrereqs.h:206
void clearStates(void)
Definition: OISMultiTouch.h:134
Definition: OISEffect.h:28
Definition: OISMultiTouch.h:43
void clear()
Used internally by OIS.
Definition: OISPrereqs.h:218
Definition: OISMultiTouch.h:44
Definition: OISMultiTouch.h:116
void clear()
Clear all the values.
Definition: OISMultiTouch.h:77
Axis X
X Axis component.
Definition: OISMultiTouch.h:61