comparison src/video/uikit/SDL_uikitview.m @ 4661:03dcb795c583

Merged changes from the main SDL codebase
author Sam Lantinga <slouken@libsdl.org>
date Mon, 12 Jul 2010 21:09:23 -0700
parents b15e7017409b 06c7423f8c60
children 3c4e0130c9b1
comparison
equal deleted inserted replaced
4660:b15e7017409b 4661:03dcb795c583
46 46
47 #if SDL_IPHONE_KEYBOARD 47 #if SDL_IPHONE_KEYBOARD
48 [self initializeKeyboard]; 48 [self initializeKeyboard];
49 #endif 49 #endif
50 50
51 #if FIXME_MULTITOUCH
52 int i;
53 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
54 mice[i].id = i;
55 mice[i].driverdata = NULL;
56 SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
57 }
58 self.multipleTouchEnabled = YES;
59 #endif
60 #if FIXED_MULTITOUCH 51 #if FIXED_MULTITOUCH
61 SDL_Touch touch; 52 SDL_Touch touch;
62 touch.id = 0; //TODO: Should be -1? 53 touch.id = 0; //TODO: Should be -1?
63 54
64 //touch.driverdata = SDL_malloc(sizeof(EventTouchData)); 55 //touch.driverdata = SDL_malloc(sizeof(EventTouchData));
75 touch.pressureres = touch.pressure_max - touch.pressure_min; 66 touch.pressureres = touch.pressure_max - touch.pressure_min;
76 67
77 68
78 touchId = SDL_AddTouch(&touch, "IPHONE SCREEN"); 69 touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
79 #endif 70 #endif
80 71
81 return self; 72 return self;
82 73
83 } 74 }
84 75
85 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 76 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
86 77
87 NSEnumerator *enumerator = [touches objectEnumerator]; 78 NSEnumerator *enumerator = [touches objectEnumerator];
88 UITouch *touch = (UITouch*)[enumerator nextObject]; 79 UITouch *touch = (UITouch*)[enumerator nextObject];
89 80
90 #if FIXME_MULTITOUCH
91 /* associate touches with mice, so long as we have slots */
92 int i;
93 int found = 0;
94 for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) {
95
96 /* check if this mouse is already tracking a touch */
97 if (mice[i].driverdata != NULL) {
98 continue;
99 }
100 /*
101 mouse not associated with anything right now,
102 associate the touch with this mouse
103 */
104 found = 1;
105
106 /* save old mouse so we can switch back */
107 int oldMouse = SDL_SelectMouse(-1);
108
109 /* select this slot's mouse */
110 SDL_SelectMouse(i);
111 CGPoint locationInView = [touch locationInView: self];
112
113 /* set driver data to touch object, we'll use touch object later */
114 mice[i].driverdata = [touch retain];
115
116 /* send moved event */
117 SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
118
119 /* send mouse down event */
120 SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT);
121
122 /* re-calibrate relative mouse motion */
123 SDL_GetRelativeMouseState(i, NULL, NULL);
124
125 /* switch back to our old mouse */
126 SDL_SelectMouse(oldMouse);
127
128 /* grab next touch */
129 touch = (UITouch*)[enumerator nextObject];
130 }
131 #else
132 if (touch) { 81 if (touch) {
133 CGPoint locationInView = [touch locationInView: self]; 82 CGPoint locationInView = [touch locationInView: self];
134 83
135 /* send moved event */ 84 /* send moved event */
136 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); 85 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
137 86
138 /* send mouse down event */ 87 /* send mouse down event */
139 SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); 88 SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
140 } 89 }
141 #endif
142 90
143 #if FIXED_MULTITOUCH 91 #if FIXED_MULTITOUCH
144 while(touch) { 92 while(touch) {
145 CGPoint locationInView = [touch locationInView: self]; 93 CGPoint locationInView = [touch locationInView: self];
146 SDL_SendFingerDown(touchId,(int)touch, 94 SDL_SendFingerDown(touchId,(int)touch,
155 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 103 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
156 104
157 NSEnumerator *enumerator = [touches objectEnumerator]; 105 NSEnumerator *enumerator = [touches objectEnumerator];
158 UITouch *touch = (UITouch*)[enumerator nextObject]; 106 UITouch *touch = (UITouch*)[enumerator nextObject];
159 107
160 #if FIXME_MULTITOUCH
161 while(touch) {
162 /* search for the mouse slot associated with this touch */
163 int i, found = NO;
164 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
165 if (mice[i].driverdata == touch) {
166 /* found the mouse associate with the touch */
167 [(UITouch*)(mice[i].driverdata) release];
168 mice[i].driverdata = NULL;
169 /* send mouse up */
170 SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT);
171 /* discontinue search for this touch */
172 found = YES;
173 }
174 }
175
176 /* grab next touch */
177 touch = (UITouch*)[enumerator nextObject];
178 }
179 #else
180 if (touch) { 108 if (touch) {
181 /* send mouse up */ 109 /* send mouse up */
182 SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); 110 SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
183 } 111 }
184 #endif 112
185 #if FIXED_MULTITOUCH 113 #if FIXED_MULTITOUCH
186 while(touch) { 114 while(touch) {
187 CGPoint locationInView = [touch locationInView: self]; 115 CGPoint locationInView = [touch locationInView: self];
188 SDL_SendFingerDown(touchId,(int)touch, 116 SDL_SendFingerDown(touchId,(int)touch,
189 SDL_FALSE,locationInView.x,locationInView.y, 117 SDL_FALSE,locationInView.x,locationInView.y,
206 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 134 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
207 135
208 NSEnumerator *enumerator = [touches objectEnumerator]; 136 NSEnumerator *enumerator = [touches objectEnumerator];
209 UITouch *touch = (UITouch*)[enumerator nextObject]; 137 UITouch *touch = (UITouch*)[enumerator nextObject];
210 138
211 #if FIXME_MULTITOUCH
212 while(touch) {
213 /* try to find the mouse associated with this touch */
214 int i, found = NO;
215 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
216 if (mice[i].driverdata == touch) {
217 /* found proper mouse */
218 CGPoint locationInView = [touch locationInView: self];
219 /* send moved event */
220 SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
221 /* discontinue search */
222 found = YES;
223 }
224 }
225
226 /* grab next touch */
227 touch = (UITouch*)[enumerator nextObject];
228 }
229 #else
230 if (touch) { 139 if (touch) {
231 CGPoint locationInView = [touch locationInView: self]; 140 CGPoint locationInView = [touch locationInView: self];
232 141
233 /* send moved event */ 142 /* send moved event */
234 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); 143 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
235 } 144 }
236 #endif
237 145
238 #if FIXED_MULTITOUCH 146 #if FIXED_MULTITOUCH
239 while(touch) { 147 while(touch) {
240 CGPoint locationInView = [touch locationInView: self]; 148 CGPoint locationInView = [touch locationInView: self];
241 SDL_SendTouchMotion(touchId,(int)touch, 149 SDL_SendTouchMotion(touchId,(int)touch,