[Scummvm-cvs-logs] SF.net SVN: scummvm: [22019] scummvm/trunk/gui

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue Apr 18 20:18:02 CEST 2006


Revision: 22019
Author:   lordhoto
Date:     2006-04-18 20:17:00 -0700 (Tue, 18 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22019&view=rev

Log Message:
-----------
Implements custom cursor support for the new theme and includes a standard cursor (it should be replaced though).

Modified Paths:
--------------
    scummvm/trunk/gui/ThemeNew.cpp
    scummvm/trunk/gui/newgui.cpp
    scummvm/trunk/gui/theme.h
    scummvm/trunk/gui/themes/modern.ini
    scummvm/trunk/gui/themes/modern.zip
Modified: scummvm/trunk/gui/ThemeNew.cpp
===================================================================
--- scummvm/trunk/gui/ThemeNew.cpp	2006-04-19 01:07:16 UTC (rev 22018)
+++ scummvm/trunk/gui/ThemeNew.cpp	2006-04-19 03:17:00 UTC (rev 22019)
@@ -38,7 +38,7 @@
 #define kShadowTr3 64
 #define kShadowTr4 128
 
-#define THEME_VERSION 9
+#define THEME_VERSION 10
 
 using Graphics::Surface;
 
@@ -216,6 +216,8 @@
 	_configFile.getKey("popupwidget_top", "pixmaps", imageHandlesTable[kPopUpWidgetBkgdTop]);
 	_configFile.getKey("popupwidget_left", "pixmaps", imageHandlesTable[kPopUpWidgetBkgdLeft]);
 	_configFile.getKey("popupwidget_bkgd", "pixmaps", imageHandlesTable[kPopUpWidgetBkgd]);
+
+	_configFile.getKey("cursor_image", "pixmaps", imageHandlesTable[kGUICursor]);
 	
 	// load the gradient factors from the config file
 	getFactorFromConfig(_configFile, "main_dialog", _gradientFactors[kMainDialogFactor]);
@@ -242,6 +244,9 @@
 	getExtraValueFromConfig(_configFile, "shadow_right_width", _shadowRightWidth, 4);
 	getExtraValueFromConfig(_configFile, "shadow_top_height", _shadowTopHeight, 2);
 	getExtraValueFromConfig(_configFile, "shadow_bottom_height", _shadowBottomHeight, 4);
+
+	getExtraValueFromConfig(_configFile, "cursor_hotspot_x", _cursorHotspotX, 0);
+	getExtraValueFromConfig(_configFile, "cursor_hotspot_y", _cursorHotspotY, 0);
 	
 	// inactive dialog shading stuff
 	_dialogShadingCallback = 0;
@@ -293,12 +298,16 @@
 	}
 	
 	_lastUsedBitMask = gBitFormat;
