diff options
author | Martin Kiewitz | 2009-10-07 14:53:15 +0000 |
---|---|---|
committer | Martin Kiewitz | 2009-10-07 14:53:15 +0000 |
commit | 1dfe7578cba4894630bd6fa093cfa1607fbdad6e (patch) | |
tree | f8b14f9eea63060f11f27fd38320ec3c32d53128 /engines/sci/gui | |
parent | ece4f55db970c27a82d99aac76bc621790478b61 (diff) | |
download | scummvm-rg350-1dfe7578cba4894630bd6fa093cfa1607fbdad6e.tar.gz scummvm-rg350-1dfe7578cba4894630bd6fa093cfa1607fbdad6e.tar.bz2 scummvm-rg350-1dfe7578cba4894630bd6fa093cfa1607fbdad6e.zip |
SCI/newgui: kSetCursor (show, hide, pos, shape) implemented
svn-id: r44734
Diffstat (limited to 'engines/sci/gui')
-rw-r--r-- | engines/sci/gui/gui.cpp | 12 | ||||
-rw-r--r-- | engines/sci/gui/gui.h | 3 | ||||
-rw-r--r-- | engines/sci/gui/gui_cursor.cpp | 69 | ||||
-rw-r--r-- | engines/sci/gui/gui_cursor.h | 10 |
4 files changed, 93 insertions, 1 deletions
diff --git a/engines/sci/gui/gui.cpp b/engines/sci/gui/gui.cpp index 36e24a10fc..25c61ae7fb 100644 --- a/engines/sci/gui/gui.cpp +++ b/engines/sci/gui/gui.cpp @@ -461,6 +461,18 @@ void SciGui::setNowSeen(reg_t objectReference) { _gfx->SetNowSeen(objectReference); } +void SciGui::setCursorHide() { + _cursor->hide(); +} + +void SciGui::setCursorShow() { + _cursor->show(); +} + +void SciGui::setCursorShape(GuiResourceId cursorId) { + _cursor->setShape(cursorId); +} + void SciGui::setCursorPos(Common::Point pos) { // FIXME: try to find out if we need to adjust position somehow, currently just forwarding to moveCursor() moveCursor(pos); diff --git a/engines/sci/gui/gui.h b/engines/sci/gui/gui.h index 4997d0ff03..fafc6a8a10 100644 --- a/engines/sci/gui/gui.h +++ b/engines/sci/gui/gui.h @@ -84,6 +84,9 @@ public: virtual void addToPicView(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control); virtual void setNowSeen(reg_t objectReference); + virtual void setCursorHide(); + virtual void setCursorShow(); + virtual void setCursorShape(GuiResourceId cursorId); virtual void setCursorPos(Common::Point pos); virtual void moveCursor(Common::Point pos); diff --git a/engines/sci/gui/gui_cursor.cpp b/engines/sci/gui/gui_cursor.cpp index c77c85968a..baf2be01f8 100644 --- a/engines/sci/gui/gui_cursor.cpp +++ b/engines/sci/gui/gui_cursor.cpp @@ -23,7 +23,7 @@ * */ -#include "common/timer.h" +#include "graphics/cursorman.h" #include "common/util.h" #include "sci/sci.h" @@ -44,6 +44,73 @@ SciGuiCursor::~SciGuiCursor() { } void SciGuiCursor::init() { + _rawBitmap = NULL; +} + +void SciGuiCursor::show() { + CursorMan.showMouse(true); +} + +void SciGuiCursor::hide() { + CursorMan.showMouse(false); +} + +void SciGuiCursor::setShape(GuiResourceId resourceId) { + Resource *resource; + byte *resourceData; + Common::Point hotspot = Common::Point(0, 0); + byte colorMapping[4]; + int16 x, y; + byte color; + int16 maskA, maskB; + byte *pOut; + + if (resourceId == -1) { + // no resourceId given, so we actually hide the cursor + hide(); + return; + } + + // Load cursor resource... + resource = _s->resMan->findResource(ResourceId(kResourceTypeCursor, resourceId), false); + if (!resource) + error("cursor resource %d not found", resourceId); + if (resource->size != SCI_CURSOR_SCI0_RESOURCESIZE) + error("cursor resource %d has invalid size", resourceId); + + resourceData = resource->data; + // hotspot is specified for SCI1 cursors + hotspot.x = READ_LE_UINT16(resourceData); + hotspot.y = READ_LE_UINT16(resourceData + 2); + // bit 0 of resourceData[3] is set on <SCI1 games, which means center hotspot + if ((hotspot.x == 0) && (hotspot.y == 256)) + hotspot.x = hotspot.y = SCI_CURSOR_SCI0_HEIGHTWIDTH / 2; + + // Now find out what colors we are supposed to use + colorMapping[0] = 0; // Black is hardcoded + colorMapping[1] = _palette->matchColor(&_palette->_sysPalette, 255, 255, 255); // White + colorMapping[2] = SCI_CURSOR_SCI0_TRANSPARENCYCOLOR; + colorMapping[3] = _palette->matchColor(&_palette->_sysPalette, 170, 170, 170); // Grey + + // Seek to actual data + resourceData += 4; + + if (!_rawBitmap) + _rawBitmap = new byte[SCI_CURSOR_SCI0_HEIGHTWIDTH*SCI_CURSOR_SCI0_HEIGHTWIDTH]; + + pOut = _rawBitmap; + for (y = 0; y < SCI_CURSOR_SCI0_HEIGHTWIDTH; y++) { + maskA = READ_LE_UINT16(resourceData + (y << 1)); + maskB = READ_LE_UINT16(resourceData + 32 + (y << 1)); + + for (x = 0; x < SCI_CURSOR_SCI0_HEIGHTWIDTH; x++) { + color = (((maskA << x) & 0x8000) | (((maskB << x) >> 1) & 0x4000)) >> 14; + *pOut++ = colorMapping[color]; + } + } + + CursorMan.replaceCursor(_rawBitmap, SCI_CURSOR_SCI0_HEIGHTWIDTH, SCI_CURSOR_SCI0_HEIGHTWIDTH, hotspot.x, hotspot.y, SCI_CURSOR_SCI0_TRANSPARENCYCOLOR); + CursorMan.showMouse(true); } void SciGuiCursor::setPosition(Common::Point pos) { diff --git a/engines/sci/gui/gui_cursor.h b/engines/sci/gui/gui_cursor.h index bf2dad04e8..2a14f9e5e5 100644 --- a/engines/sci/gui/gui_cursor.h +++ b/engines/sci/gui/gui_cursor.h @@ -30,6 +30,11 @@ namespace Sci { +#define SCI_CURSOR_SCI0_HEIGHTWIDTH 16 +#define SCI_CURSOR_SCI0_RESOURCESIZE 68 + +#define SCI_CURSOR_SCI0_TRANSPARENCYCOLOR 1 + class SciGuiView; class SciGuiPalette; class SciGuiCursor { @@ -37,6 +42,9 @@ public: SciGuiCursor(EngineState *state, SciGuiPalette *palette); ~SciGuiCursor(); + void show(); + void hide(); + void setShape(GuiResourceId resourceId); void setPosition(Common::Point pos); private: @@ -45,6 +53,8 @@ private: EngineState *_s; SciGuiScreen *_screen; SciGuiPalette *_palette; + + byte *_rawBitmap; }; } // End of namespace Sci |