comparison src/video/uikit/SDL_uikitview.m @ 4488:6dc6a2bdd55e

Re-implemented single mouse touches on the iPhone/iPad
author Sam Lantinga <slouken@libsdl.org>
date Tue, 06 Jul 2010 22:08:19 -0700
parents 3e69e077cb95
children 06c7423f8c60
comparison
equal deleted inserted replaced
4487:ba7b2bc1f1a1 4488:6dc6a2bdd55e
62 } 62 }
63 63
64 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 64 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
65 65
66 NSEnumerator *enumerator = [touches objectEnumerator]; 66 NSEnumerator *enumerator = [touches objectEnumerator];
67 UITouch *touch =(UITouch*)[enumerator nextObject]; 67 UITouch *touch = (UITouch*)[enumerator nextObject];
68 68
69 #if FIXME_MULTITOUCH 69 #if FIXME_MULTITOUCH
70 /* associate touches with mice, so long as we have slots */ 70 /* associate touches with mice, so long as we have slots */
71 int i; 71 int i;
72 int found = 0; 72 int found = 0;
99 SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT); 99 SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT);
100 100
101 /* re-calibrate relative mouse motion */ 101 /* re-calibrate relative mouse motion */
102 SDL_GetRelativeMouseState(i, NULL, NULL); 102 SDL_GetRelativeMouseState(i, NULL, NULL);
103 103
104 /* switch back to our old mouse */
105 SDL_SelectMouse(oldMouse);
106
104 /* grab next touch */ 107 /* grab next touch */
105 touch = (UITouch*)[enumerator nextObject]; 108 touch = (UITouch*)[enumerator nextObject];
106 109 }
107 /* switch back to our old mouse */ 110 #else
108 SDL_SelectMouse(oldMouse); 111 if (touch) {
109 112 CGPoint locationInView = [touch locationInView: self];
113
114 /* send moved event */
115 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
116
117 /* send mouse down event */
118 SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
110 } 119 }
111 #endif 120 #endif
112 } 121 }
113 122
114 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 123 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
115 124
116 NSEnumerator *enumerator = [touches objectEnumerator]; 125 NSEnumerator *enumerator = [touches objectEnumerator];
117 UITouch *touch=nil; 126 UITouch *touch = (UITouch*)[enumerator nextObject];
118 127
119 #if FIXME_MULTITOUCH 128 #if FIXME_MULTITOUCH
120 while(touch = (UITouch *)[enumerator nextObject]) { 129 while(touch) {
121 /* search for the mouse slot associated with this touch */ 130 /* search for the mouse slot associated with this touch */
122 int i, found = NO; 131 int i, found = NO;
123 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { 132 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
124 if (mice[i].driverdata == touch) { 133 if (mice[i].driverdata == touch) {
125 /* found the mouse associate with the touch */ 134 /* found the mouse associate with the touch */
129 SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT); 138 SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT);
130 /* discontinue search for this touch */ 139 /* discontinue search for this touch */
131 found = YES; 140 found = YES;
132 } 141 }
133 } 142 }
143
144 /* grab next touch */
145 touch = (UITouch*)[enumerator nextObject];
146 }
147 #else
148 if (touch) {
149 /* send mouse up */
150 SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
134 } 151 }
135 #endif 152 #endif
136 } 153 }
137 154
138 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { 155 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
145 } 162 }
146 163
147 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 164 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
148 165
149 NSEnumerator *enumerator = [touches objectEnumerator]; 166 NSEnumerator *enumerator = [touches objectEnumerator];
150 UITouch *touch=nil; 167 UITouch *touch = (UITouch*)[enumerator nextObject];
151 168
152 #if FIXME_MULTITOUCH 169 #if FIXME_MULTITOUCH
153 while(touch = (UITouch *)[enumerator nextObject]) { 170 while(touch) {
154 /* try to find the mouse associated with this touch */ 171 /* try to find the mouse associated with this touch */
155 int i, found = NO; 172 int i, found = NO;
156 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { 173 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
157 if (mice[i].driverdata == touch) { 174 if (mice[i].driverdata == touch) {
158 /* found proper mouse */ 175 /* found proper mouse */
161 SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0); 178 SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
162 /* discontinue search */ 179 /* discontinue search */
163 found = YES; 180 found = YES;
164 } 181 }
165 } 182 }
183
184 /* grab next touch */
185 touch = (UITouch*)[enumerator nextObject];
186 }
187 #else
188 if (touch) {
189 CGPoint locationInView = [touch locationInView: self];
190
191 /* send moved event */
192 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
166 } 193 }
167 #endif 194 #endif
168 } 195 }
169 196
170 /* 197 /*