diff options
author | Johannes Schickel | 2012-02-22 01:50:25 +0100 |
---|---|---|
committer | Johannes Schickel | 2012-02-22 01:53:20 +0100 |
commit | 1b26346fc887ce2681b3a70c6b5af030542dc3f1 (patch) | |
tree | 160510785b207322a88e065899a58eb2dde75d11 /backends/platform/iphone | |
parent | aa26d5def4265d496c03ef81fb2aa128020b08d4 (diff) | |
download | scummvm-rg350-1b26346fc887ce2681b3a70c6b5af030542dc3f1.tar.gz scummvm-rg350-1b26346fc887ce2681b3a70c6b5af030542dc3f1.tar.bz2 scummvm-rg350-1b26346fc887ce2681b3a70c6b5af030542dc3f1.zip |
IPHONE: Implement setShakeOffset.
This should fix bug #3374656 "IPHONE: setShakePos not implemented".
Diffstat (limited to 'backends/platform/iphone')
-rw-r--r-- | backends/platform/iphone/iphone_common.h | 1 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_video.h | 1 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_video.m | 60 | ||||
-rw-r--r-- | backends/platform/iphone/osys_video.cpp | 3 |
4 files changed, 46 insertions, 19 deletions
diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h index 2f03309215..3c2d414304 100644 --- a/backends/platform/iphone/iphone_common.h +++ b/backends/platform/iphone/iphone_common.h @@ -75,6 +75,7 @@ void iPhone_updateScreen(int mouseX, int mouseY); void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2); void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2); void iPhone_initSurface(int width, int height); +void iPhone_setShakeOffset(int offset); bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY); const char *iPhone_getDocumentsDir(); bool iPhone_isHighResDevice(); diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h index f2253f3e21..6d64b8464b 100644 --- a/backends/platform/iphone/iphone_video.h +++ b/backends/platform/iphone/iphone_video.h @@ -61,6 +61,7 @@ - (void *)getSurface; - (void)initSurface; +- (void)setViewTransformation; - (void)setGraphicsMode; diff --git a/backends/platform/iphone/iphone_video.m b/backends/platform/iphone/iphone_video.m index 5cd9534611..5adf594a15 100644 --- a/backends/platform/iphone/iphone_video.m +++ b/backends/platform/iphone/iphone_video.m @@ -60,6 +60,9 @@ static int _mouseCursorEnabled = 0; static GLint _renderBufferWidth; static GLint _renderBufferHeight; +static int _shakeOffsetY; +static int _scaledShakeOffsetY; + #if 0 static long lastTick = 0; static int frames = 0; @@ -148,9 +151,15 @@ void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, in void iPhone_initSurface(int width, int height) { _width = width; _height = height; + _shakeOffsetY = 0; [sharedInstance performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES]; } +void iPhone_setShakeOffset(int offset) { + _shakeOffsetY = offset; + [sharedInstance performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES]; +} + bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY) { id event = [sharedInstance getEvent]; if (event == nil) { @@ -214,38 +223,35 @@ static bool convertToRotatedCoords(UIDeviceOrientation orientation, CGPoint poin } } -static bool normalizeMouseCoords(CGPoint *point, CGRect area) { - if (point->x < CGRectGetMinX(area) || point->x > CGRectGetMaxX(area) || - point->y < CGRectGetMinY(area) || point->y > CGRectGetMaxY(area)) { - return false; - } - - point->x = (point->x - CGRectGetMinX(area)) / CGRectGetWidth(area); - point->y = (point->y - CGRectGetMinY(area)) / CGRectGetHeight(area); - return true; -} - static bool getMouseCoords(UIDeviceOrientation orientation, CGPoint point, int *x, int *y) { if (!convertToRotatedCoords(orientation, point, &point)) return false; - int width, height; + CGRect *area; + int width, height, offsetY; if (_overlayIsEnabled) { - if (!normalizeMouseCoords(&point, _overlayRect)) - return false; - + area = &_overlayRect; width = _overlayWidth; height = _overlayHeight; + offsetY = _shakeOffsetY; } else { - if (!normalizeMouseCoords(&point, _gameScreenRect)) - return false; - + area = &_gameScreenRect; width = _width; height = _height; + offsetY = _scaledShakeOffsetY; } + point.x = (point.x - CGRectGetMinX(*area)) / CGRectGetWidth(*area); + point.y = (point.y - CGRectGetMinY(*area)) / CGRectGetHeight(*area); + *x = point.x * width; - *y = point.y * height; + // offsetY describes the translation of the screen in the upward direction, + // thus we need to add it here. + *y = point.y * height + offsetY; + + // Clip coordinates + if (*x < 0 || *x > CGRectGetWidth(*area) || *y < 0 || *y > CGRectGetHeight(*area)) + return false; return true; } @@ -682,6 +688,22 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { _overlayVertCoords[2] = _overlayVertCoords[6] = CGRectGetMaxX(_overlayRect); _overlayVertCoords[5] = _overlayVertCoords[7] = CGRectGetMaxY(_overlayRect); + + [self setViewTransformation]; +} + +- (void)setViewTransformation { + // Set the modelview matrix. This matrix will be used for the shake offset + // support. + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + // Scale the shake offset according to the overlay size. We need this to + // adjust the overlay mouse click coordinates when an offset is set. + _scaledShakeOffsetY = _shakeOffsetY / (GLfloat)_height * CGRectGetHeight(_overlayRect); + + // Apply the shakeing to the output screen. + glTranslatef(0, -_scaledShakeOffsetY, 0); } - (void)clearColorBuffer { diff --git a/backends/platform/iphone/osys_video.cpp b/backends/platform/iphone/osys_video.cpp index 78c6cd4625..2b45b5568c 100644 --- a/backends/platform/iphone/osys_video.cpp +++ b/backends/platform/iphone/osys_video.cpp @@ -245,6 +245,9 @@ void OSystem_IPHONE::unlockScreen() { void OSystem_IPHONE::setShakePos(int shakeOffset) { //printf("setShakePos(%i)\n", shakeOffset); + iPhone_setShakeOffset(shakeOffset); + // HACK: We use this to force a redraw. + _mouseDirty = true; } void OSystem_IPHONE::showOverlay() { |