Extend setMouseCursor with additional keycolor parameter. Lets saga use 255

as white color. Made this function more safe by copying cursor data to
newly created buffer.

svn-id: r13777
This commit is contained in:
Eugene Sandulenko 2004-05-05 02:32:46 +00:00
parent 5d0f0ea0c6
commit b7e62e4b61
13 changed files with 76 additions and 29 deletions

View file

@ -62,6 +62,7 @@ void OSystem_PALMOS::init_intern(UInt16 gfx_mode) {
_vibrate = gVars->vibrator; _vibrate = gVars->vibrator;
_fullscreen = (ConfMan.getBool("fullscreen") && OPTIONS_TST(kOptModeWide)); _fullscreen = (ConfMan.getBool("fullscreen") && OPTIONS_TST(kOptModeWide));
_adjustAspectRatio = ConfMan.getBool("aspect_ratio"); _adjustAspectRatio = ConfMan.getBool("aspect_ratio");
_mouseDataP = NULL;
} }
void OSystem_PALMOS::setPalette(const byte *colors, uint start, uint num) { void OSystem_PALMOS::setPalette(const byte *colors, uint start, uint num) {
@ -701,14 +702,19 @@ void OSystem_PALMOS::set_mouse_pos(int x, int y) {
} }
} }
void OSystem_PALMOS::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) { void OSystem_PALMOS::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor) {
_mouseCurState.w = w; _mouseCurState.w = w;
_mouseCurState.h = h; _mouseCurState.h = h;
_mouseHotspotX = hotspot_x; _mouseHotspotX = hotspot_x;
_mouseHotspotY = hotspot_y; _mouseHotspotY = hotspot_y;
_mouseDataP = (byte*)buf; _mouseKeycolor = keycolor;
if (_mouseDataP)
free(_mouseDataP);
_mouseDataP = malloc(w * h);
memcpy(_mouseDataP, buf, w * h);
undraw_mouse(); undraw_mouse();
} }
@ -1316,7 +1322,7 @@ void OSystem_PALMOS::draw_mouse() {
while (width > 0) { while (width > 0) {
*bak++ = *dst; *bak++ = *dst;
color = *src++; color = *src++;
if (color != 0xFF) // 0xFF = transparent, don't draw if (color != _mouseKeycolor) // transparent, don't draw
*dst = color; *dst = color;
dst++; dst++;
width--; width--;

View file

@ -76,7 +76,7 @@ public:
// Set the bitmap that's used when drawing the cursor. // Set the bitmap that's used when drawing the cursor.
void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y); void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor = 255);
// Shaking is used in SCUMM. Set current shake position. // Shaking is used in SCUMM. Set current shake position.
void set_shake_pos(int shake_pos); void set_shake_pos(int shake_pos);
@ -215,6 +215,7 @@ private:
MousePos _mouseOldState; MousePos _mouseOldState;
int16 _mouseHotspotX; int16 _mouseHotspotX;
int16 _mouseHotspotY; int16 _mouseHotspotY;
byte _mouseKeycolor;
int _current_shake_pos; int _current_shake_pos;
int _new_shake_pos; int _new_shake_pos;

View file

@ -85,7 +85,7 @@ class OSystem_Dreamcast : public OSystem {
void warpMouse(int x, int y); void warpMouse(int x, int y);
// Set the bitmap that's used when drawing the cursor. // Set the bitmap that's used when drawing the cursor.
void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y); void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor = 255);
// Shaking is used in SCUMM. Set current shake position. // Shaking is used in SCUMM. Set current shake position.
void set_shake_pos(int shake_pos); void set_shake_pos(int shake_pos);
@ -163,6 +163,7 @@ class OSystem_Dreamcast : public OSystem {
int _current_shake_pos, _screen_w, _screen_h; int _current_shake_pos, _screen_w, _screen_h;
int _overlay_x, _overlay_y; int _overlay_x, _overlay_y;
unsigned char *_ms_buf; unsigned char *_ms_buf;
unsigned char _ms_keycolor;
SoundProc _sound_proc; SoundProc _sound_proc;
void *_sound_proc_param; void *_sound_proc_param;
bool _overlay_visible, _overlay_dirty, _screen_dirty; bool _overlay_visible, _overlay_dirty, _screen_dirty;

View file

@ -259,7 +259,7 @@ void OSystem_Dreamcast::warpMouse(int x, int y)
} }
void OSystem_Dreamcast::setMouseCursor(const byte *buf, uint w, uint h, void OSystem_Dreamcast::setMouseCursor(const byte *buf, uint w, uint h,
int hotspot_x, int hotspot_y) int hotspot_x, int hotspot_y, byte keycolor)
{ {
_ms_cur_w = w; _ms_cur_w = w;
_ms_cur_h = h; _ms_cur_h = h;
@ -267,7 +267,13 @@ void OSystem_Dreamcast::setMouseCursor(const byte *buf, uint w, uint h,
_ms_hotspot_x = hotspot_x; _ms_hotspot_x = hotspot_x;
_ms_hotspot_y = hotspot_y; _ms_hotspot_y = hotspot_y;
_ms_buf = (byte*)buf; _ms_keycolor = keycolor;
if (_ms_buf)
free(_ms_buf);
_ms_buf = (byte *)malloc(w * h);
memcpy(_ms_buf, buf, w * h);
} }
void OSystem_Dreamcast::set_shake_pos(int shake_pos) void OSystem_Dreamcast::set_shake_pos(int shake_pos)
@ -456,7 +462,7 @@ void OSystem_Dreamcast::drawMouse(int xdraw, int ydraw, int w, int h,
for(int y=0; y<h; y++) { for(int y=0; y<h; y++) {
int x; int x;
for(x=0; x<w; x++) for(x=0; x<w; x++)
if(*buf == 0xff) { if(*buf == _ms_keycolor) {
*dst++ = 0; *dst++ = 0;
buf++; buf++;
} else } else

View file

@ -67,6 +67,7 @@ void OSystem_GP32::initSize(uint w, uint h) {
if (_dirty_checksums) if (_dirty_checksums)
free(_dirty_checksums); free(_dirty_checksums);
_dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32)); _dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32));
_mouseData = NULL;
unload_gfx_mode(); unload_gfx_mode();
load_gfx_mode(); load_gfx_mode();
@ -538,7 +539,7 @@ void OSystem_GP32::draw_mouse() {
while (width > 0) { while (width > 0) {
*bak++ = *dst; *bak++ = *dst;
color = *src++; color = *src++;
if (color != 0xFF) // 0xFF = transparent, don't draw if (color != _mouseKeycolor) // transparent, don't draw
*dst = color; *dst = color;
dst++; dst++;
width--; width--;
@ -830,14 +831,20 @@ void OSystem_GP32::warpMouse(int x, int y) {
} }
// Set the bitmap that's used when drawing the cursor. // Set the bitmap that's used when drawing the cursor.
void OSystem_GP32::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) { void OSystem_GP32::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor) {
_mouse_cur_state.w = w; _mouse_cur_state.w = w;
_mouse_cur_state.h = h; _mouse_cur_state.h = h;
_mouseHotspotX = hotspot_x; _mouseHotspotX = hotspot_x;
_mouseHotspotY = hotspot_y; _mouseHotspotY = hotspot_y;
_mouseData = (byte*)buf; _mouseKeycolor = keycolor;
if (_mouseData)
free(_mouseData);
_mouseData = (byte *)malloc(w * h);
memcpy(_mouseData, buf, w * h);
undraw_mouse(); undraw_mouse();
} }

View file

@ -62,7 +62,7 @@ public:
void set_mouse_pos(int x, int y); void set_mouse_pos(int x, int y);
// Set the bitmap that's used when drawing the cursor. // Set the bitmap that's used when drawing the cursor.
void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y); void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, int keycolor = 255);
// Shaking is used in SCUMM. Set current shake position. // Shaking is used in SCUMM. Set current shake position.
void set_shake_pos(int shake_pos); void set_shake_pos(int shake_pos);
@ -188,6 +188,7 @@ private:
MousePos _mouse_old_state; MousePos _mouse_old_state;
int16 _mouseHotspotX; int16 _mouseHotspotX;
int16 _mouseHotspotY; int16 _mouseHotspotY;
byte _mouseKeycolor;
// Shake mode // Shake mode
int _currentShakePos; int _currentShakePos;

