Added Iphone support (untested)
This commit is contained in:
parent
99ed0692e1
commit
08bce778c8
2 changed files with 112 additions and 29 deletions
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#include "SDL_stdinc.h"
|
#include "SDL_stdinc.h"
|
||||||
#include "SDL_mouse.h"
|
|
||||||
#include "SDL_mouse_c.h"
|
|
||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
|
|
||||||
#if SDL_IPHONE_MULTIPLE_MICE
|
#if SDL_IPHONE_MULTIPLE_MICE
|
||||||
|
@ -39,7 +37,13 @@
|
||||||
@interface SDL_uikitview : UIView {
|
@interface SDL_uikitview : UIView {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if FIXME_MULTITOUCH
|
||||||
SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES];
|
SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FIXED_MULTITOUCH
|
||||||
|
int touchId;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SDL_IPHONE_KEYBOARD
|
#if SDL_IPHONE_KEYBOARD
|
||||||
UITextField *textField;
|
UITextField *textField;
|
||||||
|
|
|
@ -22,8 +22,10 @@
|
||||||
|
|
||||||
#import "SDL_uikitview.h"
|
#import "SDL_uikitview.h"
|
||||||
|
|
||||||
|
#include "../../events/SDL_keyboard_c.h"
|
||||||
|
#include "../../events/SDL_mouse_c.h"
|
||||||
|
|
||||||
#if SDL_IPHONE_KEYBOARD
|
#if SDL_IPHONE_KEYBOARD
|
||||||
#import "SDL_keyboard_c.h"
|
|
||||||
#import "keyinfotable.h"
|
#import "keyinfotable.h"
|
||||||
#import "SDL_uikitappdelegate.h"
|
#import "SDL_uikitappdelegate.h"
|
||||||
#import "SDL_uikitwindow.h"
|
#import "SDL_uikitwindow.h"
|
||||||
|
@ -33,7 +35,6 @@
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
#if SDL_IPHONE_KEYBOARD
|
#if SDL_IPHONE_KEYBOARD
|
||||||
SDL_DelKeyboard(0);
|
|
||||||
[textField release];
|
[textField release];
|
||||||
#endif
|
#endif
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
@ -47,6 +48,7 @@
|
||||||
[self initializeKeyboard];
|
[self initializeKeyboard];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if FIXME_MULTITOUCH
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
|
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
|
||||||
mice[i].id = i;
|
mice[i].id = i;
|
||||||
|
@ -54,6 +56,27 @@
|
||||||
SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
|
SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
|
||||||
}
|
}
|
||||||
self.multipleTouchEnabled = YES;
|
self.multipleTouchEnabled = YES;
|
||||||
|
#endif
|
||||||
|
#if FIXED_MULTITOUCH
|
||||||
|
SDL_Touch touch;
|
||||||
|
touch.id = 0; //TODO: Should be -1?
|
||||||
|
|
||||||
|
//touch.driverdata = SDL_malloc(sizeof(EventTouchData));
|
||||||
|
//EventTouchData* data = (EventTouchData*)(touch.driverdata);
|
||||||
|
|
||||||
|
touch.x_min = 0;
|
||||||
|
touch.x_max = frame.size.width;
|
||||||
|
touch.xres = touch.x_max - touch.x_min;
|
||||||
|
touch.y_min = 0;
|
||||||
|
touch.y_max = frame.size.height;
|
||||||
|
touch.yres = touch.y_max - touch.y_min;
|
||||||
|
touch.pressure_min = 0;
|
||||||
|
touch.pressure_max = 1;
|
||||||
|
touch.pressureres = touch.pressure_max - touch.pressure_min;
|
||||||
|
|
||||||
|
|
||||||
|
touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
|
||||||
|
#endif
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
|
@ -64,6 +87,7 @@
|
||||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
NSEnumerator *enumerator = [touches objectEnumerator];
|
||||||
UITouch *touch = (UITouch*)[enumerator nextObject];
|
UITouch *touch = (UITouch*)[enumerator nextObject];
|
||||||
|
|
||||||
|
#if FIXME_MULTITOUCH
|
||||||
/* associate touches with mice, so long as we have slots */
|
/* associate touches with mice, so long as we have slots */
|
||||||
int i;
|
int i;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
@ -98,21 +122,43 @@
|
||||||
/* re-calibrate relative mouse motion */
|
/* re-calibrate relative mouse motion */
|
||||||
SDL_GetRelativeMouseState(i, NULL, NULL);
|
SDL_GetRelativeMouseState(i, NULL, NULL);
|
||||||
|
|
||||||
/* grab next touch */
|
|
||||||
touch = (UITouch*)[enumerator nextObject];
|
|
||||||
|
|
||||||
/* switch back to our old mouse */
|
/* switch back to our old mouse */
|
||||||
SDL_SelectMouse(oldMouse);
|
SDL_SelectMouse(oldMouse);
|
||||||
|
|
||||||
|
/* grab next touch */
|
||||||
|
touch = (UITouch*)[enumerator nextObject];
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (touch) {
|
||||||
|
CGPoint locationInView = [touch locationInView: self];
|
||||||
|
|
||||||
|
/* send moved event */
|
||||||
|
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
|
||||||
|
|
||||||
|
/* send mouse down event */
|
||||||
|
SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FIXED_MULTITOUCH
|
||||||
|
while(touch) {
|
||||||
|
CGPoint locationInView = [touch locationInView: self];
|
||||||
|
SDL_SendFingerDown(touchId,(int)touch,
|
||||||
|
SDL_TRUE,locationInView.x,locationInView.y,
|
||||||
|
1);
|
||||||
|
|
||||||
|
touch = (UITouch*)[enumerator nextObject];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
|
|
||||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
NSEnumerator *enumerator = [touches objectEnumerator];
|
||||||
UITouch *touch=nil;
|
UITouch *touch = (UITouch*)[enumerator nextObject];
|
||||||
|
|
||||||
while(touch = (UITouch *)[enumerator nextObject]) {
|
#if FIXME_MULTITOUCH
|
||||||
|
while(touch) {
|
||||||
/* search for the mouse slot associated with this touch */
|
/* search for the mouse slot associated with this touch */
|
||||||
int i, found = NO;
|
int i, found = NO;
|
||||||
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
|
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
|
||||||
|
@ -126,7 +172,26 @@
|
||||||
found = YES;
|
found = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* grab next touch */
|
||||||
|
touch = (UITouch*)[enumerator nextObject];
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (touch) {
|
||||||
|
/* send mouse up */
|
||||||
|
SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if FIXED_MULTITOUCH
|
||||||
|
while(touch) {
|
||||||
|
CGPoint locationInView = [touch locationInView: self];
|
||||||
|
SDL_SendFingerDown(touchId,(int)touch,
|
||||||
|
SDL_FALSE,locationInView.x,locationInView.y,
|
||||||
|
1);
|
||||||
|
|
||||||
|
touch = (UITouch*)[enumerator nextObject];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
|
@ -141,9 +206,10 @@
|
||||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
|
|
||||||
NSEnumerator *enumerator = [touches objectEnumerator];
|
NSEnumerator *enumerator = [touches objectEnumerator];
|
||||||
UITouch *touch=nil;
|
UITouch *touch = (UITouch*)[enumerator nextObject];
|
||||||
|
|
||||||
while(touch = (UITouch *)[enumerator nextObject]) {
|
#if FIXME_MULTITOUCH
|
||||||
|
while(touch) {
|
||||||
/* try to find the mouse associated with this touch */
|
/* try to find the mouse associated with this touch */
|
||||||
int i, found = NO;
|
int i, found = NO;
|
||||||
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
|
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
|
||||||
|
@ -156,7 +222,29 @@
|
||||||
found = YES;
|
found = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* grab next touch */
|
||||||
|
touch = (UITouch*)[enumerator nextObject];
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (touch) {
|
||||||
|
CGPoint locationInView = [touch locationInView: self];
|
||||||
|
|
||||||
|
/* send moved event */
|
||||||
|
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FIXED_MULTITOUCH
|
||||||
|
while(touch) {
|
||||||
|
CGPoint locationInView = [touch locationInView: self];
|
||||||
|
SDL_SendTouchMotion(touchId,(int)touch,
|
||||||
|
SDL_FALSE,locationInView.x,locationInView.y,
|
||||||
|
1);
|
||||||
|
|
||||||
|
touch = (UITouch*)[enumerator nextObject];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -190,15 +278,6 @@
|
||||||
keyboardVisible = NO;
|
keyboardVisible = NO;
|
||||||
/* add the UITextField (hidden) to our view */
|
/* add the UITextField (hidden) to our view */
|
||||||
[self addSubview: textField];
|
[self addSubview: textField];
|
||||||
|
|
||||||
/* create our SDL_Keyboard */
|
|
||||||
SDL_Keyboard keyboard;
|
|
||||||
SDL_zero(keyboard);
|
|
||||||
SDL_AddKeyboard(&keyboard, 0);
|
|
||||||
SDLKey keymap[SDL_NUM_SCANCODES];
|
|
||||||
SDL_GetDefaultKeymap(keymap);
|
|
||||||
SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reveal onscreen virtual keyboard */
|
/* reveal onscreen virtual keyboard */
|
||||||
|
@ -218,8 +297,8 @@
|
||||||
|
|
||||||
if ([string length] == 0) {
|
if ([string length] == 0) {
|
||||||
/* it wants to replace text with nothing, ie a delete */
|
/* it wants to replace text with nothing, ie a delete */
|
||||||
SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_DELETE);
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DELETE);
|
||||||
SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_DELETE);
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DELETE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* go through all the characters in the string we've been sent
|
/* go through all the characters in the string we've been sent
|
||||||
|
@ -245,14 +324,14 @@
|
||||||
|
|
||||||
if (mod & KMOD_SHIFT) {
|
if (mod & KMOD_SHIFT) {
|
||||||
/* If character uses shift, press shift down */
|
/* If character uses shift, press shift down */
|
||||||
SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
|
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
|
||||||
}
|
}
|
||||||
/* send a keydown and keyup even for the character */
|
/* send a keydown and keyup even for the character */
|
||||||
SDL_SendKeyboardKey( 0, SDL_PRESSED, code);
|
SDL_SendKeyboardKey(SDL_PRESSED, code);
|
||||||
SDL_SendKeyboardKey( 0, SDL_RELEASED, code);
|
SDL_SendKeyboardKey(SDL_RELEASED, code);
|
||||||
if (mod & KMOD_SHIFT) {
|
if (mod & KMOD_SHIFT) {
|
||||||
/* If character uses shift, press shift back up */
|
/* If character uses shift, press shift back up */
|
||||||
SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
|
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue