mirror of
https://github.com/libretro/scummvm.git
synced 2024-11-30 21:00:39 +00:00
IPHONE: Implement cursor palette support.
This commit is contained in:
parent
65cda4cd6b
commit
8102e7e645
2
NEWS
2
NEWS
@ -27,6 +27,8 @@ For a more comprehensive changelog of the latest experimental code, see:
|
||||
|
||||
iPhone port:
|
||||
- Changed "F5 (menu)" gesture to open up the global main menu instead.
|
||||
- Added support for custom cursor palettes, this makes the moderm theme use
|
||||
the red pointer cursor for example.
|
||||
|
||||
Windows port:
|
||||
- Changed default savegames location for Windows NT4/2000/XP/Vista/7.
|
||||
|
@ -76,7 +76,7 @@ int iPhone_getScreenHeight();
|
||||
int iPhone_getScreenWidth();
|
||||
void iPhone_enableOverlay(int state);
|
||||
void iPhone_showCursor(int state);
|
||||
void iPhone_setMouseCursor(short *buffer, int width, int height, int hotspotX, int hotspotY);
|
||||
void iPhone_setMouseCursor(unsigned short *buffer, int width, int height, int hotspotX, int hotspotY);
|
||||
|
||||
uint getSizeNextPOT(uint size);
|
||||
|
||||
|
@ -48,7 +48,7 @@ static int _overlayIsEnabled = 0;
|
||||
static UITouch *_firstTouch = NULL;
|
||||
static UITouch *_secondTouch = NULL;
|
||||
|
||||
static short *_mouseCursor = NULL;
|
||||
static unsigned short *_mouseCursor = NULL;
|
||||
static int _mouseCursorHeight = 0;
|
||||
static int _mouseCursorWidth = 0;
|
||||
static int _mouseCursorHotspotX = 0;
|
||||
@ -79,7 +79,7 @@ void iPhone_showCursor(int state) {
|
||||
_mouseCursorEnabled = state;
|
||||
}
|
||||
|
||||
void iPhone_setMouseCursor(short *buffer, int width, int height, int hotspotX, int hotspotY) {
|
||||
void iPhone_setMouseCursor(unsigned short *buffer, int width, int height, int hotspotX, int hotspotY) {
|
||||
_mouseCursor = buffer;
|
||||
|
||||
_mouseCursorWidth = width;
|
||||
@ -326,7 +326,6 @@ bool getLocalMouseCoords(CGPoint *point) {
|
||||
// due to the iPhone internals having to convert the whole texture back from its internal format when used.
|
||||
// In the future we could use several tiled textures instead.
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _textureWidth, _textureHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, _textureBuffer); printOpenGLError();
|
||||
glDisable(GL_BLEND);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError();
|
||||
}
|
||||
|
||||
@ -353,7 +352,6 @@ bool getLocalMouseCoords(CGPoint *point) {
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, _overlayTexture); printOpenGLError();
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _overlayTexWidth, _overlayTexHeight, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _overlayTexBuffer); printOpenGLError();
|
||||
glEnable(GL_BLEND);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError();
|
||||
}
|
||||
|
||||
@ -413,7 +411,6 @@ bool getLocalMouseCoords(CGPoint *point) {
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, texCoords); printOpenGLError();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError();
|
||||
glEnable(GL_BLEND);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError();
|
||||
}
|
||||
|
||||
@ -463,6 +460,7 @@ bool getLocalMouseCoords(CGPoint *point) {
|
||||
glViewport(0, 0, _backingWidth, _backingHeight); printOpenGLError();
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); printOpenGLError();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glEnable(GL_TEXTURE_2D); printOpenGLError();
|
||||
|
@ -56,11 +56,11 @@ OSystem_IPHONE::OSystem_IPHONE() :
|
||||
_mixer(NULL), _gameScreenRaw(NULL),
|
||||
_overlayVisible(false), _gameScreenConverted(NULL),
|
||||
_mouseHeight(0), _mouseWidth(0), _mouseBuf(NULL), _lastMouseTap(0), _queuedEventTime(0),
|
||||
_secondaryTapped(false), _lastSecondaryTap(0),
|
||||
_mouseNeedTextureUpdate(false), _secondaryTapped(false), _lastSecondaryTap(0),
|
||||
_screenOrientation(kScreenOrientationFlippedLandscape), _mouseClickAndDragEnabled(false),
|
||||
_gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), _fullScreenOverlayIsDirty(false),
|
||||
_mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1), _screenChangeCount(0),
|
||||
_overlayHeight(0), _overlayWidth(0), _overlayBuffer(0) {
|
||||
_overlayHeight(0), _overlayWidth(0), _overlayBuffer(0), _mouseCursorPaletteEnabled(false) {
|
||||
_queuedInputEvent.type = Common::EVENT_INVALID;
|
||||
_touchpadModeEnabled = !iPhone_isHighResDevice();
|
||||
_fsFactory = new POSIXFilesystemFactory();
|
||||
@ -99,14 +99,38 @@ void OSystem_IPHONE::initBackend() {
|
||||
}
|
||||
|
||||
bool OSystem_IPHONE::hasFeature(Feature f) {
|
||||
return false;
|
||||
switch (f) {
|
||||
case kFeatureCursorPalette:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_IPHONE::setFeatureState(Feature f, bool enable) {
|
||||
switch (f) {
|
||||
case kFeatureCursorPalette:
|
||||
if (_mouseCursorPaletteEnabled != enable) {
|
||||
_mouseNeedTextureUpdate = true;
|
||||
_mouseDirty = true;
|
||||
_mouseCursorPaletteEnabled = enable;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OSystem_IPHONE::getFeatureState(Feature f) {
|
||||
return false;
|
||||
switch (f) {
|
||||
case kFeatureCursorPalette:
|
||||
return _mouseCursorPaletteEnabled;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_IPHONE::suspendLoop() {
|
||||
|
@ -82,12 +82,15 @@ protected:
|
||||
uint32 _timeSuspended;
|
||||
|
||||
bool _mouseVisible;
|
||||
bool _mouseCursorPaletteEnabled;
|
||||
uint16 _mouseCursorPalette[256];
|
||||
byte *_mouseBuf;
|
||||
byte _mouseKeyColor;
|
||||
uint _mouseWidth, _mouseHeight;
|
||||
uint _mouseX, _mouseY;
|
||||
int _mouseHotspotX, _mouseHotspotY;
|
||||
bool _mouseDirty;
|
||||
bool _mouseNeedTextureUpdate;
|
||||
long _lastMouseDown;
|
||||
long _lastMouseTap;
|
||||
long _queuedEventTime;
|
||||
@ -159,6 +162,7 @@ public:
|
||||
|
||||
virtual void warpMouse(int x, int y);
|
||||
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 255, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL);
|
||||
virtual void setCursorPalette(const byte *colors, uint start, uint num);
|
||||
|
||||
virtual bool pollEvent(Common::Event &event);
|
||||
virtual uint32 getMillis();
|
||||
@ -195,6 +199,7 @@ protected:
|
||||
void drawDirtyRect(const Common::Rect &dirtyRect);
|
||||
void drawDirtyOverlayRect(const Common::Rect &dirtyRect);
|
||||
void updateHardwareSurfaceForRect(const Common::Rect &updatedRect);
|
||||
void updateMouseTexture();
|
||||
static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB);
|
||||
static int timerHandler(int t);
|
||||
|
||||
|
@ -81,6 +81,7 @@ void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelForm
|
||||
_fullScreenIsDirty = false;
|
||||
dirtyFullScreen();
|
||||
_mouseVisible = false;
|
||||
_mouseCursorPaletteEnabled = false;
|
||||
_screenChangeCount++;
|
||||
updateScreen();
|
||||
}
|
||||
@ -174,6 +175,11 @@ void OSystem_IPHONE::updateScreen() {
|
||||
}
|
||||
|
||||
void OSystem_IPHONE::internUpdateScreen() {
|
||||
if (_mouseNeedTextureUpdate) {
|
||||
updateMouseTexture();
|
||||
_mouseNeedTextureUpdate = false;
|
||||
}
|
||||
|
||||
while (_dirtyRects.size()) {
|
||||
Common::Rect dirtyRect = _dirtyRects.remove_at(_dirtyRects.size() - 1);
|
||||
|
||||
@ -355,24 +361,6 @@ void OSystem_IPHONE::dirtyFullOverlayScreen() {
|
||||
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);
|
||||
|
||||
int texWidth = getSizeNextPOT(w);
|
||||
int texHeight = getSizeNextPOT(h);
|
||||
int bufferSize = texWidth * texHeight * sizeof(int16);
|
||||
int16 *mouseBuf = (int16 *)malloc(bufferSize);
|
||||
memset(mouseBuf, 0, bufferSize);
|
||||
|
||||
for (uint x = 0; x < w; ++x) {
|
||||
for (uint y = 0; y < h; ++y) {
|
||||
byte color = buf[y * w + x];
|
||||
if (color != keycolor)
|
||||
mouseBuf[y * texWidth + x] = _gamePaletteRGBA5551[color] | 0x1;
|
||||
else
|
||||
mouseBuf[y * texWidth + x] = 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
iPhone_setMouseCursor(mouseBuf, w, h, hotspotX, hotspotY);
|
||||
|
||||
if (_mouseBuf != NULL && (_mouseWidth != w || _mouseHeight != h)) {
|
||||
free(_mouseBuf);
|
||||
_mouseBuf = NULL;
|
||||
@ -392,4 +380,45 @@ void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspot
|
||||
memcpy(_mouseBuf, buf, w * h);
|
||||
|
||||
_mouseDirty = true;
|
||||
_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() {
|
||||
int texWidth = getSizeNextPOT(_mouseWidth);
|
||||
int texHeight = getSizeNextPOT(_mouseHeight);
|
||||
int bufferSize = texWidth * texHeight * sizeof(int16);
|
||||
uint16 *mouseBuf = (uint16 *)malloc(bufferSize);
|
||||
memset(mouseBuf, 0, bufferSize);
|
||||
|
||||
const uint16 *palette;
|
||||
if (_mouseCursorPaletteEnabled)
|
||||
palette = _mouseCursorPalette;
|
||||
else
|
||||
palette = _gamePaletteRGBA5551;
|
||||
|
||||
for (uint x = 0; x < _mouseWidth; ++x) {
|
||||
for (uint y = 0; y < _mouseHeight; ++y) {
|
||||
const byte color = _mouseBuf[y * _mouseWidth + x];
|
||||
if (color != _mouseKeyColor)
|
||||
mouseBuf[y * texWidth + x] = palette[color] | 0x1;
|
||||
else
|
||||
mouseBuf[y * texWidth + x] = 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
iPhone_setMouseCursor(mouseBuf, _mouseWidth, _mouseHeight, _mouseHotspotX, _mouseHotspotY);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user