diff options
author | Johannes Schickel | 2006-04-14 02:16:55 +0000 |
---|---|---|
committer | Johannes Schickel | 2006-04-14 02:16:55 +0000 |
commit | 96cf7028b98cd12e2278b37aee43b3d669214abb (patch) | |
tree | c9ea75045b671229d8ac4e2656d8475ac5909471 /gui | |
parent | 1470dadb1de3250dfceeaa246604ca0f26889bbf (diff) | |
download | scummvm-rg350-96cf7028b98cd12e2278b37aee43b3d669214abb.tar.gz scummvm-rg350-96cf7028b98cd12e2278b37aee43b3d669214abb.tar.bz2 scummvm-rg350-96cf7028b98cd12e2278b37aee43b3d669214abb.zip |
- implements .bdf font loader based on convbdf (sure could have some clean up)
- adds three different font styles to the themes (normal, bold (default one), italic)
- implements code for specifing the font files in the theme config ('fontfile_normal','fontfile_bold' and 'fontfile_italic' in the 'extra' section)
- changes EditTextWidget to use the normal font (has some minor aligment problems with the caret now, though)
- extends the FontManager (new functions: getFontByName, assignFontToName, removeFontName)
- adds the font style constans to the builtin constants for the evaluator)
svn-id: r21868
Diffstat (limited to 'gui')
-rw-r--r-- | gui/EditTextWidget.cpp | 2 | ||||
-rw-r--r-- | gui/ThemeClassic.cpp | 2 | ||||
-rw-r--r-- | gui/ThemeNew.cpp | 145 | ||||
-rw-r--r-- | gui/eval.cpp | 4 | ||||
-rw-r--r-- | gui/newgui.h | 8 | ||||
-rw-r--r-- | gui/theme.h | 46 |
6 files changed, 165 insertions, 42 deletions
diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp index de54e46048..fa5bdfdca8 100644 --- a/gui/EditTextWidget.cpp +++ b/gui/EditTextWidget.cpp @@ -72,7 +72,7 @@ void EditTextWidget::drawWidget(bool hilite) { // Draw the text adjustOffset(); - g_gui.theme()->drawText(Common::Rect(_x+2,_y+2, _x+getEditRect().width()-2, _y+_h-2), _editString, Theme::kStateEnabled, Theme::kTextAlignLeft, false, -_editScrollOffset, false); + g_gui.theme()->drawText(Common::Rect(_x+2,_y+2, _x+getEditRect().width()-2, _y+_h-2), _editString, Theme::kStateEnabled, Theme::kTextAlignLeft, false, -_editScrollOffset, false, Theme::kFontStyleNormal); } Common::Rect EditTextWidget::getEditRect() const { diff --git a/gui/ThemeClassic.cpp b/gui/ThemeClassic.cpp index 47cb4c6122..d33897774d 100644 --- a/gui/ThemeClassic.cpp +++ b/gui/ThemeClassic.cpp @@ -149,7 +149,7 @@ void ThemeClassic::drawDialogBackground(const Common::Rect &r, uint16 hints, kSt addDirtyRect(r, (hints & THEME_HINT_SAVE_BACKGROUND) != 0); } -void ThemeClassic::drawText(const Common::Rect &r, const Common::String &str, kState state, kTextAlign align, bool inverted, int deltax, bool useEllipsis) { +void ThemeClassic::drawText(const Common::Rect &r, const Common::String &str, kState state, kTextAlign align, bool inverted, int deltax, bool useEllipsis, kFontStyle font) { if (!_initOk) return; diff --git a/gui/ThemeNew.cpp b/gui/ThemeNew.cpp index d6ab1666e7..0f064baa29 100644 --- a/gui/ThemeNew.cpp +++ b/gui/ThemeNew.cpp @@ -119,7 +119,8 @@ OverlayColor calcGradient(OverlayColor start, OverlayColor end, int pos, int max #pragma mark - ThemeNew::ThemeNew(OSystem *system, Common::String stylefile) : Theme(), _system(system), _screen(), _initOk(false), -_lastUsedBitMask(0), _forceRedraw(false), _font(0), _imageHandles(0), _images(0), _colors(), _gradientFactors() { +_lastUsedBitMask(0), _forceRedraw(false), _fonts(), _imageHandles(0), _images(0), _colors(), _gradientFactors() { + _stylefile = stylefile; _initOk = false; memset(&_screen, 0, sizeof(_screen)); memset(&_dialog, 0, sizeof(_dialog)); @@ -130,11 +131,6 @@ _lastUsedBitMask(0), _forceRedraw(false), _font(0), _imageHandles(0), _images(0) if (_screen.pixels) { _initOk = true; clearAll(); - if (_screen.w >= 400 && _screen.h >= 300) { - _font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont); - } else { - _font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont); - } } if (ConfMan.hasKey("extrapath")) @@ -167,6 +163,7 @@ _lastUsedBitMask(0), _forceRedraw(false), _font(0), _imageHandles(0), _images(0) delete [] buffer; buffer = 0; } else { + unzClose(zipFile); warning("Can not find theme config file '%s'", (stylefile + ".ini").c_str()); return; } @@ -296,6 +293,9 @@ _lastUsedBitMask(0), _forceRedraw(false), _font(0), _imageHandles(0), _images(0) warning("no valid 'inactive_dialog_shading' specified"); } } + + // load up all fonts + setupFonts(); // load the colors from the config file setupColors(); @@ -314,6 +314,7 @@ _lastUsedBitMask(0), _forceRedraw(false), _font(0), _imageHandles(0), _images(0) } ThemeNew::~ThemeNew() { + deleteFonts(); deinit(); delete [] _images; _images = 0; @@ -338,11 +339,7 @@ bool ThemeNew::init() { if (_screen.pixels) { _initOk = true; clearAll(); - if (_screen.w >= 400 && _screen.h >= 300) { - _font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont); - } else { - _font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont); - } + setupFonts(); } if (isThemeLoadingRequired()) { @@ -471,10 +468,10 @@ void ThemeNew::drawDialogBackground(const Common::Rect &r, uint16 hints, kState addDirtyRect(r2, (hints & THEME_HINT_SAVE_BACKGROUND) != 0, true); } -void ThemeNew::drawText(const Common::Rect &r, const Common::String &str, kState state, kTextAlign align, bool inverted, int deltax, bool useEllipsis) { +void ThemeNew::drawText(const Common::Rect &r, const Common::String &str, kState state, kTextAlign align, bool inverted, int deltax, bool useEllipsis, kFontStyle font) { if (!_initOk) return; - Common::Rect r2(r.left, r.top, r.right, r.top+_font->getFontHeight()); + Common::Rect r2(r.left, r.top, r.right, r.top+getFontHeight(font)); uint32 color; restoreBackground(r2); @@ -487,7 +484,7 @@ void ThemeNew::drawText(const Common::Rect &r, const Common::String &str, kState color = getColor(state); } - _font->drawString(&_screen, str, r.left, r.top, r.width(), color, convertAligment(align), deltax, useEllipsis); + getFont(font)->drawString(&_screen, str, r.left, r.top, r.width(), color, convertAligment(align), deltax, useEllipsis); addDirtyRect(r2); } @@ -559,7 +556,7 @@ void ThemeNew::drawButton(const Common::Rect &r, const Common::String &str, kSta _gradientFactors[kButtonFactor]); } - const int off = (r.height() - _font->getFontHeight()) / 2; + const int off = (r.height() - getFontHeight()) / 2; OverlayColor col = 0; switch (state) { @@ -576,7 +573,7 @@ void ThemeNew::drawButton(const Common::Rect &r, const Common::String &str, kSta break; }; - _font->drawString(&_screen, str, r.left, r.top + off, r.width(), col, Graphics::kTextAlignCenter, 0, true); + getFont()->drawString(&_screen, str, r.left, r.top + off, r.width(), col, Graphics::kTextAlignCenter, 0, true); addDirtyRect(r2); } @@ -657,7 +654,7 @@ void ThemeNew::drawCheckbox(const Common::Rect &r, const Common::String &str, bo drawSurface(Common::Rect(r.left, r.top, r.left+checkBox->w, r.top+checkBox->h), checkBox, false, false, (state == kStateDisabled) ? 128 : 256); r2.left += checkBoxSize + 5; - _font->drawString(&_screen, str, r2.left, r2.top, r2.width(), getColor(state), Graphics::kTextAlignLeft, 0, false); + getFont()->drawString(&_screen, str, r2.left, r2.top, r2.width(), getColor(state), Graphics::kTextAlignLeft, 0, false); addDirtyRect(r); } @@ -679,7 +676,7 @@ void ThemeNew::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const drawRectMasked(tabRect, surface(kTabBkgdCorner), surface(kTabBkgdTop), surface(kTabBkgdLeft), surface(kTabBkgd), 128, _colors[kTabBackgroundStart], tabEnd, _gradientFactors[kTabFactor], true); - _font->drawString(&_screen, tabs[i], tabRect.left, tabRect.top+2, tabRect.width(), getColor(kStateEnabled), Graphics::kTextAlignCenter, 0, true); + getFont()->drawString(&_screen, tabs[i], tabRect.left, tabRect.top+2, tabRect.width(), getColor(kStateEnabled), Graphics::kTextAlignCenter, 0, true); } Common::Rect widgetBackground = Common::Rect(r.left, r.top + tabHeight, r.right, r.bottom); @@ -692,7 +689,7 @@ void ThemeNew::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const drawRectMasked(tabRect, surface(kTabBkgdCorner), surface(kTabBkgdTop), surface(kTabBkgdLeft), surface(kTabBkgd), 256, _colors[kTabBackgroundStart], tabEnd, _gradientFactors[kTabFactor], true); - _font->drawString(&_screen, tabs[active], tabRect.left, tabRect.top+2, tabRect.width(), getColor(kStateHighlight), Graphics::kTextAlignCenter, 0, true); + getFont()->drawString(&_screen, tabs[active], tabRect.left, tabRect.top+2, tabRect.width(), getColor(kStateHighlight), Graphics::kTextAlignCenter, 0, true); addDirtyRect(r); } @@ -1266,6 +1263,116 @@ void ThemeNew::setupColors() { getColorFromConfig(_configFile, "caret_color", _colors[kCaretColor]); } +#define FONT_NAME_NORMAL "newgui_normal" +#define FONT_NAME_BOLD "newgui_bold" +#define FONT_NAME_ITALIC "newgui_italic" + +void ThemeNew::setupFonts() { + if (_screen.w >= 400 && _screen.h >= 300) { + if (_configFile.hasKey("fontfile_bold", "extra")) { + _fonts[kFontStyleBold] = FontMan.getFontByName(FONT_NAME_BOLD); + + if (!_fonts[kFontStyleBold]) { + Common::String temp; + _configFile.getKey("fontfile_bold", "extra", temp); + + _fonts[kFontStyleBold] = loadFont(temp.c_str()); + if (!_fonts[kFontStyleBold]) + error("Couldn't load bold font '%s'", temp.c_str()); + + FontMan.assignFontToName(FONT_NAME_BOLD, _fonts[kFontStyleBold]); + } + } else { + _fonts[kFontStyleBold] = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont); + } + + if (_configFile.hasKey("fontfile_normal", "extra")) { + _fonts[kFontStyleNormal] = FontMan.getFontByName(FONT_NAME_NORMAL); + + if (!_fonts[kFontStyleNormal]) { + Common::String temp; + _configFile.getKey("fontfile_normal", "extra", temp); + + _fonts[kFontStyleNormal] = loadFont(temp.c_str()); + if (!_fonts[kFontStyleNormal]) + error("Couldn't load normal font '%s'", temp.c_str()); + + FontMan.assignFontToName(FONT_NAME_NORMAL, _fonts[kFontStyleNormal]); + } + } else { + _fonts[kFontStyleNormal] = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont); + } + + if (_configFile.hasKey("fontfile_italic", "extra")) { + _fonts[kFontStyleItalic] = FontMan.getFontByName(FONT_NAME_ITALIC); + + if (!_fonts[kFontStyleItalic]) { + Common::String temp; + _configFile.getKey("fontfile_italic", "extra", temp); + + _fonts[kFontStyleNormal] = loadFont(temp.c_str()); + if (!_fonts[kFontStyleItalic]) + error("Couldn't load italic font '%s'", temp.c_str()); + + FontMan.assignFontToName(FONT_NAME_ITALIC, _fonts[kFontStyleItalic]); + } + } else { + _fonts[kFontStyleItalic] = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont); + } + } else { + _fonts[kFontStyleBold] = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont); + _fonts[kFontStyleNormal] = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont); + _fonts[kFontStyleItalic] = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont); + } +} + +void ThemeNew::deleteFonts() { + const Graphics::Font *normal = FontMan.getFontByName(FONT_NAME_NORMAL); + const Graphics::Font *bold = FontMan.getFontByName(FONT_NAME_BOLD); + const Graphics::Font *italic = FontMan.getFontByName(FONT_NAME_ITALIC); + + delete normal; + delete bold; + delete italic; + + FontMan.removeFontName(FONT_NAME_NORMAL); + FontMan.removeFontName(FONT_NAME_BOLD); + FontMan.removeFontName(FONT_NAME_ITALIC); +} + +const Graphics::Font *ThemeNew::loadFont(const char *filename) { + const Graphics::Font *font = 0; + + Common::File fontFile; + if (fontFile.open(filename)) { + font = Graphics::loadFont(fontFile); + if (font) + return font; + } + +#ifdef USE_ZLIB + unzFile zipFile = unzOpen((_stylefile + ".zip").c_str()); + if (zipFile && unzLocateFile(zipFile, filename, 2) == UNZ_OK) { + unz_file_info fileInfo; + unzOpenCurrentFile(zipFile); + unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0); + uint8 *buffer = new uint8[fileInfo.uncompressed_size+1]; + assert(buffer); + memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8)); + unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size); + unzCloseCurrentFile(zipFile); + Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1); + + font = Graphics::loadFont(stream); + + delete [] buffer; + buffer = 0; + } + unzClose(zipFile); +#endif + return font; +} + #pragma mark - OverlayColor ThemeNew::calcLuminance(OverlayColor col) { diff --git a/gui/eval.cpp b/gui/eval.cpp index 5d661cc9cf..61f5307355 100644 --- a/gui/eval.cpp +++ b/gui/eval.cpp @@ -250,6 +250,10 @@ static const BuiltinConsts builtinConsts[] = { {"kTextAlignRight", kTextAlignRight}, {"kTextAlignCenter", kTextAlignCenter}, + {"kFontStyleBold", Theme::kFontStyleBold}, + {"kFontStyleNormal", Theme::kFontStyleNormal}, + {"kFontStyleItalic", Theme::kFontStyleItalic}, + {"false", 0}, {"true", 1}, {NULL, 0} diff --git a/gui/newgui.h b/gui/newgui.h index 8b8babe27c..9e46738162 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -73,10 +73,10 @@ public: Theme *theme() { return _theme; } Eval *evaluator() { return _theme->_evaluator; } - const Graphics::Font &getFont() const { return *(_theme->getFont()); } - int getFontHeight() const { return _theme->getFontHeight(); } - int getStringWidth(const Common::String &str) const { return _theme->getStringWidth(str); } - int getCharWidth(byte c) const { return _theme->getCharWidth(c); } + const Graphics::Font &getFont(Theme::kFontStyle style = Theme::kFontStyleBold) const { return *(_theme->getFont(style)); } + int getFontHeight(Theme::kFontStyle style = Theme::kFontStyleBold) const { return _theme->getFontHeight(style); } + int getStringWidth(const Common::String &str, Theme::kFontStyle style = Theme::kFontStyleBold) const { return _theme->getStringWidth(str, style); } + int getCharWidth(byte c, Theme::kFontStyle style = Theme::kFontStyleBold) const { return _theme->getCharWidth(c, style); } WidgetSize getWidgetSize(); diff --git a/gui/theme.h b/gui/theme.h index 9c3bcf95d4..734ff3c37a 100644 --- a/gui/theme.h +++ b/gui/theme.h @@ -94,6 +94,13 @@ public: kScrollbarStateSinglePage }; + enum kFontStyle { + kFontStyleBold = 0, // standard font + kFontStyleNormal = 1, + kFontStyleItalic = 2, + kFontStyleMax + }; + virtual bool init() = 0; virtual void deinit() = 0; @@ -114,13 +121,13 @@ public: virtual const Common::ConfigFile &getConfigFile() { return _configFile; } - virtual const Graphics::Font *getFont() const = 0; - virtual int getFontHeight() const = 0; - virtual int getStringWidth(const Common::String &str) const = 0; - virtual int getCharWidth(byte c) const = 0; + virtual const Graphics::Font *getFont(kFontStyle font = kFontStyleBold) const = 0; + virtual int getFontHeight(kFontStyle font = kFontStyleBold) const = 0; + virtual int getStringWidth(const Common::String &str, kFontStyle font = kFontStyleBold) const = 0; + virtual int getCharWidth(byte c, kFontStyle font = kFontStyleBold) const = 0; virtual void drawDialogBackground(const Common::Rect &r, uint16 hints, kState state = kStateEnabled) = 0; - virtual void drawText(const Common::Rect &r, const Common::String &str, kState state = kStateEnabled, kTextAlign align = kTextAlignCenter, bool inverted = false, int deltax = 0, bool useEllipsis = true) = 0; + virtual void drawText(const Common::Rect &r, const Common::String &str, kState state = kStateEnabled, kTextAlign align = kTextAlignCenter, bool inverted = false, int deltax = 0, bool useEllipsis = true, kFontStyle font = kFontStyleBold) = 0; // this should ONLY be used by the debugger until we get a nicer solution virtual void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, kState state = kStateEnabled) = 0; @@ -211,13 +218,13 @@ public: typedef Common::String String; - const Graphics::Font *getFont() const { return _font; } - int getFontHeight() const { if (_initOk) return _font->getFontHeight(); return 0; } - int getStringWidth(const String &str) const { if (_initOk) return _font->getStringWidth(str); return 0; } - int getCharWidth(byte c) const { if (_initOk) return _font->getCharWidth(c); return 0; } + const Graphics::Font *getFont(kFontStyle font) const { return _font; } + int getFontHeight(kFontStyle font = kFontStyleBold) const { if (_initOk) return _font->getFontHeight(); return 0; } + int getStringWidth(const String &str, kFontStyle font) const { if (_initOk) return _font->getStringWidth(str); return 0; } + int getCharWidth(byte c, kFontStyle font) const { if (_initOk) return _font->getCharWidth(c); return 0; } void drawDialogBackground(const Common::Rect &r, uint16 hints, kState state); - void drawText(const Common::Rect &r, const String &str, kState state, kTextAlign align, bool inverted, int deltax, bool useEllipsis); + void drawText(const Common::Rect &r, const String &str, kState state, kTextAlign align, bool inverted, int deltax, bool useEllipsis, kFontStyle font); void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, kState state); void drawWidgetBackground(const Common::Rect &r, uint16 hints, kWidgetBackground background, kState state); @@ -284,13 +291,13 @@ public: void setDrawArea(const Common::Rect &r); void resetDrawArea(); - const Graphics::Font *getFont() const { return _font; } - int getFontHeight() const { if (_font) return _font->getFontHeight(); return 0; } - int getStringWidth(const String &str) const { if (_font) return _font->getStringWidth(str); return 0; } - int getCharWidth(byte c) const { if (_font) return _font->getCharWidth(c); return 0; } + const Graphics::Font *getFont(kFontStyle font = kFontStyleBold) const { return _fonts[font]; } + int getFontHeight(kFontStyle font = kFontStyleBold) const { if (_fonts[font]) return _fonts[font]->getFontHeight(); return 0; } + int getStringWidth(const String &str, kFontStyle font = kFontStyleBold) const { if (_fonts[font]) return _fonts[font]->getStringWidth(str); return 0; } + int getCharWidth(byte c, kFontStyle font = kFontStyleBold) const { if (_fonts[font]) return _fonts[font]->getCharWidth(c); return 0; } void drawDialogBackground(const Common::Rect &r, uint16 hints, kState state); - void drawText(const Common::Rect &r, const String &str, kState state, kTextAlign align, bool inverted, int deltax, bool useEllipsis); + void drawText(const Common::Rect &r, const String &str, kState state, kTextAlign align, bool inverted, int deltax, bool useEllipsis, kFontStyle font); void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, kState state); void drawWidgetBackground(const Common::Rect &r, uint16 hints, kWidgetBackground background, kState state); @@ -338,9 +345,11 @@ private: Graphics::Surface _screen; Common::Rect _shadowDrawArea; + Common::String _stylefile; + bool _initOk; bool _forceRedraw; - + int _lastUsedBitMask; void resetupGuiRenderer(); void setupColors(); @@ -352,7 +361,10 @@ private: Graphics::Surface screen; } *_dialog; - const Graphics::Font *_font; + void setupFonts(); + void deleteFonts(); + const Graphics::Font *loadFont(const char *filename); + const Graphics::Font *_fonts[kFontStyleMax]; public: enum kImageHandles { |