[Scummvm-cvs-logs] SF.net SVN: scummvm:[39984] scummvm/trunk/backends/platform/iphone

vinterstum at users.sourceforge.net vinterstum at users.sourceforge.net
Sat Apr 18 15:52:31 CEST 2009


Revision: 39984
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39984&view=rev
Author:   vinterstum
Date:     2009-04-18 13:52:30 +0000 (Sat, 18 Apr 2009)

Log Message:
-----------
iPhone: Updated input event system to firmware 2.x standard

Modified Paths:
--------------
    scummvm/trunk/backends/platform/iphone/iphone_common.h
    scummvm/trunk/backends/platform/iphone/iphone_main.m
    scummvm/trunk/backends/platform/iphone/iphone_video.m
    scummvm/trunk/backends/platform/iphone/osys_iphone.cpp
    scummvm/trunk/backends/platform/iphone/osys_iphone.h

Modified: scummvm/trunk/backends/platform/iphone/iphone_common.h
===================================================================
--- scummvm/trunk/backends/platform/iphone/iphone_common.h	2009-04-18 13:11:28 UTC (rev 39983)
+++ scummvm/trunk/backends/platform/iphone/iphone_common.h	2009-04-18 13:52:30 UTC (rev 39984)
@@ -28,7 +28,9 @@
 	kInputMouseDown,
 	kInputMouseUp,
 	kInputMouseDragged,
-	kInputMouseSecondToggled,
+	kInputMouseSecondDragged,
+	kInputMouseSecondDown,
+	kInputMouseSecondUp,
 	kInputOrientationChanged,
 	kInputKeyPressed,
 	kInputApplicationSuspended,

Modified: scummvm/trunk/backends/platform/iphone/iphone_main.m
===================================================================
--- scummvm/trunk/backends/platform/iphone/iphone_main.m	2009-04-18 13:11:28 UTC (rev 39983)
+++ scummvm/trunk/backends/platform/iphone/iphone_main.m	2009-04-18 13:52:30 UTC (rev 39984)
@@ -50,7 +50,6 @@
         [ NSAutoreleasePool alloc ] init
     ];
 
-    UIApplicationUseLegacyEvents(1);
     int returnCode = UIApplicationMain(argc, argv, @"iPhoneMain", @"iPhoneMain");
     [ autoreleasePool release ];
     return returnCode;
@@ -86,7 +85,9 @@
 	_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];

Modified: scummvm/trunk/backends/platform/iphone/iphone_video.m
===================================================================
--- scummvm/trunk/backends/platform/iphone/iphone_video.m	2009-04-18 13:11:28 UTC (rev 39983)
+++ scummvm/trunk/backends/platform/iphone/iphone_video.m	2009-04-18 13:52:30 UTC (rev 39984)
@@ -279,109 +279,142 @@
 	];
 }
 
-- (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)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+	NSSet *allTouches = [event allTouches];
 	
-- (void)mouseUp:(struct __GSEvent *)event {
-	//printf("mouseUp()\n");
-	CGPoint point = GSEventGetLocationInWindow(event);
-	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
-		]
-	];
+	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];
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+{
+	NSSet *allTouches = [event allTouches];
 	
-	if (!getLocalMouseCoords(&point))
-		return;
-	
-	[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];
-
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+	NSSet *allTouches = [event allTouches];
 	
-	if (!getLocalMouseCoords(&point))
-		return;
-	
-	[self addEvent:
-		[[NSDictionary alloc] initWithObjectsAndKeys:
-		 [NSNumber numberWithInt:kInputMouseSecondToggled], @"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: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)mouseExited:(struct __GSEvent *)event {
-	//printf("mouseExited().\n");
-	// [self addEvent:
-	//	[[NSDictionary alloc] initWithObjectsAndKeys:
-	//	 @"mouseExited", @"type",
-	//	 nil
-	//	]
-	// ];
-}
-
-- (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 @@
 	];
 }
 
-- (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:

Modified: scummvm/trunk/backends/platform/iphone/osys_iphone.cpp
===================================================================
--- scummvm/trunk/backends/platform/iphone/osys_iphone.cpp	2009-04-18 13:11:28 UTC (rev 39983)
+++ scummvm/trunk/backends/platform/iphone/osys_iphone.cpp	2009-04-18 13:52:30 UTC (rev 39984)
@@ -731,20 +731,21 @@
 			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 @@
 	_lastDragPosY = y;
 
 	//printf("Mouse dragged at (%u, %u)\n", x, y);
-	if (_secondaryTapped) {
-		 if (_gestureStartX == -1 || _gestureStartY == -1) {
-			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;
+}
 
-		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;
-
-			} 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) {

Modified: scummvm/trunk/backends/platform/iphone/osys_iphone.h
===================================================================
--- scummvm/trunk/backends/platform/iphone/osys_iphone.h	2009-04-18 13:11:28 UTC (rev 39983)
+++ scummvm/trunk/backends/platform/iphone/osys_iphone.h	2009-04-18 13:52:30 UTC (rev 39984)
@@ -207,4 +207,5 @@
 	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);	
 };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list