2009-07-14 13:52:11 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-10-31 00:04:24 +00:00
|
|
|
// Disable symbol overrides so that we can use system headers.
|
|
|
|
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
|
|
|
|
2009-07-14 13:52:11 +00:00
|
|
|
#include "osys_main.h"
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
#include "iphone_video.h"
|
|
|
|
|
|
|
|
void OSystem_IPHONE::initVideoContext() {
|
|
|
|
_videoContext = [g_iPhoneViewInstance getVideoContext];
|
|
|
|
}
|
|
|
|
|
2012-02-19 21:18:17 +01:00
|
|
|
const OSystem::GraphicsMode *OSystem_IPHONE::getSupportedGraphicsModes() const {
|
2009-07-14 13:52:11 +00:00
|
|
|
return s_supportedGraphicsModes;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OSystem_IPHONE::getDefaultGraphicsMode() const {
|
2012-02-20 02:32:10 +01:00
|
|
|
return kGraphicsModeLinear;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OSystem_IPHONE::setGraphicsMode(int mode) {
|
2012-02-20 02:32:10 +01:00
|
|
|
switch (mode) {
|
|
|
|
case kGraphicsModeNone:
|
|
|
|
case kGraphicsModeLinear:
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->graphicsMode = (GraphicsModes)mode;
|
|
|
|
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES];
|
2012-02-20 02:32:10 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int OSystem_IPHONE::getGraphicsMode() const {
|
2012-02-23 03:13:09 +01:00
|
|
|
return _videoContext->graphicsMode;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
2009-08-22 13:34:38 +00:00
|
|
|
void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
|
2009-07-14 13:52:11 +00:00
|
|
|
//printf("initSize(%i, %i)\n", width, height);
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->screenWidth = width;
|
|
|
|
_videoContext->screenHeight = height;
|
|
|
|
_videoContext->shakeOffsetY = 0;
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2012-02-20 00:35:14 +01:00
|
|
|
free(_gameScreenRaw);
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2012-02-20 00:35:14 +01:00
|
|
|
_gameScreenRaw = (byte *)malloc(width * height);
|
|
|
|
bzero(_gameScreenRaw, width * height);
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
updateOutputSurface();
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
clearOverlay();
|
|
|
|
|
2009-07-14 13:52:11 +00:00
|
|
|
_fullScreenIsDirty = false;
|
|
|
|
dirtyFullScreen();
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->mouseIsVisible = false;
|
2012-02-20 01:07:48 +01:00
|
|
|
_mouseCursorPaletteEnabled = false;
|
2009-07-14 13:52:11 +00:00
|
|
|
_screenChangeCount++;
|
2012-02-23 03:13:09 +01:00
|
|
|
|
2009-07-14 13:52:11 +00:00
|
|
|
updateScreen();
|
|
|
|
}
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
void OSystem_IPHONE::updateOutputSurface() {
|
|
|
|
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES];
|
|
|
|
}
|
|
|
|
|
2009-07-14 13:52:11 +00:00
|
|
|
int16 OSystem_IPHONE::getHeight() {
|
2012-02-23 03:13:09 +01:00
|
|
|
return _videoContext->screenHeight;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int16 OSystem_IPHONE::getWidth() {
|
2012-02-23 03:13:09 +01:00
|
|
|
return _videoContext->screenWidth;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) {
|
2010-06-01 22:29:55 +00:00
|
|
|
assert(start + num <= 256);
|
2009-07-14 13:52:11 +00:00
|
|
|
const byte *b = colors;
|
|
|
|
|
|
|
|
for (uint i = start; i < start + num; ++i) {
|
2012-02-19 22:16:38 +01:00
|
|
|
_gamePalette[i] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(b[0], b[1], b[2]);
|
2012-02-19 22:19:38 +01:00
|
|
|
_gamePaletteRGBA5551[i] = Graphics::RGBToColor<Graphics::ColorMasks<5551> >(b[0], b[1], b[2]);
|
2011-02-15 23:49:49 +01:00
|
|
|
b += 3;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dirtyFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::grabPalette(byte *colors, uint start, uint num) {
|
2010-06-01 22:29:55 +00:00
|
|
|
assert(start + num <= 256);
|
|
|
|
byte *b = colors;
|
|
|
|
|
|
|
|
for (uint i = start; i < start + num; ++i) {
|
2012-02-19 22:16:38 +01:00
|
|
|
Graphics::colorToRGB<Graphics::ColorMasks<565> >(_gamePalette[i], b[0], b[1], b[2]);
|
2011-02-15 23:49:49 +01:00
|
|
|
b += 3;
|
2010-06-01 22:29:55 +00:00
|
|
|
}
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
|
|
|
|
//printf("copyRectToScreen(%i, %i, %i, %i)\n", x, y, w, h);
|
|
|
|
//Clip the coordinates
|
|
|
|
if (x < 0) {
|
|
|
|
w += x;
|
|
|
|
buf -= x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y < 0) {
|
|
|
|
h += y;
|
|
|
|
buf -= y * pitch;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
if (w > (int)_videoContext->screenWidth - x) {
|
|
|
|
w = _videoContext->screenWidth - x;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
if (h > (int)_videoContext->screenHeight - y) {
|
|
|
|
h = _videoContext->screenHeight - y;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (w <= 0 || h <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!_fullScreenIsDirty) {
|
|
|
|
_dirtyRects.push_back(Common::Rect(x, y, x + w, y + h));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
byte *dst = _gameScreenRaw + y * _videoContext->screenWidth + x;
|
|
|
|
if ((int)_videoContext->screenWidth == pitch && pitch == w)
|
2009-07-14 13:52:11 +00:00
|
|
|
memcpy(dst, buf, h * w);
|
|
|
|
else {
|
|
|
|
do {
|
|
|
|
memcpy(dst, buf, w);
|
|
|
|
buf += pitch;
|
2012-02-23 03:13:09 +01:00
|
|
|
dst += _videoContext->screenWidth;
|
2009-07-14 13:52:11 +00:00
|
|
|
} while (--h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::updateScreen() {
|
|
|
|
//printf("updateScreen(): %i dirty rects.\n", _dirtyRects.size());
|
|
|
|
|
|
|
|
if (_dirtyRects.size() == 0 && _dirtyOverlayRects.size() == 0 && !_mouseDirty)
|
|
|
|
return;
|
|
|
|
|
|
|
|
internUpdateScreen();
|
2012-02-20 00:04:47 +01:00
|
|
|
_mouseDirty = false;
|
2009-07-14 13:52:11 +00:00
|
|
|
_fullScreenIsDirty = false;
|
|
|
|
_fullScreenOverlayIsDirty = false;
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
iPhone_updateScreen();
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::internUpdateScreen() {
|
2012-02-20 01:07:48 +01:00
|
|
|
if (_mouseNeedTextureUpdate) {
|
|
|
|
updateMouseTexture();
|
|
|
|
_mouseNeedTextureUpdate = false;
|
|
|
|
}
|
|
|
|
|
2009-07-14 13:52:11 +00:00
|
|
|
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);
|
2012-02-23 21:51:59 +01:00
|
|
|
// TODO: Implement dirty rect code
|
|
|
|
//updateHardwareSurfaceForRect(dirtyRect);
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
if (_videoContext->overlayVisible) {
|
2012-02-23 21:34:12 +01:00
|
|
|
// TODO: Implement dirty rect code
|
|
|
|
_dirtyOverlayRects.clear();
|
|
|
|
/*while (_dirtyOverlayRects.size()) {
|
2009-07-14 13:52:11 +00:00
|
|
|
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);
|
2012-02-23 21:34:12 +01:00
|
|
|
}*/
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 21:18:17 +01:00
|
|
|
void OSystem_IPHONE::drawDirtyRect(const Common::Rect &dirtyRect) {
|
2009-07-14 13:52:11 +00:00
|
|
|
int h = dirtyRect.bottom - dirtyRect.top;
|
|
|
|
int w = dirtyRect.right - dirtyRect.left;
|
|
|
|
|
2012-02-23 21:51:59 +01:00
|
|
|
byte *src = &_gameScreenRaw[dirtyRect.top * _videoContext->screenWidth + dirtyRect.left];
|
|
|
|
byte *dstRaw = (byte *)_videoContext->screenTexture.getBasePtr(dirtyRect.left, dirtyRect.top);
|
2009-07-14 13:52:11 +00:00
|
|
|
for (int y = h; y > 0; y--) {
|
2012-02-23 21:51:59 +01:00
|
|
|
uint16 *dst = (uint16 *)dstRaw;
|
2009-07-14 13:52:11 +00:00
|
|
|
for (int x = w; x > 0; x--)
|
2012-02-19 22:16:38 +01:00
|
|
|
*dst++ = _gamePalette[*src++];
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2012-02-23 21:51:59 +01:00
|
|
|
dstRaw += _videoContext->screenTexture.pitch;
|
2012-02-23 03:13:09 +01:00
|
|
|
src += _videoContext->screenWidth - w;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Graphics::Surface *OSystem_IPHONE::lockScreen() {
|
|
|
|
//printf("lockScreen()\n");
|
|
|
|
|
2012-02-20 00:35:14 +01:00
|
|
|
_framebuffer.pixels = _gameScreenRaw;
|
2012-02-23 03:13:09 +01:00
|
|
|
_framebuffer.w = _videoContext->screenWidth;
|
|
|
|
_framebuffer.h = _videoContext->screenHeight;
|
|
|
|
_framebuffer.pitch = _videoContext->screenWidth;
|
2011-04-17 21:14:19 +02:00
|
|
|
_framebuffer.format = Graphics::PixelFormat::createFormatCLUT8();
|
2009-07-14 13:52:11 +00:00
|
|
|
|
|
|
|
return &_framebuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::unlockScreen() {
|
|
|
|
//printf("unlockScreen()\n");
|
|
|
|
dirtyFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::setShakePos(int shakeOffset) {
|
|
|
|
//printf("setShakePos(%i)\n", shakeOffset);
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->shakeOffsetY = shakeOffset;
|
|
|
|
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES];
|
2012-02-22 01:50:25 +01:00
|
|
|
// HACK: We use this to force a redraw.
|
|
|
|
_mouseDirty = true;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::showOverlay() {
|
|
|
|
//printf("showOverlay()\n");
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->overlayVisible = true;
|
2009-07-14 13:52:11 +00:00
|
|
|
dirtyFullOverlayScreen();
|
2011-06-04 23:34:12 -04:00
|
|
|
updateScreen();
|
2012-02-23 03:13:09 +01:00
|
|
|
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES];
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::hideOverlay() {
|
|
|
|
//printf("hideOverlay()\n");
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->overlayVisible = false;
|
2009-07-14 13:52:11 +00:00
|
|
|
_dirtyOverlayRects.clear();
|
|
|
|
dirtyFullScreen();
|
2012-02-23 03:13:09 +01:00
|
|
|
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES];
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::clearOverlay() {
|
|
|
|
//printf("clearOverlay()\n");
|
2012-02-23 21:34:12 +01:00
|
|
|
bzero(_videoContext->overlayTexture.getBasePtr(0, 0), _videoContext->overlayTexture.h * _videoContext->overlayTexture.pitch);
|
2009-07-14 13:52:11 +00:00
|
|
|
dirtyFullOverlayScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::grabOverlay(OverlayColor *buf, int pitch) {
|
|
|
|
//printf("grabOverlay()\n");
|
2012-02-23 03:13:09 +01:00
|
|
|
int h = _videoContext->overlayHeight;
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2012-02-23 21:34:12 +01:00
|
|
|
const byte *src = (const byte *)_videoContext->overlayTexture.getBasePtr(0, 0);
|
2009-07-14 13:52:11 +00:00
|
|
|
do {
|
2012-02-23 03:13:09 +01:00
|
|
|
memcpy(buf, src, _videoContext->overlayWidth * sizeof(OverlayColor));
|
2012-02-23 21:34:12 +01:00
|
|
|
src += _videoContext->overlayTexture.pitch;
|
2009-07-14 13:52:11 +00:00
|
|
|
buf += pitch;
|
|
|
|
} while (--h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
|
|
|
|
//printf("copyRectToOverlay(buf, pitch=%i, x=%i, y=%i, w=%i, h=%i)\n", pitch, x, y, w, h);
|
|
|
|
|
|
|
|
//Clip the coordinates
|
|
|
|
if (x < 0) {
|
|
|
|
w += x;
|
|
|
|
buf -= x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y < 0) {
|
|
|
|
h += y;
|
|
|
|
buf -= y * pitch;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
if (w > (int)_videoContext->overlayWidth - x)
|
|
|
|
w = _videoContext->overlayWidth - x;
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
if (h > (int)_videoContext->overlayHeight - y)
|
|
|
|
h = _videoContext->overlayHeight - y;
|
2009-07-14 13:52:11 +00:00
|
|
|
|
|
|
|
if (w <= 0 || h <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!_fullScreenOverlayIsDirty) {
|
|
|
|
_dirtyOverlayRects.push_back(Common::Rect(x, y, x + w, y + h));
|
|
|
|
}
|
|
|
|
|
2012-02-23 21:34:12 +01:00
|
|
|
byte *dst = (byte *)_videoContext->overlayTexture.getBasePtr(x, y);
|
|
|
|
do {
|
|
|
|
memcpy(dst, buf, w * sizeof(OverlayColor));
|
|
|
|
buf += pitch;
|
|
|
|
dst += _videoContext->overlayTexture.pitch;
|
|
|
|
} while (--h);
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int16 OSystem_IPHONE::getOverlayHeight() {
|
2012-02-23 03:13:09 +01:00
|
|
|
return _videoContext->overlayHeight;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int16 OSystem_IPHONE::getOverlayWidth() {
|
2012-02-23 03:13:09 +01:00
|
|
|
return _videoContext->overlayWidth;
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OSystem_IPHONE::showMouse(bool visible) {
|
2012-02-23 03:13:09 +01:00
|
|
|
bool last = _videoContext->mouseIsVisible;
|
|
|
|
_videoContext->mouseIsVisible = visible;
|
2009-07-14 13:52:11 +00:00
|
|
|
_mouseDirty = true;
|
|
|
|
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::warpMouse(int x, int y) {
|
|
|
|
//printf("warpMouse()\n");
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->mouseX = x;
|
|
|
|
_videoContext->mouseY = y;
|
2009-07-14 13:52:11 +00:00
|
|
|
_mouseDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::dirtyFullScreen() {
|
|
|
|
if (!_fullScreenIsDirty) {
|
|
|
|
_dirtyRects.clear();
|
2012-02-23 03:13:09 +01:00
|
|
|
_dirtyRects.push_back(Common::Rect(0, 0, _videoContext->screenWidth, _videoContext->screenHeight));
|
2009-07-14 13:52:11 +00:00
|
|
|
_fullScreenIsDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::dirtyFullOverlayScreen() {
|
|
|
|
if (!_fullScreenOverlayIsDirty) {
|
|
|
|
_dirtyOverlayRects.clear();
|
2012-02-23 03:13:09 +01:00
|
|
|
_dirtyOverlayRects.push_back(Common::Rect(0, 0, _videoContext->overlayWidth, _videoContext->overlayHeight));
|
2009-07-14 13:52:11 +00:00
|
|
|
_fullScreenOverlayIsDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-22 14:52:26 +00:00
|
|
|
void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
|
2010-09-29 00:19:13 +00:00
|
|
|
//printf("setMouseCursor(%i, %i, scale %u)\n", hotspotX, hotspotY, cursorTargetScale);
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
if (_mouseBuf != NULL && (_videoContext->mouseWidth != w || _videoContext->mouseHeight != h)) {
|
2009-07-14 13:52:11 +00:00
|
|
|
free(_mouseBuf);
|
|
|
|
_mouseBuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_mouseBuf == NULL)
|
|
|
|
_mouseBuf = (byte *)malloc(w * h);
|
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->mouseWidth = w;
|
|
|
|
_videoContext->mouseHeight = h;
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2012-02-23 03:13:09 +01:00
|
|
|
_videoContext->mouseHotspotX = hotspotX;
|
|
|
|
_videoContext->mouseHotspotY = hotspotY;
|
2009-07-14 13:52:11 +00:00
|
|
|
|
2011-04-14 14:12:27 +02:00
|
|
|
_mouseKeyColor = (byte)keycolor;
|
2009-07-14 13:52:11 +00:00
|
|
|
|
|
|
|
memcpy(_mouseBuf, buf, w * h);
|
|
|
|
|
|
|
|
_mouseDirty = true;
|
2012-02-20 01:07:48 +01:00
|
|
|
_mouseNeedTextureUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::setCursorPalette(const byte *colors, uint start, uint num) {
|
|
|
|
assert(start + num <= 256);
|
|
|
|
|
|
|
|
for (uint i = start; i < start + num; ++i, colors += 3)
|
|
|
|
_mouseCursorPalette[i] = Graphics::RGBToColor<Graphics::ColorMasks<5551> >(colors[0], colors[1], colors[2]);
|
|
|
|
|
|
|
|
// FIXME: This is just stupid, our client code seems to assume that this
|
|
|
|
// automatically enables the cursor palette.
|
|
|
|
_mouseCursorPaletteEnabled = true;
|
|
|
|
|
|
|
|
if (_mouseCursorPaletteEnabled)
|
|
|
|
_mouseDirty = _mouseNeedTextureUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_IPHONE::updateMouseTexture() {
|
2012-02-24 00:55:52 +01:00
|
|
|
uint texWidth = getSizeNextPOT(_videoContext->mouseWidth);
|
|
|
|
uint texHeight = getSizeNextPOT(_videoContext->mouseHeight);
|
|
|
|
|
|
|
|
Graphics::Surface &mouseTexture = _videoContext->mouseTexture;
|
|
|
|
if (mouseTexture.w != texWidth || mouseTexture.h != texHeight)
|
|
|
|
mouseTexture.create(texWidth, texHeight, Graphics::createPixelFormat<5551>());
|
2012-02-20 01:07:48 +01:00
|
|
|
|
|
|
|
const uint16 *palette;
|
|
|
|
if (_mouseCursorPaletteEnabled)
|
|
|
|
palette = _mouseCursorPalette;
|
|
|
|
else
|
|
|
|
palette = _gamePaletteRGBA5551;
|
|
|
|
|
2012-02-24 00:55:52 +01:00
|
|
|
uint16 *mouseBuf = (uint16 *)mouseTexture.getBasePtr(0, 0);
|
2012-02-23 03:13:09 +01:00
|
|
|
for (uint x = 0; x < _videoContext->mouseWidth; ++x) {
|
|
|
|
for (uint y = 0; y < _videoContext->mouseHeight; ++y) {
|
|
|
|
const byte color = _mouseBuf[y * _videoContext->mouseWidth + x];
|
2012-02-20 01:07:48 +01:00
|
|
|
if (color != _mouseKeyColor)
|
|
|
|
mouseBuf[y * texWidth + x] = palette[color] | 0x1;
|
|
|
|
else
|
|
|
|
mouseBuf[y * texWidth + x] = 0x0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-24 00:55:52 +01:00
|
|
|
[g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES];
|
2009-07-14 13:52:11 +00:00
|
|
|
}
|