View file

@ -130,6 +130,7 @@ OSystem_MorphOS::OSystem_MorphOS(SCALERTYPE gfx_mode, bool full_screen)
ScummNoCursor = NULL; ScummNoCursor = NULL;
UpdateRegion = NULL; UpdateRegion = NULL;
NewUpdateRegion = NULL; NewUpdateRegion = NULL;
MouseImage = NULL;
} }
bool OSystem_MorphOS::Initialise() bool OSystem_MorphOS::Initialise()
@ -1360,7 +1361,7 @@ void OSystem_MorphOS::DrawMouse()
if (xdraw+x < ScummBufferWidth) if (xdraw+x < ScummBufferWidth)
{ {
bak[x] = dst[x]; bak[x] = dst[x];
if ((color=buf[x])!=0xFF) if ((color=buf[x])!=MouseKeycolor)
dst[x] = color; dst[x] = color;
} }
} }
@ -1423,7 +1424,7 @@ void OSystem_MorphOS::set_mouse_pos(int x, int y)
} }
} }
void OSystem_MorphOS::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) void OSystem_MorphOS::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor = 255)
{ {
MouseWidth = w; MouseWidth = w;
MouseHeight = h; MouseHeight = h;
@ -1431,7 +1432,13 @@ void OSystem_MorphOS::setMouseCursor(const byte *buf, uint w, uint h, int hotspo
MouseHotspotX = hotspot_x; MouseHotspotX = hotspot_x;
MouseHotspotY = hotspot_y; MouseHotspotY = hotspot_y;
MouseImage = (byte*)buf; MouseKeycolor = keycolor;
if (MouseImage)
free(MouseImage);
MouseImage = (byte *)malloc(w * h);
memcpy(mouseImage, buf, w * h);
UndrawMouse(); UndrawMouse();
} }

View file

@ -64,7 +64,7 @@ class OSystem_MorphOS : public OSystem
virtual void set_mouse_pos(int x, int y); virtual void set_mouse_pos(int x, int y);
// Set the bitmap that's used when drawing the cursor. // Set the bitmap that's used when drawing the cursor.
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y); virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor = 255);
// Shaking is used in SCUMM. Set current shake position. // Shaking is used in SCUMM. Set current shake position.
virtual void set_shake_pos(int shake_pos); virtual void set_shake_pos(int shake_pos);
@ -201,6 +201,7 @@ class OSystem_MorphOS : public OSystem
int MouseOldWidth, MouseOldHeight; int MouseOldWidth, MouseOldHeight;
int MouseHotspotX, MouseHotspotY; int MouseHotspotX, MouseHotspotY;
byte *MouseImage, MouseBackup[MAX_MOUSE_W*MAX_MOUSE_H]; byte *MouseImage, MouseBackup[MAX_MOUSE_W*MAX_MOUSE_H];
byte MouseKeycolor;
MsgPort* InputMsgPort; MsgPort* InputMsgPort;
IOStdReq*InputIORequest; IOStdReq*InputIORequest;