+
+	// creats the cursor image
+	createCursor();
 }
 
 ThemeNew::~ThemeNew() {
 	deleteFonts();
 	deinit();
 	delete [] _images;
+	delete [] _cursor;
 	_images = 0;
 	if (_imageHandles) {
 		for (int i = 0; i < kImageHandlesMax; ++i) {
@@ -353,10 +362,12 @@
 	resetDrawArea();
 	_system->showOverlay();
 	clearAll();
+	setUpCursor();
 }
 
 void ThemeNew::disable() {
 	_system->hideOverlay();
+	_system->setPalette(_backUpCols, 0, MAX_CURS_COLORS);
 }
 
 void ThemeNew::openDialog(bool topDialog) {
@@ -1487,6 +1498,65 @@
 
 #pragma mark -
 
+void ThemeNew::setUpCursor() {
+	_system->grabPalette(_backUpCols, 0, MAX_CURS_COLORS);
+	_system->setPalette(_cursorPal, 0, MAX_CURS_COLORS);
+
+	_system->setMouseCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY);
+}
+
+void ThemeNew::createCursor() {
+	const Surface *cursor = _images[kGUICursor];
+
+	_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;
+
+	_system->colorToRGB(_colors[kColorTransparency], r, g, b);
+	uint16 transparency = RGBToColor<ColorMasks<565> >(r, g, b);
+
+	_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;
+	}
+
+	delete [] table;
+}
+
+#pragma mark -
+
 template<class T>
 inline OverlayColor getColorAlphaImpl(OverlayColor col1, OverlayColor col2, int alpha) {
 	OverlayColor output = 0;

Modified: scummvm/trunk/gui/newgui.cpp
===================================================================
--- scummvm/trunk/gui/newgui.cpp	2006-04-19 01:07:16 UTC (rev 22018)
+++ scummvm/trunk/gui/newgui.cpp	2006-04-19 03:17:00 UTC (rev 22019)
@@ -144,6 +144,7 @@
 	}
 
 	int i;
+	bool useStandardCurs = !_theme->ownCursor();
 
 	while (!_dialogStack.empty() && activeDialog == _dialogStack.top()) {
 		activeDialog->handleTickle();
@@ -172,7 +173,8 @@
 			_needRedraw = false;
 		}
 
-		animateCursor();
+		if (useStandardCurs)
+			animateCursor();
 		_theme->drawAll();
 		_system->updateScreen();
 

Modified: scummvm/trunk/gui/theme.h
===================================================================
--- scummvm/trunk/gui/theme.h	2006-04-19 01:07:16 UTC (rev 22018)
+++ scummvm/trunk/gui/theme.h	2006-04-19 03:17:00 UTC (rev 22019)
@@ -106,6 +106,8 @@
 
 	virtual void refresh() = 0;
 
+	virtual bool ownCursor() { return false; }
+
 	virtual void enable() = 0;
 	virtual void disable() = 0;
 
@@ -281,6 +283,8 @@
 
 	void refresh();
 
+	bool ownCursor() { return true; }
+
 	void enable();
 	void disable();
 	
@@ -428,6 +432,8 @@
 		kPopUpWidgetBkgdTop = 41,
 		kPopUpWidgetBkgdLeft = 42,
 		kPopUpWidgetBkgd = 43,
+
+		kGUICursor = 44,
 		
 		kImageHandlesMax
 	};
@@ -441,6 +447,15 @@
 	OverlayColor calcLuminance(OverlayColor col);
 	OverlayColor calcDimColor(OverlayColor col);
 
+	void setUpCursor();
+	void createCursor();
+	int _cursorHotspotX, _cursorHotspotY;
+#define MAX_CURS_COLORS 255
+	byte *_cursor;
+	uint _cursorWidth, _cursorHeight;
+	byte _cursorPal[4*MAX_CURS_COLORS];
+	byte _backUpCols[4*MAX_CURS_COLORS];
+
 private:
 	const String *_imageHandles;
 	const Graphics::Surface **_images;

Modified: scummvm/trunk/gui/themes/modern.ini
===================================================================
--- scummvm/trunk/gui/themes/modern.ini	2006-04-19 01:07:16 UTC (rev 22018)
+++ scummvm/trunk/gui/themes/modern.ini	2006-04-19 03:17:00 UTC (rev 22019)
@@ -1,7 +1,7 @@
 # $URL$
 # $Id$
 [theme]
-version=9
+version=10
 
 [pixmaps]
 dialog_corner=dialog_bkgd_corner.bmp
@@ -61,6 +61,8 @@
 
 theme_logo=logo.bmp
 
+cursor_image=cursor.bmp
+
 [colors]
 main_dialog_start=210 114 10
 main_dialog_end=239 196 24
@@ -146,6 +148,8 @@
 inactive_dialog_shading=dim
 shading_dim_percent=30
 fontfile_normal=helvr12-l1.bdf
+cursor_hotspot_x=0
+cursor_hotspot_y=0
 
 [640xY]
 def_launcherX=23

Modified: scummvm/trunk/gui/themes/modern.zip
===================================================================
(Binary files differ)


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