[Scummvm-cvs-logs] SF.net SVN: scummvm:[33517] scummvm/branches/branch-0-12-0/backends/ platform/iphone

vinterstum at users.sourceforge.net vinterstum at users.sourceforge.net
Sat Aug 2 11:24:11 CEST 2008


Revision: 33517
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33517&view=rev
Author:   vinterstum
Date:     2008-08-02 09:24:10 +0000 (Sat, 02 Aug 2008)

Log Message:
-----------
iPhone: Split up the bloated pollEvent() into new functions, and fixed some input issues

Modified Paths:
--------------
    scummvm/branches/branch-0-12-0/backends/platform/iphone/iphone_video.m
    scummvm/branches/branch-0-12-0/backends/platform/iphone/osys_iphone.cpp
    scummvm/branches/branch-0-12-0/backends/platform/iphone/osys_iphone.h

Modified: scummvm/branches/branch-0-12-0/backends/platform/iphone/iphone_video.m
===================================================================
--- scummvm/branches/branch-0-12-0/backends/platform/iphone/iphone_video.m	2008-08-02 09:03:22 UTC (rev 33516)
+++ scummvm/branches/branch-0-12-0/backends/platform/iphone/iphone_video.m	2008-08-02 09:24:10 UTC (rev 33517)
@@ -201,10 +201,13 @@
 		[screenLayer setFrame: _screenRect];
 	} else {
 		float ratio = (float)_height / (float)_width;
-		_screenRect = CGRectMake(0, 0, _fullWidth, _fullWidth * ratio);
+		int height = _fullWidth * ratio;
+		//printf("Making rect (%u, %u)\n", _fullWidth, height);
+		_screenRect = CGRectMake(0, 0, _fullWidth - 1, height - 1);
 		[screenLayer setFrame: _screenRect];
 
-		CGRect keyFrame = CGRectMake(0.0f, _screenRect.size.height, _fullWidth, _fullHeight - _screenRect.size.height);
+		//CGRect keyFrame = CGRectMake(0.0f, _screenRect.size.height, _fullWidth, _fullHeight - _screenRect.size.height);
+		CGRect keyFrame = CGRectMake(0.0f, 0.0f, 0.0f, 0.0f);
 		if (_keyboardView == nil) {
 			_keyboardView = [[SoftKeyboard alloc] initWithFrame:keyFrame];
 			[_keyboardView setInputDelegate:self];
@@ -246,9 +249,6 @@
 	[self lock];
 
 	id event = [_events objectAtIndex: 0];
-	if (event == nil) {
-		return nil;
-	}
 
 	[_events removeObjectAtIndex: 0];
 	[self unlock];

Modified: scummvm/branches/branch-0-12-0/backends/platform/iphone/osys_iphone.cpp
===================================================================
--- scummvm/branches/branch-0-12-0/backends/platform/iphone/osys_iphone.cpp	2008-08-02 09:03:22 UTC (rev 33516)
+++ scummvm/branches/branch-0-12-0/backends/platform/iphone/osys_iphone.cpp	2008-08-02 09:24:10 UTC (rev 33517)
@@ -65,7 +65,8 @@
 	_secondaryTapped(false), _lastSecondaryTap(0), _screenOrientation(kScreenOrientationFlippedLandscape),
 	_needEventRestPeriod(false), _mouseClickAndDragEnabled(false), _touchpadModeEnabled(false),
 	_gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false),
-	_mouseDirty(false), _timeSuspended(0)
+	_mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1)
+	
 {
 	_queuedInputEvent.type = (Common::EventType)0;
 	_lastDrawnMouseRect = Common::Rect(0, 0, 0, 0);
@@ -684,371 +685,438 @@
 
 		switch ((InputEvent)eventType) {
 			case kInputMouseDown:
-				//printf("Mouse down at (%u, %u)\n", x, y);
+				if (!handleEvent_mouseDown(event, x, y))
+					return false;
+				break;
 
-				// Workaround: kInputMouseSecondToggled isn't always sent when the
-				// secondary finger is lifted. Need to make sure we get out of that mode.
-				_secondaryTapped = false;
+			case kInputMouseUp:
+			if (!handleEvent_mouseUp(event, x, y))
+				return false;			
+				break;
 
-				if (_touchpadModeEnabled) {
-					_lastPadX = x;
-					_lastPadY = y;
-				} else
-					warpMouse(x, y);
+			case kInputMouseDragged:
+				if (!handleEvent_mouseDragged(event, x, y))
+					return false;
+				break;
 
-				// 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;
-					return true;
+			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 {
-					_lastMouseDown = curTime;
+					if (!handleEvent_secondMouseUp(event, x, y))
+						return false;
 				}
+				break;
+
+			case kInputOrientationChanged:
+				handleEvent_orientationChanged((int)xUnit);	
 				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;
-					event.mouse.y = _mouseY;
-				} else {
-					if (curTime - _lastMouseDown < 250) {
-						event.type = Common::EVENT_LBUTTONDOWN;
-						event.mouse.x = _mouseX;
-						event.mouse.y = _mouseY;
 
-						_queuedInputEvent.type = Common::EVENT_LBUTTONUP;
-						_queuedInputEvent.mouse.x = _mouseX;
-						_queuedInputEvent.mouse.y = _mouseY;
-						_lastMouseTap = curTime;
-						_needEventRestPeriod = true;
-					} else
-						return false;
-				}
+			case kInputApplicationSuspended:
+				suspendLoop();
+				return false;
+				break;
 
+			case kInputKeyPressed:
+				handleEvent_keyPressed(event, (int)xUnit);
 				break;
-			case kInputMouseDragged:
-				//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);
+			case kInputSwipe:
+				if (!handleEvent_swipe(event, (int)xUnit))
+					return false;
+				break;
 
-					if (lengthSq > 15000) { // Long enough gesture to react upon.
-						_gestureStartX = -1;
-						_gestureStartY = -1;
+			default:
+				break;
+		}
 
-						float vecLength = sqrt(lengthSq);
-						float vecXNorm = vecX / vecLength;
-						float vecYNorm = vecY / vecLength;
+		return true;
+	}
+	return false;
+}
 
