Skip to content

Commit

Permalink
IPHONE: Only update on screen mouse coordinates when it's needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schickel committed Feb 24, 2012
1 parent 5c55866 commit c3b5234
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 2 additions & 0 deletions backends/platform/iphone/iphone_video.h
Expand Up @@ -60,6 +60,7 @@
GLfloat _overlayTexCoords[4 * 2];
CGRect _overlayRect;

GLfloat _mouseVertCoords[4 * 2];
GLfloat _mouseTexCoords[4 * 2];
GLint _mouseHotspotX, _mouseHotspotY;
GLint _mouseWidth, _mouseHeight;
Expand All @@ -85,6 +86,7 @@
- (void)updateMouseSurface;
- (void)clearColorBuffer;

- (void)notifyMouseMove;
- (void)updateMouseCursorScaling;
- (void)updateMouseCursor;

Expand Down
41 changes: 21 additions & 20 deletions backends/platform/iphone/iphone_video.mm
Expand Up @@ -217,6 +217,11 @@ - (id)initWithFrame:(struct CGRect)frame {
_overlayTexCoords[4] = _overlayTexCoords[5] =
_overlayTexCoords[6] = _overlayTexCoords[7] = 0;

_mouseVertCoords[0] = _mouseVertCoords[1] =
_mouseVertCoords[2] = _mouseVertCoords[3] =
_mouseVertCoords[4] = _mouseVertCoords[5] =
_mouseVertCoords[6] = _mouseVertCoords[7] = 0;

_mouseTexCoords[0] = _mouseTexCoords[1] =
_mouseTexCoords[2] = _mouseTexCoords[3] =
_mouseTexCoords[4] = _mouseTexCoords[5] =
Expand Down Expand Up @@ -304,6 +309,16 @@ - (void)updateSurface {

}

- (void)notifyMouseMove {
const GLint mouseX = (GLint)(_videoContext.mouseX * _mouseScaleX) - _mouseHotspotX;
const GLint mouseY = (GLint)(_videoContext.mouseY * _mouseScaleY) - _mouseHotspotY;

_mouseVertCoords[0] = _mouseVertCoords[4] = mouseX;
_mouseVertCoords[1] = _mouseVertCoords[3] = mouseY;
_mouseVertCoords[2] = _mouseVertCoords[6] = mouseX + _mouseWidth;
_mouseVertCoords[5] = _mouseVertCoords[7] = mouseY + _mouseHeight;
}

- (void)updateMouseCursorScaling {
CGRect *rect;
int maxWidth, maxHeight;
Expand Down Expand Up @@ -338,6 +353,11 @@ - (void)updateMouseCursorScaling {
// since the hotspot offset is substracted from the position.
_mouseHotspotX -= (GLint)CGRectGetMinX(*rect);
_mouseHotspotY -= (GLint)CGRectGetMinY(*rect);

// FIXME: For now we also adapt the mouse position here. In reality we
// would be better off to also adjust the event position when switching
// from overlay to game screen or vica versa.
[self notifyMouseMove];
}

- (void)updateMouseCursor {
Expand Down Expand Up @@ -378,26 +398,7 @@ - (void)updateOverlaySurface {
}

- (void)updateMouseSurface {
int mouseX = _videoContext.mouseX;
int mouseY = _videoContext.mouseY;

mouseX = (int)(mouseX * _mouseScaleX) - _mouseHotspotX;
mouseY = (int)(mouseY * _mouseScaleY) - _mouseHotspotY;

GLfloat vertices[] = {
// Top left
mouseX , mouseY,
// Top right
mouseX + _mouseWidth, mouseY,
// Bottom left
mouseX , mouseY + _mouseHeight,
// Bottom right
mouseX + _mouseWidth, mouseY + _mouseHeight
};

//printf("Cursor: width %u height %u\n", _videoContext.mouseWidth, _videoContext.mouseHeight);

glVertexPointer(2, GL_FLOAT, 0, vertices); printOpenGLError();
glVertexPointer(2, GL_FLOAT, 0, _mouseVertCoords); printOpenGLError();
glTexCoordPointer(2, GL_FLOAT, 0, _mouseTexCoords); printOpenGLError();

glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError();
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/iphone/osys_video.mm
Expand Up @@ -332,9 +332,9 @@

void OSystem_IPHONE::warpMouse(int x, int y) {
//printf("warpMouse()\n");

_videoContext->mouseX = x;
_videoContext->mouseY = y;
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(notifyMouseMove) withObject:nil waitUntilDone: YES];
_mouseDirty = true;
}

Expand Down

0 comments on commit c3b5234

Please sign in to comment.