From 1d5392d56f61165b2730e43548e972bf519c00c3 Mon Sep 17 00:00:00 2001 From: Oystein Eftevaag Date: Sat, 24 Nov 2007 21:45:39 +0000 Subject: Now always sending a mouse-moved event before a click (some engines don't update the mouse position on click events, it seems). Also added a workaround for an event not always being received when the secondary finger is lifted from the touchscreen. svn-id: r29629 --- backends/platform/iphone/iphone_common.h | 1 + backends/platform/iphone/iphone_video.h | 10 +++++++++- backends/platform/iphone/iphone_video.m | 32 ++++++++++++++++++++++++++------ backends/platform/iphone/osys_iphone.cpp | 30 ++++++++++++++++++++++-------- 4 files changed, 58 insertions(+), 15 deletions(-) (limited to 'backends/platform/iphone') diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h index 567f54800e..fec25940a2 100644 --- a/backends/platform/iphone/iphone_common.h +++ b/backends/platform/iphone/iphone_common.h @@ -43,6 +43,7 @@ void iphone_main(int argc, char *argv[]); // On the ObjC side void iPhone_updateScreen(); +void iPhone_updateScreenRect(int x1, int y1, int x2, int y2); unsigned short* iPhone_getSurface(); void iPhone_lockSurface(); void iPhone_unlockSurface(); diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h index 9a0492bad3..3ac3d6a31a 100644 --- a/backends/platform/iphone/iphone_video.h +++ b/backends/platform/iphone/iphone_video.h @@ -35,6 +35,14 @@ #import "iphone_keyboard.h" +typedef enum +{ + kUIViewSwipeUp = 1, + kUIViewSwipeDown = 2, + kUIViewSwipeLeft = 4, + kUIViewSwipeRight = 8 +} UIViewSwipeDirection; + @interface iPhoneView : UIView { CoreSurfaceBufferRef _screenSurface; @@ -57,7 +65,7 @@ - (void)initSurface; -- (void)updateScreen; +- (void)updateScreenRect:(id)rect; - (id)getEvent; diff --git a/backends/platform/iphone/iphone_video.m b/backends/platform/iphone/iphone_video.m index df15f61a6b..261d447290 100644 --- a/backends/platform/iphone/iphone_video.m +++ b/backends/platform/iphone/iphone_video.m @@ -49,7 +49,12 @@ unsigned short* iPhone_getSurface() { } void iPhone_updateScreen() { - [sharedInstance performSelectorOnMainThread:@selector(updateScreen) withObject:nil waitUntilDone: NO]; + [sharedInstance performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone: NO]; +} + +void iPhone_updateScreenRect(int x1, int y1, int x2, int y2) { + NSRect rect = NSMakeRect(x1, y1, x2, y2); + [sharedInstance performSelectorOnMainThread:@selector(updateScreenRect:) withObject: [NSValue valueWithRect:rect] waitUntilDone: NO]; } void iPhone_lockSurface() { @@ -110,6 +115,7 @@ bool getLocalMouseCoords(CGPoint *point) { sharedInstance = self; _keyboardView = nil; + //[super setTapDelegate: self]; return self; } @@ -139,8 +145,10 @@ bool getLocalMouseCoords(CGPoint *point) { // } } -- (void)updateScreen { - [sharedInstance setNeedsDisplay]; +- (void)updateScreenRect:(id)rect { + NSRect nsRect = [rect rectValue]; + CGRect cgRect = CGRectMake(nsRect.origin.x, nsRect.origin.y, nsRect.size.width, nsRect.size.height); + [sharedInstance setNeedsDisplayInRect: cgRect]; } - (void)initSurface { @@ -324,7 +332,7 @@ bool getLocalMouseCoords(CGPoint *point) { } - (void)mouseEntered:(GSEvent*)event { - printf("mouseEntered()\n"); + //printf("mouseEntered()\n"); // struct CGPoint point = GSEventGetLocationInWindow(event); // // if (!getLocalMouseCoords(&point)) @@ -341,7 +349,7 @@ bool getLocalMouseCoords(CGPoint *point) { } - (void)mouseExited:(GSEvent*)event { - printf("mouseExited().\n"); + //printf("mouseExited().\n"); // [self addEvent: // [[NSDictionary alloc] initWithObjectsAndKeys: // @"mouseExited", @"type", @@ -352,7 +360,7 @@ bool getLocalMouseCoords(CGPoint *point) { - (void)mouseMoved:(GSEvent*)event { - printf("mouseMoved()\n"); + //printf("mouseMoved()\n"); struct CGPoint point = GSEventGetLocationInWindow(event); if (!getLocalMouseCoords(&point)) @@ -379,5 +387,17 @@ bool getLocalMouseCoords(CGPoint *point) { ]; } +- (BOOL)canHandleSwipes { + return FALSE; +} + +- (int)swipe:(UIViewSwipeDirection)num withEvent:(GSEvent*)event { + //printf("swipe: %i\n", num); +} + +- (void)view:(UIView *)view handleTapWithCount:(int)count event:(GSEvent *)event fingerCount:(int)fingerCount{ + //printf("handleTapWithCount(%i, %i)\n", count, fingerCount); +} + @end diff --git a/backends/platform/iphone/osys_iphone.cpp b/backends/platform/iphone/osys_iphone.cpp index b649de87d1..5de3712387 100644 --- a/backends/platform/iphone/osys_iphone.cpp +++ b/backends/platform/iphone/osys_iphone.cpp @@ -366,6 +366,8 @@ void OSystem_IPHONE::internUpdateScreen() { } } } + + //iPhone_updateScreenRect(dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom ); } } @@ -561,19 +563,25 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) { case kInputMouseDown: //printf("Mouse down at (%u, %u)\n", x, y); + // Workaround: kInputMouseSecondToggled isn't always sent when the + // secondary finger is lifted. Need to make sure we get out of that mode. + _secondaryTapped = false; + warpMouse(x, y); + event.type = Common::EVENT_MOUSEMOVE; + event.mouse.x = _mouseX; + event.mouse.y = _mouseY; + if (_mouseClickAndDragEnabled) { - event.type = Common::EVENT_LBUTTONDOWN; - event.mouse.x = _mouseX; - event.mouse.y = _mouseY; - } else { + _queuedInputEvent.type = Common::EVENT_LBUTTONDOWN; + _queuedInputEvent.mouse.x = _mouseX; + _queuedInputEvent.mouse.y = _mouseY; + } else { _lastMouseDown = curTime; - return false; } break; case kInputMouseUp: //printf("Mouse up at (%u, %u)\n", x, y); - if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONUP; event.mouse.x = _mouseX; @@ -628,8 +636,14 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) { } else if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm < -0.75) { // Swipe up _mouseClickAndDragEnabled = !_mouseClickAndDragEnabled; - GUI::TimedMessageDialog dialog("Toggling mouse-click-and-drag mode.", 1500); + const char *dialogMsg; + if (_mouseClickAndDragEnabled) + dialogMsg = "Mouse-click-and-drag mode enabled."; + else + dialogMsg = "Mouse-click-and-drag mode disabled."; + GUI::TimedMessageDialog dialog(dialogMsg, 1500); dialog.runModal(); + } else if (vecXNorm > 0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) { // Swipe right // _secondaryTapped = !_secondaryTapped; @@ -655,7 +669,7 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) { break; case kInputMouseSecondToggled: _secondaryTapped = !_secondaryTapped; - printf("Mouse second at (%u, %u). State now %s.\n", x, y, _secondaryTapped ? "on" : "off"); + //printf("Mouse second at (%u, %u). State now %s.\n", x, y, _secondaryTapped ? "on" : "off"); if (_secondaryTapped) { _lastSecondaryDown = curTime; _gestureStartX = x; -- cgit v1.2.3