-						//printf("Swipe vector: (%.2f, %.2f)\n", vecXNorm, vecYNorm);
+bool OSystem_IPHONE::handleEvent_mouseDown(Common::Event &event, int x, int y) {
+	printf("Mouse down at (%u, %u)\n", x, y);
 
-						if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm > 0.75) {
-							// Swipe down
-							event.type = Common::EVENT_KEYDOWN;
-							_queuedInputEvent.type = Common::EVENT_KEYUP;
+	// Workaround: kInputMouseSecondToggled isn't always sent when the
+	// secondary finger is lifted. Need to make sure we get out of that mode.
+	_secondaryTapped = false;
 
-							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)
-								dialogMsg = "Mouse-click-and-drag mode enabled.";
-							else
-								dialogMsg = "Mouse-click-and-drag mode disabled.";
-							GUI::TimedMessageDialog dialog(dialogMsg, 1500);
-							dialog.runModal();
-							return false;
+	if (_touchpadModeEnabled) {
+		_lastPadX = x;
+		_lastPadY = y;
+	} else
+		warpMouse(x, y);
 
-						} 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;
+	if (_mouseClickAndDragEnabled) {
+		event.type = Common::EVENT_LBUTTONDOWN;
+		event.mouse.x = _mouseX;
+		event.mouse.y = _mouseY;
+		return true;
+	} else {
+		_lastMouseDown = getMillis();
+	}
+	return false;	
+}
 
-						} else if (vecXNorm < -0.75 && vecYNorm >  -0.5 && vecYNorm < 0.5) {
-							// Swipe left
-							return false;
-						} else
-							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;
+bool OSystem_IPHONE::handleEvent_mouseUp(Common::Event &event, int x, int y) {
+	//printf("Mouse up at (%u, %u)\n", x, y);
+	
+	if (_secondaryTapped) {
+		_secondaryTapped = false;
+		if (!handleEvent_secondMouseUp(event, x, y))
+			return false;
+	}
+	else if (_mouseClickAndDragEnabled) {
+		event.type = Common::EVENT_LBUTTONUP;
+		event.mouse.x = _mouseX;
+		event.mouse.y = _mouseY;
+	} else {
+		if (getMillis() - _lastMouseDown < 250) {
+			event.type = Common::EVENT_LBUTTONDOWN;
+			event.mouse.x = _mouseX;
+			event.mouse.y = _mouseY;
 
-						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);
-				}
-				break;
-			case kInputMouseSecondToggled:
-				_secondaryTapped = !_secondaryTapped;
-				//printf("Mouse second at (%u, %u). State now %s.\n", x, y, _secondaryTapped ? "on" : "off");
-				if (_secondaryTapped) {
-					_lastSecondaryDown = curTime;
-					_gestureStartX = x;
-					_gestureStartY = y;
-					if (_mouseClickAndDragEnabled) {
-						event.type = Common::EVENT_LBUTTONUP;
-						event.mouse.x = _mouseX;
-						event.mouse.y = _mouseY;
+			_queuedInputEvent.type = Common::EVENT_LBUTTONUP;
+			_queuedInputEvent.mouse.x = _mouseX;
+			_queuedInputEvent.mouse.y = _mouseY;
+			_lastMouseTap = getMillis();
+			_needEventRestPeriod = true;
+		} else
+			return false;
+	}
+	
+	return true;
+}
 
