[Scummvm-cvs-logs] SF.net SVN: scummvm:[44734] scummvm/trunk/engines/sci

m_kiewitz at users.sourceforge.net m_kiewitz at users.sourceforge.net
Wed Oct 7 16:53:15 CEST 2009


Revision: 44734
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44734&view=rev
Author:   m_kiewitz
Date:     2009-10-07 14:53:15 +0000 (Wed, 07 Oct 2009)

Log Message:
-----------
SCI/newgui: kSetCursor (show, hide, pos, shape) implemented

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/gui/gui.cpp
    scummvm/trunk/engines/sci/gui/gui.h
    scummvm/trunk/engines/sci/gui/gui_cursor.cpp
    scummvm/trunk/engines/sci/gui/gui_cursor.h
    scummvm/trunk/engines/sci/gui32/gui32.cpp
    scummvm/trunk/engines/sci/gui32/gui32.h

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-10-07 13:27:43 UTC (rev 44733)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-10-07 14:53:15 UTC (rev 44734)
@@ -269,20 +269,20 @@
 
 static reg_t kSetCursorSci0(EngineState *s, int argc, reg_t *argv) {
 	Common::Point pos;
+	GuiResourceId cursorId = argv[0].toSint16();
 
-	int16 cursor = argv[0].toSint16();
-
-	if ((argc >= 2) && (argv[1].toSint16() == 0))
-		cursor = GFXOP_NO_POINTER;
-
-	gfxop_set_pointer_cursor(s->gfx_state, cursor);
-
 	// Set pointer position, if requested
 	if (argc >= 4) {
 		pos.y = argv[3].toSint16();
 		pos.x = argv[2].toSint16();
 		s->gui->setCursorPos(pos);
 	}
+
+	if ((argc >= 2) && (argv[1].toSint16() == 0)) {
+		cursorId = -1;
+	}
+
+	s->gui->setCursorShape(cursorId);
 	return s->r_acc;
 }
 
@@ -292,7 +292,10 @@
 
 	switch (argc) {
 	case 1:
-		CursorMan.showMouse(argv[0].toSint16() != 0);
+		if (argv[0].isNull())
+			s->gui->setCursorHide();
+		else
+			s->gui->setCursorShow();
 		break;
 	case 2:
 		pos.y = argv[1].toSint16();

Modified: scummvm/trunk/engines/sci/gui/gui.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui.cpp	2009-10-07 13:27:43 UTC (rev 44733)
+++ scummvm/trunk/engines/sci/gui/gui.cpp	2009-10-07 14:53:15 UTC (rev 44734)
@@ -461,6 +461,18 @@
 	_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);

Modified: scummvm/trunk/engines/sci/gui/gui.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui.h	2009-10-07 13:27:43 UTC (rev 44733)
+++ scummvm/trunk/engines/sci/gui/gui.h	2009-10-07 14:53:15 UTC (rev 44734)
@@ -84,6 +84,9 @@
 	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);
 

Modified: scummvm/trunk/engines/sci/gui/gui_cursor.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_cursor.cpp	2009-10-07 13:27:43 UTC (rev 44733)
+++ scummvm/trunk/engines/sci/gui/gui_cursor.cpp	2009-10-07 14:53:15 UTC (rev 44734)
@@ -23,7 +23,7 @@
  *
  */
 
-#include "common/timer.h"
+#include "graphics/cursorman.h"
 #include "common/util.h"
 
 #include "sci/sci.h"
@@ -44,8 +44,75 @@
 }
 
 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) {
 	g_system->warpMouse(pos.x, pos.y);
 }

Modified: scummvm/trunk/engines/sci/gui/gui_cursor.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_cursor.h	2009-10-07 13:27:43 UTC (rev 44733)
+++ scummvm/trunk/engines/sci/gui/gui_cursor.h	2009-10-07 14:53:15 UTC (rev 44734)
@@ -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 @@
 	SciGuiCursor(EngineState *state, SciGuiPalette *palette);
 	~SciGuiCursor();
 
+	void show();
+	void hide();
+	void setShape(GuiResourceId resourceId);
 	void setPosition(Common::Point pos);
 
 private:
@@ -45,6 +53,8 @@
 	EngineState *_s;
 	SciGuiScreen *_screen;
 	SciGuiPalette *_palette;
+
+	byte *_rawBitmap;
 };
 
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/gui32/gui32.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui32/gui32.cpp	2009-10-07 13:27:43 UTC (rev 44733)
+++ scummvm/trunk/engines/sci/gui32/gui32.cpp	2009-10-07 14:53:15 UTC (rev 44734)
@@ -23,6 +23,7 @@
  *
  */
 
+#include "graphics/cursorman.h"
 #include "common/util.h"
 
 #include "sci/sci.h"
@@ -2002,6 +2003,21 @@
 	_k_set_now_seen(objectReference);
 }
 
+void SciGui32::setCursorHide() {
+	CursorMan.showMouse(false);
+}
+
+void SciGui32::setCursorShow() {
+	CursorMan.showMouse(true);
+}
+
+void SciGui32::setCursorShape(GuiResourceId cursorId) {
+	if (cursorId == -1)
+		gfxop_set_pointer_cursor(s->gfx_state, GFXOP_NO_POINTER);
+	else
+		gfxop_set_pointer_cursor(s->gfx_state, cursorId);
+}
+
 void SciGui32::setCursorPos(Common::Point pos) {
 	pos.y += s->port->_bounds.y;
 	pos.x += s->port->_bounds.x;

Modified: scummvm/trunk/engines/sci/gui32/gui32.h
===================================================================
--- scummvm/trunk/engines/sci/gui32/gui32.h	2009-10-07 13:27:43 UTC (rev 44733)
+++ scummvm/trunk/engines/sci/gui32/gui32.h	2009-10-07 14:53:15 UTC (rev 44734)
@@ -77,6 +77,9 @@
 	void addToPicView(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control);
 	void setNowSeen(reg_t objectReference);
 
+	void setCursorHide();
+	void setCursorShow();
+	void setCursorShape(GuiResourceId cursorId);
 	void setCursorPos(Common::Point pos);
 	void moveCursor(Common::Point pos);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list