aboutsummaryrefslogtreecommitdiff
path: root/gui/ThemeEngine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/ThemeEngine.cpp')
-rw-r--r--gui/ThemeEngine.cpp187
1 files changed, 109 insertions, 78 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index cf16eec238..2cb1635e20 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -34,6 +34,7 @@
#include "graphics/surface.h"
#include "graphics/VectorRenderer.h"
#include "graphics/fonts/bdf.h"
+#include "graphics/fonts/ttf.h"
#include "gui/widget.h"
#include "gui/ThemeEngine.h"
@@ -45,6 +46,7 @@ namespace GUI {
const char * const ThemeEngine::kImageLogo = "logo.bmp";
const char * const ThemeEngine::kImageLogoSmall = "logo_small.bmp";
const char * const ThemeEngine::kImageSearch = "search.bmp";
+const char * const ThemeEngine::kImageEraser = "eraser.bmp";
struct TextDrawData {
const Graphics::Font *_fontPtr;
@@ -260,7 +262,8 @@ void ThemeItemBitmap::drawSelf(bool draw, bool restore) {
ThemeEngine::ThemeEngine(Common::String id, GraphicsMode mode) :
_system(0), _vectorRenderer(0),
_buffering(false), _bytesPerPixel(0), _graphicsMode(kGfxDisabled),
- _font(0), _initOk(false), _themeOk(false), _enabled(false), _cursor(0) {
+ _font(0), _initOk(false), _themeOk(false), _enabled(false), _themeFiles(),
+ _cursor(0) {
_system = g_system;
_parser = new ThemeParser(this);
@@ -293,6 +296,9 @@ ThemeEngine::ThemeEngine(Common::String id, GraphicsMode mode) :
_graphicsMode = mode;
_themeArchive = 0;
_initOk = false;
+
+ // We prefer files in archive bundles over the common search paths.
+ _themeFiles.add("default", &SearchMan, 0, false);
}
ThemeEngine::~ThemeEngine() {
@@ -316,7 +322,6 @@ ThemeEngine::~ThemeEngine() {
delete _parser;
delete _themeEval;
delete[] _cursor;
- delete _themeArchive;
}
@@ -405,6 +410,9 @@ bool ThemeEngine::init() {
}
}
}
+
+ if (_themeArchive)
+ _themeFiles.add("theme_archive", _themeArchive, 1, true);
}
// Load the theme
@@ -550,7 +558,7 @@ bool ThemeEngine::addTextData(const Common::String &drawDataId, TextData textId,
return true;
}
-bool ThemeEngine::addFont(TextData textId, const Common::String &file) {
+bool ThemeEngine::addFont(TextData textId, const Common::String &file, const Common::String &scalableFile, const int pointsize) {
if (textId == -1)
return false;
@@ -563,35 +571,26 @@ bool ThemeEngine::addFont(TextData textId, const Common::String &file) {
_texts[textId]->_fontPtr = _font;
} else {
Common::String localized = FontMan.genLocalizedFontFilename(file);
- // Try built-in fonts
- _texts[textId]->_fontPtr = FontMan.getFontByName(localized);
-
- if (!_texts[textId]->_fontPtr) {
- // First try to load localized font
- _texts[textId]->_fontPtr = loadFont(localized);
-
- if (_texts[textId]->_fontPtr)
- FontMan.assignFontToName(localized, _texts[textId]->_fontPtr);
+ const Common::String charset
+#ifdef USE_TRANSLATION
+ (TransMan.getCurrentCharset())
+#endif
+ ;
- // Fallback to non-localized font and default translation
- else {
- // Try built-in fonts
- _texts[textId]->_fontPtr = FontMan.getFontByName(file);
+ // Try localized fonts
+ _texts[textId]->_fontPtr = loadFont(localized, scalableFile, charset, pointsize, textId == kTextDataDefault);
- // Try to load it
- if (!_texts[textId]->_fontPtr) {
- _texts[textId]->_fontPtr = loadFont(file);
+ if (!_texts[textId]->_fontPtr) {
+ // Try standard fonts
+ _texts[textId]->_fontPtr = loadFont(file, scalableFile, Common::String(), pointsize, textId == kTextDataDefault);
- if (!_texts[textId]->_fontPtr)
- error("Couldn't load font '%s'", file.c_str());
+ if (!_texts[textId]->_fontPtr)
+ error("Couldn't load font '%s'/'%s'", file.c_str(), scalableFile.c_str());
- FontMan.assignFontToName(file, _texts[textId]->_fontPtr);
- }
#ifdef USE_TRANSLATION
- TransMan.setLanguage("C");
+ TransMan.setLanguage("C");
#endif
- warning("Failed to load localized font '%s'. Using non-localized font and default GUI language instead", localized.c_str());
- }
+ warning("Failed to load localized font '%s'. Using non-localized font and default GUI language instead", localized.c_str());
}
}
@@ -622,12 +621,16 @@ bool ThemeEngine::addBitmap(const Common::String &filename) {
return true;
// If not, try to load the bitmap via the ImageDecoder class.
- surf = Graphics::ImageDecoder::loadFile(filename, _overlayFormat);
- if (!surf && _themeArchive) {
- Common::SeekableReadStream *stream = _themeArchive->createReadStreamForMember(filename);
+ Common::ArchiveMemberList members;
+ _themeFiles.listMatchingMembers(members, filename);
+ for (Common::ArchiveMemberList::const_iterator i = members.begin(), end = members.end(); i != end; ++i) {
+ Common::SeekableReadStream *stream = (*i)->createReadStream();
if (stream) {
surf = Graphics::ImageDecoder::loadFile(*stream, _overlayFormat);
delete stream;
+
+ if (surf)
+ break;
}
}
@@ -844,7 +847,7 @@ void ThemeEngine::queueBitmap(const Graphics::Surface *bitmap, const Common::Rec
ThemeItemBitmap *q = new ThemeItemBitmap(this, area, bitmap, alpha);
if (_buffering) {
- _bufferQueue.push_back(q);
+ _screenQueue.push_back(q);
} else {
q->drawSelf(true, false);
delete q;
@@ -903,7 +906,7 @@ void ThemeEngine::drawCheckbox(const Common::Rect &r, const Common::String &str,
r2.left = r2.right + checkBoxSize;
r2.right = r.right;
- queueDDText(getTextData(dd), getTextColor(dd), r2, str, false, false, _widgets[kDDCheckboxDefault]->_textAlignH, _widgets[dd]->_textAlignV);
+ queueDDText(getTextData(dd), getTextColor(dd), r2, str, true, false, _widgets[kDDCheckboxDefault]->_textAlignH, _widgets[dd]->_textAlignV);
}
void ThemeEngine::drawRadiobutton(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state) {
@@ -929,7 +932,7 @@ void ThemeEngine::drawRadiobutton(const Common::Rect &r, const Common::String &s
r2.left = r2.right + checkBoxSize;
r2.right = r.right;
- queueDDText(getTextData(dd), getTextColor(dd), r2, str, false, false, _widgets[kDDRadiobuttonDefault]->_textAlignH, _widgets[dd]->_textAlignV);
+ queueDDText(getTextData(dd), getTextColor(dd), r2, str, true, false, _widgets[kDDRadiobuttonDefault]->_textAlignH, _widgets[dd]->_textAlignV);
}
void ThemeEngine::drawSlider(const Common::Rect &r, int width, WidgetStateInfo state) {
@@ -971,7 +974,7 @@ void ThemeEngine::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHe
r2.left += 1;
r2.right -= 1;
r2.top += sliderY;
- r2.bottom = r2.top + sliderHeight - 1;
+ r2.bottom = r2.top + sliderHeight;
r2.top += r.width() / 5;
r2.bottom -= r.width() / 5;
@@ -1370,6 +1373,10 @@ int ThemeEngine::getCharWidth(byte c, FontStyle font) const {
return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getCharWidth(c) : 0;
}
+int ThemeEngine::getKerningOffset(byte left, byte right, FontStyle font) const {
+ return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getKerningOffset(left, right) : 0;
+}
+
TextData ThemeEngine::getTextData(DrawData ddId) const {
return _widgets[ddId] ? (TextData)_widgets[ddId]->_textDataId : kTextDataNone;
}
@@ -1390,66 +1397,90 @@ DrawData ThemeEngine::parseDrawDataId(const Common::String &name) const {
* External data loading
*********************************************************/
-const Graphics::Font *ThemeEngine::loadFontFromArchive(const Common::String &filename) {
- Common::SeekableReadStream *stream = 0;
- const Graphics::Font *font = 0;
+const Graphics::Font *ThemeEngine::loadScalableFont(const Common::String &filename, const Common::String &charset, const int pointsize, Common::String &name) {
+#ifdef USE_FREETYPE2
+ name = Common::String::format("%s-%s@%d", filename.c_str(), charset.c_str(), pointsize);
- if (_themeArchive)
- stream = _themeArchive->createReadStreamForMember(filename);
- if (stream) {
- font = Graphics::BdfFont::loadFont(*stream);
- delete stream;
- }
+ // Try already loaded fonts.
+ const Graphics::Font *font = FontMan.getFontByName(name);
+ if (font)
+ return font;
- return font;
-}
+ Common::ArchiveMemberList members;
+ _themeFiles.listMatchingMembers(members, filename);
-const Graphics::Font *ThemeEngine::loadCachedFontFromArchive(const Common::String &filename) {
- Common::SeekableReadStream *stream = 0;
- const Graphics::Font *font = 0;
+ for (Common::ArchiveMemberList::const_iterator i = members.begin(), end = members.end(); i != end; ++i) {
+ Common::SeekableReadStream *stream = (*i)->createReadStream();
+ if (stream) {
+ font = Graphics::loadTTFFont(*stream, pointsize, false,
+#ifdef USE_TRANSLATION
+ TransMan.getCharsetMapping()
+#else
+ 0
+#endif
+ );
+ delete stream;
- if (_themeArchive)
- stream = _themeArchive->createReadStreamForMember(filename);
- if (stream) {
- font = Graphics::BdfFont::loadFromCache(*stream);
- delete stream;
+ if (font)
+ return font;
+ }
}
-
- return font;
+#endif
+ return 0;
}
-const Graphics::Font *ThemeEngine::loadFont(const Common::String &filename) {
- const Graphics::Font *font = 0;
- Common::String cacheFilename = genCacheFilename(filename);
- Common::File fontFile;
+const Graphics::Font *ThemeEngine::loadFont(const Common::String &filename, Common::String &name) {
+ name = filename;
- if (!cacheFilename.empty()) {
- if (fontFile.open(cacheFilename)) {
- font = Graphics::BdfFont::loadFromCache(fontFile);
- }
+ // Try already loaded fonts.
+ const Graphics::Font *font = FontMan.getFontByName(name);
+ if (font)
+ return font;
- if (font)
- return font;
+ Common::ArchiveMemberList members;
+ const Common::String cacheFilename(genCacheFilename(filename));
+ _themeFiles.listMatchingMembers(members, cacheFilename);
+ _themeFiles.listMatchingMembers(members, filename);
- if ((font = loadCachedFontFromArchive(cacheFilename)))
- return font;
- }
+ for (Common::ArchiveMemberList::const_iterator i = members.begin(), end = members.end(); i != end; ++i) {
+ Common::SeekableReadStream *stream = (*i)->createReadStream();
+ if (stream) {
+ if ((*i)->getName().equalsIgnoreCase(cacheFilename)) {
+ font = Graphics::BdfFont::loadFromCache(*stream);
+ } else {
+ font = Graphics::BdfFont::loadFont(*stream);
+ if (font && !cacheFilename.empty()) {
+ if (!Graphics::BdfFont::cacheFontData(*(const Graphics::BdfFont *)font, cacheFilename))
+ warning("Couldn't create cache file for font '%s'", filename.c_str());
+ }
+ }
+ delete stream;
- // normal open
- if (fontFile.open(filename)) {
- font = Graphics::BdfFont::loadFont(fontFile);
+ if (font)
+ return font;
+ }
}
- if (!font) {
- font = loadFontFromArchive(filename);
- }
+ return 0;
+}
+const Graphics::Font *ThemeEngine::loadFont(const Common::String &filename, const Common::String &scalableFilename, const Common::String &charset, const int pointsize, const bool makeLocalizedFont) {
+ Common::String fontName;
+
+ const Graphics::Font *font = 0;
+
+ // Prefer scalable fonts over non-scalable fonts
+ font = loadScalableFont(scalableFilename, charset, pointsize, fontName);
+ if (!font)
+ font = loadFont(filename, fontName);
+
+ // If the font is successfully loaded store it in the font manager.
if (font) {
- if (!cacheFilename.empty()) {
- if (!Graphics::BdfFont::cacheFontData(*(const Graphics::BdfFont *)font, cacheFilename)) {
- warning("Couldn't create cache file for font '%s'", filename.c_str());
- }
- }
+ FontMan.assignFontToName(fontName, font);
+ // If this font should be the new default localized font, we set it up
+ // for that.
+ if (makeLocalizedFont)
+ FontMan.setLocalizedFont(fontName);
}
return font;