aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorMax Horn2008-11-03 16:00:13 +0000
committerMax Horn2008-11-03 16:00:13 +0000
commit78221818e48ccb6fc48b1fa29a45083e4d2092c8 (patch)
treee837bbab6095b033c6c048a516ab201bc6207ddb /gui
parent188da3547fa39b09c6c129196c0e0ba36ce7cc8c (diff)
downloadscummvm-rg350-78221818e48ccb6fc48b1fa29a45083e4d2092c8.tar.gz
scummvm-rg350-78221818e48ccb6fc48b1fa29a45083e4d2092c8.tar.bz2
scummvm-rg350-78221818e48ccb6fc48b1fa29a45083e4d2092c8.zip
Documented & cleaned up ThemeEngine::createCursor
svn-id: r34879
Diffstat (limited to 'gui')
-rw-r--r--gui/ThemeEngine.cpp44
1 files changed, 24 insertions, 20 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index 4181d69514..b23502b1c0 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -1023,12 +1023,13 @@ void ThemeEngine::setUpCursor() {
bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int hotspotY, int scale) {
if (!_system->hasFeature(OSystem::kFeatureCursorHasPalette))
return true;
-
- const Surface *cursor = _bitmaps[filename];
+ // Try to locate the specified file among all loaded bitmaps
+ const Surface *cursor = _bitmaps[filename];
if (!cursor)
return false;
-
+
+ // Set up the cursor parameters
_cursorHotspotX = hotspotX;
_cursorHotspotY = hotspotY;
_cursorTargetScale = scale;
@@ -1036,26 +1037,30 @@ bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int
_cursorWidth = cursor->w;
_cursorHeight = cursor->h;
- uint colorsFound = 0;
- const OverlayColor *src = (const OverlayColor*)cursor->pixels;
-
- Common::HashMap<int, int> colorToIndex;
-
- byte r, g, b;
-
- uint16 transparency = RGBToColor<ColorMasks<565> >(255, 0, 255);
-
+ // Allocate a new buffer for the cursor
delete[] _cursor;
-
_cursor = new byte[_cursorWidth * _cursorHeight];
assert(_cursor);
memset(_cursor, 0xFF, sizeof(byte) * _cursorWidth * _cursorHeight);
+ // Now, scan the bitmap. We have to convert it from 16 bit color mode
+ // to 8 bit mode, and have to create a suitable palette on the fly.
+ uint colorsFound = 0;
+ Common::HashMap<int, int> colorToIndex;
+ const OverlayColor *src = (const OverlayColor*)cursor->pixels;
for (uint y = 0; y < _cursorHeight; ++y) {
for (uint x = 0; x < _cursorWidth; ++x) {
+ byte r, g, b;
_system->colorToRGB(src[x], r, g, b);
- uint16 col = RGBToColor<ColorMasks<565> >(r, g, b);
- if (!colorToIndex.contains(col) && col != transparency) {
+ const int col = (r << 16) | (g << 8) | b;
+
+ // Skip transparent colors
+ // (transparent actually is 0xFF00FF), but the RGB convert chops of the lower bits
+ if ((r > 0xF1) && (g < 0x03) && (b > 0xF1))
+ continue;
+
+ // If there is no entry yet for this color in the palette: Add one
+ if (!colorToIndex.contains(col)) {
const int index = colorsFound++;
colorToIndex[col] = index;
@@ -1065,15 +1070,14 @@ bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int
_cursorPal[index * 4 + 3] = 0xFF;
if (colorsFound > MAX_CURS_COLORS) {
- warning("Cursor contains too much colors (%d, but only %d are allowed)", colorsFound, MAX_CURS_COLORS);
+ warning("Cursor contains too many colors (%d, but only %d are allowed)", colorsFound, MAX_CURS_COLORS);
return false;
}
}
- if (col != transparency) {
- const int index = colorToIndex[col];
- _cursor[y * _cursorWidth + x] = index;
- }
+ // Copy pixel from the 16 bit source surface to the 8bit target surface
+ const int index = colorToIndex[col];
+ _cursor[y * _cursorWidth + x] = index;
}
src += _cursorWidth;
}