From 2071f606a9d3d6395eb1202d77d95500f922572b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 8 Nov 2008 00:54:58 +0000 Subject: Moved some internal stuff from ThemeEngine.h to ThemeEngine.cpp svn-id: r34935 --- gui/ThemeEngine.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ gui/ThemeEngine.h | 121 ++++------------------------------------------------ 2 files changed, 129 insertions(+), 112 deletions(-) diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 20638b827d..64e2fc373e 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -45,6 +45,105 @@ namespace GUI { using namespace Graphics; +struct TextDrawData { + const Graphics::Font *_fontPtr; + + struct { + uint8 r, g, b; + } _color; +}; + +struct WidgetDrawData { + /** List of all the steps needed to draw this widget */ + Common::List _steps; + + int _textDataId; + GUI::Theme::TextAlign _textAlignH; + GUI::Theme::TextAlignVertical _textAlignV; + + /** Extra space that the widget occupies when it's drawn. + E.g. when taking into account rounded corners, drop shadows, etc + Used when restoring the widget background */ + uint16 _backgroundOffset; + + /** Sets whether the widget is cached beforehand. */ + bool _cached; + bool _buffer; + + /** Texture where the cached widget is stored. */ + Graphics::Surface *_surfaceCache; + + ~WidgetDrawData() { + _steps.clear(); + + if (_surfaceCache) { + _surfaceCache->free(); + delete _surfaceCache; + } + } +}; + +class ThemeItem { + +public: + ThemeItem(ThemeEngine *engine, const Common::Rect &area) : + _engine(engine), _area(area) {} + virtual ~ThemeItem() {} + + virtual void drawSelf(bool doDraw, bool doRestore) = 0; + +protected: + ThemeEngine *_engine; + Common::Rect _area; +}; + +class ThemeItemDrawData : public ThemeItem { +public: + ThemeItemDrawData(ThemeEngine *engine, const WidgetDrawData *data, const Common::Rect &area, uint32 dynData) : + ThemeItem(engine, area), _dynamicData(dynData), _data(data) {} + + void drawSelf(bool draw, bool restore); + +protected: + uint32 _dynamicData; + const WidgetDrawData *_data; +}; + +class ThemeItemTextData : public ThemeItem { +public: + ThemeItemTextData(ThemeEngine *engine, const TextDrawData *data, const Common::Rect &area, const Common::String &text, + GUI::Theme::TextAlign alignH, GUI::Theme::TextAlignVertical alignV, + bool ellipsis, bool restoreBg, int deltaX) : + ThemeItem(engine, area), _data(data), _text(text), _alignH(alignH), _alignV(alignV), + _ellipsis(ellipsis), _restoreBg(restoreBg), _deltax(deltaX) {} + + void drawSelf(bool draw, bool restore); + +protected: + const TextDrawData *_data; + Common::String _text; + GUI::Theme::TextAlign _alignH; + GUI::Theme::TextAlignVertical _alignV; + bool _ellipsis; + bool _restoreBg; + int _deltax; +}; + +class ThemeItemBitmap : public ThemeItem { +public: + ThemeItemBitmap(ThemeEngine *engine, const Common::Rect &area, const Graphics::Surface *bitmap, bool alpha) : + ThemeItem(engine, area), _bitmap(bitmap), _alpha(alpha) {} + + void drawSelf(bool draw, bool restore); + +protected: + const Graphics::Surface *_bitmap; + bool _alpha; +}; + + + + const ThemeEngine::Renderer ThemeEngine::_rendererModes[] = { { "Disabled GFX", "none", kGfxDisabled }, { "Standard Renderer (16bpp)", "normal_16bpp", kGfxStandard16bit }, @@ -1094,4 +1193,25 @@ bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int return true; } +const Graphics::Font *ThemeEngine::getFont(FontStyle font) const { + return _texts[fontStyleToData(font)]->_fontPtr; +} + +int ThemeEngine::getFontHeight(FontStyle font) const { + return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getFontHeight() : 0; +} + +int ThemeEngine::getStringWidth(const Common::String &str, FontStyle font) const { + return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getStringWidth(str) : 0; +} + +int ThemeEngine::getCharWidth(byte c, FontStyle font) const { + return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getCharWidth(c) : 0; +} + +ThemeEngine::TextData ThemeEngine::getTextData(DrawData ddId) { + return _widgets[ddId] ? (TextData)_widgets[ddId]->_textDataId : kTextDataNone; +} + + } // end of namespace GUI. diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index 0b054c53f5..d0205b8c0a 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -43,104 +43,9 @@ namespace GUI { struct WidgetDrawData; struct DrawDataInfo; +struct TextDrawData; class ThemeEval; - -struct TextDrawData { - const Graphics::Font *_fontPtr; - - struct { - uint8 r, g, b; - } _color; -}; - -struct WidgetDrawData { - /** List of all the steps needed to draw this widget */ - Common::List _steps; - - int _textDataId; - GUI::Theme::TextAlign _textAlignH; - GUI::Theme::TextAlignVertical _textAlignV; - - /** Extra space that the widget occupies when it's drawn. - E.g. when taking into account rounded corners, drop shadows, etc - Used when restoring the widget background */ - uint16 _backgroundOffset; - - /** Sets whether the widget is cached beforehand. */ - bool _cached; - bool _buffer; - - /** Texture where the cached widget is stored. */ - Graphics::Surface *_surfaceCache; - - ~WidgetDrawData() { - _steps.clear(); - - if (_surfaceCache) { - _surfaceCache->free(); - delete _surfaceCache; - } - } -}; - -class ThemeItem { - -public: - ThemeItem(ThemeEngine *engine, const Common::Rect &area) : - _engine(engine), _area(area) {} - virtual ~ThemeItem() {} - - virtual void drawSelf(bool doDraw, bool doRestore) = 0; - -protected: - ThemeEngine *_engine; - Common::Rect _area; -}; - -class ThemeItemDrawData : public ThemeItem { -public: - ThemeItemDrawData(ThemeEngine *engine, const WidgetDrawData *data, const Common::Rect &area, uint32 dynData) : - ThemeItem(engine, area), _dynamicData(dynData), _data(data) {} - - void drawSelf(bool draw, bool restore); - -protected: - uint32 _dynamicData; - const WidgetDrawData *_data; -}; - -class ThemeItemTextData : public ThemeItem { -public: - ThemeItemTextData(ThemeEngine *engine, const TextDrawData *data, const Common::Rect &area, const Common::String &text, - GUI::Theme::TextAlign alignH, GUI::Theme::TextAlignVertical alignV, - bool ellipsis, bool restoreBg, int deltaX) : - ThemeItem(engine, area), _data(data), _text(text), _alignH(alignH), _alignV(alignV), - _ellipsis(ellipsis), _restoreBg(restoreBg), _deltax(deltaX) {} - - void drawSelf(bool draw, bool restore); - -protected: - const TextDrawData *_data; - Common::String _text; - GUI::Theme::TextAlign _alignH; - GUI::Theme::TextAlignVertical _alignV; - bool _ellipsis; - bool _restoreBg; - int _deltax; -}; - -class ThemeItemBitmap : public ThemeItem { -public: - ThemeItemBitmap(ThemeEngine *engine, const Common::Rect &area, const Graphics::Surface *bitmap, bool alpha) : - ThemeItem(engine, area), _bitmap(bitmap), _alpha(alpha) {} - - void drawSelf(bool draw, bool restore); - -protected: - const Graphics::Surface *_bitmap; - bool _alpha; -}; - +class ThemeItem; class ThemeEngine : public Theme { protected: @@ -321,19 +226,13 @@ public: } } - const Graphics::Font *getFont(FontStyle font) const { return _texts[fontStyleToData(font)]->_fontPtr; } + const Graphics::Font *getFont(FontStyle font) const; - int getFontHeight(FontStyle font = kFontStyleBold) const { - return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getFontHeight() : 0; - } + int getFontHeight(FontStyle font = kFontStyleBold) const; - int getStringWidth(const Common::String &str, FontStyle font) const { - return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getStringWidth(str) : 0; - } + int getStringWidth(const Common::String &str, FontStyle font) const; - int getCharWidth(byte c, FontStyle font) const { - return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getCharWidth(c) : 0; - } + int getCharWidth(byte c, FontStyle font) const; /** @@ -625,9 +524,7 @@ protected: } } - TextData getTextData(DrawData ddId) { - return _widgets[ddId] ? (TextData)_widgets[ddId]->_textDataId : kTextDataNone; - } + TextData getTextData(DrawData ddId); /** * Draws a cached widget directly on the screen. Currently deprecated. @@ -720,10 +617,10 @@ protected: Common::List _dirtyScreen; /** Queue with all the drawing that must be done to the Back Buffer */ - Common::List _bufferQueue; + Common::List _bufferQueue; /** Queue with all the drawing that must be done to the screen */ - Common::List _screenQueue; + Common::List _screenQueue; bool _initOk; /** Class and renderer properly initialized */ bool _themeOk; /** Theme data successfully loaded. */ -- cgit v1.2.3