-						_queuedInputEvent.type = Common::EVENT_RBUTTONDOWN;
-						_queuedInputEvent.mouse.x = _mouseX;
-						_queuedInputEvent.mouse.y = _mouseY;
-					}
-					else
-						return false;
-				} else {
-					if (curTime - _lastSecondaryDown < 400 ) {
-						if (curTime - _lastSecondaryTap < 400 && !_overlayVisible) {
-							event.type = Common::EVENT_KEYDOWN;
-							_queuedInputEvent.type = Common::EVENT_KEYUP;
+bool OSystem_IPHONE::handleEvent_secondMouseDown(Common::Event &event, int x, int y) {
+	_lastSecondaryDown = getMillis();
+	_gestureStartX = x;
+	_gestureStartY = y;
 
-							event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
-							event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_ESCAPE;
-							event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_ESCAPE;
-							_needEventRestPeriod = true;
-							_lastSecondaryTap = 0;
-						} else if (!_mouseClickAndDragEnabled) {
-							event.type = Common::EVENT_RBUTTONDOWN;
-							event.mouse.x = _mouseX;
-							event.mouse.y = _mouseY;
-							_queuedInputEvent.type = Common::EVENT_RBUTTONUP;
-							_queuedInputEvent.mouse.x = _mouseX;
-							_queuedInputEvent.mouse.y = _mouseY;
-							_lastSecondaryTap = curTime;
-							_needEventRestPeriod = true;
-						}
-					}
-					if (_mouseClickAndDragEnabled) {
-						event.type = Common::EVENT_RBUTTONUP;
-						event.mouse.x = _mouseX;
-						event.mouse.y = _mouseY;
-					}
-				}
-				break;
-			case kInputOrientationChanged:
-				//printf("Orientation: %i", (int)xUnit);
+	if (_mouseClickAndDragEnabled) {
+		event.type = Common::EVENT_LBUTTONUP;
+		event.mouse.x = _mouseX;
+		event.mouse.y = _mouseY;
 
-				ScreenOrientation newOrientation;
-				switch ((int)xUnit) {
-					case 1:
-						newOrientation = kScreenOrientationPortrait;
-						break;
-					case 3:
-						newOrientation = kScreenOrientationLandscape;
-						break;
-					case 4:
-						newOrientation = kScreenOrientationFlippedLandscape;
-						break;
-					default:
-						return false;
-				}
+		_queuedInputEvent.type = Common::EVENT_RBUTTONDOWN;
+		_queuedInputEvent.mouse.x = _mouseX;
+		_queuedInputEvent.mouse.y = _mouseY;
+	}
+	else
+		return false;
 
+	return true;
+}
 
-				if (_screenOrientation != newOrientation) {
-					_screenOrientation = newOrientation;
-					if (_screenOrientation != kScreenOrientationPortrait)
-						iPhone_initSurface(_screenHeight, _screenWidth, true);
-					else
-						iPhone_initSurface(_screenWidth, _screenHeight, false);
+bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int y) {
+	int curTime = getMillis();
 
-					dirtyFullScreen();
-					updateScreen();
-				}
-				break;
+	if (curTime - _lastSecondaryDown < 400 ) {
+		//printf("Right tap!\n");
+		if (curTime - _lastSecondaryTap < 400 && !_overlayVisible) {
+			//printf("Right escape!\n");
+			event.type = Common::EVENT_KEYDOWN;
+			_queuedInputEvent.type = Common::EVENT_KEYUP;
 
-			case kInputApplicationSuspended:
-				suspendLoop();
-				break;
+			event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
+			event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_ESCAPE;
+			event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_ESCAPE;
+			_needEventRestPeriod = true;
+			_lastSecondaryTap = 0;
+		} else if (!_mouseClickAndDragEnabled) {
+			//printf("Rightclick!\n");
+			event.type = Common::EVENT_RBUTTONDOWN;
+			event.mouse.x = _mouseX;
+			event.mouse.y = _mouseY;
+			_queuedInputEvent.type = Common::EVENT_RBUTTONUP;
+			_queuedInputEvent.mouse.x = _mouseX;
+			_queuedInputEvent.mouse.y = _mouseY;
+			_lastSecondaryTap = curTime;
+			_needEventRestPeriod = true;
+		} else {
+			//printf("Right nothing!\n");
+			return false;
+		}
+	}
+	if (_mouseClickAndDragEnabled) {
+		event.type = Common::EVENT_RBUTTONUP;
+		event.mouse.x = _mouseX;
+		event.mouse.y = _mouseY;
+	}
+	
+	return true;	
+}
 
