aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/platform/iphone/iphone_common.h4
-rw-r--r--backends/platform/iphone/iphone_main.m5
-rw-r--r--backends/platform/iphone/iphone_video.m221
-rw-r--r--backends/platform/iphone/osys_iphone.cpp208
-rw-r--r--backends/platform/iphone/osys_iphone.h1
5 files changed, 237 insertions, 202 deletions
diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h
index 3c34af99ea..e46d1c0d96 100644
--- a/backends/platform/iphone/iphone_common.h
+++ b/backends/platform/iphone/iphone_common.h
@@ -28,7 +28,9 @@ enum InputEvent {
kInputMouseDown,
kInputMouseUp,
kInputMouseDragged,
- kInputMouseSecondToggled,
+ kInputMouseSecondDragged,
+ kInputMouseSecondDown,
+ kInputMouseSecondUp,
kInputOrientationChanged,
kInputKeyPressed,
kInputApplicationSuspended,
diff --git a/backends/platform/iphone/iphone_main.m b/backends/platform/iphone/iphone_main.m
index 90dc4c8558..a9900823ed 100644
--- a/backends/platform/iphone/iphone_main.m
+++ b/backends/platform/iphone/iphone_main.m
@@ -50,7 +50,6 @@ int main(int argc, char** argv) {
[ NSAutoreleasePool alloc ] init
];
- UIApplicationUseLegacyEvents(1);
int returnCode = UIApplicationMain(argc, argv, @"iPhoneMain", @"iPhoneMain");
[ autoreleasePool release ];
return returnCode;
@@ -86,7 +85,9 @@ int main(int argc, char** argv) {
_window = [[UIWindow alloc] initWithFrame:rect];
[_window retain];
- _view = [[iPhoneView alloc] initWithFrame: rect];
+ _view = [[iPhoneView alloc] initWithFrame: rect];
+ _view.multipleTouchEnabled = YES;
+
[_window setContentView: _view];
//[_window orderFront: self];
diff --git a/backends/platform/iphone/iphone_video.m b/backends/platform/iphone/iphone_video.m
index d8919ec2b4..016e9d4088 100644
--- a/backends/platform/iphone/iphone_video.m
+++ b/backends/platform/iphone/iphone_video.m
@@ -279,109 +279,142 @@ bool getLocalMouseCoords(CGPoint *point) {
];
}
-- (void)mouseDown:(struct __GSEvent *)event {
- //printf("mouseDown()\n");
- CGPoint point = GSEventGetLocationInWindow(event);
- point = [self convertPoint:point fromView:nil];
-
- if (!getLocalMouseCoords(&point))
- return;
-
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseDown], @"type",
- [NSNumber numberWithFloat:point.x], @"x",
- [NSNumber numberWithFloat:point.y], @"y",
- nil
- ]
- ];
-}
-- (void)touchesBegan {
- //printf("touchesBegan()\n");
-}
-
-- (void)mouseUp:(struct __GSEvent *)event {
- //printf("mouseUp()\n");
- CGPoint point = GSEventGetLocationInWindow(event);
- point = [self convertPoint:point fromView:nil];
-
- if (!getLocalMouseCoords(&point))
- return;
+- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ NSSet *allTouches = [event allTouches];
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseUp], @"type",
- [NSNumber numberWithFloat:point.x], @"x",
- [NSNumber numberWithFloat:point.y], @"y",
- nil
- ]
- ];
+ switch ([allTouches count]) {
+ case 1:
+ {
+ UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
+ CGPoint point = [touch locationInView:self];
+ //point = [self convertPoint:point fromView:nil];
+ if (!getLocalMouseCoords(&point))
+ return;
+
+ [self addEvent:
+ [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithInt:kInputMouseDown], @"type",
+ [NSNumber numberWithFloat:point.x], @"x",
+ [NSNumber numberWithFloat:point.y], @"y",
+ nil
+ ]
+ ];
+ break;
+ }
+ case 2:
+ {
+ UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
+ CGPoint point = [touch locationInView:self];
+ //point = [self convertPoint:point fromView:nil];
+ if (!getLocalMouseCoords(&point))
+ return;
+
+ [self addEvent:
+ [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithInt:kInputMouseSecondDown], @"type",
+ [NSNumber numberWithFloat:point.x], @"x",
+ [NSNumber numberWithFloat:point.y], @"y",
+ nil
+ ]
+ ];
+ break;
+ }
+ }
}
-- (void)mouseDragged:(struct __GSEvent *)event {
- //printf("mouseDragged()\n");
- CGPoint point = GSEventGetLocationInWindow(event);
- point = [self convertPoint:point fromView:nil];
-
- if (!getLocalMouseCoords(&point))
- return;
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ NSSet *allTouches = [event allTouches];
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseDragged], @"type",
- [NSNumber numberWithFloat:point.x], @"x",
- [NSNumber numberWithFloat:point.y], @"y",
- nil
- ]
- ];
+ switch ([allTouches count]) {
+ case 1:
+ {
+ UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
+ CGPoint point = [touch locationInView:self];
+ //point = [self convertPoint:point fromView:nil];
+ if (!getLocalMouseCoords(&point))
+ return;
+
+ [self addEvent:
+ [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithInt:kInputMouseDragged], @"type",
+ [NSNumber numberWithFloat:point.x], @"x",
+ [NSNumber numberWithFloat:point.y], @"y",
+ nil
+ ]
+ ];
+ break;
+ }
+ case 2:
+ {
+ UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
+ CGPoint point = [touch locationInView:self];
+ //point = [self convertPoint:point fromView:nil];
+ if (!getLocalMouseCoords(&point))
+ return;
+
+ [self addEvent:
+ [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithInt:kInputMouseSecondDragged], @"type",
+ [NSNumber numberWithFloat:point.x], @"x",
+ [NSNumber numberWithFloat:point.y], @"y",
+ nil
+ ]
+ ];
+ break;
+ }
+ }
}
-- (void)mouseEntered:(struct __GSEvent *)event {
- //printf("mouseEntered()\n");
- CGPoint point = GSEventGetLocationInWindow(event);
- point = [self convertPoint:point fromView:nil];
-
-
- if (!getLocalMouseCoords(&point))
- return;
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ NSSet *allTouches = [event allTouches];
- [self addEvent:
- [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:kInputMouseSecondToggled], @"type",
- [NSNumber numberWithFloat:point.x], @"x",
- [NSNumber numberWithFloat:point.y], @"y",
- nil
- ]
- ];
-}
-
-- (void)mouseExited:(struct __GSEvent *)event {
- //printf("mouseExited().\n");
- // [self addEvent:
- // [[NSDictionary alloc] initWithObjectsAndKeys:
- // @"mouseExited", @"type",
- // nil
- // ]
- // ];
+ switch ([allTouches count]) {
+ case 1:
+ {
+ UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
+ CGPoint point = [touch locationInView:self];
+ //point = [self convertPoint:point fromView:nil];
+ if (!getLocalMouseCoords(&point))
+ return;
+
+ [self addEvent:
+ [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithInt:kInputMouseUp], @"type",
+ [NSNumber numberWithFloat:point.x], @"x",
+ [NSNumber numberWithFloat:point.y], @"y",
+ nil
+ ]
+ ];
+ break;
+ }
+ case 2:
+ {
+ UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
+ CGPoint point = [touch locationInView:self];
+ //point = [self convertPoint:point fromView:nil];
+ if (!getLocalMouseCoords(&point))
+ return;
+
+ [self addEvent:
+ [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithInt:kInputMouseSecondUp], @"type",
+ [NSNumber numberWithFloat:point.x], @"x",
+ [NSNumber numberWithFloat:point.y], @"y",
+ nil
+ ]
+ ];
+ break;
+ }
+ }
}
-- (void)mouseMoved:(struct __GSEvent *)event
+- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
- //printf("mouseMoved()\n");
- // struct CGPoint point = GSEventGetLocationInWindow(event);
- //
- // if (!getLocalMouseCoords(&point))
- // return;
- //
- // [self addEvent:
- // [[NSDictionary alloc] initWithObjectsAndKeys:
- // [NSNumber numberWithInt:kInputMouseSecondToggled], @"type",
- // [NSNumber numberWithFloat:point.x], @"x",
- // [NSNumber numberWithFloat:point.y], @"y",
- // nil
- // ]
- // ];
+
}
- (void)handleKeyPress:(unichar)c {
@@ -412,10 +445,6 @@ bool getLocalMouseCoords(CGPoint *point) {
];
}
-- (void)view:(UIView *)view handleTapWithCount:(int)count event:(struct __GSEvent *)event fingerCount:(int)fingerCount{
- //printf("handleTapWithCount(%i, %i)\n", count, fingerCount);
-}
-
- (void)applicationSuspend {
[self addEvent:
[[NSDictionary alloc] initWithObjectsAndKeys:
diff --git a/backends/platform/iphone/osys_iphone.cpp b/backends/platform/iphone/osys_iphone.cpp
index ca32a8d3d4..3f99720b9c 100644
--- a/backends/platform/iphone/osys_iphone.cpp
+++ b/backends/platform/iphone/osys_iphone.cpp
@@ -731,20 +731,21 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) {
case kInputMouseDragged:
if (!handleEvent_mouseDragged(event, x, y))
return false;
+ break;
+ case kInputMouseSecondDragged:
+ if (!handleEvent_mouseSecondDragged(event, x, y))
+ return false;
break;
-
- case kInputMouseSecondToggled:
- _secondaryTapped = !_secondaryTapped;
- //printf("Mouse second at (%u, %u). State now %s.\n", x, y, _secondaryTapped ? "on" : "off");
- if (_secondaryTapped) {
- if (!handleEvent_secondMouseDown(event, x, y))
- return false;
- } else {
- if (!handleEvent_secondMouseUp(event, x, y))
- return false;
- }
+ case kInputMouseSecondDown:
+ _secondaryTapped = true;
+ if (!handleEvent_secondMouseDown(event, x, y))
+ return false;
break;
-
+ case kInputMouseSecondUp:
+ _secondaryTapped = false;
+ if (!handleEvent_secondMouseUp(event, x, y))
+ return false;
+ break;
case kInputOrientationChanged:
handleEvent_orientationChanged((int)xUnit);
return false;
@@ -894,101 +895,102 @@ bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y
_lastDragPosY = y;
//printf("Mouse dragged at (%u, %u)\n", x, y);
- if (_secondaryTapped) {
- if (_gestureStartX == -1 || _gestureStartY == -1) {
- return false;
- }
-
- int vecX = (x - _gestureStartX);
- int vecY = (y - _gestureStartY);
- int lengthSq = vecX * vecX + vecY * vecY;
- //printf("Lengthsq: %u\n", lengthSq);
-
- if (lengthSq > 15000) { // Long enough gesture to react upon.
- _gestureStartX = -1;
- _gestureStartY = -1;
-
- float vecLength = sqrt(lengthSq);
- float vecXNorm = vecX / vecLength;
- float vecYNorm = vecY / vecLength;
-
- //printf("Swipe vector: (%.2f, %.2f)\n", vecXNorm, vecYNorm);
-
- if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm > 0.75) {
- // Swipe down
- event.type = Common::EVENT_KEYDOWN;
- _queuedInputEvent.type = Common::EVENT_KEYUP;
-
- event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
- event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_F5;
- event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_F5;
- _needEventRestPeriod = true;
- } else if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm < -0.75) {
- // Swipe up
- _mouseClickAndDragEnabled = !_mouseClickAndDragEnabled;
- const char *dialogMsg;
- if (_mouseClickAndDragEnabled) {
- _touchpadModeEnabled = false;
- dialogMsg = "Mouse-click-and-drag mode enabled.";
- } else
- dialogMsg = "Mouse-click-and-drag mode disabled.";
- GUI::TimedMessageDialog dialog(dialogMsg, 1500);
- dialog.runModal();
- return false;
-
- } else if (vecXNorm > 0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
- // Swipe right
- _touchpadModeEnabled = !_touchpadModeEnabled;
- const char *dialogMsg;
- if (_touchpadModeEnabled)
- dialogMsg = "Touchpad mode enabled.";
- else
- dialogMsg = "Touchpad mode disabled.";
- GUI::TimedMessageDialog dialog(dialogMsg, 1500);
- dialog.runModal();
- return false;
+ int mouseNewPosX;
+ int mouseNewPosY;
+ if (_touchpadModeEnabled ) {
+ int deltaX = _lastPadX - x;
+ int deltaY = _lastPadY - y;
+ _lastPadX = x;
+ _lastPadY = y;
+
+ mouseNewPosX = (int)(_mouseX - deltaX / 0.5f);
+ mouseNewPosY = (int)(_mouseY - deltaY / 0.5f);
+
+ if (mouseNewPosX < 0)
+ mouseNewPosX = 0;
+ else if (mouseNewPosX > _screenWidth)
+ mouseNewPosX = _screenWidth;
+
+ if (mouseNewPosY < 0)
+ mouseNewPosY = 0;
+ else if (mouseNewPosY > _screenHeight)
+ mouseNewPosY = _screenHeight;
+
+ } else {
+ mouseNewPosX = x;
+ mouseNewPosY = y;
+ }
+
+ event.type = Common::EVENT_MOUSEMOVE;
+ event.mouse.x = mouseNewPosX;
+ event.mouse.y = mouseNewPosY;
+ warpMouse(mouseNewPosX, mouseNewPosY);
+
+ return true;
+}
- } else if (vecXNorm < -0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
- // Swipe left
- return false;
+bool OSystem_IPHONE::handleEvent_mouseSecondDragged(Common::Event &event, int x, int y) {
+ if (_gestureStartX == -1 || _gestureStartY == -1) {
+ return false;
+ }
+
+ int vecX = (x - _gestureStartX);
+ int vecY = (y - _gestureStartY);
+ int lengthSq = vecX * vecX + vecY * vecY;
+ //printf("Lengthsq: %u\n", lengthSq);
+
+ if (lengthSq > 15000) { // Long enough gesture to react upon.
+ _gestureStartX = -1;
+ _gestureStartY = -1;
+
+ float vecLength = sqrt(lengthSq);
+ float vecXNorm = vecX / vecLength;
+ float vecYNorm = vecY / vecLength;
+
+ //printf("Swipe vector: (%.2f, %.2f)\n", vecXNorm, vecYNorm);
+
+ if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm > 0.75) {
+ // Swipe down
+ event.type = Common::EVENT_KEYDOWN;
+ _queuedInputEvent.type = Common::EVENT_KEYUP;
+
+ event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
+ event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_F5;
+ event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_F5;
+ _needEventRestPeriod = true;
+ } else if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm < -0.75) {
+ // Swipe up
+ _mouseClickAndDragEnabled = !_mouseClickAndDragEnabled;
+ const char *dialogMsg;
+ if (_mouseClickAndDragEnabled) {
+ _touchpadModeEnabled = false;
+ dialogMsg = "Mouse-click-and-drag mode enabled.";
} else
- return false;
+ dialogMsg = "Mouse-click-and-drag mode disabled.";
+ GUI::TimedMessageDialog dialog(dialogMsg, 1500);
+ dialog.runModal();
+ return false;
+
+ } else if (vecXNorm > 0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
+ // Swipe right
+ _touchpadModeEnabled = !_touchpadModeEnabled;
+ const char *dialogMsg;
+ if (_touchpadModeEnabled)
+ dialogMsg = "Touchpad mode enabled.";
+ else
+ dialogMsg = "Touchpad mode disabled.";
+ GUI::TimedMessageDialog dialog(dialogMsg, 1500);
+ dialog.runModal();
+ return false;
+
+ } else if (vecXNorm < -0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
+ // Swipe left
+ return false;
} else
return false;
- } else {
- int mouseNewPosX;
- int mouseNewPosY;
- if (_touchpadModeEnabled ) {
- int deltaX = _lastPadX - x;
- int deltaY = _lastPadY - y;
- _lastPadX = x;
- _lastPadY = y;
-
- mouseNewPosX = (int)(_mouseX - deltaX / 0.5f);
- mouseNewPosY = (int)(_mouseY - deltaY / 0.5f);
-
- if (mouseNewPosX < 0)
- mouseNewPosX = 0;
- else if (mouseNewPosX > _screenWidth)
- mouseNewPosX = _screenWidth;
-
- if (mouseNewPosY < 0)
- mouseNewPosY = 0;
- else if (mouseNewPosY > _screenHeight)
- mouseNewPosY = _screenHeight;
-
- } else {
- mouseNewPosX = x;
- mouseNewPosY = y;
- }
-
- event.type = Common::EVENT_MOUSEMOVE;
- event.mouse.x = mouseNewPosX;
- event.mouse.y = mouseNewPosY;
- warpMouse(mouseNewPosX, mouseNewPosY);
- }
-
- return true;
+ } else
+ return false;
+
}
void OSystem_IPHONE::handleEvent_orientationChanged(int orientation) {
diff --git a/backends/platform/iphone/osys_iphone.h b/backends/platform/iphone/osys_iphone.h
index c652d06086..140133fb90 100644
--- a/backends/platform/iphone/osys_iphone.h
+++ b/backends/platform/iphone/osys_iphone.h
@@ -207,4 +207,5 @@ protected:
bool handleEvent_secondMouseUp(Common::Event &event, int x, int y);
bool handleEvent_mouseDragged(Common::Event &event, int x, int y);
+ bool handleEvent_mouseSecondDragged(Common::Event &event, int x, int y);
};