comparison src/video/uikit/SDL_uikitview.m @ 2353:07acabba25d9 gsoc2008_iphone

SDL_uikitview is just a generic view class which SDL_uikitopenglview inherits from. The functionality found in this class relates to (right now) mouse/touch input support. The reason for putting it here is that if someone wanted to write a render driver for iPhone based around CoreGraphics rather than OpenGL ES, they could make their Core Graphics view inherit from this class as well.
author Holmes Futrell <hfutrell@umail.ucsb.edu>
date Thu, 17 Jul 2008 22:43:09 +0000
parents
children e9a1eed243c9
comparison
equal deleted inserted replaced
2352:1ecbeff9eb4c 2353:07acabba25d9
1 //
2 // SDL_uikitview.m
3 // iPodSDL
4 //
5 // Created by Holmes Futrell on 6/23/08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "SDL_uikitview.h"
10
11 @implementation SDL_uikitview
12
13 - (void)dealloc {
14 [super dealloc];
15 }
16
17 - (id)initWithFrame:(CGRect)frame {
18
19 self = [super initWithFrame: frame];
20
21 int i;
22 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
23 mice[i].driverdata = NULL;
24 SDL_AddMouse(&(mice[i]), i);
25 }
26 self.multipleTouchEnabled = YES;
27
28 return self;
29
30 }
31
32 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
33
34 NSEnumerator *enumerator = [touches objectEnumerator];
35 UITouch *touch=(UITouch*)[enumerator nextObject];
36
37 // associate touches with mice, so long as we have slots
38 int i;
39 int found = 0;
40 for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) {
41
42 // check if this mouse is already tracking a touch
43 if (mice[i].driverdata != NULL) {
44 continue;
45 }
46
47 found = 1;
48
49 int oldMouse = SDL_SelectMouse(-1);
50 SDL_SelectMouse(i);
51 CGPoint locationInView = [touch locationInView: self];
52 mice[i].driverdata = [touch retain];
53 SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y);
54 SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT);
55 SDL_GetRelativeMouseState(NULL, NULL);
56 touch = (UITouch*)[enumerator nextObject];
57
58 SDL_SelectMouse(oldMouse);
59
60 }
61 }
62
63 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
64
65 NSEnumerator *enumerator = [touches objectEnumerator];
66 UITouch *touch=nil;
67
68 while(touch = (UITouch *)[enumerator nextObject]) {
69 int i, found = NO;
70 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
71 if (mice[i].driverdata == touch) {
72 [(UITouch*)(mice[i].driverdata) release];
73 mice[i].driverdata = NULL;
74 SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT);
75
76 found = YES;
77 }
78 }
79 }
80 }
81
82 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
83 /*
84 this can happen if the user puts more than 5 touches on the screen
85 at once, or perhaps in other circumstances. Usually all active
86 touches are canceled.
87 */
88 [self touchesEnded: touches withEvent: event];
89 }
90
91 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
92
93 NSEnumerator *enumerator = [touches objectEnumerator];
94 UITouch *touch=nil;
95
96 while(touch = (UITouch *)[enumerator nextObject]) {
97 int i, found = NO;
98 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
99 if (mice[i].driverdata == touch) {
100 CGPoint locationInView = [touch locationInView: self];
101 SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y);
102 found = YES;
103 }
104 }
105 }
106 }
107
108 @end