-			case kInputKeyPressed: {
-				int keyPressed = (int)xUnit;
-				int ascii = keyPressed;
-				//printf("key: %i\n", keyPressed);
+bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y) {
+	if (_lastDragPosX == x && _lastDragPosY == y)
+		return false;
+		
+	_lastDragPosX = x;
+	_lastDragPosY = y;
 
-				// We remap some of the iPhone keyboard keys.
-				// The first ten here are the row of symbols below the numeric keys.
-				switch (keyPressed) {
-					case 45:
-						keyPressed = Common::KEYCODE_F1;
-						ascii = Common::ASCII_F1;
-						break;
-					case 47:
-						keyPressed = Common::KEYCODE_F2;
-						ascii = Common::ASCII_F2;
-						break;
-					case 58:
-						keyPressed = Common::KEYCODE_F3;
-						ascii = Common::ASCII_F3;
-						break;
-					case 59:
-						keyPressed = Common::KEYCODE_F4;
-						ascii = Common::ASCII_F4;
-						break;
-					case 40:
-						keyPressed = Common::KEYCODE_F5;
-						ascii = Common::ASCII_F5;
-						break;
-					case 41:
-						keyPressed = Common::KEYCODE_F6;
-						ascii = Common::ASCII_F6;
-						break;
-					case 36:
-						keyPressed = Common::KEYCODE_F7;
-						ascii = Common::ASCII_F7;
-						break;
-					case 38:
-						keyPressed = Common::KEYCODE_F8;
-						ascii = Common::ASCII_F8;
-						break;
-					case 64:
-						keyPressed = Common::KEYCODE_F9;
-						ascii = Common::ASCII_F9;
-						break;
-					case 34:
-						keyPressed = Common::KEYCODE_F10;
-						ascii = Common::ASCII_F10;
-						break;
-					case 10:
-						keyPressed = Common::KEYCODE_RETURN;
-						ascii = Common::ASCII_RETURN;
-						break;
-				}
-				event.type = Common::EVENT_KEYDOWN;
-				_queuedInputEvent.type = Common::EVENT_KEYUP;
+	//printf("Mouse dragged at (%u, %u)\n", x, y);
+	if (_secondaryTapped) {
+		 if (_gestureStartX == -1 || _gestureStartY == -1) {
+			return false;
+		 }
 
-				event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
-				event.kbd.keycode = _queuedInputEvent.kbd.keycode = (Common::KeyCode)keyPressed;
-				event.kbd.ascii = _queuedInputEvent.kbd.ascii = ascii;
-				_needEventRestPeriod = true;
-				break;
-			}
+		int vecX = (x - _gestureStartX);
+		int vecY = (y - _gestureStartY);
+		int lengthSq =  vecX * vecX + vecY * vecY;
+		//printf("Lengthsq: %u\n", lengthSq);
 
-			case kInputSwipe: {
-				Common::KeyCode keycode = Common::KEYCODE_INVALID;
-				switch (_screenOrientation) {
-					case kScreenOrientationPortrait:
-						switch ((UIViewSwipeDirection)xUnit) {
-							case kUIViewSwipeUp:
-								keycode = Common::KEYCODE_UP;
-								break;
-							case kUIViewSwipeDown:
-								keycode = Common::KEYCODE_DOWN;
-								break;
-							case kUIViewSwipeLeft:
-								keycode = Common::KEYCODE_LEFT;
-								break;
-							case kUIViewSwipeRight:
-								keycode = Common::KEYCODE_RIGHT;
-								break;
-							default:
-								return false;
-						}
-						break;
-					case kScreenOrientationLandscape:
-						switch ((UIViewSwipeDirection)xUnit) {
-							case kUIViewSwipeUp:
-								keycode = Common::KEYCODE_LEFT;
-								break;
-							case kUIViewSwipeDown:
-								keycode = Common::KEYCODE_RIGHT;
-								break;
-							case kUIViewSwipeLeft:
-								keycode = Common::KEYCODE_DOWN;
-								break;
-							case kUIViewSwipeRight:
-								keycode = Common::KEYCODE_UP;
-								break;
-							default:
-								return false;
-						}
-						break;
-					case kScreenOrientationFlippedLandscape:
-						switch ((UIViewSwipeDirection)xUnit) {
-							case kUIViewSwipeUp:
-								keycode = Common::KEYCODE_RIGHT;
-								break;
-							case kUIViewSwipeDown:
-								keycode = Common::KEYCODE_LEFT;
-								break;
-							case kUIViewSwipeLeft:
-								keycode = Common::KEYCODE_UP;
-								break;
-							case kUIViewSwipeRight:
-								keycode = Common::KEYCODE_DOWN;
-								break;
-							default:
-								return false;
-						}
-						break;
-				}
+		if (lengthSq > 15000) { // Long enough gesture to react upon.
+			_gestureStartX = -1;
+			_gestureStartY = -1;
 
-				event.kbd.keycode = _queuedInputEvent.kbd.keycode = keycode;
-				event.kbd.ascii = _queuedInputEvent.kbd.ascii = 0;
+			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;
-				break;
-			}
+			} else if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm < -0.75) {
+				// Swipe up
+				_mouseClickAndDragEnabled = !_mouseClickAndDragEnabled;
+				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();
+				return false;
 
-			default:
-				break;
+			} 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
+			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;
+}
 
