IPHONE: Always use the mouse texture.

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.
This commit is contained in:
Johannes Schickel 2012-02-20 00:04:47 +01:00
parent 87d85a7b20
commit 68bbe973bd
4 changed files with 31 additions and 120 deletions

View File

@ -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;
@ -259,16 +259,14 @@ bool getLocalMouseCoords(CGPoint *point) {
}
_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];
@ -350,14 +348,32 @@ bool getLocalMouseCoords(CGPoint *point) {
- (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);

View File

@ -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();
}

View File

@ -91,7 +91,6 @@ protected:
long _lastMouseDown;
long _lastMouseTap;
long _queuedEventTime;
Common::Rect _lastDrawnMouseRect;
Common::Event _queuedInputEvent;
bool _secondaryTapped;
long _lastSecondaryDown;
@ -192,11 +191,9 @@ protected:
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);

View File

@ -159,32 +159,6 @@ 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());
@ -192,6 +166,7 @@ void OSystem_IPHONE::updateScreen() {
return;
internUpdateScreen();
_mouseDirty = false;
_fullScreenIsDirty = false;
_fullScreenOverlayIsDirty = false;
@ -199,40 +174,11 @@ void OSystem_IPHONE::updateScreen() {
}
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);
}
@ -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);
}
}
}
@ -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);
}