[Scummvm-cvs-logs] scummvm master -> 1b26346fc887ce2681b3a70c6b5af030542dc3f1
lordhoto
lordhoto at gmail.com
Wed Feb 22 01:54:00 CET 2012
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
1b26346fc8 IPHONE: Implement setShakeOffset.
Commit: 1b26346fc887ce2681b3a70c6b5af030542dc3f1
https://github.com/scummvm/scummvm/commit/1b26346fc887ce2681b3a70c6b5af030542dc3f1
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-02-21T16:53:20-08:00
Commit Message:
IPHONE: Implement setShakeOffset.
This should fix bug #3374656 "IPHONE: setShakePos not implemented".
Changed paths:
backends/platform/iphone/iphone_common.h
backends/platform/iphone/iphone_video.h
backends/platform/iphone/iphone_video.m
backends/platform/iphone/osys_video.cpp
diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h
index 2f03309..3c2d414 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 f2253f3..6d64b84 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 5cd9534..5adf594 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 78c6cd4..2b45b55 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() {
More information about the Scummvm-git-logs
mailing list