Skip to content

Commit

Permalink
IPHONE: Fix cursor hotspots.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schickel committed Feb 19, 2012
1 parent 68bbe97 commit 438bc50
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backends/platform/iphone/iphone_common.h
Expand Up @@ -75,7 +75,7 @@ bool iPhone_isHighResDevice();
int iPhone_getScreenHeight();
int iPhone_getScreenWidth();
void iPhone_enableOverlay(int state);
void iPhone_setMouseCursor(short *buffer, int width, int height);
void iPhone_setMouseCursor(short *buffer, int width, int height, int hotspotX, int hotspotY);

uint getSizeNextPOT(uint size);

Expand Down
17 changes: 16 additions & 1 deletion backends/platform/iphone/iphone_video.m
Expand Up @@ -51,6 +51,8 @@
static short *_mouseCursor = NULL;
static int _mouseCursorHeight = 0;
static int _mouseCursorWidth = 0;
static int _mouseCursorHotspotX = 0;
static int _mouseCursorHotspotY = 0;
static int _mouseX = 0;
static int _mouseY = 0;

Expand All @@ -72,12 +74,15 @@ int printOglError(const char *file, int line) {
return retCode;
}

void iPhone_setMouseCursor(short *buffer, int width, int height) {
void iPhone_setMouseCursor(short *buffer, int width, int height, int hotspotX, int hotspotY) {
_mouseCursor = buffer;

_mouseCursorWidth = width;
_mouseCursorHeight = height;

_mouseCursorHotspotX = hotspotX;
_mouseCursorHotspotY = hotspotY;

[sharedInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES];
}

Expand Down Expand Up @@ -354,21 +359,31 @@ - (void)updateMouseSurface {
int mouseX = _mouseX;
int mouseY = _mouseY;

int hotspotX = _mouseCursorHotspotX;
int hotspotY = _mouseCursorHotspotY;

if (!_overlayIsEnabled) {
const GLint gameWidth = (_visibleHeight - 2 * _widthOffset);
const GLint gameHeight = (_visibleWidth - 2 * _heightOffset);

mouseX = (_width - mouseX) / (float)_width * gameHeight + _heightOffset;
mouseY = mouseY / (float)_height * gameWidth + _widthOffset;
hotspotX = hotspotX / (float)_width * gameHeight;
hotspotY = hotspotY / (float)_height * gameWidth;
width = width / (float)_width * gameHeight;
height = height / (float)_height * gameWidth;
} else {
mouseX = (_overlayWidth - mouseX) / (float)_overlayWidth * _backingWidth;
mouseY = mouseY / (float)_overlayHeight * _backingHeight;
hotspotX = hotspotX / (float)_overlayWidth * _backingWidth;
hotspotY = hotspotY / (float)_overlayHeight * _backingHeight;
width = width / (float)_overlayWidth * _backingWidth;
height = height / (float)_overlayHeight * _backingHeight;
}

mouseX -= hotspotX;
mouseY -= hotspotY;

GLfloat vertices[] = {
mouseX , mouseY,
mouseX + width, mouseY,
Expand Down
4 changes: 2 additions & 2 deletions backends/platform/iphone/osys_video.cpp
Expand Up @@ -170,7 +170,7 @@ void OSystem_IPHONE::updateScreen() {
_fullScreenIsDirty = false;
_fullScreenOverlayIsDirty = false;

iPhone_updateScreen(_mouseX - _mouseHotspotX, _mouseY - _mouseHotspotY);
iPhone_updateScreen(_mouseX, _mouseY);
}

void OSystem_IPHONE::internUpdateScreen() {
Expand Down Expand Up @@ -380,7 +380,7 @@ void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspot
}
}

iPhone_setMouseCursor(mouseBuf, w, h);
iPhone_setMouseCursor(mouseBuf, w, h, hotspotX, hotspotY);

if (_mouseBuf != NULL && (_mouseWidth != w || _mouseHeight != h)) {
free(_mouseBuf);
Expand Down

0 comments on commit 438bc50

Please sign in to comment.