[Scummvm-cvs-logs] SF.net SVN: scummvm:[33753] scummvm/branches/gsoc2008-gui/gui

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Sun Aug 10 13:09:29 CEST 2008


Revision: 33753
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33753&view=rev
Author:   Tanoku
Date:     2008-08-10 11:09:28 +0000 (Sun, 10 Aug 2008)

Log Message:
-----------
Graphic cursors.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-08-10 10:11:47 UTC (rev 33752)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-08-10 11:09:28 UTC (rev 33753)
@@ -30,7 +30,7 @@
 #include "common/events.h"
 #include "common/config-manager.h"
 #include "graphics/imageman.h"
-
+#include "graphics/cursorman.h"
 #include "gui/launcher.h"
 
 #include "gui/ThemeRenderer.h"
@@ -98,10 +98,12 @@
 ThemeRenderer::ThemeRenderer(Common::String fileName, GraphicsMode mode) : 
 	_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled), 
 	_screen(0), _backBuffer(0), _bytesPerPixel(0), _initOk(false), 
-	_themeOk(false), _enabled(false), _buffering(false) {
+	_themeOk(false), _enabled(false), _buffering(false), _cursor(0) {
 	_system = g_system;
 	_parser = new ThemeParser(this);
 	_themeEval = new GUI::ThemeEval();
+	
+	_useCursor = false;
 
 	for (int i = 0; i < kDrawDataMAX; ++i) {
 		_widgets[i] = 0;
@@ -131,6 +133,7 @@
 	unloadTheme();
 	delete _parser;
 	delete _themeEval;
+	delete[] _cursor;
 	
 	for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i)
 		ImageMan.unregisterSurface(i->_key);
@@ -200,14 +203,18 @@
 	init();
 	if (_enabled) {
 		_system->showOverlay();
-//		CursorMan.replaceCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
-//		CursorMan.replaceCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, _cursorTargetScale);
+		CursorMan.replaceCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
+		CursorMan.replaceCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, _cursorTargetScale);
 	}
 }
 
 void ThemeRenderer::enable() {
 	init();
 	resetDrawArea();
+	
+	if (_useCursor)
+		setUpCursor();
+	
 	_system->showOverlay();
 	clearAll();
 	_enabled = true;
@@ -215,6 +222,12 @@
 
 void ThemeRenderer::disable() {
 	_system->hideOverlay();
+	
+	if (_useCursor) {
+		CursorMan.popCursorPalette();
+		CursorMan.popCursor();
+	}
+	
 	_enabled = false;
 }
 
@@ -373,6 +386,10 @@
 		}
 	}
 	
+	if (_system->hasFeature(OSystem::kFeatureCursorHasPalette)) {
+		createCursor();
+	}
+	
 	_themeName = "DEBUG - A Theme name";
 	_themeOk = true;
 	return true;
@@ -890,4 +907,70 @@
 	_vectorRenderer->setSurface(_screen);
 }
 
+void ThemeRenderer::setUpCursor() {
+	CursorMan.pushCursorPalette(_cursorPal, 0, MAX_CURS_COLORS);
+	CursorMan.pushCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, _cursorTargetScale);
+	CursorMan.showMouse(true);
+}
+
+void ThemeRenderer::createCursor() {
+	const Surface *cursor = _bitmaps["cursor.bmp"];
+	
+	if (!cursor)
+		return;
+		
+	_cursorHotspotX = _themeEval->getVar("Cursor.Hotspot.X", 0);
+	_cursorHotspotY = _themeEval->getVar("Cursor.Hotspot.Y", 0);
+
+	_cursorTargetScale = _themeEval->getVar("Cursor.TargetScale", 3);
+
+	_cursorWidth = cursor->w;
+	_cursorHeight = cursor->h;
+
+	uint colorsFound = 0;
+	const OverlayColor *src = (const OverlayColor*)cursor->pixels;
+
+	byte *table = new byte[65536];
+	assert(table);
+	memset(table, 0, sizeof(byte)*65536);
+
+	byte r, g, b;
+
+	uint16 transparency = RGBToColor<ColorMasks<565> >(255, 0, 255);
+
+	delete[] _cursor;
+
+	_cursor = new byte[_cursorWidth * _cursorHeight];
+	assert(_cursor);
+	memset(_cursor, 255, sizeof(byte)*_cursorWidth*_cursorHeight);
+
+	for (uint y = 0; y < _cursorHeight; ++y) {
+		for (uint x = 0; x < _cursorWidth; ++x) {
+			_system->colorToRGB(src[x], r, g, b);
+			uint16 col = RGBToColor<ColorMasks<565> >(r, g, b);
+			if (!table[col] && col != transparency) {
+				table[col] = colorsFound++;
+
+				uint index = table[col];
+				_cursorPal[index * 4 + 0] = r;
+				_cursorPal[index * 4 + 1] = g;
+				_cursorPal[index * 4 + 2] = b;
+				_cursorPal[index * 4 + 3] = 0xFF;
+
+				if (colorsFound > MAX_CURS_COLORS)
+					error("Cursor contains too much colors (%d, but only %d are allowed)", colorsFound, MAX_CURS_COLORS);
+			}
+
+			if (col != transparency) {
+				uint index = table[col];
+				_cursor[y * _cursorWidth + x] = index;
+			}
+		}
+		src += _cursorWidth;
+	}
+
+	_useCursor = true;
+	delete[] table;
+}
+
 } // end of namespace GUI.

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h	2008-08-10 10:11:47 UTC (rev 33752)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h	2008-08-10 11:09:28 UTC (rev 33753)
@@ -458,7 +458,9 @@
 	}
 	
 	void *evaluator() { return _themeEval; }
+	
 	bool supportsImages() const { return true; }
+	bool ownCursor() const { return _useCursor; }
 	
 	Graphics::Surface *getBitmap(const Common::String &name) {
 		return _bitmaps.contains(name) ? _bitmaps[name] : 0;
@@ -697,6 +699,19 @@
 
 	Common::String _themeName; /** Name of the currently loaded theme */
 	Common::String _themeFileName;
+	
+	/** Custom Cursor Management */
+	void setUpCursor();
+	void createCursor();
+	
+	bool _useCursor;
+	int _cursorHotspotX, _cursorHotspotY;
+	int _cursorTargetScale;
+#define MAX_CURS_COLORS 255
+	byte *_cursor;
+	bool _needPaletteUpdates;
+	uint _cursorWidth, _cursorHeight;
+	byte _cursorPal[4*MAX_CURS_COLORS];
 };
 
 } // end of namespace GUI.


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