aboutsummaryrefslogtreecommitdiff
path: root/gui/ThemeEngine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/ThemeEngine.cpp')
-rw-r--r--gui/ThemeEngine.cpp116
1 files changed, 76 insertions, 40 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index e2fa2580f5..9fe482ddcc 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -50,6 +50,14 @@ const char * const ThemeEngine::kImageEraser = "eraser.bmp";
const char * const ThemeEngine::kImageDelbtn = "delbtn.bmp";
const char * const ThemeEngine::kImageList = "list.bmp";
const char * const ThemeEngine::kImageGrid = "grid.bmp";
+const char * const ThemeEngine::kImageStopbtn = "stopbtn.bmp";
+const char * const ThemeEngine::kImageEditbtn = "editbtn.bmp";
+const char * const ThemeEngine::kImageSwitchModebtn = "switchbtn.bmp";
+const char * const ThemeEngine::kImageFastReplaybtn = "fastreplay.bmp";
+const char * const ThemeEngine::kImageStopSmallbtn = "stopbtn_small.bmp";
+const char * const ThemeEngine::kImageEditSmallbtn = "editbtn_small.bmp";
+const char * const ThemeEngine::kImageSwitchModeSmallbtn = "switchbtn_small.bmp";
+const char * const ThemeEngine::kImageFastReplaySmallbtn = "fastreplay_small.bmp";
struct TextDrawData {
const Graphics::Font *_fontPtr;
@@ -114,15 +122,16 @@ protected:
class ThemeItemTextData : public ThemeItem {
public:
- ThemeItemTextData(ThemeEngine *engine, const TextDrawData *data, const TextColorData *color, const Common::Rect &area, const Common::String &text,
- Graphics::TextAlign alignH, GUI::ThemeEngine::TextAlignVertical alignV,
+ ThemeItemTextData(ThemeEngine *engine, const TextDrawData *data, const TextColorData *color, const Common::Rect &area, const Common::Rect &textDrawableArea,
+ const Common::String &text, Graphics::TextAlign alignH, GUI::ThemeEngine::TextAlignVertical alignV,
bool ellipsis, bool restoreBg, int deltaX) :
ThemeItem(engine, area), _data(data), _color(color), _text(text), _alignH(alignH), _alignV(alignV),
- _ellipsis(ellipsis), _restoreBg(restoreBg), _deltax(deltaX) {}
+ _ellipsis(ellipsis), _restoreBg(restoreBg), _deltax(deltaX), _textDrawableArea(textDrawableArea) {}
void drawSelf(bool draw, bool restore);
protected:
+ Common::Rect _textDrawableArea;
const TextDrawData *_data;
const TextColorData *_color;
Common::String _text;
@@ -238,7 +247,7 @@ void ThemeItemTextData::drawSelf(bool draw, bool restore) {
if (draw) {
_engine->renderer()->setFgColor(_color->r, _color->g, _color->b);
- _engine->renderer()->drawString(_data->_fontPtr, _text, _area, _alignH, _alignV, _deltax, _ellipsis);
+ _engine->renderer()->drawString(_data->_fontPtr, _text, _area, _alignH, _alignV, _deltax, _ellipsis, _textDrawableArea);
}
_engine->addDirtyRect(_area);
@@ -335,9 +344,9 @@ ThemeEngine::~ThemeEngine() {
*********************************************************/
const ThemeEngine::Renderer ThemeEngine::_rendererModes[] = {
{ _s("Disabled GFX"), _sc("Disabled GFX", "lowres"), "none", kGfxDisabled },
- { _s("Standard Renderer (16bpp)"), _s("Standard (16bpp)"), "normal_16bpp", kGfxStandard16bit },
+ { _s("Standard Renderer"), _s("Standard"), "normal", kGfxStandard },
#ifndef DISABLE_FANCY_THEMES
- { _s("Antialiased Renderer (16bpp)"), _s("Antialiased (16bpp)"), "aa_16bpp", kGfxAntialias16bit }
+ { _s("Antialiased Renderer"), _s("Antialiased"), "antialias", kGfxAntialias }
#endif
};
@@ -345,9 +354,9 @@ const uint ThemeEngine::_rendererModesSize = ARRAYSIZE(ThemeEngine::_rendererMod
const ThemeEngine::GraphicsMode ThemeEngine::_defaultRendererMode =
#ifndef DISABLE_FANCY_THEMES
- ThemeEngine::kGfxAntialias16bit;
+ ThemeEngine::kGfxAntialias;
#else
- ThemeEngine::kGfxStandard16bit;
+ ThemeEngine::kGfxStandard;
#endif
ThemeEngine::GraphicsMode ThemeEngine::findMode(const Common::String &cfg) {
@@ -381,7 +390,7 @@ bool ThemeEngine::init() {
_overlayFormat = _system->getOverlayFormat();
setGraphicsMode(_graphicsMode);
- if (_screen.pixels && _backBuffer.pixels) {
+ if (_screen.getPixels() && _backBuffer.getPixels()) {
_initOk = true;
}
@@ -431,7 +440,7 @@ bool ThemeEngine::init() {
void ThemeEngine::clearAll() {
if (_initOk) {
_system->clearOverlay();
- _system->grabOverlay(_screen.pixels, _screen.pitch);
+ _system->grabOverlay(_screen.getPixels(), _screen.pitch);
}
}
@@ -465,11 +474,7 @@ void ThemeEngine::enable() {
if (_enabled)
return;
- if (_useCursor) {
- CursorMan.pushCursorPalette(_cursorPal, 0, _cursorPalSize);
- CursorMan.pushCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, true);
- CursorMan.showMouse(true);
- }
+ showCursor();
_system->showOverlay();
clearAll();
@@ -482,23 +487,25 @@ void ThemeEngine::disable() {
_system->hideOverlay();
- if (_useCursor) {
- CursorMan.popCursorPalette();
- CursorMan.popCursor();
- }
+ hideCursor();
+
_enabled = false;
}
void ThemeEngine::setGraphicsMode(GraphicsMode mode) {
switch (mode) {
- case kGfxStandard16bit:
+ case kGfxStandard:
#ifndef DISABLE_FANCY_THEMES
- case kGfxAntialias16bit:
+ case kGfxAntialias:
#endif
- _bytesPerPixel = sizeof(uint16);
- break;
-
+ if (g_system->getOverlayFormat().bytesPerPixel == 4) {
+ _bytesPerPixel = sizeof(uint32);
+ break;
+ } else if (g_system->getOverlayFormat().bytesPerPixel == 2) {
+ _bytesPerPixel = sizeof(uint16);
+ break;
+ }
default:
error("Invalid graphics mode");
}
@@ -515,6 +522,12 @@ void ThemeEngine::setGraphicsMode(GraphicsMode mode) {
delete _vectorRenderer;
_vectorRenderer = Graphics::createRenderer(mode);
_vectorRenderer->setSurface(&_screen);
+
+ // Since we reinitialized our screen surfaces we know nothing has been
+ // drawn so far. Sometimes we still end up with dirty screen bits in the
+ // list. Clearing it avoids invalid overlay writes when the backend
+ // resizes the overlay.
+ _dirtyScreen.clear();
}
void WidgetDrawData::calcBackgroundOffset() {
@@ -830,7 +843,7 @@ void ThemeEngine::queueDD(DrawData type, const Common::Rect &r, uint32 dynamic,
}
void ThemeEngine::queueDDText(TextData type, TextColor color, const Common::Rect &r, const Common::String &text, bool restoreBg,
- bool ellipsis, Graphics::TextAlign alignH, TextAlignVertical alignV, int deltax) {
+ bool ellipsis, Graphics::TextAlign alignH, TextAlignVertical alignV, int deltax, const Common::Rect &drawableTextArea) {
if (_texts[type] == 0)
return;
@@ -838,7 +851,7 @@ void ThemeEngine::queueDDText(TextData type, TextColor color, const Common::Rect
Common::Rect area = r;
area.clip(_screen.w, _screen.h);
- ThemeItemTextData *q = new ThemeItemTextData(this, _texts[type], _textColors[color], area, text, alignH, alignV, ellipsis, restoreBg, deltax);
+ ThemeItemTextData *q = new ThemeItemTextData(this, _texts[type], _textColors[color], area, drawableTextArea, text, alignH, alignV, ellipsis, restoreBg, deltax);
if (_buffering) {
_screenQueue.push_back(q);
@@ -1109,7 +1122,7 @@ void ThemeEngine::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, co
}
}
-void ThemeEngine::drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, Graphics::TextAlign align, TextInversionState inverted, int deltax, bool useEllipsis, FontStyle font, FontColor color, bool restore) {
+void ThemeEngine::drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, Graphics::TextAlign align, TextInversionState inverted, int deltax, bool useEllipsis, FontStyle font, FontColor color, bool restore, const Common::Rect &drawableTextArea) {
if (!ready())
return;
@@ -1179,7 +1192,7 @@ void ThemeEngine::drawText(const Common::Rect &r, const Common::String &str, Wid
break;
}
- queueDDText(textId, colorId, r, str, restore, useEllipsis, align, kTextAlignVCenter, deltax);
+ queueDDText(textId, colorId, r, str, restore, useEllipsis, align, kTextAlignVCenter, deltax, drawableTextArea);
}
void ThemeEngine::drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state, FontColor color) {
@@ -1217,7 +1230,7 @@ void ThemeEngine::updateScreen(bool render) {
}
_vectorRenderer->setSurface(&_screen);
- memcpy(_screen.getBasePtr(0, 0), _backBuffer.getBasePtr(0, 0), _screen.pitch * _screen.h);
+ memcpy(_screen.getPixels(), _backBuffer.getPixels(), _screen.pitch * _screen.h);
_bufferQueue.clear();
}
@@ -1285,7 +1298,7 @@ void ThemeEngine::openDialog(bool doBuffer, ShadingStyle style) {
addDirtyRect(Common::Rect(0, 0, _screen.w, _screen.h));
}
- memcpy(_backBuffer.getBasePtr(0, 0), _screen.getBasePtr(0, 0), _screen.pitch * _screen.h);
+ memcpy(_backBuffer.getPixels(), _screen.getPixels(), _screen.pitch * _screen.h);
_vectorRenderer->setSurface(&_screen);
}
@@ -1318,44 +1331,52 @@ bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int
memset(_cursor, 0xFF, sizeof(byte) * _cursorWidth * _cursorHeight);
// the transparent color is 0xFF00FF
- const int colTransparent = _overlayFormat.RGBToColor(0xFF, 0, 0xFF);
+ const uint32 colTransparent = _overlayFormat.RGBToColor(0xFF, 0, 0xFF);
// 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;
+ const byte *src = (const byte *)cursor->getPixels();
for (uint y = 0; y < _cursorHeight; ++y) {
for (uint x = 0; x < _cursorWidth; ++x) {
+ uint32 color = colTransparent;
byte r, g, b;
+ if (cursor->format.bytesPerPixel == 2) {
+ color = READ_UINT16(src);
+ } else if (cursor->format.bytesPerPixel == 4) {
+ color = READ_UINT32(src);
+ }
+
+ src += cursor->format.bytesPerPixel;
+
// Skip transparency
- if (src[x] == colTransparent)
+ if (color == colTransparent)
continue;
- _overlayFormat.colorToRGB(src[x], r, g, b);
+ cursor->format.colorToRGB(color, r, g, b);
const int col = (r << 16) | (g << 8) | b;
// If there is no entry yet for this color in the palette: Add one
if (!colorToIndex.contains(col)) {
+ if (colorsFound >= MAX_CURS_COLORS) {
+ warning("Cursor contains too many colors (%d, but only %d are allowed)", colorsFound, MAX_CURS_COLORS);
+ return false;
+ }
+
const int index = colorsFound++;
colorToIndex[col] = index;
_cursorPal[index * 3 + 0] = r;
_cursorPal[index * 3 + 1] = g;
_cursorPal[index * 3 + 2] = b;
-
- if (colorsFound > MAX_CURS_COLORS) {
- warning("Cursor contains too many colors (%d, but only %d are allowed)", colorsFound, MAX_CURS_COLORS);
- return false;
- }
}
// 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;
}
_useCursor = true;
@@ -1787,5 +1808,20 @@ Common::String ThemeEngine::getThemeId(const Common::String &filename) {
}
}
+void ThemeEngine::showCursor() {
+ if (_useCursor) {
+ CursorMan.pushCursorPalette(_cursorPal, 0, _cursorPalSize);
+ CursorMan.pushCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, 255, true);
+ CursorMan.showMouse(true);
+ }
+}
+
+void ThemeEngine::hideCursor() {
+ if (_useCursor) {
+ CursorMan.popCursorPalette();
+ CursorMan.popCursor();
+ }
+}
+
} // End of namespace GUI.