cocoaTouch/SDLOverrides/SDL_uikitview.m
changeset 2724 601158aaa201
parent 2714 c85ffe57d971
child 2725 89908847b155
equal deleted inserted replaced
2723:eaa6ac1e95ea 2724:601158aaa201
    63         mice[i].id = i;
    63         mice[i].id = i;
    64 		mice[i].driverdata = NULL;
    64 		mice[i].driverdata = NULL;
    65 		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
    65 		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
    66 	}
    66 	}
    67 
    67 
       
    68 	self.multipleTouchEnabled = YES;
       
    69 
       
    70 	// custom code
    68 	attackButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 480, 260,50)];
    71 	attackButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 480, 260,50)];
    69 	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
    72 	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
    70 	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateHighlighted];
    73 	[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateHighlighted];
    71 	[attackButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchDown];
    74 	[attackButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchDown];
    72 	[attackButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
    75 	[attackButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
    75 	menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)];
    78 	menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)];
    76 	[menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
    79 	[menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
    77 	[menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    80 	[menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    78 	[self addSubview:menuButton];
    81 	[self addSubview:menuButton];
    79 
    82 
    80 	self.multipleTouchEnabled = YES;
       
    81 
    83 
    82 	return self;
    84 	return self;
    83 }
    85 }
    84 
    86 
    85 #pragma mark -
    87 #pragma mark -
   164 	UITouch *touch = [touches anyObject];
   166 	UITouch *touch = [touches anyObject];
   165 	gestureStartPoint = [touch locationInView:self];
   167 	gestureStartPoint = [touch locationInView:self];
   166 
   168 
   167 	// one tap - single click
   169 	// one tap - single click
   168 	if (1 == [touch tapCount] ) {
   170 	if (1 == [touch tapCount] ) {
   169 		//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, gestureStartPoint.x, gestureStartPoint.y);
   171 		CGFloat oldX = gestureStartPoint.x;
       
   172 		gestureStartPoint.x = gestureStartPoint.y;
       
   173 		gestureStartPoint.y = 320 - oldX;
       
   174 
       
   175 		SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, gestureStartPoint.x, gestureStartPoint.y);
   170 		HW_click();
   176 		HW_click();
   171 	}
   177 	}
   172 	
   178 	
   173 	// two taps - right click
   179 	// two taps - right click
   174 	if (2 == [touch tapCount] ) {
   180 	if (2 == [touch tapCount] ) {
   189 	}
   195 	}
   190 }
   196 }
   191 
   197 
   192 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   198 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   193 	initialDistance = 0;
   199 	initialDistance = 0;
   194 //	NSLog(@"touches ended, sigh");
       
   195 	
   200 	
   196 	HW_allKeysUp();
   201 	HW_allKeysUp();
   197 	/*NSEnumerator *enumerator = [touches objectEnumerator];
   202 	/*NSEnumerator *enumerator = [touches objectEnumerator];
   198 	UITouch *touch=nil;
   203 	UITouch *touch=nil;
   199 	
   204 	
   225 
   230 
   226 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   231 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   227 	UITouch *touch = [touches anyObject];
   232 	UITouch *touch = [touches anyObject];
   228 	CGPoint currentPosition = [touch locationInView:self];
   233 	CGPoint currentPosition = [touch locationInView:self];
   229 	
   234 	
   230 	CGFloat Xdiff = gestureStartPoint.x - currentPosition.x;
   235 	// remember that we have x and y inverted
   231 	CGFloat Ydiff = gestureStartPoint.y - currentPosition.y;
   236 	CGFloat Xdiff = gestureStartPoint.y - currentPosition.y;
       
   237 	CGFloat Ydiff = gestureStartPoint.x - currentPosition.x;
   232 	CGFloat deltaX = fabsf(Xdiff);
   238 	CGFloat deltaX = fabsf(Xdiff);
   233 	CGFloat deltaY = fabsf(Ydiff);
   239 	CGFloat deltaY = fabsf(Ydiff);
   234     
   240     
   235 	if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
   241 	if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
   236 		NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x);
   242 		NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x);
   237 		if (Xdiff > 0) HW_walkLeft();
   243 		if (Xdiff > 0) HW_walkLeft();
   238 		else HW_walkRight();
   244 		else HW_walkRight();
   239 	}
   245 	} else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
   240 	else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
       
   241 		NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
   246 		NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
   242 		if (Ydiff > 0) HW_aimUp();
   247 		if (Ydiff > 0) HW_aimUp();
   243 		else HW_aimDown();
   248 		else HW_aimDown();
   244 	}
   249 	}
   245 	
   250