diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h index 93637a3bb522..18821e697f5d 100644 --- a/backends/platform/iphone/iphone_common.h +++ b/backends/platform/iphone/iphone_common.h @@ -75,20 +75,13 @@ struct VideoContext { }; // On the ObjC side -void iPhone_setGraphicsMode(GraphicsModes mode); -void iPhone_updateScreen(int mouseX, int mouseY); -void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2); -void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2); -void iPhone_initSurface(int width, int height); -void iPhone_setShakeOffset(int offset); +void iPhone_updateScreen(); +void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2, int width); +void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2, int width); bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY); const char *iPhone_getDocumentsDir(); bool iPhone_isHighResDevice(); -int iPhone_getScreenHeight(); -int iPhone_getScreenWidth(); -void iPhone_enableOverlay(bool state); -void iPhone_showCursor(int state); -void iPhone_setMouseCursor(unsigned short *buffer, int width, int height, int hotspotX, int hotspotY); +void iPhone_setMouseCursor(unsigned short *buffer); uint getSizeNextPOT(uint size); diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h index 2677267171ac..1d9d7e7d359b 100644 --- a/backends/platform/iphone/iphone_video.h +++ b/backends/platform/iphone/iphone_video.h @@ -35,6 +35,8 @@ #include "iphone_common.h" @interface iPhoneView : UIView { + VideoContext _videoContext; + NSMutableArray *_events; SoftKeyboard *_keyboardView; @@ -56,6 +58,8 @@ - (id)initWithFrame:(struct CGRect)frame; +- (VideoContext *)getVideoContext; + - (void)drawRect:(CGRect)frame; - (void)initSurface; @@ -81,4 +85,6 @@ @end +extern iPhoneView *g_iPhoneViewInstance; + #endif diff --git a/backends/platform/iphone/iphone_video.mm b/backends/platform/iphone/iphone_video.mm index a4de97042070..387ed7252f00 100644 --- a/backends/platform/iphone/iphone_video.mm +++ b/backends/platform/iphone/iphone_video.mm @@ -22,7 +22,7 @@ #include "iphone_video.h" -static iPhoneView *sharedInstance = nil; +iPhoneView *g_iPhoneViewInstance = nil; static int _fullWidth; static int _fullHeight; static CGRect _gameScreenRect; @@ -48,8 +48,6 @@ static int _scaledShakeOffsetY; -static VideoContext _videoContext; - #if 0 static long lastTick = 0; static int frames = 0; @@ -70,83 +68,36 @@ int printOglError(const char *file, int line) { return retCode; } -void iPhone_setGraphicsMode(GraphicsModes mode) { - _videoContext.graphicsMode = mode; - - [sharedInstance performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES]; -} - -void iPhone_showCursor(int state) { - _videoContext.mouseIsVisible = state; -} - -void iPhone_setMouseCursor(unsigned short *buffer, int width, int height, int hotspotX, int hotspotY) { +void iPhone_setMouseCursor(unsigned short *buffer) { _mouseCursor = buffer; - - _videoContext.mouseWidth = width; - _videoContext.mouseHeight = height; - - _videoContext.mouseHotspotX = hotspotX; - _videoContext.mouseHotspotY = hotspotY; - - [sharedInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; -} - -void iPhone_enableOverlay(bool state) { - _videoContext.overlayVisible = state; - - [sharedInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; -} - -int iPhone_getScreenHeight() { - return _videoContext.overlayHeight; -} - -int iPhone_getScreenWidth() { - return _videoContext.overlayWidth; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; } bool iPhone_isHighResDevice() { return _fullHeight > 480; } -void iPhone_updateScreen(int mouseX, int mouseY) { +void iPhone_updateScreen() { //printf("Mouse: (%i, %i)\n", mouseX, mouseY); - - _videoContext.mouseX = mouseX; - _videoContext.mouseY = mouseY; - if (!_needsScreenUpdate) { _needsScreenUpdate = 1; - [sharedInstance performSelectorOnMainThread:@selector(updateSurface) withObject:nil waitUntilDone: NO]; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateSurface) withObject:nil waitUntilDone: NO]; } } -void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2) { +void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2, int width) { for (int y = y1; y < y2; ++y) - memcpy(&_gameScreenTextureBuffer[(y * _gameScreenTextureWidth + x1) * 2], &screen[y * _videoContext.screenWidth + x1], (x2 - x1) * 2); + memcpy(&_gameScreenTextureBuffer[(y * _gameScreenTextureWidth + x1) * 2], &screen[y * width + x1], (x2 - x1) * 2); } -void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2) { +void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2, int width) { //printf("Overlaywidth: %u, fullwidth %u\n", _videoContext.overlayWidth, _fullWidth); for (int y = y1; y < y2; ++y) - memcpy(&_overlayTexBuffer[(y * _overlayTexWidth + x1) * 2], &screen[y * _videoContext.overlayWidth + x1], (x2 - x1) * 2); -} - -void iPhone_initSurface(int width, int height) { - _videoContext.screenWidth = width; - _videoContext.screenHeight = height; - _videoContext.shakeOffsetY = 0; - [sharedInstance performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES]; -} - -void iPhone_setShakeOffset(int offset) { - _videoContext.shakeOffsetY = offset; - [sharedInstance performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES]; + memcpy(&_overlayTexBuffer[(y * _overlayTexWidth + x1) * 2], &screen[y * width + x1], (x2 - x1) * 2); } bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY) { - id event = [sharedInstance getEvent]; + id event = [g_iPhoneViewInstance getEvent]; if (event == nil) { return false; } @@ -189,6 +140,10 @@ + (Class)layerClass { return [CAEAGLLayer class]; } +- (VideoContext *)getVideoContext { + return &_videoContext; +} + - (void)createContext { CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; @@ -263,13 +218,14 @@ - (id)initWithFrame:(struct CGRect)frame { _fullWidth = (int)frame.size.width; _fullHeight = (int)frame.size.height; - sharedInstance = self; + g_iPhoneViewInstance = self; _keyboardView = nil; _screenTexture = 0; _overlayTexture = 0; _mouseCursorTexture = 0; + memset(&_videoContext, 0, sizeof(_videoContext)); _videoContext.graphicsMode = kGraphicsModeLinear; _videoContext.overlayVisible = false; diff --git a/backends/platform/iphone/osys_events.cpp b/backends/platform/iphone/osys_events.cpp index 94ef5653173d..85efbda2083c 100644 --- a/backends/platform/iphone/osys_events.cpp +++ b/backends/platform/iphone/osys_events.cpp @@ -122,8 +122,8 @@ bool OSystem_IPHONE::handleEvent_mouseDown(Common::Event &event, int x, int y) { if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONDOWN; - event.mouse.x = _videoContext.mouseX; - event.mouse.y = _videoContext.mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; return true; } else { _lastMouseDown = getMillis(); @@ -140,17 +140,17 @@ bool OSystem_IPHONE::handleEvent_mouseUp(Common::Event &event, int x, int y) { return false; } else if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONUP; - event.mouse.x = _videoContext.mouseX; - event.mouse.y = _videoContext.mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; } else { if (getMillis() - _lastMouseDown < 250) { event.type = Common::EVENT_LBUTTONDOWN; - event.mouse.x = _videoContext.mouseX; - event.mouse.y = _videoContext.mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_LBUTTONUP; - _queuedInputEvent.mouse.x = _videoContext.mouseX; - _queuedInputEvent.mouse.y = _videoContext.mouseY; + _queuedInputEvent.mouse.x = _videoContext->mouseX; + _queuedInputEvent.mouse.y = _videoContext->mouseY; _lastMouseTap = getMillis(); _queuedEventTime = _lastMouseTap + kQueuedInputEventDelay; } else @@ -167,12 +167,12 @@ bool OSystem_IPHONE::handleEvent_secondMouseDown(Common::Event &event, int x, in if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONUP; - event.mouse.x = _videoContext.mouseX; - event.mouse.y = _videoContext.mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_RBUTTONDOWN; - _queuedInputEvent.mouse.x = _videoContext.mouseX; - _queuedInputEvent.mouse.y = _videoContext.mouseY; + _queuedInputEvent.mouse.x = _videoContext->mouseX; + _queuedInputEvent.mouse.y = _videoContext->mouseY; } else return false; @@ -184,7 +184,7 @@ bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int if (curTime - _lastSecondaryDown < 400) { //printf("Right tap!\n"); - if (curTime - _lastSecondaryTap < 400 && !_videoContext.overlayVisible) { + if (curTime - _lastSecondaryTap < 400 && !_videoContext->overlayVisible) { //printf("Right escape!\n"); event.type = Common::EVENT_KEYDOWN; _queuedInputEvent.type = Common::EVENT_KEYUP; @@ -197,11 +197,11 @@ bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int } else if (!_mouseClickAndDragEnabled) { //printf("Rightclick!\n"); event.type = Common::EVENT_RBUTTONDOWN; - event.mouse.x = _videoContext.mouseX; - event.mouse.y = _videoContext.mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_RBUTTONUP; - _queuedInputEvent.mouse.x = _videoContext.mouseX; - _queuedInputEvent.mouse.y = _videoContext.mouseY; + _queuedInputEvent.mouse.x = _videoContext->mouseX; + _queuedInputEvent.mouse.y = _videoContext->mouseY; _lastSecondaryTap = curTime; _queuedEventTime = curTime + kQueuedInputEventDelay; } else { @@ -211,8 +211,8 @@ bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int } if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_RBUTTONUP; - event.mouse.x = _videoContext.mouseX; - event.mouse.y = _videoContext.mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; } return true; @@ -234,11 +234,11 @@ bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y _lastPadX = x; _lastPadY = y; - mouseNewPosX = (int)(_videoContext.mouseX - deltaX / 0.5f); - mouseNewPosY = (int)(_videoContext.mouseY - deltaY / 0.5f); + mouseNewPosX = (int)(_videoContext->mouseX - deltaX / 0.5f); + mouseNewPosY = (int)(_videoContext->mouseY - deltaY / 0.5f); - int widthCap = _videoContext.overlayVisible ? _videoContext.overlayWidth : _videoContext.screenWidth; - int heightCap = _videoContext.overlayVisible ? _videoContext.overlayHeight : _videoContext.screenHeight; + int widthCap = _videoContext->overlayVisible ? _videoContext->overlayWidth : _videoContext->screenWidth; + int heightCap = _videoContext->overlayVisible ? _videoContext->overlayHeight : _videoContext->screenHeight; if (mouseNewPosX < 0) mouseNewPosX = 0; @@ -350,10 +350,10 @@ void OSystem_IPHONE::handleEvent_orientationChanged(int orientation) { if (_screenOrientation != newOrientation) { _screenOrientation = newOrientation; - iPhone_initSurface(_videoContext.screenWidth, _videoContext.screenHeight); + updateOutputSurface(); dirtyFullScreen(); - if (_videoContext.overlayVisible) + if (_videoContext->overlayVisible) dirtyFullOverlayScreen(); updateScreen(); } diff --git a/backends/platform/iphone/osys_main.cpp b/backends/platform/iphone/osys_main.cpp index 9e73fe77563d..368434c4762d 100644 --- a/backends/platform/iphone/osys_main.cpp +++ b/backends/platform/iphone/osys_main.cpp @@ -65,11 +65,7 @@ OSystem_IPHONE::OSystem_IPHONE() : _queuedInputEvent.type = Common::EVENT_INVALID; _touchpadModeEnabled = !iPhone_isHighResDevice(); _fsFactory = new POSIXFilesystemFactory(); - - _videoContext.mouseWidth = _videoContext.mouseHeight = 0; - _videoContext.overlayWidth = _videoContext.overlayHeight = 0; - _videoContext.overlayVisible = false; - _videoContext.graphicsMode = kGraphicsModeLinear; + initVideoContext(); } OSystem_IPHONE::~OSystem_IPHONE() { diff --git a/backends/platform/iphone/osys_main.h b/backends/platform/iphone/osys_main.h index f654537ac686..39395ac99a39 100644 --- a/backends/platform/iphone/osys_main.h +++ b/backends/platform/iphone/osys_main.h @@ -61,7 +61,7 @@ class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager { Audio::MixerImpl *_mixer; - VideoContext _videoContext; + VideoContext *_videoContext; Graphics::Surface _framebuffer; byte *_gameScreenRaw; @@ -183,6 +183,9 @@ class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager { virtual void logMessage(LogMessageType::Type type, const char *message); protected: + void initVideoContext(); + void updateOutputSurface(); + void internUpdateScreen(); void dirtyFullScreen(); void dirtyFullOverlayScreen(); diff --git a/backends/platform/iphone/osys_video.mm b/backends/platform/iphone/osys_video.mm index 574fc07d0d87..a40fcae78cdd 100644 --- a/backends/platform/iphone/osys_video.mm +++ b/backends/platform/iphone/osys_video.mm @@ -25,11 +25,16 @@ #include "osys_main.h" +#include "iphone_video.h" + +void OSystem_IPHONE::initVideoContext() { + _videoContext = [g_iPhoneViewInstance getVideoContext]; +} + const OSystem::GraphicsMode *OSystem_IPHONE::getSupportedGraphicsModes() const { return s_supportedGraphicsModes; } - int OSystem_IPHONE::getDefaultGraphicsMode() const { return kGraphicsModeLinear; } @@ -38,8 +43,8 @@ switch (mode) { case kGraphicsModeNone: case kGraphicsModeLinear: - _videoContext.graphicsMode = (GraphicsModes)mode; - iPhone_setGraphicsMode((GraphicsModes)mode); + _videoContext->graphicsMode = (GraphicsModes)mode; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES]; return true; default: @@ -48,14 +53,15 @@ } int OSystem_IPHONE::getGraphicsMode() const { - return _videoContext.graphicsMode; + return _videoContext->graphicsMode; } void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelFormat *format) { //printf("initSize(%i, %i)\n", width, height); - _videoContext.screenWidth = width; - _videoContext.screenHeight = height; + _videoContext->screenWidth = width; + _videoContext->screenHeight = height; + _videoContext->shakeOffsetY = 0; free(_gameScreenRaw); @@ -64,39 +70,42 @@ //free(_overlayBuffer); - int fullSize = _videoContext.screenWidth * _videoContext.screenHeight * sizeof(OverlayColor); + int fullSize = _videoContext->screenWidth * _videoContext->screenHeight * sizeof(OverlayColor); //_overlayBuffer = (OverlayColor *)malloc(fullSize); - clearOverlay(); free(_gameScreenConverted); _gameScreenConverted = (uint16 *)malloc(fullSize); bzero(_gameScreenConverted, fullSize); - iPhone_initSurface(width, height); + updateOutputSurface(); if (_overlayBuffer == NULL) { - _videoContext.overlayHeight = iPhone_getScreenHeight(); - _videoContext.overlayWidth = iPhone_getScreenWidth(); - - printf("Overlay: (%u x %u)\n", _videoContext.overlayWidth, _videoContext.overlayHeight); - _overlayBuffer = new OverlayColor[_videoContext.overlayHeight * _videoContext.overlayWidth]; + printf("Overlay: (%u x %u)\n", _videoContext->overlayWidth, _videoContext->overlayHeight); + _overlayBuffer = new OverlayColor[_videoContext->overlayHeight * _videoContext->overlayWidth]; } + clearOverlay(); + _fullScreenIsDirty = false; dirtyFullScreen(); - _videoContext.mouseIsVisible = false; + _videoContext->mouseIsVisible = false; _mouseCursorPaletteEnabled = false; _screenChangeCount++; + updateScreen(); } +void OSystem_IPHONE::updateOutputSurface() { + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES]; +} + int16 OSystem_IPHONE::getHeight() { - return _videoContext.screenHeight; + return _videoContext->screenHeight; } int16 OSystem_IPHONE::getWidth() { - return _videoContext.screenWidth; + return _videoContext->screenWidth; } void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) { @@ -137,12 +146,12 @@ y = 0; } - if (w > (int)_videoContext.screenWidth - x) { - w = _videoContext.screenWidth - x; + if (w > (int)_videoContext->screenWidth - x) { + w = _videoContext->screenWidth - x; } - if (h > (int)_videoContext.screenHeight - y) { - h = _videoContext.screenHeight - y; + if (h > (int)_videoContext->screenHeight - y) { + h = _videoContext->screenHeight - y; } if (w <= 0 || h <= 0) @@ -153,14 +162,14 @@ } - byte *dst = _gameScreenRaw + y * _videoContext.screenWidth + x; - if ((int)_videoContext.screenWidth == pitch && pitch == w) + byte *dst = _gameScreenRaw + y * _videoContext->screenWidth + x; + if ((int)_videoContext->screenWidth == pitch && pitch == w) memcpy(dst, buf, h * w); else { do { memcpy(dst, buf, w); buf += pitch; - dst += _videoContext.screenWidth; + dst += _videoContext->screenWidth; } while (--h); } } @@ -176,7 +185,7 @@ _fullScreenIsDirty = false; _fullScreenOverlayIsDirty = false; - iPhone_updateScreen(_videoContext.mouseX, _videoContext.mouseY); + iPhone_updateScreen(); } void OSystem_IPHONE::internUpdateScreen() { @@ -193,7 +202,7 @@ updateHardwareSurfaceForRect(dirtyRect); } - if (_videoContext.overlayVisible) { + if (_videoContext->overlayVisible) { while (_dirtyOverlayRects.size()) { Common::Rect dirtyRect = _dirtyOverlayRects.remove_at(_dirtyOverlayRects.size() - 1); @@ -207,32 +216,32 @@ int h = dirtyRect.bottom - dirtyRect.top; int w = dirtyRect.right - dirtyRect.left; - byte *src = &_gameScreenRaw[dirtyRect.top * _videoContext.screenWidth + dirtyRect.left]; - uint16 *dst = &_gameScreenConverted[dirtyRect.top * _videoContext.screenWidth + dirtyRect.left]; + byte *src = &_gameScreenRaw[dirtyRect.top * _videoContext->screenWidth + dirtyRect.left]; + uint16 *dst = &_gameScreenConverted[dirtyRect.top * _videoContext->screenWidth + dirtyRect.left]; for (int y = h; y > 0; y--) { for (int x = w; x > 0; x--) *dst++ = _gamePalette[*src++]; - dst += _videoContext.screenWidth - w; - src += _videoContext.screenWidth - w; + dst += _videoContext->screenWidth - w; + src += _videoContext->screenWidth - w; } } void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect &dirtyRect) { - iPhone_updateOverlayRect(_overlayBuffer, dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); + iPhone_updateOverlayRect(_overlayBuffer, dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom, _videoContext->overlayWidth); } void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect &updatedRect) { - iPhone_updateScreenRect(_gameScreenConverted, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom); + iPhone_updateScreenRect(_gameScreenConverted, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom, _videoContext->screenWidth); } Graphics::Surface *OSystem_IPHONE::lockScreen() { //printf("lockScreen()\n"); _framebuffer.pixels = _gameScreenRaw; - _framebuffer.w = _videoContext.screenWidth; - _framebuffer.h = _videoContext.screenHeight; - _framebuffer.pitch = _videoContext.screenWidth; + _framebuffer.w = _videoContext->screenWidth; + _framebuffer.h = _videoContext->screenHeight; + _framebuffer.pitch = _videoContext->screenWidth; _framebuffer.format = Graphics::PixelFormat::createFormatCLUT8(); return &_framebuffer; @@ -245,41 +254,42 @@ void OSystem_IPHONE::setShakePos(int shakeOffset) { //printf("setShakePos(%i)\n", shakeOffset); - iPhone_setShakeOffset(shakeOffset); + _videoContext->shakeOffsetY = shakeOffset; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES]; // HACK: We use this to force a redraw. _mouseDirty = true; } void OSystem_IPHONE::showOverlay() { //printf("showOverlay()\n"); - _videoContext.overlayVisible = true; + _videoContext->overlayVisible = true; dirtyFullOverlayScreen(); updateScreen(); - iPhone_enableOverlay(true); + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; } void OSystem_IPHONE::hideOverlay() { //printf("hideOverlay()\n"); - _videoContext.overlayVisible = false; + _videoContext->overlayVisible = false; _dirtyOverlayRects.clear(); dirtyFullScreen(); - iPhone_enableOverlay(false); + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; } void OSystem_IPHONE::clearOverlay() { //printf("clearOverlay()\n"); - bzero(_overlayBuffer, _videoContext.overlayWidth * _videoContext.overlayHeight * sizeof(OverlayColor)); + bzero(_overlayBuffer, _videoContext->overlayWidth * _videoContext->overlayHeight * sizeof(OverlayColor)); dirtyFullOverlayScreen(); } void OSystem_IPHONE::grabOverlay(OverlayColor *buf, int pitch) { //printf("grabOverlay()\n"); - int h = _videoContext.overlayHeight; + int h = _videoContext->overlayHeight; OverlayColor *src = _overlayBuffer; do { - memcpy(buf, src, _videoContext.overlayWidth * sizeof(OverlayColor)); - src += _videoContext.overlayWidth; + memcpy(buf, src, _videoContext->overlayWidth * sizeof(OverlayColor)); + src += _videoContext->overlayWidth; buf += pitch; } while (--h); } @@ -300,11 +310,11 @@ y = 0; } - if (w > (int)_videoContext.overlayWidth - x) - w = _videoContext.overlayWidth - x; + if (w > (int)_videoContext->overlayWidth - x) + w = _videoContext->overlayWidth - x; - if (h > (int)_videoContext.overlayHeight - y) - h = _videoContext.overlayHeight - y; + if (h > (int)_videoContext->overlayHeight - y) + h = _videoContext->overlayHeight - y; if (w <= 0 || h <= 0) return; @@ -313,30 +323,29 @@ _dirtyOverlayRects.push_back(Common::Rect(x, y, x + w, y + h)); } - OverlayColor *dst = _overlayBuffer + (y * _videoContext.overlayWidth + x); - if ((int)_videoContext.overlayWidth == pitch && pitch == w) + OverlayColor *dst = _overlayBuffer + (y * _videoContext->overlayWidth + x); + if ((int)_videoContext->overlayWidth == pitch && pitch == w) memcpy(dst, buf, h * w * sizeof(OverlayColor)); else { do { memcpy(dst, buf, w * sizeof(OverlayColor)); buf += pitch; - dst += _videoContext.overlayWidth; + dst += _videoContext->overlayWidth; } while (--h); } } int16 OSystem_IPHONE::getOverlayHeight() { - return _videoContext.overlayHeight; + return _videoContext->overlayHeight; } int16 OSystem_IPHONE::getOverlayWidth() { - return _videoContext.overlayWidth; + return _videoContext->overlayWidth; } bool OSystem_IPHONE::showMouse(bool visible) { - bool last = _videoContext.mouseIsVisible; - _videoContext.mouseIsVisible = visible; - iPhone_showCursor(visible); + bool last = _videoContext->mouseIsVisible; + _videoContext->mouseIsVisible = visible; _mouseDirty = true; return last; @@ -345,15 +354,15 @@ void OSystem_IPHONE::warpMouse(int x, int y) { //printf("warpMouse()\n"); - _videoContext.mouseX = x; - _videoContext.mouseY = y; + _videoContext->mouseX = x; + _videoContext->mouseY = y; _mouseDirty = true; } void OSystem_IPHONE::dirtyFullScreen() { if (!_fullScreenIsDirty) { _dirtyRects.clear(); - _dirtyRects.push_back(Common::Rect(0, 0, _videoContext.screenWidth, _videoContext.screenHeight)); + _dirtyRects.push_back(Common::Rect(0, 0, _videoContext->screenWidth, _videoContext->screenHeight)); _fullScreenIsDirty = true; } } @@ -361,7 +370,7 @@ void OSystem_IPHONE::dirtyFullOverlayScreen() { if (!_fullScreenOverlayIsDirty) { _dirtyOverlayRects.clear(); - _dirtyOverlayRects.push_back(Common::Rect(0, 0, _videoContext.overlayWidth, _videoContext.overlayHeight)); + _dirtyOverlayRects.push_back(Common::Rect(0, 0, _videoContext->overlayWidth, _videoContext->overlayHeight)); _fullScreenOverlayIsDirty = true; } } @@ -369,7 +378,7 @@ void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { //printf("setMouseCursor(%i, %i, scale %u)\n", hotspotX, hotspotY, cursorTargetScale); - if (_mouseBuf != NULL && (_videoContext.mouseWidth != w || _videoContext.mouseHeight != h)) { + if (_mouseBuf != NULL && (_videoContext->mouseWidth != w || _videoContext->mouseHeight != h)) { free(_mouseBuf); _mouseBuf = NULL; } @@ -377,11 +386,11 @@ if (_mouseBuf == NULL) _mouseBuf = (byte *)malloc(w * h); - _videoContext.mouseWidth = w; - _videoContext.mouseHeight = h; + _videoContext->mouseWidth = w; + _videoContext->mouseHeight = h; - _videoContext.mouseHotspotX = hotspotX; - _videoContext.mouseHotspotY = hotspotY; + _videoContext->mouseHotspotX = hotspotX; + _videoContext->mouseHotspotY = hotspotY; _mouseKeyColor = (byte)keycolor; @@ -406,8 +415,8 @@ } void OSystem_IPHONE::updateMouseTexture() { - int texWidth = getSizeNextPOT(_videoContext.mouseWidth); - int texHeight = getSizeNextPOT(_videoContext.mouseHeight); + int texWidth = getSizeNextPOT(_videoContext->mouseWidth); + int texHeight = getSizeNextPOT(_videoContext->mouseHeight); int bufferSize = texWidth * texHeight * sizeof(int16); uint16 *mouseBuf = (uint16 *)malloc(bufferSize); memset(mouseBuf, 0, bufferSize); @@ -418,9 +427,9 @@ else palette = _gamePaletteRGBA5551; - for (uint x = 0; x < _videoContext.mouseWidth; ++x) { - for (uint y = 0; y < _videoContext.mouseHeight; ++y) { - const byte color = _mouseBuf[y * _videoContext.mouseWidth + x]; + for (uint x = 0; x < _videoContext->mouseWidth; ++x) { + for (uint y = 0; y < _videoContext->mouseHeight; ++y) { + const byte color = _mouseBuf[y * _videoContext->mouseWidth + x]; if (color != _mouseKeyColor) mouseBuf[y * texWidth + x] = palette[color] | 0x1; else @@ -428,5 +437,5 @@ } } - iPhone_setMouseCursor(mouseBuf, _videoContext.mouseWidth, _videoContext.mouseHeight, _videoContext.mouseHotspotX, _videoContext.mouseHotspotY); + iPhone_setMouseCursor(mouseBuf); }