Skip to content

Commit

Permalink
iphone mouse support
Browse files Browse the repository at this point in the history
git-svn-id: http://www.verge-rpg.com/svn/verge3/trunk@361 85f9bd53-ed1e-0410-abaf-ef5a3fdb13a8
  • Loading branch information
zeromus committed Mar 1, 2009
1 parent c39196e commit 9901e19
Show file tree
Hide file tree
Showing 9 changed files with 884 additions and 328 deletions.
8 changes: 6 additions & 2 deletions iphone/GLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>

#define MAX_SIMULTANEOUS_TOUCHES 5
#include "iphone_interface.h"

@interface GLView : UIView
{
Expand All @@ -22,7 +22,11 @@
unsigned int* data;
}

- (void)displayLayer:(CALayer *)theLayer;
- (void)displayLayer:(CALayer *)theLayer;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event;
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;


@end
Expand Down
97 changes: 85 additions & 12 deletions iphone/GLView.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

@implementation GLView

const void * _CGDataProviderGetBytePointerCallback(void *info)
{
return (void*)view->data;
}

void _CGDataProviderReleaseBytePointerCallback(void *info,const void *pointer)
{
}

const void * _CGDataProviderGetBytePointerCallback(void *info)
{
return (void*)view->data;
}

void _CGDataProviderReleaseBytePointerCallback(void *info,const void *pointer)
{
}

- (void)displayLayer:(CALayer *)theLayer
{

Expand All @@ -36,13 +36,13 @@ - (void)displayLayer:(CALayer *)theLayer
callbacks.getBytesAtPosition = NULL;
callbacks.releaseInfo = NULL;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();



//CGDataProviderRef bitmapProvider = CGDataProviderCreateDirect(NULL,320*480*2,&callbacks);
//CGImageRef bitmap = CGImageCreate(320,480,5,16,320*2,colorSpace, 0, bitmapProvider, NULL, FALSE, kCGRenderingIntentDefault);
CGDataProviderRef bitmapProvider = CGDataProviderCreateDirect(NULL,320*480*4,&callbacks);
CGDataProviderRef bitmapProvider = CGDataProviderCreateDirect(NULL,320*480*4,&callbacks);
CGImageRef bitmap = CGImageCreate(320,480,8,32,320*4,colorSpace, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, bitmapProvider, NULL, FALSE, kCGRenderingIntentDefault);


Expand All @@ -59,11 +59,14 @@ - (void)displayLayer:(CALayer *)theLayer

-(id)initWithFrame:(CGRect)frame
{
int i=0;
self = [super initWithFrame:frame];
view = self;
layer = [self layer];
layer.opaque = YES;
//layer.delegate = drawDelegate;
for(i=0;i<MAX_SIMULTANEOUS_TOUCHES;i++)
iphone_mouses[i].data = NULL;
return self;
}

Expand All @@ -73,4 +76,74 @@ - (void)dealloc
[super dealloc];
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event {

NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch = (UITouch*)[enumerator nextObject];

int i;
int found = 0;
for(i=0;touch&&i<MAX_SIMULTANEOUS_TOUCHES;i++) {
//check if this mouse is already tracking a touch
if(iphone_mouses[i].data != NULL) continue;

//mouse not associated with anything right now.
//associate the mosue with this touch
found = 1;

CGPoint locationInView = [touch locationInView: self];
iphone_mouses[i].data = [touch retain];

//send press event
iphone_mouses[i].l = 1;
iphone_mouses[i].x = locationInView.x;
iphone_mouses[i].y = locationInView.y;

touch = (UITouch*)[enumerator nextObject];

}
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event {
NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch = nil;

while(touch = (UITouch*)[enumerator nextObject]) {
//search for the mouse slot associated with this touch
int i, found = NO;
for(i=0;i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
if(iphone_mouses[i].data == touch) {
//found the mouse associated with the touch
[(UITouch*)(iphone_mouses[i].data) release];
iphone_mouses[i].data = NULL;
iphone_mouses[i].l = 0;
found = YES;
}
}
}
}

- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
[self touchesEnded: touches withEvent: event];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch = nil;

while(touch = (UITouch*)[enumerator nextObject]) {
//try to find the mouse associated with this touch
int i, found = NO;
for(i=0;i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
if(iphone_mouses[i].data == touch) {
//found proper mouse
CGPoint locationInView = [touch locationInView: self];
iphone_mouses[i].x = locationInView.x;
iphone_mouses[i].y = locationInView.y;
found = YES;
}
}
}
}

@end
Loading

0 comments on commit 9901e19

Please sign in to comment.