View file

@ -36,7 +36,7 @@ public:
void updateScreen() {} void updateScreen() {}
bool showMouse(bool visible) { return false; } bool showMouse(bool visible) { return false; }
void set_mouse_pos(int x, int y) {} void set_mouse_pos(int x, int y) {}
void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) {} void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor = 255) {}
void set_shake_pos(int shake_pos) {} void set_shake_pos(int shake_pos) {}
uint32 get_msecs(); uint32 get_msecs();
void delay_msecs(uint msecs); void delay_msecs(uint msecs);

View file

@ -175,6 +175,8 @@ void OSystem_SDL::initSize(uint w, uint h) {
free(_dirty_checksums); free(_dirty_checksums);
_dirty_checksums = (uint32 *)calloc(CKSUM_NUM * 2, sizeof(uint32)); _dirty_checksums = (uint32 *)calloc(CKSUM_NUM * 2, sizeof(uint32));
_mouseData = NULL;
unload_gfx_mode(); unload_gfx_mode();
load_gfx_mode(); load_gfx_mode();
} }
@ -992,7 +994,7 @@ void OSystem_SDL::warpMouse(int x, int y) {
} }
} }
void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) { void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor) {
undraw_mouse(); undraw_mouse();
@ -1004,7 +1006,13 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x,
_mouseHotspotX = hotspot_x; _mouseHotspotX = hotspot_x;
_mouseHotspotY = hotspot_y; _mouseHotspotY = hotspot_y;
_mouseData = buf; _mouseKeycolor = keycolor;
if (_mouseData)
free(_mouseData);
_mouseData = (byte *)malloc(w * h);
memcpy(_mouseData, buf, w * h);
} }
void OSystem_SDL::toggleMouseGrab() { void OSystem_SDL::toggleMouseGrab() {
@ -1063,7 +1071,7 @@ void OSystem_SDL::draw_mouse() {
while (width > 0) { while (width > 0) {
*bak++ = *dst; *bak++ = *dst;
color = *src++; color = *src++;
if (color != 0xFF) // 0xFF = transparent, don't draw if (color != _mouseKeycolor) // transparent, don't draw
*dst = color; *dst = color;
dst++; dst++;
width--; width--;

View file

@ -64,7 +64,7 @@ public:
void warpMouse(int x, int y); void warpMouse(int x, int y);
// Set the bitmap that's used when drawing the cursor. // Set the bitmap that's used when drawing the cursor.
void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y); void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor = 255);
// Shaking is used in SCUMM. Set current shake position. // Shaking is used in SCUMM. Set current shake position.
void set_shake_pos(int shake_pos); void set_shake_pos(int shake_pos);
@ -217,11 +217,12 @@ protected:
// mouse // mouse
bool _mouseVisible; bool _mouseVisible;
bool _mouseDrawn; bool _mouseDrawn;
const byte *_mouseData; byte *_mouseData;
byte *_mouseBackup; byte *_mouseBackup;
MousePos _mouseCurState; MousePos _mouseCurState;
int16 _mouseHotspotX; int16 _mouseHotspotX;
int16 _mouseHotspotY; int16 _mouseHotspotY;
byte _mouseKeycolor;
// joystick // joystick
SDL_Joystick *_joystick; SDL_Joystick *_joystick;

View file

@ -107,7 +107,7 @@ public:
void warpMouse(int x, int y); void warpMouse(int x, int y);
// Set the bitmap that's used when drawing the cursor. // Set the bitmap that's used when drawing the cursor.
void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y); void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor = 255);
// Shaking is used in SCUMM. Set current shake position. // Shaking is used in SCUMM. Set current shake position.
void set_shake_pos(int shake_pos); void set_shake_pos(int shake_pos);
@ -222,9 +222,10 @@ private:
int hot_x, hot_y; int hot_x, hot_y;
} mouse_state; } mouse_state;
mouse_state old_state, cur_state; mouse_state old_state, cur_state;
const byte *_ms_buf; byte *_ms_buf;
bool _mouse_visible; bool _mouse_visible;
bool _mouse_state_changed; bool _mouse_state_changed;
byte _mouseKeycolor;
uint32 _timer_duration, _timer_next_expiry; uint32 _timer_duration, _timer_next_expiry;
bool _timer_active; bool _timer_active;
@ -363,6 +364,7 @@ OSystem_X11::OSystem_X11() {
_overlay_visible = false; _overlay_visible = false;
_mouse_state_changed = true; _mouse_state_changed = true;
_mouse_visible = true; _mouse_visible = true;
_ms_buf = NULL;
cur_state.x = 0; cur_state.x = 0;
cur_state.y = 0; cur_state.y = 0;
cur_state.hot_x = 0; cur_state.hot_x = 0;
@ -780,7 +782,7 @@ void OSystem_X11::draw_mouse(dirty_square *dout) {
int width = real_w; int width = real_w;
while (width > 0) { while (width > 0) {
byte color = *buf; byte color = *buf;
if (color != 0xFF) { if (color != _mouseKeycolor) {
*dst = palette[color]; *dst = palette[color];
} }
buf++; buf++;
@ -808,16 +810,21 @@ void OSystem_X11::warpMouse(int x, int y) {
set_mouse_pos(x, y); set_mouse_pos(x, y);
} }
void OSystem_X11::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) { void OSystem_X11::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor) {
cur_state.w = w; cur_state.w = w;
cur_state.h = h; cur_state.h = h;
cur_state.hot_x = hotspot_x; cur_state.hot_x = hotspot_x;
cur_state.hot_y = hotspot_y; cur_state.hot_y = hotspot_y;
_ms_buf = buf;
if (_ms_buf)
free(_ms_buf);
_ms_buf = malloc(w * h);
memcpy(_ms_buf, buf, w * h);
if (_mouse_state_changed == false) { if (_mouse_state_changed == false) {
undraw_mouse(); undraw_mouse();
} }
_mouseKeycolor = keycolor;
_mouse_state_changed = true; _mouse_state_changed = true;
} }

View file

@ -357,8 +357,9 @@ public:
* @param h height of the mouse cursor * @param h height of the mouse cursor
* @param hotspotX horizontal offset from the left side to the hotspot * @param hotspotX horizontal offset from the left side to the hotspot
* @param hotspotY vertical offset from the top side to the hotspot * @param hotspotY vertical offset from the top side to the hotspot
* @param keycolor transparency color index
*/ */
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY) = 0; virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255) = 0;
//@} //@}