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. gsoc2008_iphone
authorHolmes Futrell <hfutrell@umail.ucsb.edu>
Thu, 17 Jul 2008 22:43:09 +0000
branchgsoc2008_iphone
changeset 235307acabba25d9
parent 2352 1ecbeff9eb4c
child 2354 2e4fea4a4416
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.
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/uikit/SDL_uikitview.h	Thu Jul 17 22:43:09 2008 +0000
     1.3 @@ -0,0 +1,26 @@
     1.4 +//
     1.5 +//  SDL_uikitview.h
     1.6 +//  iPodSDL
     1.7 +//
     1.8 +//  Created by Holmes Futrell on 6/23/08.
     1.9 +//  Copyright 2008 __MyCompanyName__. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import <UIKit/UIKit.h>
    1.13 +#include "SDL_stdinc.h"
    1.14 +#include "SDL_mouse.h"
    1.15 +#include "SDL_mouse_c.h"
    1.16 +#include "SDL_events.h"
    1.17 +
    1.18 +#define MAX_SIMULTANEOUS_TOUCHES 5
    1.19 +
    1.20 +@interface SDL_uikitview : UIView {
    1.21 +		
    1.22 +	SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES];
    1.23 +	
    1.24 +}
    1.25 +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
    1.26 +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
    1.27 +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
    1.28 +
    1.29 +@end
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/video/uikit/SDL_uikitview.m	Thu Jul 17 22:43:09 2008 +0000
     2.3 @@ -0,0 +1,108 @@
     2.4 +//
     2.5 +//  SDL_uikitview.m
     2.6 +//  iPodSDL
     2.7 +//
     2.8 +//  Created by Holmes Futrell on 6/23/08.
     2.9 +//  Copyright 2008 __MyCompanyName__. All rights reserved.
    2.10 +//
    2.11 +
    2.12 +#import "SDL_uikitview.h"
    2.13 +
    2.14 +@implementation SDL_uikitview
    2.15 +
    2.16 +- (void)dealloc {
    2.17 +	[super dealloc];
    2.18 +}
    2.19 +
    2.20 +- (id)initWithFrame:(CGRect)frame {
    2.21 +
    2.22 +	self = [super initWithFrame: frame];
    2.23 +	
    2.24 +	int i;
    2.25 +	for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
    2.26 +		mice[i].driverdata = NULL;
    2.27 +		SDL_AddMouse(&(mice[i]), i);
    2.28 +	}
    2.29 +	self.multipleTouchEnabled = YES;
    2.30 +		
    2.31 +	return self;
    2.32 +
    2.33 +}
    2.34 +
    2.35 +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    2.36 +
    2.37 +	NSEnumerator *enumerator = [touches objectEnumerator];
    2.38 +	UITouch *touch=(UITouch*)[enumerator nextObject];
    2.39 +	
    2.40 +	// associate touches with mice, so long as we have slots
    2.41 +	int i;
    2.42 +	int found = 0;
    2.43 +	for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) {
    2.44 +	
    2.45 +		// check if this mouse is already tracking a touch
    2.46 +		if (mice[i].driverdata != NULL) {
    2.47 +			continue;
    2.48 +		}
    2.49 +		
    2.50 +		found = 1;
    2.51 +		
    2.52 +		int oldMouse = SDL_SelectMouse(-1);
    2.53 +		SDL_SelectMouse(i);
    2.54 +		CGPoint locationInView = [touch locationInView: self];
    2.55 +		mice[i].driverdata = [touch retain];
    2.56 +		SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y);
    2.57 +		SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT);
    2.58 +		SDL_GetRelativeMouseState(NULL, NULL);
    2.59 +		touch = (UITouch*)[enumerator nextObject]; 
    2.60 +		
    2.61 +		SDL_SelectMouse(oldMouse);
    2.62 +		
    2.63 +	}	
    2.64 +}
    2.65 +
    2.66 +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    2.67 +	
    2.68 +	NSEnumerator *enumerator = [touches objectEnumerator];
    2.69 +	UITouch *touch=nil;
    2.70 +	
    2.71 +	while(touch = (UITouch *)[enumerator nextObject]) {
    2.72 +		int i, found = NO;
    2.73 +		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
    2.74 +			if (mice[i].driverdata == touch) {
    2.75 +				[(UITouch*)(mice[i].driverdata) release];
    2.76 +				mice[i].driverdata = NULL;
    2.77 +				SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT);
    2.78 +
    2.79 +				found = YES;
    2.80 +			}
    2.81 +		}
    2.82 +	}
    2.83 +}
    2.84 +
    2.85 +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    2.86 +	/*
    2.87 +		this can happen if the user puts more than 5 touches on the screen
    2.88 +		at once, or perhaps in other circumstances.  Usually all active
    2.89 +		touches are canceled.
    2.90 +	*/
    2.91 +	[self touchesEnded: touches withEvent: event];
    2.92 +}
    2.93 +
    2.94 +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    2.95 +	
    2.96 +	NSEnumerator *enumerator = [touches objectEnumerator];
    2.97 +	UITouch *touch=nil;
    2.98 +	
    2.99 +	while(touch = (UITouch *)[enumerator nextObject]) {
   2.100 +		int i, found = NO;
   2.101 +		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
   2.102 +			if (mice[i].driverdata == touch) {
   2.103 +				CGPoint locationInView = [touch locationInView: self];
   2.104 +				SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y);
   2.105 +				found = YES;
   2.106 +			}
   2.107 +		}
   2.108 +	}
   2.109 +}
   2.110 +
   2.111 +@end