My Project: openb3dlib.mod/openb3d/src/touch.h Source File

My Project

touch.h
Go to the documentation of this file.
1 /*
2 * touch.h
3 * iminib3d
4 *
5 * Created by Simon Harrison.
6 * Copyright Si Design. All rights reserved.
7 *
8 */
9
10 #ifndef TOUCH_H
11 #define TOUCH_H
12
13 #include <iostream>
14 #include <vector>
15 using namespace std;
16
17 class Touch{
18
19 public:
20
21 //static int no_touches;
22 static vector<Touch*> touch_list; // includes active touches only
23 static vector<Touch*> all_touch_list; // includes active and 'dead' touches - i.e. recently removed and cancelled touches
24
25 float x,y;
26 float old_x,old_y;
27 int type;
28 int hit;
29
30 Touch(int xx,int yy,int old_xx,int old_yy,int touch_type){
31
32 old_x=old_xx;
33 old_y=old_yy;
34 x=xx;
35 y=yy;
36 type=touch_type;
37 if(type==1) hit=true; else hit=false;
38
39 if(type>=1 && type<=3) touch_list.push_back(this); // only add begin, stationary and move touches
40
41 all_touch_list.push_back(this); // add all touches, including dead touches end and cancel
42
43 };
44
45 static void ClearTouches(){
46
47 vector<Touch*>::iterator it;
48
49 for(it=touch_list.begin();it!=touch_list.end();it++){
50
51 Touch* touch=*it;
52 delete touch;
53
54 }
55
56 touch_list.clear();
57 all_touch_list.clear();
58
59 }
60
61 static int CountTouches(){
62
63 return touch_list.size();
64
65 }
66
67 static int CountAllTouches(){ // includes dead touches
68
69 return all_touch_list.size();
70
71 }
72
73 // returns touch type
74 // 1=began
75 // 2=moving
76 // 3=stationary
77 // 4=ended
78 // 5=cancelled
79 static int TouchType(int touch_no,int all=false){
80
81 if(!all){
82 return touch_list[touch_no]->type;
83 }else{
84 return all_touch_list[touch_no]->type;
85 }
86
87 }
88
89 static int TouchX(int touch_no,int all=false){
90
91 if(!all){
92 return touch_list[touch_no]->x;
93 }else{
94 return all_touch_list[touch_no]->x;
95 }
96
97 }
98
99 static int TouchY(int touch_no,int all=false){
100
101 if(!all){
102 return touch_list[touch_no]->y;
103 }else{
104 return all_touch_list[touch_no]->y;
105 }
106
107 }
108
109 static int TouchXPrev(int touch_no,int all=false){
110
111 if(!all){
112 return touch_list[touch_no]->old_x;
113 }else{
114 return all_touch_list[touch_no]->old_x;
115 }
116
117 }
118
119 static int TouchYPrev(int touch_no,int all=false){
120
121 if(!all){
122 return touch_list[touch_no]->old_y;
123 }else{
124 return all_touch_list[touch_no]->old_y;
125 }
126
127 }
128
129 static int TouchXSpeed(int touch_no){
130
131 return touch_list[touch_no]->x-touch_list[touch_no]->old_x;
132
133 }
134
135 static int TouchYSpeed(int touch_no){
136
137 return touch_list[touch_no]->y-touch_list[touch_no]->old_y;
138
139 }
140
141 // returns x speed of all touches since last time
142 static int TouchesXSpeed(){
143
144 int swipe_x=0;
145
146 for( unsigned int i=0;i<touch_list.size();i++){
147
148 swipe_x=swipe_x+(touch_list[i]->x-touch_list[i]->old_x);
149
150 }
151
152 return swipe_x;
153
154 }
155
156 // returns y speed of all touches since last time
157 static int TouchesYSpeed(){
158
159 int swipe_y=0;
160
161 for(unsigned int i=0;i<touch_list.size();i++){
162
163 swipe_y=swipe_y+(touch_list[i]->y-touch_list[i]->old_y);
164
165 }
166
167 return swipe_y;
168
169 }
170
171 static int TouchHit(int touch_no,int all=false){
172
173 if(!all){
174 int hit=touch_list[touch_no]->hit;
175 touch_list[touch_no]->hit=false;
176 return hit;
177 }else{
178 int hit=all_touch_list[touch_no]->hit;
179 all_touch_list[touch_no]->hit=false;
180 return hit;
181 }
182
183 }
184
185 // returns true if any touch
186 static int TouchesDown(){
187
188 return touch_list.size();
189
190 }
191
192 // returns true if any touch hits after no touches last time
193 static int TouchesHit(){
194
195 static int down=false;
196
197 if(touch_list.size()>0){
198
199 if(down==false){
200 down=true;
201 return true;
202 }
203 }
204
205 if(touch_list.size()==0){
206
207 down=false;
208 return false;
209
210 }
211
212 return false;
213
214 }
215
216 // returns true if no touches after a touch last time
217 static int TouchesRelease(){
218
219 static int down=false;
220
221 if(touch_list.size()==0){
222
223 if(down==true){
224 down=false;
225 return true;
226 }
227
228 }
229
230 if(touch_list.size()>0){
231
232 down=true;
233 return false;
234
235 }
236
237 return false;
238
239 }
240
241 };
242
243 #endif
Touch::TouchesRelease
static int TouchesRelease()
Definition: touch.h:217
Touch::old_y
float old_y
Definition: touch.h:26
Touch::Touch
Touch(int xx, int yy, int old_xx, int old_yy, int touch_type)
Definition: touch.h:30
Touch::TouchesXSpeed
static int TouchesXSpeed()
Definition: touch.h:142
Touch::TouchType
static int TouchType(int touch_no, int all=false)
Definition: touch.h:79
std
Touch::type
int type
Definition: touch.h:27
Touch::CountAllTouches
static int CountAllTouches()
Definition: touch.h:67
Touch::TouchYPrev
static int TouchYPrev(int touch_no, int all=false)
Definition: touch.h:119
Touch::CountTouches
static int CountTouches()
Definition: touch.h:61
Touch
Definition: touch.h:17
Touch::TouchX
static int TouchX(int touch_no, int all=false)
Definition: touch.h:89
Touch::TouchesYSpeed
static int TouchesYSpeed()
Definition: touch.h:157
Touch::ClearTouches
static void ClearTouches()
Definition: touch.h:45
Touch::hit
int hit
Definition: touch.h:28
Touch::TouchY
static int TouchY(int touch_no, int all=false)
Definition: touch.h:99
Touch::TouchesHit
static int TouchesHit()
Definition: touch.h:193
Touch::touch_list
static vector< Touch * > touch_list
Definition: touch.h:22
Touch::TouchXSpeed
static int TouchXSpeed(int touch_no)
Definition: touch.h:129
Touch::TouchHit
static int TouchHit(int touch_no, int all=false)
Definition: touch.h:171
Touch::y
float y
Definition: touch.h:25
Touch::TouchYSpeed
static int TouchYSpeed(int touch_no)
Definition: touch.h:135
Touch::TouchesDown
static int TouchesDown()
Definition: touch.h:186
Touch::all_touch_list
static vector< Touch * > all_touch_list
Definition: touch.h:23
Touch::TouchXPrev
static int TouchXPrev(int touch_no, int all=false)
Definition: touch.h:109