From 5b86801553966b0fc71ae9b357506fac4e37a944 Mon Sep 17 00:00:00 2001 From: Oystein Eftevaag Date: Sun, 15 Feb 2009 13:58:15 +0000 Subject: Merged revisions 36329, 38212, 38226and 38234 from branch-0-13-0 to trunk: iPhone backend updates svn-id: r38240 --- backends/platform/iphone/iphone_main.m | 35 +-- backends/platform/iphone/iphone_video.h | 1 - backends/platform/iphone/iphone_video.m | 32 ++- backends/platform/iphone/osys_iphone.cpp | 418 +++++++++++++++++-------------- backends/platform/iphone/osys_iphone.h | 14 +- backends/platform/sdl/sdl.cpp | 2 +- configure | 2 +- gui/ThemeEngine.cpp | 4 +- 8 files changed, 283 insertions(+), 225 deletions(-) diff --git a/backends/platform/iphone/iphone_main.m b/backends/platform/iphone/iphone_main.m index 6b709b0803..90dc4c8558 100644 --- a/backends/platform/iphone/iphone_main.m +++ b/backends/platform/iphone/iphone_main.m @@ -51,7 +51,7 @@ int main(int argc, char** argv) { ]; UIApplicationUseLegacyEvents(1); - int returnCode = UIApplicationMain(argc, argv, [iPhoneMain class]); + int returnCode = UIApplicationMain(argc, argv, @"iPhoneMain", @"iPhoneMain"); [ autoreleasePool release ]; return returnCode; } @@ -69,47 +69,52 @@ int main(int argc, char** argv) { [[NSAutoreleasePool alloc] init]; iphone_main(gArgc, gArgv); - [UIApp terminate]; + exit(0); } - (iPhoneView*) getView { return _view; } -- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { +- (void)applicationDidFinishLaunching:(UIApplication *)application { + CGRect rect = [[UIScreen mainScreen] bounds]; + // hide the status bar - [UIHardware _setStatusBarHeight:0.0f]; - [self setStatusBarHidden:YES animated:NO]; + [application setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO]; + [application setStatusBarHidden:YES animated:YES]; - _window = [[UIWindow alloc] initWithContentRect: [UIHardware fullScreenApplicationContentRect]]; + _window = [[UIWindow alloc] initWithFrame:rect]; [_window retain]; - _view = [[iPhoneView alloc] initWithFrame: [UIHardware fullScreenApplicationContentRect]]; + _view = [[iPhoneView alloc] initWithFrame: rect]; [_window setContentView: _view]; - [_window orderFront: self]; - [_window makeKey: self]; + //[_window orderFront: self]; + //[_window makeKey: self]; + + [_window addSubview:_view]; + [_window makeKeyAndVisible]; [NSThread detachNewThreadSelector:@selector(mainLoop:) toTarget:self withObject:nil]; } -- (void)applicationSuspend:(GSEventRef)event { +- (void)applicationSuspend:(struct __GSEvent *)event { [self setApplicationBadge:NSLocalizedString(@"ON", nil)]; [_view applicationSuspend]; } -- (void)applicationResume:(GSEventRef)event { +- (void)applicationResume:(struct __GSEvent *)event { [self removeApplicationBadge]; [_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 + [self setStatusBarHidden:YES animated:YES]; + [self setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO]; + [self setStatusBarHidden:YES animated:YES]; } -- (void)deviceOrientationChanged:(GSEvent *)event { +- (void)deviceOrientationChanged:(struct __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 6e4b446926..ebfeb1ce0b 100644 --- a/backends/platform/iphone/iphone_video.h +++ b/backends/platform/iphone/iphone_video.h @@ -27,7 +27,6 @@ #define _IPHONE_VIDEO__H #import -#import #import #import diff --git a/backends/platform/iphone/iphone_video.m b/backends/platform/iphone/iphone_video.m index 910f14ab58..400bb102d2 100644 --- a/backends/platform/iphone/iphone_video.m +++ b/backends/platform/iphone/iphone_video.m @@ -27,11 +27,9 @@ #include "iphone_common.h" #import -#import #import #import #import -#import #import static iPhoneView *sharedInstance = nil; @@ -278,10 +276,10 @@ bool getLocalMouseCoords(CGPoint *point) { ]; } -- (void)mouseDown:(GSEvent*)event { +- (void)mouseDown:(struct __GSEvent *)event { //printf("mouseDown()\n"); - CGRect rect = GSEventGetLocationInWindow(event); - CGPoint point = CGPointMake(rect.origin.x, rect.origin.y); + CGPoint point = GSEventGetLocationInWindow(event); + point = [self convertPoint:point fromView:nil]; if (!getLocalMouseCoords(&point)) return; @@ -300,10 +298,10 @@ bool getLocalMouseCoords(CGPoint *point) { //printf("touchesBegan()\n"); } -- (void)mouseUp:(GSEvent*)event { +- (void)mouseUp:(struct __GSEvent *)event { //printf("mouseUp()\n"); - CGRect rect = GSEventGetLocationInWindow(event); - CGPoint point = CGPointMake(rect.origin.x, rect.origin.y); + CGPoint point = GSEventGetLocationInWindow(event); + point = [self convertPoint:point fromView:nil]; if (!getLocalMouseCoords(&point)) return; @@ -318,10 +316,10 @@ bool getLocalMouseCoords(CGPoint *point) { ]; } -- (void)mouseDragged:(GSEvent*)event { +- (void)mouseDragged:(struct __GSEvent *)event { //printf("mouseDragged()\n"); - CGRect rect = GSEventGetLocationInWindow(event); - CGPoint point = CGPointMake(rect.origin.x, rect.origin.y); + CGPoint point = GSEventGetLocationInWindow(event); + point = [self convertPoint:point fromView:nil]; if (!getLocalMouseCoords(&point)) return; @@ -336,10 +334,10 @@ bool getLocalMouseCoords(CGPoint *point) { ]; } -- (void)mouseEntered:(GSEvent*)event { +- (void)mouseEntered:(struct __GSEvent *)event { //printf("mouseEntered()\n"); - CGRect rect = GSEventGetLocationInWindow(event); - CGPoint point = CGPointMake(rect.origin.x, rect.origin.y); + CGPoint point = GSEventGetLocationInWindow(event); + point = [self convertPoint:point fromView:nil]; if (!getLocalMouseCoords(&point)) @@ -355,7 +353,7 @@ bool getLocalMouseCoords(CGPoint *point) { ]; } -- (void)mouseExited:(GSEvent*)event { +- (void)mouseExited:(struct __GSEvent *)event { //printf("mouseExited().\n"); // [self addEvent: // [[NSDictionary alloc] initWithObjectsAndKeys: @@ -365,7 +363,7 @@ bool getLocalMouseCoords(CGPoint *point) { // ]; } -- (void)mouseMoved:(GSEvent*)event +- (void)mouseMoved:(struct __GSEvent *)event { //printf("mouseMoved()\n"); // struct CGPoint point = GSEventGetLocationInWindow(event); @@ -411,7 +409,7 @@ bool getLocalMouseCoords(CGPoint *point) { ]; } -- (void)view:(UIView *)view handleTapWithCount:(int)count event:(GSEvent *)event fingerCount:(int)fingerCount{ +- (void)view:(UIView *)view handleTapWithCount:(int)count event:(struct __GSEvent *)event fingerCount:(int)fingerCount{ //printf("handleTapWithCount(%i, %i)\n", count, fingerCount); } diff --git a/backends/platform/iphone/osys_iphone.cpp b/backends/platform/iphone/osys_iphone.cpp index 226626d551..f22063e3d5 100644 --- a/backends/platform/iphone/osys_iphone.cpp +++ b/backends/platform/iphone/osys_iphone.cpp @@ -62,9 +62,9 @@ OSystem_IPHONE::OSystem_IPHONE() : _overlayVisible(false), _overlayBuffer(NULL), _fullscreen(NULL), _mouseHeight(0), _mouseWidth(0), _mouseBuf(NULL), _lastMouseTap(0), _secondaryTapped(false), _lastSecondaryTap(0), _screenOrientation(kScreenOrientationFlippedLandscape), - _needEventRestPeriod(false), _mouseClickAndDragEnabled(false), _touchpadModeEnabled(false), - _gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), - _mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1) + _needEventRestPeriod(false), _mouseClickAndDragEnabled(false), _touchpadModeEnabled(true), + _gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), _fullScreenOverlayIsDirty(false), + _mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1), _screenChangeCount(0) { _queuedInputEvent.type = (Common::EventType)0; @@ -164,6 +164,7 @@ void OSystem_IPHONE::initSize(uint width, uint height) { dirtyFullScreen(); _mouseVisible = false; + _screenChangeCount++; updateScreen(); } @@ -180,7 +181,7 @@ void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) { const byte *b = colors; for (uint i = start; i < start + num; ++i) { - _palette[i] = Graphics::RGBToColor >(b[0], b[1], b[2]); + _palette[i] = Graphics::RGBToColor >(b[0], b[1], b[2]); b += 4; } @@ -234,15 +235,6 @@ void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, } } -void OSystem_IPHONE::addDirtyRect(int16 x, int16 y, int16 w, int16 h) { - if (_fullScreenIsDirty) { - return; - } - - clipRectToScreen(x, y, w, h); - _dirtyRects.push_back(Common::Rect(x, y, x + w, y + h)); -} - void OSystem_IPHONE::clipRectToScreen(int16 &x, int16 &y, int16 &w, int16 &h) { if (x < 0) { w += x; @@ -272,11 +264,12 @@ void OSystem_IPHONE::clipRectToScreen(int16 &x, int16 &y, int16 &w, int16 &h) { void OSystem_IPHONE::updateScreen() { //printf("updateScreen(): %i dirty rects.\n", _dirtyRects.size()); - if (_dirtyRects.size() == 0 && !_mouseDirty) + if (_dirtyRects.size() == 0 && _dirtyOverlayRects.size() == 0 && !_mouseDirty) return; internUpdateScreen(); _fullScreenIsDirty = false; + _fullScreenOverlayIsDirty = false; //memcpy(iPhone_getSurface(), _fullscreen, _screenWidth * _screenHeight * 2); @@ -290,6 +283,7 @@ void OSystem_IPHONE::internUpdateScreen() { int16 mouseHeight = _mouseHeight; clipRectToScreen(mouseX, mouseY, mouseWidth, mouseHeight); + Common::Rect mouseRect(mouseX, mouseY, mouseX + mouseWidth, mouseY + mouseHeight); if (_mouseDirty) { @@ -297,6 +291,10 @@ void OSystem_IPHONE::internUpdateScreen() { _dirtyRects.push_back(_lastDrawnMouseRect); _dirtyRects.push_back(mouseRect); } + if (!_fullScreenOverlayIsDirty && _overlayVisible) { + _dirtyOverlayRects.push_back(_lastDrawnMouseRect); + _dirtyOverlayRects.push_back(mouseRect); + } _mouseDirty = false; _lastDrawnMouseRect = mouseRect; } @@ -305,188 +303,217 @@ void OSystem_IPHONE::internUpdateScreen() { Common::Rect dirtyRect = _dirtyRects.remove_at(_dirtyRects.size() - 1); //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); - int h = dirtyRect.bottom - dirtyRect.top; - int w = dirtyRect.right - dirtyRect.left; + + drawDirtyRect(dirtyRect); + + if (_overlayVisible) + drawDirtyOverlayRect(dirtyRect); + + drawMouseCursorOnRectUpdate(dirtyRect, mouseRect); + updateHardwareSurfaceForRect(dirtyRect); + } - if (_overlayVisible) { - switch (_screenOrientation) { - case kScreenOrientationPortrait: { - uint16 *src = (uint16 *)&_overlayBuffer[dirtyRect.top * _screenWidth + dirtyRect.left]; - uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; - int x = (dirtyRect.right - dirtyRect.left) * 2; - for (int y = h; y > 0; y--) { - memcpy(dst, src, x); - src += _screenWidth; - dst += _screenWidth; - } - break; - } - case kScreenOrientationLandscape: { - uint16 *src = (uint16 *)&_overlayBuffer[(dirtyRect.bottom - 1) * _screenWidth + dirtyRect.left]; - uint16 *dst = &_fullscreen[dirtyRect.left * _screenHeight + (_screenHeight - dirtyRect.bottom)]; - blitLandscapeScreenRect16bpp(dst, src, w, h, -_screenWidth, -_screenHeight); - break; - } - case kScreenOrientationFlippedLandscape: { - uint16 *src = (uint16 *)&_overlayBuffer[dirtyRect.top * _screenWidth + dirtyRect.left]; - uint16 *dst = &_fullscreen[(_screenWidth - dirtyRect.left - 1) * _screenHeight + dirtyRect.top]; - blitLandscapeScreenRect16bpp(dst, src, dirtyRect.right - dirtyRect.left, h, _screenWidth, _screenHeight); - break; - } - } - } else { - switch (_screenOrientation) { - case kScreenOrientationPortrait: { - byte *src = &_offscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; - uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; - for (int y = h; y > 0; y--) { - for (int x = w; x > 0; x--) - *dst++ = _palette[*src++]; - - dst += _screenWidth - w; - src += _screenWidth - w; - } - break; - } - case kScreenOrientationLandscape: { - byte *src = &_offscreen[(dirtyRect.bottom - 1) * _screenWidth + dirtyRect.left]; - uint16 *dst = &_fullscreen[dirtyRect.left * _screenHeight + (_screenHeight - dirtyRect.bottom)]; - blitLandscapeScreenRect8bpp(dst, src, w, h, _palette, -_screenWidth, -_screenHeight); - break; - } - case kScreenOrientationFlippedLandscape: { - byte *src = &_offscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; - uint16 *dst = &_fullscreen[(_screenWidth - dirtyRect.left - 1) * _screenHeight + dirtyRect.top]; - blitLandscapeScreenRect8bpp(dst, src, w, h, _palette, _screenWidth, _screenHeight); - break; - } - } + if (_overlayVisible) { + while (_dirtyOverlayRects.size()) { + Common::Rect dirtyRect = _dirtyOverlayRects.remove_at(_dirtyOverlayRects.size() - 1); + + //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); + + drawDirtyOverlayRect(dirtyRect); + drawMouseCursorOnRectUpdate(dirtyRect, mouseRect); + updateHardwareSurfaceForRect(dirtyRect); } + } + + //iPhone_updateScreenRect(dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom ); +} - //draw mouse on top - if (_mouseVisible && (dirtyRect.intersects(mouseRect))) { - int srcX = 0; - int srcY = 0; - int left = _mouseX - _mouseHotspotX; - if (left < 0) { - srcX -= left; - left = 0; - } - int top = _mouseY - _mouseHotspotY; - if (top < 0) { - srcY -= top; - top = 0; +void OSystem_IPHONE::drawDirtyRect(const Common::Rect& dirtyRect) { + int h = dirtyRect.bottom - dirtyRect.top; + int w = dirtyRect.right - dirtyRect.left; + + switch (_screenOrientation) { + case kScreenOrientationPortrait: { + byte *src = &_offscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; + uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; + for (int y = h; y > 0; y--) { + for (int x = w; x > 0; x--) + *dst++ = _palette[*src++]; + + dst += _screenWidth - w; + src += _screenWidth - w; } + break; + } + case kScreenOrientationLandscape: { + byte *src = &_offscreen[(dirtyRect.bottom - 1) * _screenWidth + dirtyRect.left]; + uint16 *dst = &_fullscreen[dirtyRect.left * _screenHeight + (_screenHeight - dirtyRect.bottom)]; + blitLandscapeScreenRect8bpp(dst, src, w, h, _palette, -_screenWidth, -_screenHeight); + break; + } + case kScreenOrientationFlippedLandscape: { + byte *src = &_offscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; + uint16 *dst = &_fullscreen[(_screenWidth - dirtyRect.left - 1) * _screenHeight + dirtyRect.top]; + blitLandscapeScreenRect8bpp(dst, src, w, h, _palette, _screenWidth, _screenHeight); + break; + } + } +} - //int right = left + _mouseWidth; - int bottom = top + _mouseHeight; - if (bottom > _screenWidth) - bottom = _screenWidth; +void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect& dirtyRect) { + int h = dirtyRect.bottom - dirtyRect.top; + int w = dirtyRect.right - dirtyRect.left; + switch (_screenOrientation) { + case kScreenOrientationPortrait: { + uint16 *src = (uint16 *)&_overlayBuffer[dirtyRect.top * _screenWidth + dirtyRect.left]; + uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; + int x = (dirtyRect.right - dirtyRect.left) * 2; + for (int y = h; y > 0; y--) { + memcpy(dst, src, x); + src += _screenWidth; + dst += _screenWidth; + } + break; + } + case kScreenOrientationLandscape: { + uint16 *src = (uint16 *)&_overlayBuffer[(dirtyRect.bottom - 1) * _screenWidth + dirtyRect.left]; + uint16 *dst = &_fullscreen[dirtyRect.left * _screenHeight + (_screenHeight - dirtyRect.bottom)]; + blitLandscapeScreenRect16bpp(dst, src, w, h, -_screenWidth, -_screenHeight); + break; + } + case kScreenOrientationFlippedLandscape: { + uint16 *src = (uint16 *)&_overlayBuffer[dirtyRect.top * _screenWidth + dirtyRect.left]; + uint16 *dst = &_fullscreen[(_screenWidth - dirtyRect.left - 1) * _screenHeight + dirtyRect.top]; + blitLandscapeScreenRect16bpp(dst, src, dirtyRect.right - dirtyRect.left, h, _screenWidth, _screenHeight); + break; + } + } +} + +void OSystem_IPHONE::drawMouseCursorOnRectUpdate(const Common::Rect& updatedRect, const Common::Rect& mouseRect) { + //draw mouse on top + if (_mouseVisible && (updatedRect.intersects(mouseRect))) { + int srcX = 0; + int srcY = 0; + int left = _mouseX - _mouseHotspotX; + if (left < 0) { + srcX -= left; + left = 0; + } + int top = _mouseY - _mouseHotspotY; + if (top < 0) { + srcY -= top; + top = 0; + } + //int right = left + _mouseWidth; + int bottom = top + _mouseHeight; + if (bottom > _screenWidth) + bottom = _screenWidth; int displayWidth = _mouseWidth; - if (_mouseWidth + left > _screenWidth) - displayWidth = _screenWidth - left; - + if (_mouseWidth + left > _screenWidth) + displayWidth = _screenWidth - left; int displayHeight = _mouseHeight; - if (_mouseHeight + top > _screenHeight) - displayHeight = _screenHeight - top; - + if (_mouseHeight + top > _screenHeight) + displayHeight = _screenHeight - top; switch (_screenOrientation) { - case kScreenOrientationPortrait: { - byte *src = &_mouseBuf[srcY * _mouseWidth + srcX]; - uint16 *dst = &_fullscreen[top * _screenWidth + left]; - for (int y = displayHeight; y > srcY; y--) { - for (int x = displayWidth; x > srcX; x--) { - if (*src != _mouseKeyColour) - *dst = _palette[*src]; - dst++; - src++; - } - dst += _screenWidth - displayWidth + srcX; - src += _mouseWidth - displayWidth + srcX; + case kScreenOrientationPortrait: { + byte *src = &_mouseBuf[srcY * _mouseWidth + srcX]; + uint16 *dst = &_fullscreen[top * _screenWidth + left]; + for (int y = displayHeight; y > srcY; y--) { + for (int x = displayWidth; x > srcX; x--) { + if (*src != _mouseKeyColour) + *dst = _palette[*src]; + dst++; + src++; } - break; + dst += _screenWidth - displayWidth + srcX; + src += _mouseWidth - displayWidth + srcX; } - case kScreenOrientationLandscape: { - byte *src = &_mouseBuf[(_mouseHeight - 1 - srcY) * _mouseWidth + srcX]; - uint16 *dst = &_fullscreen[left * _screenHeight + (_screenHeight - bottom + srcY)]; - for (int x = displayWidth; x > srcX; x--) { - for (int y = displayHeight; y > srcY; y--) { - if (*src != _mouseKeyColour) - *dst = _palette[*src]; - dst++; - src -= _mouseWidth; - } - dst -= -_screenHeight + displayHeight - srcY; - src += 1 - (displayHeight - srcY) * -_mouseWidth; + break; + } + case kScreenOrientationLandscape: { + byte *src = &_mouseBuf[(_mouseHeight - 1 - srcY) * _mouseWidth + srcX]; + uint16 *dst = &_fullscreen[left * _screenHeight + (_screenHeight - bottom + srcY)]; + for (int x = displayWidth; x > srcX; x--) { + for (int y = displayHeight; y > srcY; y--) { + if (*src != _mouseKeyColour) + *dst = _palette[*src]; + dst++; + src -= _mouseWidth; } - break; + dst -= -_screenHeight + displayHeight - srcY; + src += 1 - (displayHeight - srcY) * -_mouseWidth; } - case kScreenOrientationFlippedLandscape: { - byte *src = &_mouseBuf[srcY * _mouseWidth + srcX]; - uint16 *dst = &_fullscreen[(_screenWidth - left - 1) * _screenHeight + top]; - for (int x = displayWidth; x > srcX; x--) { - for (int y = displayHeight; y > srcY; y--) { - if (*src != _mouseKeyColour) - *dst = _palette[*src]; - dst++; - src += _mouseWidth; - } - dst -= _screenHeight + displayHeight - srcY; - src += 1 - (displayHeight - srcY) * _mouseWidth; + break; + } + case kScreenOrientationFlippedLandscape: { + byte *src = &_mouseBuf[srcY * _mouseWidth + srcX]; + uint16 *dst = &_fullscreen[(_screenWidth - left - 1) * _screenHeight + top]; + for (int x = displayWidth; x > srcX; x--) { + for (int y = displayHeight; y > srcY; y--) { + if (*src != _mouseKeyColour) + *dst = _palette[*src]; + dst++; + src += _mouseWidth; } - break; + dst -= _screenHeight + displayHeight - srcY; + src += 1 - (displayHeight - srcY) * _mouseWidth; } + break; } } + } +} +void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect& updatedRect) { + uint16 *surface = iPhone_getSurface(); + + int h = updatedRect.bottom - updatedRect.top; + int w = updatedRect.right - updatedRect.left; - uint16 *surface = iPhone_getSurface(); - if (w == _screenWidth && h == _screenHeight) - memcpy(surface, _fullscreen, _screenWidth * _screenHeight * 2); - else { - switch (_screenOrientation) { - case kScreenOrientationPortrait: { - int width = w * 2; - int offset = dirtyRect.top * _screenWidth + dirtyRect.left; - uint16 *fs = _fullscreen + offset; - surface += offset; - for (int y = h; y > 0; y--) { - memcpy(surface, fs, width); - surface += _screenWidth; - fs += _screenWidth; - } - break; + if (w == _screenWidth && h == _screenHeight) + memcpy(surface, _fullscreen, _screenWidth * _screenHeight * 2); + else { + switch (_screenOrientation) { + case kScreenOrientationPortrait: { + int width = w * 2; + int offset = updatedRect.top * _screenWidth + updatedRect.left; + uint16 *fs = _fullscreen + offset; + surface += offset; + for (int y = h; y > 0; y--) { + memcpy(surface, fs, width); + surface += _screenWidth; + fs += _screenWidth; } - case kScreenOrientationLandscape: { - int height = h * 2; - int offset = dirtyRect.left * _screenHeight + (_screenHeight - dirtyRect.bottom); - uint16 *fs = _fullscreen + offset; - surface += offset; - for (int x = w; x > 0; x--) { - memcpy(surface, fs, height); - surface += _screenHeight; - fs += _screenHeight; - } - break; + break; + } + case kScreenOrientationLandscape: { + int height = h * 2; + int offset = updatedRect.left * _screenHeight + (_screenHeight - updatedRect.bottom); + uint16 *fs = _fullscreen + offset; + surface += offset; + for (int x = w; x > 0; x--) { + memcpy(surface, fs, height); + surface += _screenHeight; + fs += _screenHeight; } - case kScreenOrientationFlippedLandscape: { - int height = h * 2; - int offset = ((_screenWidth - dirtyRect.left - 1) * _screenHeight + dirtyRect.top); - uint16 *fs = _fullscreen + offset; - surface += offset; - for (int x = w; x > 0; x--) { - memcpy(surface, fs, height); - surface -= _screenHeight; - fs -= _screenHeight; - } - break; + break; + } + case kScreenOrientationFlippedLandscape: { + int height = h * 2; + int offset = ((_screenWidth - updatedRect.left - 1) * _screenHeight + updatedRect.top); + uint16 *fs = _fullscreen + offset; + surface += offset; + for (int x = w; x > 0; x--) { + memcpy(surface, fs, height); + surface -= _screenHeight; + fs -= _screenHeight; } + break; } } - - //iPhone_updateScreenRect(dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom ); - } + } } Graphics::Surface *OSystem_IPHONE::lockScreen() { @@ -507,25 +534,26 @@ void OSystem_IPHONE::unlockScreen() { } void OSystem_IPHONE::setShakePos(int shakeOffset) { - printf("setShakePos(%i)\n", shakeOffset); + //printf("setShakePos(%i)\n", shakeOffset); } void OSystem_IPHONE::showOverlay() { //printf("showOverlay()\n"); _overlayVisible = true; - dirtyFullScreen(); + dirtyFullOverlayScreen(); } void OSystem_IPHONE::hideOverlay() { //printf("hideOverlay()\n"); _overlayVisible = false; + _dirtyOverlayRects.clear(); dirtyFullScreen(); } void OSystem_IPHONE::clearOverlay() { //printf("clearOverlay()\n"); bzero(_overlayBuffer, _screenWidth * _screenHeight * sizeof(OverlayColor)); - dirtyFullScreen(); + dirtyFullOverlayScreen(); } void OSystem_IPHONE::grabOverlay(OverlayColor *buf, int pitch) { @@ -565,8 +593,8 @@ void OSystem_IPHONE::copyRectToOverlay(const OverlayColor *buf, int pitch, int x if (w <= 0 || h <= 0) return; - if (!_fullScreenIsDirty) { - _dirtyRects.push_back(Common::Rect(x, y, x + w, y + h)); + if (!_fullScreenOverlayIsDirty) { + _dirtyOverlayRects.push_back(Common::Rect(x, y, x + w, y + h)); } OverlayColor *dst = _overlayBuffer + (y * _screenWidth + x); @@ -605,10 +633,6 @@ void OSystem_IPHONE::warpMouse(int x, int y) { _mouseDirty = true; } -void OSystem_IPHONE::dirtyMouseCursor() { - addDirtyRect(_mouseX - _mouseHotspotX, _mouseY - _mouseHotspotY, _mouseX + _mouseWidth - _mouseHotspotX, _mouseY + _mouseHeight - _mouseHotspotY); -} - void OSystem_IPHONE::dirtyFullScreen() { if (!_fullScreenIsDirty) { _dirtyRects.clear(); @@ -617,6 +641,14 @@ void OSystem_IPHONE::dirtyFullScreen() { } } +void OSystem_IPHONE::dirtyFullOverlayScreen() { + if (!_fullScreenOverlayIsDirty) { + _dirtyOverlayRects.clear(); + _dirtyOverlayRects.push_back(Common::Rect(0, 0, _screenWidth, _screenHeight)); + _fullScreenOverlayIsDirty = true; + } +} + void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) { //printf("setMouseCursor(%i, %i)\n", hotspotX, hotspotY); @@ -742,7 +774,7 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) { } bool OSystem_IPHONE::handleEvent_mouseDown(Common::Event &event, int x, int y) { - printf("Mouse down at (%u, %u)\n", x, 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. @@ -895,9 +927,10 @@ bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y // Swipe up _mouseClickAndDragEnabled = !_mouseClickAndDragEnabled; const char *dialogMsg; - if (_mouseClickAndDragEnabled) + if (_mouseClickAndDragEnabled) { + _touchpadModeEnabled = false; dialogMsg = "Mouse-click-and-drag mode enabled."; - else + } else dialogMsg = "Mouse-click-and-drag mode disabled."; GUI::TimedMessageDialog dialog(dialogMsg, 1500); dialog.runModal(); @@ -985,6 +1018,8 @@ void OSystem_IPHONE::handleEvent_orientationChanged(int orientation) { iPhone_initSurface(_screenWidth, _screenHeight, false); dirtyFullScreen(); + if (_overlayVisible) + dirtyFullOverlayScreen(); updateScreen(); } } @@ -1322,6 +1357,21 @@ Common::WriteStream *OSystem_IPHONE::createConfigWriteStream() { return file.createWriteStream(); } +void OSystem_IPHONE::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { + // Get URL of the Resource directory of the .app bundle + CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); + if (fileUrl) { + // Try to convert the URL to an absolute path + UInt8 buf[MAXPATHLEN]; + if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) { + // Success: Add it to the search path + Common::String bundlePath((const char *)buf); + s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath), priority); + } + CFRelease(fileUrl); + } +} + void iphone_main(int argc, char *argv[]) { //OSystem_IPHONE::migrateApp(); diff --git a/backends/platform/iphone/osys_iphone.h b/backends/platform/iphone/osys_iphone.h index b3404c15c2..c61461622c 100644 --- a/backends/platform/iphone/osys_iphone.h +++ b/backends/platform/iphone/osys_iphone.h @@ -105,9 +105,11 @@ protected: TimerProc _timerCallback; Common::Array _dirtyRects; + Common::Array _dirtyOverlayRects; ScreenOrientation _screenOrientation; bool _fullScreenIsDirty; - + bool _fullScreenOverlayIsDirty; + int _screenChangeCount; FilesystemFactory *_fsFactory; public: @@ -163,10 +165,11 @@ public: virtual void setupMixer(void); virtual int getOutputSampleRate() const; virtual void setTimerCallback(TimerProc callback, int interval); - + virtual int getScreenChangeID() const { return _screenChangeCount; } virtual void quit(); FilesystemFactory *getFilesystemFactory() { return _fsFactory; } + virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); virtual void getTimeAndDate(struct tm &t) const; virtual void setWindowCaption(const char *caption); @@ -182,12 +185,15 @@ public: virtual Common::WriteStream *createConfigWriteStream(); protected: - inline void addDirtyRect(int16 x1, int16 y1, int16 w, int16 h); void internUpdateScreen(); - void dirtyMouseCursor(); void dirtyFullScreen(); + void dirtyFullOverlayScreen(); void clipRectToScreen(int16 &x, int16 &y, int16 &w, int16 &h); void suspendLoop(); + void drawDirtyRect(const Common::Rect& dirtyRect); + void drawDirtyOverlayRect(const Common::Rect& dirtyRect); + void drawMouseCursorOnRectUpdate(const Common::Rect& updatedRect, const Common::Rect& mouseRect); + void updateHardwareSurfaceForRect(const Common::Rect& updatedRect); static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB); static int timerHandler(int t); diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 8b095dbc12..38f7203aa5 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -301,7 +301,7 @@ void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) } #endif -#if defined(MACOSX) || defined(IPHONE) +#ifdef MACOSX // Get URL of the Resource directory of the .app bundle CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); if (fileUrl) { diff --git a/configure b/configure index 87e750ef8d..78a04d6fe0 100755 --- a/configure +++ b/configure @@ -1691,7 +1691,7 @@ case $_backend in ;; iphone) OBJCFLAGS="$OBJCFLAGS --std=c99" - LIBS="$LIBS -lobjc -framework UIKit -framework CoreGraphics -framework CoreSurface -framework LayerKit -framework GraphicsServices -framework CoreFoundation -framework Foundation -framework AudioToolbox -framework CoreAudio" + LIBS="$LIBS -lobjc -framework UIKit -framework CoreGraphics -framework CoreSurface -framework QuartzCore -framework GraphicsServices -framework CoreFoundation -framework Foundation -framework AudioToolbox -framework CoreAudio" DEFINES="$DEFINES -DIPHONE_BACKEND" MODULES="$MODULES backends/platform/iphone" ;; diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index f5d6fc6d29..d895910988 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -42,7 +42,7 @@ #include "gui/ThemeEval.h" #include "gui/ThemeParser.h" -#ifdef MACOSX +#if defined(MACOSX) || defined(IPHONE) #include #endif @@ -1385,7 +1385,7 @@ void ThemeEngine::listUsableThemes(Common::List &list) { listUsableThemes(Common::FSNode(DATA_PATH), list); #endif -#ifdef MACOSX +#if defined(MACOSX) || defined(IPHONE) CFURLRef resourceUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); if (resourceUrl) { char buf[256]; -- cgit v1.2.3