aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/gui
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/gui')
-rw-r--r--engines/sci/gui/gui.cpp12
-rw-r--r--engines/sci/gui/gui.h3
-rw-r--r--engines/sci/gui/gui_cursor.cpp69
-rw-r--r--engines/sci/gui/gui_cursor.h10
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