Skip to content

Commit

Permalink
IPHONE: Always use the mouse texture.
Browse files Browse the repository at this point in the history
Formerly the mouse texture was only used when the overlay was visible. When
only the game screen was visible, the code rendered the mouse cursor on the
game screen texture.

This simplifies the drawing pipeline a bit.
  • Loading branch information
Johannes Schickel committed Feb 19, 2012
1 parent 87d85a7 commit 68bbe97
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 120 deletions.
44 changes: 30 additions & 14 deletions backends/platform/iphone/iphone_video.m
Expand Up @@ -108,8 +108,8 @@ void iPhone_updateScreen(int mouseX, int mouseY) {
//_mouseX = _overlayHeight - mouseX;
//_mouseY = mouseY;

_mouseX = (_overlayWidth - mouseX) / (float)_overlayWidth * _overlayHeight;
_mouseY = mouseY / (float)_overlayHeight * _overlayWidth;
_mouseX = mouseX;
_mouseY = mouseY;

if (!_needsScreenUpdate) {
_needsScreenUpdate = 1;
Expand Down Expand Up @@ -259,16 +259,14 @@ - (void)updateSurface {
}
_needsScreenUpdate = 0;

if (_overlayIsEnabled) {
glClear(GL_COLOR_BUFFER_BIT); printOpenGLError();
}
glClear(GL_COLOR_BUFFER_BIT); printOpenGLError();

[self updateMainSurface];

if (_overlayIsEnabled) {
if (_overlayIsEnabled)
[self updateOverlaySurface];
[self updateMouseSurface];
}

[self updateMouseSurface];

glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer); printOpenGLError();
[_context presentRenderbuffer:GL_RENDERBUFFER_OES];
Expand Down Expand Up @@ -350,14 +348,32 @@ - (void)updateOverlaySurface {

- (void)updateMouseSurface {

int width = _mouseCursorWidth / (float)_backingWidth * _backingHeight;
int height = _mouseCursorHeight / (float)_backingHeight * _backingWidth;
int width = _mouseCursorWidth;
int height = _mouseCursorHeight;

int mouseX = _mouseX;
int mouseY = _mouseY;

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;
width = width / (float)_width * gameHeight;
height = height / (float)_height * gameWidth;
} else {
mouseX = (_overlayWidth - mouseX) / (float)_overlayWidth * _backingWidth;
mouseY = mouseY / (float)_overlayHeight * _backingHeight;
width = width / (float)_overlayWidth * _backingWidth;
height = height / (float)_overlayHeight * _backingHeight;
}

GLfloat vertices[] = {
_mouseX, _mouseY,
_mouseX + height, _mouseY,
_mouseX, _mouseY + width,
_mouseX + height, _mouseY + width
mouseX , mouseY,
mouseX + width, mouseY,
mouseX , mouseY + height,
mouseX + width, mouseY + height
};

//printf("Cursor: width %u height %u\n", _mouseCursorWidth, _mouseCursorHeight);
Expand Down
2 changes: 0 additions & 2 deletions backends/platform/iphone/osys_main.cpp
Expand Up @@ -62,8 +62,6 @@ OSystem_IPHONE::OSystem_IPHONE() :
_mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1), _screenChangeCount(0),
_overlayHeight(0), _overlayWidth(0), _overlayBuffer(0) {
_queuedInputEvent.type = Common::EVENT_INVALID;
_lastDrawnMouseRect = Common::Rect(0, 0, 0, 0);

_touchpadModeEnabled = !iPhone_isHighResDevice();
_fsFactory = new POSIXFilesystemFactory();
}
Expand Down
3 changes: 0 additions & 3 deletions backends/platform/iphone/osys_main.h
Expand Up @@ -91,7 +91,6 @@ class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager {
long _lastMouseDown;
long _lastMouseTap;
long _queuedEventTime;
Common::Rect _lastDrawnMouseRect;
Common::Event _queuedInputEvent;
bool _secondaryTapped;
long _lastSecondaryDown;
Expand Down Expand Up @@ -192,11 +191,9 @@ class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager {
void internUpdateScreen();
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);
Expand Down
102 changes: 1 addition & 101 deletions backends/platform/iphone/osys_video.cpp
Expand Up @@ -159,80 +159,26 @@ void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y,
}
}

void OSystem_IPHONE::clipRectToScreen(int16 &x, int16 &y, int16 &w, int16 &h) {
if (x < 0) {
w += x;
x = 0;
}

if (y < 0) {
h += y;
y = 0;
}

if (w > _screenWidth - x)
w = _screenWidth - x;

if (h > _screenHeight - y)
h = _screenHeight - y;

if (w < 0) {
w = 0;
}

if (h < 0) {
h = 0;
}
}

void OSystem_IPHONE::updateScreen() {
//printf("updateScreen(): %i dirty rects.\n", _dirtyRects.size());

if (_dirtyRects.size() == 0 && _dirtyOverlayRects.size() == 0 && !_mouseDirty)
return;

internUpdateScreen();
_mouseDirty = false;
_fullScreenIsDirty = false;
_fullScreenOverlayIsDirty = false;

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

void OSystem_IPHONE::internUpdateScreen() {
int16 mouseX = _mouseX - _mouseHotspotX;
int16 mouseY = _mouseY - _mouseHotspotY;
int16 mouseWidth = _mouseWidth;
int16 mouseHeight = _mouseHeight;

clipRectToScreen(mouseX, mouseY, mouseWidth, mouseHeight);

Common::Rect mouseRect(mouseX, mouseY, mouseX + mouseWidth, mouseY + mouseHeight);

if (_mouseDirty) {
if (!_fullScreenIsDirty) {
_dirtyRects.push_back(_lastDrawnMouseRect);
_dirtyRects.push_back(mouseRect);
}
if (!_fullScreenOverlayIsDirty && _overlayVisible) {
_dirtyOverlayRects.push_back(_lastDrawnMouseRect);
_dirtyOverlayRects.push_back(mouseRect);
}
_mouseDirty = false;
_lastDrawnMouseRect = mouseRect;
}

while (_dirtyRects.size()) {
Common::Rect dirtyRect = _dirtyRects.remove_at(_dirtyRects.size() - 1);

//printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom);

drawDirtyRect(dirtyRect);

if (_overlayVisible)
drawDirtyOverlayRect(dirtyRect);
else
drawMouseCursorOnRectUpdate(dirtyRect, mouseRect);

updateHardwareSurfaceForRect(dirtyRect);
}

Expand All @@ -241,10 +187,7 @@ void OSystem_IPHONE::internUpdateScreen() {
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);
}
}
}
Expand Down Expand Up @@ -278,49 +221,6 @@ void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect &dirtyRect) {
iPhone_updateOverlayRect(_overlayBuffer, dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom);
}

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 bottom = top + _mouseHeight;
if (bottom > _screenWidth)
bottom = _screenWidth;

int displayWidth = _mouseWidth;
if (_mouseWidth + left > _screenWidth)
displayWidth = _screenWidth - left;

int displayHeight = _mouseHeight;
if (_mouseHeight + top > _screenHeight)
displayHeight = _screenHeight - top;

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 != _mouseKeyColor)
*dst = _gamePalette[*src];
dst++;
src++;
}
dst += _screenWidth - displayWidth + srcX;
src += _mouseWidth - displayWidth + srcX;
}
}
}

void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect &updatedRect) {
iPhone_updateScreenRect(_fullscreen, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom);
}
Expand Down

0 comments on commit 68bbe97

Please sign in to comment.