diff options
author | Oystein Eftevaag | 2008-09-10 19:46:08 +0000 |
---|---|---|
committer | Oystein Eftevaag | 2008-09-10 19:46:08 +0000 |
commit | 3b83564ad593d0b57464fcef19b573698d918410 (patch) | |
tree | 6be6de971d88416ebb9f0aa9f24bd84f25d01aeb /backends | |
parent | a54d1dbde66884afc1402809af1e57d1c214d9c7 (diff) | |
download | scummvm-rg350-3b83564ad593d0b57464fcef19b573698d918410.tar.gz scummvm-rg350-3b83564ad593d0b57464fcef19b573698d918410.tar.bz2 scummvm-rg350-3b83564ad593d0b57464fcef19b573698d918410.zip |
Merged up iPhone backend changes from 0.12 to trunk
svn-id: r34483
Diffstat (limited to 'backends')
-rw-r--r-- | backends/platform/iphone/iphone_keyboard.m | 3 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_main.m | 13 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_video.m | 14 | ||||
-rw-r--r-- | backends/platform/iphone/osys_iphone.cpp | 753 | ||||
-rw-r--r-- | backends/platform/iphone/osys_iphone.h | 30 |
5 files changed, 463 insertions, 350 deletions
diff --git a/backends/platform/iphone/iphone_keyboard.m b/backends/platform/iphone/iphone_keyboard.m index bd4948e30a..fda481933d 100644 --- a/backends/platform/iphone/iphone_keyboard.m +++ b/backends/platform/iphone/iphone_keyboard.m @@ -54,8 +54,7 @@ @implementation SoftKeyboard - (id)initWithFrame:(CGRect)frame { - //self = [super initWithFrame:frame]; - self = [super initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)]; + self = [super initWithFrame:frame]; inputDelegate = nil; inputView = [[TextInputHandler alloc] initWithKeyboard:self]; return self; diff --git a/backends/platform/iphone/iphone_main.m b/backends/platform/iphone/iphone_main.m index b01e9f3f34..6b709b0803 100644 --- a/backends/platform/iphone/iphone_main.m +++ b/backends/platform/iphone/iphone_main.m @@ -79,10 +79,7 @@ int main(int argc, char** argv) { - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // hide the status bar [UIHardware _setStatusBarHeight:0.0f]; - //[self setStatusBarMode:2 orientation:0 duration:0.0f fenceID:0]; - - //[self setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO]; - [self setStatusBarHidden:YES animated:YES]; + [self setStatusBarHidden:YES animated:NO]; _window = [[UIWindow alloc] initWithContentRect: [UIHardware fullScreenApplicationContentRect]]; [_window retain]; @@ -103,9 +100,13 @@ int main(int argc, char** argv) { - (void)applicationResume:(GSEventRef)event { [self removeApplicationBadge]; - [UIHardware _setStatusBarHeight:0.0f]; - [self setStatusBarHidden:YES animated:YES]; [_view applicationResume]; + + // Workaround, need to "hide" and unhide the statusbar to properly remove it, + // since the Springboard has put it back without apparently flagging our application. + [self setStatusBarHidden:NO animated:NO]; // hide status bar + [UIHardware _setStatusBarHeight:0.0f]; + [self setStatusBarHidden:YES animated:NO]; // hide status bar } - (void)deviceOrientationChanged:(GSEvent *)event { diff --git a/backends/platform/iphone/iphone_video.m b/backends/platform/iphone/iphone_video.m index 89f159c1d9..910f14ab58 100644 --- a/backends/platform/iphone/iphone_video.m +++ b/backends/platform/iphone/iphone_video.m @@ -169,10 +169,6 @@ bool getLocalMouseCoords(CGPoint *point) { nil ]; - if (_screenSurface != nil) { - //[[sharedInstance _layer] removeSublayer: screenLayer]; - } - //("Allocating surface: %d\n", allocSize); _screenSurface = CoreSurfaceBufferCreate((CFDictionaryRef)dict); //printf("Surface created.\n"); @@ -205,10 +201,13 @@ bool getLocalMouseCoords(CGPoint *point) { [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]; @@ -250,9 +249,6 @@ bool getLocalMouseCoords(CGPoint *point) { [self lock]; id event = [_events objectAtIndex: 0]; - if (event == nil) { - return nil; - } [_events removeObjectAtIndex: 0]; [self unlock]; diff --git a/backends/platform/iphone/osys_iphone.cpp b/backends/platform/iphone/osys_iphone.cpp index be42ee1f33..521e91a87e 100644 --- a/backends/platform/iphone/osys_iphone.cpp +++ b/backends/platform/iphone/osys_iphone.cpp @@ -56,24 +56,27 @@ const OSystem::GraphicsMode OSystem_IPHONE::s_supportedGraphicsModes[] = { AQCallbackStruct OSystem_IPHONE::s_AudioQueue; SoundProc OSystem_IPHONE::s_soundCallback = NULL; void *OSystem_IPHONE::s_soundParam = NULL; -bool OSystem_IPHONE::s_is113OrHigher = false; OSystem_IPHONE::OSystem_IPHONE() : _savefile(NULL), _mixer(NULL), _timer(NULL), _offscreen(NULL), _overlayVisible(false), _overlayBuffer(NULL), _fullscreen(NULL), _mouseHeight(0), _mouseWidth(0), _mouseBuf(NULL), _lastMouseTap(0), _secondaryTapped(false), _lastSecondaryTap(0), _screenOrientation(kScreenOrientationFlippedLandscape), - _needEventRestPeriod(false), _mouseClickAndDragEnabled(false), + _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); + + _fsFactory = new POSIXFilesystemFactory(); } OSystem_IPHONE::~OSystem_IPHONE() { AudioQueueDispose(s_AudioQueue.queue, true); + delete _fsFactory; delete _savefile; delete _mixer; delete _timer; @@ -665,8 +668,8 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) { float xUnit, yUnit; if (iPhone_fetchEvent(&eventType, &xUnit, &yUnit)) { - int x; - int y; + int x = 0; + int y = 0; switch (_screenOrientation) { case kScreenOrientationPortrait: x = (int)(xUnit * _screenWidth); @@ -684,334 +687,436 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) { switch ((InputEvent)eventType) { 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; - return true; - } else { - _lastMouseDown = curTime; - } - return false; + if (!handleEvent_mouseDown(event, x, y)) + 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 kInputMouseUp: + if (!handleEvent_mouseUp(event, x, y)) + return false; 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); - - 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) - 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 - // _secondaryTapped = !_secondaryTapped; - // _gestureStartX = x; - // _gestureStartY = y; - // - // GUI::TimedMessageDialog dialog("Forcing toggle of pressed state.", 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 { - event.type = Common::EVENT_MOUSEMOVE; - event.mouse.x = x; - event.mouse.y = y; - warpMouse(x, y); - } + if (!handleEvent_mouseDragged(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) { - _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_RBUTTONDOWN; - _queuedInputEvent.mouse.x = _mouseX; - _queuedInputEvent.mouse.y = _mouseY; - } - else + if (!handleEvent_secondMouseDown(event, x, y)) return false; } else { - if (curTime - _lastSecondaryDown < 250 ) { - if (curTime - _lastSecondaryTap < 250 && !_overlayVisible) { - 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_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); - - ScreenOrientation newOrientation; - switch ((int)xUnit) { - case 1: - newOrientation = kScreenOrientationPortrait; - break; - case 3: - newOrientation = kScreenOrientationLandscape; - break; - case 4: - newOrientation = kScreenOrientationFlippedLandscape; - break; - default: + if (!handleEvent_secondMouseUp(event, x, y)) return false; } + break; - - if (_screenOrientation != newOrientation) { - _screenOrientation = newOrientation; - if (_screenOrientation != kScreenOrientationPortrait) - iPhone_initSurface(_screenHeight, _screenWidth, true); - else - iPhone_initSurface(_screenWidth, _screenHeight, false); - - dirtyFullScreen(); - updateScreen(); - } + case kInputOrientationChanged: + handleEvent_orientationChanged((int)xUnit); + return false; break; case kInputApplicationSuspended: suspendLoop(); + return false; break; - case kInputKeyPressed: { - int keyPressed = (int)xUnit; - 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; + case kInputKeyPressed: + handleEvent_keyPressed(event, (int)xUnit); + break; - 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; + case kInputSwipe: + if (!handleEvent_swipe(event, (int)xUnit)) + return false; break; - } - 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; - } + default: + break; + } + + return true; + } + return false; +} + +bool OSystem_IPHONE::handleEvent_mouseDown(Common::Event &event, int x, int y) { + 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; + + if (_touchpadModeEnabled) { + _lastPadX = x; + _lastPadY = y; + } else + warpMouse(x, y); + + if (_mouseClickAndDragEnabled) { + event.type = Common::EVENT_LBUTTONDOWN; + event.mouse.x = _mouseX; + event.mouse.y = _mouseY; + return true; + } else { + _lastMouseDown = getMillis(); + } + return false; +} + +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; + + _queuedInputEvent.type = Common::EVENT_LBUTTONUP; + _queuedInputEvent.mouse.x = _mouseX; + _queuedInputEvent.mouse.y = _mouseY; + _lastMouseTap = getMillis(); + _needEventRestPeriod = true; + } else + return false; + } + + return true; +} + +bool OSystem_IPHONE::handleEvent_secondMouseDown(Common::Event &event, int x, int y) { + _lastSecondaryDown = getMillis(); + _gestureStartX = x; + _gestureStartY = y; + + if (_mouseClickAndDragEnabled) { + event.type = Common::EVENT_LBUTTONUP; + event.mouse.x = _mouseX; + event.mouse.y = _mouseY; + + _queuedInputEvent.type = Common::EVENT_RBUTTONDOWN; + _queuedInputEvent.mouse.x = _mouseX; + _queuedInputEvent.mouse.y = _mouseY; + } + else + return false; + + return true; +} + +bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int y) { + int curTime = getMillis(); + + 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; + + 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; +} + +bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y) { + if (_lastDragPosX == x && _lastDragPosY == y) + return false; + + _lastDragPosX = x; + _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); - event.kbd.keycode = _queuedInputEvent.kbd.keycode = keycode; - event.kbd.ascii = _queuedInputEvent.kbd.ascii = 0; + 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() { @@ -1020,16 +1125,17 @@ void OSystem_IPHONE::suspendLoop() { float xUnit, yUnit; uint32 startTime = getMillis(); - AudioQueueStop(s_AudioQueue.queue, true); - + stopSoundsystem(); + while (!done) { if (iPhone_fetchEvent(&eventType, &xUnit, &yUnit)) if ((InputEvent)eventType == kInputApplicationResumed) done = true; usleep(100000); } + + startSoundsystem(); - AudioQueueStart(s_AudioQueue.queue, NULL); _timeSuspended += getMillis() - startTime; } @@ -1107,7 +1213,10 @@ void OSystem_IPHONE::setupMixer() { s_soundCallback = mixCallback; s_soundParam = this; + startSoundsystem(); +} +void OSystem_IPHONE::startSoundsystem() { s_AudioQueue.dataFormat.mSampleRate = AUDIO_SAMPLE_RATE; s_AudioQueue.dataFormat.mFormatID = kAudioFormatLinearPCM; s_AudioQueue.dataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; @@ -1147,6 +1256,17 @@ void OSystem_IPHONE::setupMixer() { _mixer->setReady(true); } +void OSystem_IPHONE::stopSoundsystem() { + AudioQueueStop(s_AudioQueue.queue, true); + + for (int i = 0; i < AUDIO_BUFFERS; i++) { + AudioQueueFreeBuffer(s_AudioQueue.queue, s_AudioQueue.buffers[i]); + } + + AudioQueueDispose(s_AudioQueue.queue, true); + _mixer->setReady(false); +} + int OSystem_IPHONE::getOutputSampleRate() const { return AUDIO_SAMPLE_RATE; } @@ -1196,29 +1316,6 @@ const char* OSystem_IPHONE::getConfigPath() { return SCUMMVM_PREFS_PATH; } -void OSystem_IPHONE::migrateApp() { - // Migrate to the new 1.1.3 directory structure, if needed. - - Common::FilesystemNode file("/var/mobile"); - if (file.exists() && file.isDirectory()) { - // We have 1.1.3 or above. - s_is113OrHigher = true; - file = Common::FilesystemNode(SCUMMVM_ROOT_PATH); - if (!file.exists()) { - system("mkdir " SCUMMVM_ROOT_PATH); - system("mkdir " SCUMMVM_SAVE_PATH); - - // Copy over the prefs file - system("cp " SCUMMVM_OLD_PREFS_PATH " " SCUMMVM_PREFS_PATH); - - file = Common::FilesystemNode(SCUMMVM_OLD_SAVE_PATH); - // Copy over old savegames to the new directory. - if (file.exists() && file.isDirectory()) - system("cp " SCUMMVM_OLD_SAVE_PATH "/* " SCUMMVM_SAVE_PATH "/"); - } - } -} - void iphone_main(int argc, char *argv[]) { //OSystem_IPHONE::migrateApp(); @@ -1239,6 +1336,8 @@ void iphone_main(int argc, char *argv[]) { system("mkdir " SCUMMVM_ROOT_PATH); system("mkdir " SCUMMVM_SAVE_PATH); + chdir("/var/mobile/"); + g_system = OSystem_IPHONE_create(); assert(g_system); diff --git a/backends/platform/iphone/osys_iphone.h b/backends/platform/iphone/osys_iphone.h index c058686c8c..a9a3ddad65 100644 --- a/backends/platform/iphone/osys_iphone.h +++ b/backends/platform/iphone/osys_iphone.h @@ -35,14 +35,12 @@ #include <AudioToolbox/AudioQueue.h> #define AUDIO_BUFFERS 3 -#define WAVE_BUFFER_SIZE 8192 +#define WAVE_BUFFER_SIZE 2048 #define AUDIO_SAMPLE_RATE 44100 #define SCUMMVM_ROOT_PATH "/var/mobile/Library/ScummVM" #define SCUMMVM_SAVE_PATH SCUMMVM_ROOT_PATH "/Savegames" -#define SCUMMVM_OLD_SAVE_PATH "/var/root/.scummvm" #define SCUMMVM_PREFS_PATH SCUMMVM_ROOT_PATH "/Preferences" -#define SCUMMVM_OLD_PREFS_PATH "/var/root/.scummvmrc" typedef void (*SoundProc)(void *param, byte *buf, int len); typedef int (*TimerProc)(int interval); @@ -61,7 +59,6 @@ protected: static AQCallbackStruct s_AudioQueue; static SoundProc s_soundCallback; static void *s_soundParam; - static bool s_is113OrHigher; Common::SaveFileManager *_savefile; Audio::MixerImpl *_mixer; @@ -97,6 +94,11 @@ protected: long _lastSecondaryTap; int _gestureStartX, _gestureStartY; bool _mouseClickAndDragEnabled; + bool _touchpadModeEnabled; + int _lastPadX; + int _lastPadY; + int _lastDragPosX; + int _lastDragPosY; int _timerCallbackNext; int _timerCallbackTimer; @@ -106,6 +108,8 @@ protected: ScreenOrientation _screenOrientation; bool _fullScreenIsDirty; + FilesystemFactory *_fsFactory; + public: OSystem_IPHONE(); @@ -161,7 +165,7 @@ public: virtual void quit(); - FilesystemFactory *getFilesystemFactory() { return &POSIXFilesystemFactory::instance(); } + FilesystemFactory *getFilesystemFactory() { return _fsFactory; } virtual void getTimeAndDate(struct tm &t) const; virtual void setWindowCaption(const char *caption); @@ -170,7 +174,9 @@ public: virtual Audio::Mixer *getMixer(); virtual Common::TimerManager *getTimerManager(); - static void migrateApp(); + void startSoundsystem(); + void stopSoundsystem(); + static const char* getConfigPath(); protected: @@ -182,6 +188,18 @@ protected: 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 |