diff options
author | Oystein Eftevaag | 2007-11-25 09:37:15 +0000 |
---|---|---|
committer | Oystein Eftevaag | 2007-11-25 09:37:15 +0000 |
commit | ece4ee33604d90a0e24e3cbabeaaa52745de6878 (patch) | |
tree | 8cc6d3ce68cec5b192ac41c3b394a528596ca85b /backends/platform | |
parent | 28e0985061e96cc96f8fb08faaa1437db09df673 (diff) | |
download | scummvm-rg350-ece4ee33604d90a0e24e3cbabeaaa52745de6878.tar.gz scummvm-rg350-ece4ee33604d90a0e24e3cbabeaaa52745de6878.tar.bz2 scummvm-rg350-ece4ee33604d90a0e24e3cbabeaaa52745de6878.zip |
Suspend ScummVM when the button is hit (or a call is received), putting it in a sleep loop until it's resumed
svn-id: r29633
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/iphone/iphone_common.h | 4 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_main.m | 12 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_video.h | 4 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_video.m | 22 | ||||
-rw-r--r-- | backends/platform/iphone/osys_iphone.cpp | 28 | ||||
-rw-r--r-- | backends/platform/iphone/osys_iphone.h | 5 |
6 files changed, 70 insertions, 5 deletions
diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h index fec25940a2..3240182354 100644 --- a/backends/platform/iphone/iphone_common.h +++ b/backends/platform/iphone/iphone_common.h @@ -30,7 +30,9 @@ enum InputEvent { kInputMouseDragged, kInputMouseSecondToggled, kInputOrientationChanged, - kInputKeyPressed + kInputKeyPressed, + kInputApplicationSuspended, + kInputApplicationResumed }; // We need this to be able to call functions from/in Objective-C. diff --git a/backends/platform/iphone/iphone_main.m b/backends/platform/iphone/iphone_main.m index 2391e7cbac..b338bd719a 100644 --- a/backends/platform/iphone/iphone_main.m +++ b/backends/platform/iphone/iphone_main.m @@ -88,6 +88,18 @@ int main(int argc, char** argv) { [NSThread detachNewThreadSelector:@selector(mainLoop:) toTarget:self withObject:nil]; } +- (void)applicationSuspend:(GSEventRef)event { + [self setApplicationBadge:NSLocalizedString(@"ON", nil)]; + [_view applicationSuspend]; +} + +- (void)applicationResume:(GSEventRef)event { + [self removeApplicationBadge]; + [UIHardware _setStatusBarHeight:0.0f]; + [self setStatusBarMode:2 orientation:0 duration:0.0f fenceID:0]; + [_view applicationResume]; +} + - (void)deviceOrientationChanged:(GSEvent *)event { int screenOrientation = GSEventDeviceOrientation(event); [_view deviceOrientationChanged: screenOrientation]; diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h index 3ac3d6a31a..837cd83b1a 100644 --- a/backends/platform/iphone/iphone_video.h +++ b/backends/platform/iphone/iphone_video.h @@ -71,6 +71,10 @@ typedef enum - (void)deviceOrientationChanged:(int)orientation; +- (void)applicationSuspend; + +- (void)applicationResume; + @end diff --git a/backends/platform/iphone/iphone_video.m b/backends/platform/iphone/iphone_video.m index 261d447290..7401cd0ff1 100644 --- a/backends/platform/iphone/iphone_video.m +++ b/backends/platform/iphone/iphone_video.m @@ -399,5 +399,27 @@ bool getLocalMouseCoords(CGPoint *point) { //printf("handleTapWithCount(%i, %i)\n", count, fingerCount); } +- (void)applicationSuspend { + [self addEvent: + [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:kInputApplicationSuspended], @"type", + [NSNumber numberWithFloat:0], @"x", + [NSNumber numberWithFloat:0], @"y", + nil + ] + ]; +} + +- (void)applicationResume { + [self addEvent: + [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:kInputApplicationResumed], @"type", + [NSNumber numberWithFloat:0], @"x", + [NSNumber numberWithFloat:0], @"y", + nil + ] + ]; +} + @end diff --git a/backends/platform/iphone/osys_iphone.cpp b/backends/platform/iphone/osys_iphone.cpp index 5de3712387..715131961c 100644 --- a/backends/platform/iphone/osys_iphone.cpp +++ b/backends/platform/iphone/osys_iphone.cpp @@ -63,7 +63,7 @@ OSystem_IPHONE::OSystem_IPHONE() : _secondaryTapped(false), _lastSecondaryTap(0), _landscapeMode(true), _needEventRestPeriod(false), _mouseClickAndDragEnabled(false), _gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), - _mouseDirty(false) + _mouseDirty(false), _timeSuspended(0) { _queuedInputEvent.type = (Common::EventType)0; _lastDrawnMouseRect = Common::Rect(0, 0, 0, 0); @@ -711,6 +711,11 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) { dirtyFullScreen(); } break; + + case kInputApplicationSuspended: + suspendLoop(); + break; + case kInputKeyPressed: int keyPressed = (int)xUnit; int ascii = keyPressed; @@ -782,13 +787,32 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) { return false; } +void OSystem_IPHONE::suspendLoop() { + bool done = false; + int eventType; + float xUnit, yUnit; + uint32 startTime = getMillis(); + + AudioQueueStop(s_AudioQueue.queue, true); + + while (!done) { + if (iPhone_fetchEvent(&eventType, &xUnit, &yUnit)) + if ((InputEvent)eventType == kInputApplicationResumed) + done = true; + usleep(100000); + } + + AudioQueueStart(s_AudioQueue.queue, NULL); + _timeSuspended += getMillis() - startTime; +} + uint32 OSystem_IPHONE::getMillis() { //printf("getMillis()\n"); struct timeval currentTime; gettimeofday(¤tTime, NULL); return (uint32)(((currentTime.tv_sec - _startTime.tv_sec) * 1000) + - ((currentTime.tv_usec - _startTime.tv_usec) / 1000)); + ((currentTime.tv_usec - _startTime.tv_usec) / 1000)) - _timeSuspended; } void OSystem_IPHONE::delayMillis(uint msecs) { diff --git a/backends/platform/iphone/osys_iphone.h b/backends/platform/iphone/osys_iphone.h index b9925090b3..237fe1dbf2 100644 --- a/backends/platform/iphone/osys_iphone.h +++ b/backends/platform/iphone/osys_iphone.h @@ -64,7 +64,8 @@ protected: uint16 _screenHeight; struct timeval _startTime; - + uint32 _timeSuspended; + bool _mouseVisible; byte *_mouseBuf; byte _mouseKeyColour; @@ -158,7 +159,7 @@ protected: void dirtyMouseCursor(); void dirtyFullScreen(); void clipRectToScreen(int16 &x, int16 &y, int16 &w, int16 &h); - + void suspendLoop(); static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB); static int timerHandler(int t); }; |