-		return true;
+void  OSystem_IPHONE::handleEvent_orientationChanged(int orientation) {
+	//printf("Orientation: %i\n", orientation);
+
+	ScreenOrientation newOrientation;
+	switch (orientation) {
+		case 1:
+			newOrientation = kScreenOrientationPortrait;
+			break;
+		case 3:
+			newOrientation = kScreenOrientationLandscape;
+			break;
+		case 4:
+			newOrientation = kScreenOrientationFlippedLandscape;
+			break;
+		default:
+			return;
 	}
-	return false;
+
+
+	if (_screenOrientation != newOrientation) {
+		_screenOrientation = newOrientation;
+		if (_screenOrientation != kScreenOrientationPortrait)
+			iPhone_initSurface(_screenHeight, _screenWidth, true);
+		else
+			iPhone_initSurface(_screenWidth, _screenHeight, false);
+
+		dirtyFullScreen();
+		updateScreen();
+	}	
 }
 
+void  OSystem_IPHONE::handleEvent_keyPressed(Common::Event &event, int keyPressed) {
+	int ascii = keyPressed;
+	//printf("key: %i\n", keyPressed);
+
+	// We remap some of the iPhone keyboard keys.
+	// The first ten here are the row of symbols below the numeric keys.
+	switch (keyPressed) {
+		case 45:
+			keyPressed = Common::KEYCODE_F1;
+			ascii = Common::ASCII_F1;
+			break;
+		case 47:
+			keyPressed = Common::KEYCODE_F2;
+			ascii = Common::ASCII_F2;
+			break;
+		case 58:
+			keyPressed = Common::KEYCODE_F3;
+			ascii = Common::ASCII_F3;
+			break;
+		case 59:
+			keyPressed = Common::KEYCODE_F4;
+			ascii = Common::ASCII_F4;
+			break;
+		case 40:
+			keyPressed = Common::KEYCODE_F5;
+			ascii = Common::ASCII_F5;
+			break;
+		case 41:
+			keyPressed = Common::KEYCODE_F6;
+			ascii = Common::ASCII_F6;
+			break;
+		case 36:
+			keyPressed = Common::KEYCODE_F7;
+			ascii = Common::ASCII_F7;
+			break;
+		case 38:
+			keyPressed = Common::KEYCODE_F8;
+			ascii = Common::ASCII_F8;
+			break;
+		case 64:
+			keyPressed = Common::KEYCODE_F9;
+			ascii = Common::ASCII_F9;
+			break;
+		case 34:
+			keyPressed = Common::KEYCODE_F10;
+			ascii = Common::ASCII_F10;
+			break;
+		case 10:
+			keyPressed = Common::KEYCODE_RETURN;
+			ascii = Common::ASCII_RETURN;
+			break;
+	}
+	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)keyPressed;
+	event.kbd.ascii = _queuedInputEvent.kbd.ascii = ascii;
+	_needEventRestPeriod = true;	
+}
+	
+bool OSystem_IPHONE::handleEvent_swipe(Common::Event &event, int direction) {
+	Common::KeyCode keycode = Common::KEYCODE_INVALID;
+	switch (_screenOrientation) {
+		case kScreenOrientationPortrait:
+			switch ((UIViewSwipeDirection)direction) {
+				case kUIViewSwipeUp:
+					keycode = Common::KEYCODE_UP;
+					break;
+				case kUIViewSwipeDown:
+					keycode = Common::KEYCODE_DOWN;
+					break;
+				case kUIViewSwipeLeft:
+					keycode = Common::KEYCODE_LEFT;
+					break;
+				case kUIViewSwipeRight:
+					keycode = Common::KEYCODE_RIGHT;
+					break;
+				default:
+					return false;
+			}
+			break;
+		case kScreenOrientationLandscape:
+			switch ((UIViewSwipeDirection)direction) {
+				case kUIViewSwipeUp:
+					keycode = Common::KEYCODE_LEFT;
+					break;
+				case kUIViewSwipeDown:
+					keycode = Common::KEYCODE_RIGHT;
+					break;
+				case kUIViewSwipeLeft:
+					keycode = Common::KEYCODE_DOWN;
+					break;
+				case kUIViewSwipeRight:
+					keycode = Common::KEYCODE_UP;
+					break;
+				default:
+					return false;
+			}
+			break;
+		case kScreenOrientationFlippedLandscape:
+			switch ((UIViewSwipeDirection)direction) {
+				case kUIViewSwipeUp:
+					keycode = Common::KEYCODE_RIGHT;
+					break;
+				case kUIViewSwipeDown:
+					keycode = Common::KEYCODE_LEFT;
+					break;
+				case kUIViewSwipeLeft:
+					keycode = Common::KEYCODE_UP;
+					break;
+				case kUIViewSwipeRight:
+					keycode = Common::KEYCODE_DOWN;
+					break;
+				default:
+					return false;
+			}
+			break;
+	}
+
+	event.kbd.keycode = _queuedInputEvent.kbd.keycode = keycode;
+	event.kbd.ascii = _queuedInputEvent.kbd.ascii = 0;
+	event.type = Common::EVENT_KEYDOWN;
+	_queuedInputEvent.type = Common::EVENT_KEYUP;
+	event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
+	_needEventRestPeriod = true;
+	
+	return true;
+}
+
 void OSystem_IPHONE::suspendLoop() {
 	bool done = false;
 	int eventType;

Modified: scummvm/branches/branch-0-12-0/backends/platform/iphone/osys_iphone.h
===================================================================
--- scummvm/branches/branch-0-12-0/backends/platform/iphone/osys_iphone.h	2008-08-02 09:03:22 UTC (rev 33516)
+++ scummvm/branches/branch-0-12-0/backends/platform/iphone/osys_iphone.h	2008-08-02 09:24:10 UTC (rev 33517)
@@ -100,6 +100,8 @@
 	bool _touchpadModeEnabled;
 	int _lastPadX;
 	int _lastPadY;
+	int _lastDragPosX;
+	int _lastDragPosY;
 
 	int _timerCallbackNext;
 	int _timerCallbackTimer;
@@ -188,6 +190,18 @@
 	void suspendLoop();
 	static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB);
 	static int timerHandler(int t);
+	
+	bool handleEvent_swipe(Common::Event &event, int direction);
+	void handleEvent_keyPressed(Common::Event &event, int keyPressed);
+	void handleEvent_orientationChanged(int orientation);
+
+	bool handleEvent_mouseDown(Common::Event &event, int x, int y);
+	bool handleEvent_mouseUp(Common::Event &event, int x, int y);
+	
+	bool handleEvent_secondMouseDown(Common::Event &event, int x, int y);
+	bool handleEvent_secondMouseUp(Common::Event &event, int x, int y);
+	
+	bool handleEvent_mouseDragged(Common::Event &event, int x, int y);
 };
 
 #endif


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