diff options
33 files changed, 690 insertions, 862 deletions
diff --git a/engines/dialogs.cpp b/engines/dialogs.cpp index 9ef5ba749a..552f30c032 100644 --- a/engines/dialogs.cpp +++ b/engines/dialogs.cpp @@ -35,7 +35,7 @@ #include "gui/newgui.h" #include "gui/launcher.h" #include "gui/ListWidget.h" -#include "gui/theme.h" + #include "gui/ThemeEval.h" #include "engines/dialogs.h" @@ -76,14 +76,14 @@ enum { MainMenuDialog::MainMenuDialog(Engine *engine) : GlobalDialog("GlobalMenu"), _engine(engine) { - _backgroundType = GUI::Theme::kDialogBackgroundSpecial; + _backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial; #ifndef DISABLE_FANCY_THEMES _logo = 0; if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 1 && g_gui.theme()->supportsImages()) { _logo = new GUI::GraphicsWidget(this, "GlobalMenu.Logo"); _logo->useThemeTransparency(true); - _logo->setGfx(g_gui.theme()->getImageSurface(GUI::Theme::kImageLogoSmall)); + _logo->setGfx(g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall)); } else { StaticTextWidget *title = new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM"); title->setAlign(GUI::kTextAlignCenter); @@ -217,7 +217,7 @@ void MainMenuDialog::reflowLayout() { if (!_logo) _logo = new GUI::GraphicsWidget(this, "GlobalMenu.Logo"); _logo->useThemeTransparency(true); - _logo->setGfx(g_gui.theme()->getImageSurface(GUI::Theme::kImageLogoSmall)); + _logo->setGfx(g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall)); GUI::StaticTextWidget *title = (StaticTextWidget *)findWidget("GlobalMenu.Title"); if (title) { diff --git a/engines/kyra/kyra_lok.cpp b/engines/kyra/kyra_lok.cpp index b56a96205e..e7e0ff25e0 100644 --- a/engines/kyra/kyra_lok.cpp +++ b/engines/kyra/kyra_lok.cpp @@ -28,6 +28,7 @@ #include "common/file.h" #include "common/system.h" #include "common/savefile.h" +#include "common/config-manager.h" #include "gui/message.h" diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp index 033d502478..f012c1c76b 100644 --- a/engines/parallaction/saveload.cpp +++ b/engines/parallaction/saveload.cpp @@ -248,7 +248,7 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel) : Dialog("ScummSaveLoad"), _list(0), _chooseButton(0), _gfxWidget(0) { // _drawingHints |= GUI::THEME_HINT_SPECIAL_COLOR; - _backgroundType = GUI::Theme::kDialogBackgroundSpecial; + _backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial; new GUI::StaticTextWidget(this, "ScummSaveLoad.Title", title); diff --git a/engines/scumm/dialogs.cpp b/engines/scumm/dialogs.cpp index 382a0a9338..6e126f0872 100644 --- a/engines/scumm/dialogs.cpp +++ b/engines/scumm/dialogs.cpp @@ -36,7 +36,7 @@ #endif #include "gui/about.h" -#include "gui/theme.h" + #include "gui/newgui.h" #include "gui/ListWidget.h" #include "gui/ThemeEval.h" @@ -214,7 +214,7 @@ static const ResString string_map_table_v345[] = { #pragma mark - ScummDialog::ScummDialog(String name) : GUI::Dialog(name) { - _backgroundType = GUI::Theme::kDialogBackgroundSpecial; + _backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial; } #pragma mark - @@ -235,7 +235,7 @@ enum { SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode, ScummEngine *engine) : Dialog("ScummSaveLoad"), _saveMode(saveMode), _list(0), _chooseButton(0), _gfxWidget(0), _vm(engine) { - _backgroundType = GUI::Theme::kDialogBackgroundSpecial; + _backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial; new StaticTextWidget(this, "ScummSaveLoad.Title", title); @@ -637,7 +637,7 @@ HelpDialog::HelpDialog(const GameSettings &game) _title = new StaticTextWidget(this, "ScummHelp.Title", ""); _page = 1; - _backgroundType = GUI::Theme::kDialogBackgroundDefault; + _backgroundType = GUI::ThemeEngine::kDialogBackgroundDefault; _numPages = ScummHelp::numPages(_game.id); @@ -851,7 +851,7 @@ ValueDisplayDialog::ValueDisplayDialog(const Common::String& label, int minVal, void ValueDisplayDialog::drawDialog() { const int labelWidth = _w - 8 - _percentBarWidth; - g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x+_w, _y+_h), GUI::Theme::kDialogBackgroundDefault); + g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x+_w, _y+_h), GUI::ThemeEngine::kDialogBackgroundDefault); g_gui.theme()->drawText(Common::Rect(_x+4, _y+4, _x+labelWidth+4, _y+g_gui.theme()->getFontHeight()+4), _label); g_gui.theme()->drawSlider(Common::Rect(_x+4+labelWidth, _y+4, _x+_w-4, _y+_h-4), diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp index c566b6f1e2..49cd2c4b34 100644 --- a/engines/sword1/control.cpp +++ b/engines/sword1/control.cpp @@ -29,6 +29,7 @@ #include "common/savefile.h" #include "common/events.h" #include "common/system.h" +#include "common/config-manager.h" #include "gui/message.h" diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h index f072e5d01e..4ccd6845b9 100644 --- a/graphics/VectorRenderer.h +++ b/graphics/VectorRenderer.h @@ -507,8 +507,8 @@ public: * method. */ virtual void drawString(const Graphics::Font *font, const Common::String &text, - const Common::Rect &area, GUI::Theme::TextAlign alignH, - GUI::Theme::TextAlignVertical alignV, int deltax, bool useEllipsis) = 0; + const Common::Rect &area, GUI::ThemeEngine::TextAlign alignH, + GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis) = 0; /** * Allows to temporarily enable/disable all shadows drawing. @@ -549,7 +549,7 @@ public: * Applies a whole-screen shading effect, used before opening a new dialog. * Currently supports screen dimmings and luminance (b&w). */ - virtual void applyScreenShading(GUI::Theme::ShadingStyle) = 0; + virtual void applyScreenShading(GUI::ThemeEngine::ShadingStyle) = 0; protected: Surface *_activeSurface; /**< Pointer to the surface currently being drawn */ diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp index 5f299814e4..675acd7ad3 100644 --- a/graphics/VectorRendererSpec.cpp +++ b/graphics/VectorRendererSpec.cpp @@ -354,7 +354,7 @@ blitAlphaBitmap(const Graphics::Surface *source, const Common::Rect &r) { template <typename PixelType, typename PixelFormat> void VectorRendererSpec<PixelType, PixelFormat>:: -applyScreenShading(GUI::Theme::ShadingStyle shadingStyle) { +applyScreenShading(GUI::ThemeEngine::ShadingStyle shadingStyle) { int pixels = _activeSurface->w * _activeSurface->h; PixelType *ptr = (PixelType *)_activeSurface->getBasePtr(0, 0); uint8 r, g, b; @@ -365,7 +365,7 @@ applyScreenShading(GUI::Theme::ShadingStyle shadingStyle) { (1 << PixelFormat::kRedShift) | (1 << PixelFormat::kBlueShift)) >> 1; - if (shadingStyle == GUI::Theme::kShadingDim) { + if (shadingStyle == GUI::ThemeEngine::kShadingDim) { int n = (pixels + 7) >> 3; switch (pixels % 8) { @@ -381,7 +381,7 @@ applyScreenShading(GUI::Theme::ShadingStyle shadingStyle) { } while (--n > 0); } - } else if (shadingStyle == GUI::Theme::kShadingLuminance) { + } else if (shadingStyle == GUI::ThemeEngine::kShadingLuminance) { while (pixels--) { colorToRGB<PixelFormat>(*ptr, r, g, b); lum = (r >> 2) + (g >> 1) + (b >> 3); @@ -449,16 +449,16 @@ colorFill(PixelType *first, PixelType *last, PixelType color) { template <typename PixelType, typename PixelFormat> void VectorRendererSpec<PixelType, PixelFormat>:: drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, - GUI::Theme::TextAlign alignH, GUI::Theme::TextAlignVertical alignV, int deltax, bool ellipsis) { + GUI::ThemeEngine::TextAlign alignH, GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool ellipsis) { int offset = area.top; if (font->getFontHeight() < area.height()) { switch (alignV) { - case GUI::Theme::kTextAlignVCenter: + case GUI::ThemeEngine::kTextAlignVCenter: offset = area.top + ((area.height() - font->getFontHeight()) >> 1); break; - case GUI::Theme::kTextAlignVBottom: + case GUI::ThemeEngine::kTextAlignVBottom: offset = area.bottom - font->getFontHeight(); break; default: diff --git a/graphics/VectorRendererSpec.h b/graphics/VectorRendererSpec.h index c0d3b3e00f..5b4ebf38e7 100644 --- a/graphics/VectorRendererSpec.h +++ b/graphics/VectorRendererSpec.h @@ -68,8 +68,8 @@ public: drawBevelSquareAlg(x, y, w, h, bevel, _bevelColor, _fgColor, Base::_fillMode != kFillDisabled); } void drawString(const Graphics::Font *font, const Common::String &text, - const Common::Rect &area, GUI::Theme::TextAlign alignH, - GUI::Theme::TextAlignVertical alignV, int deltax, bool elipsis); + const Common::Rect &area, GUI::ThemeEngine::TextAlign alignH, + GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool elipsis); void setFgColor(uint8 r, uint8 g, uint8 b) { _fgColor = RGBToColor<PixelFormat>(r, g, b); } void setBgColor(uint8 r, uint8 g, uint8 b) { _bgColor = RGBToColor<PixelFormat>(r, g, b); } @@ -84,7 +84,7 @@ public: void blitSubSurface(const Graphics::Surface *source, const Common::Rect &r); void blitAlphaBitmap(const Graphics::Surface *source, const Common::Rect &r); - void applyScreenShading(GUI::Theme::ShadingStyle shadingStyle); + void applyScreenShading(GUI::ThemeEngine::ShadingStyle shadingStyle); protected: diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp index 889310d958..5fc8ca6d94 100644 --- a/gui/EditTextWidget.cpp +++ b/gui/EditTextWidget.cpp @@ -55,7 +55,7 @@ void EditTextWidget::reflowLayout() { _leftPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Left", 0); _rightPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Right", 0); - _font = (Theme::FontStyle)g_gui.xmlEval()->getVar("EditTextWidget.Font", Theme::kFontStyleNormal); + _font = (ThemeEngine::FontStyle)g_gui.xmlEval()->getVar("EditTextWidget.Font", ThemeEngine::kFontStyleNormal); EditableWidget::reflowLayout(); } @@ -82,11 +82,11 @@ void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) { void EditTextWidget::drawWidget() { - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), 0, Theme::kWidgetBackgroundEditText); + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), 0, ThemeEngine::kWidgetBackgroundEditText); // Draw the text adjustOffset(); - g_gui.theme()->drawText(Common::Rect(_x+2+ _leftPadding,_y+2, _x+_leftPadding+getEditRect().width()+2, _y+_h-2), _editString, _state, Theme::kTextAlignLeft, false, -_editScrollOffset, false, _font); + g_gui.theme()->drawText(Common::Rect(_x+2+ _leftPadding,_y+2, _x+_leftPadding+getEditRect().width()+2, _y+_h-2), _editString, _state, ThemeEngine::kTextAlignLeft, false, -_editScrollOffset, false, _font); } Common::Rect EditTextWidget::getEditRect() const { diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index c17963ea95..cea4d94e13 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -360,7 +360,7 @@ void ListWidget::drawWidget() { Common::String buffer; // Draw a thin frame around the list. - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, Theme::kWidgetBackgroundBorder); + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, ThemeEngine::kWidgetBackgroundBorder); const int scrollbarW = (_scrollBar && _scrollBar->isVisible()) ? _scrollBarWidth : 0; // Draw the list items @@ -375,7 +375,7 @@ void ListWidget::drawWidget() { inverted = true; else g_gui.theme()->drawWidgetBackground(Common::Rect(_x, y - 1, _x + _w - 1, y + fontHeight - 1), - 0, Theme::kWidgetBackgroundBorderSmall); + 0, ThemeEngine::kWidgetBackgroundBorderSmall); } Common::Rect r(getEditRect()); @@ -387,7 +387,7 @@ void ListWidget::drawWidget() { sprintf(temp, "%2d. ", (pos + _numberingMode)); buffer = temp; g_gui.theme()->drawText(Common::Rect(_x, y, _x + r.left + _leftPadding, y + fontHeight - 2), - buffer, _state, Theme::kTextAlignLeft, inverted, _leftPadding); + buffer, _state, ThemeEngine::kTextAlignLeft, inverted, _leftPadding); pad = 0; } @@ -398,7 +398,7 @@ void ListWidget::drawWidget() { adjustOffset(); width = _w - r.left - _hlRightPadding - _leftPadding - scrollbarW; g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + width, y + fontHeight-2), - buffer, _state, Theme::kTextAlignLeft, inverted, pad); + buffer, _state, ThemeEngine::kTextAlignLeft, inverted, pad); } else { int maxWidth = _textWidth[i]; buffer = _list[pos]; @@ -411,7 +411,7 @@ void ListWidget::drawWidget() { if (width > maxWidth) maxWidth = width; g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + maxWidth, y + fontHeight-2), - buffer, _state, Theme::kTextAlignLeft, inverted, pad); + buffer, _state, ThemeEngine::kTextAlignLeft, inverted, pad); } _textWidth[i] = width; diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp index 6c89e7113c..15b536f760 100644 --- a/gui/PopUpWidget.cpp +++ b/gui/PopUpWidget.cpp @@ -344,8 +344,8 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) { // Draw a separator g_gui.theme()->drawLineSeparator(Common::Rect(x, y, x+w, y+kLineHeight)); } else { - g_gui.theme()->drawText(Common::Rect(x+1, y+2, x+w, y+2+kLineHeight), name, hilite ? Theme::kStateHighlight : Theme::kStateEnabled, - Theme::kTextAlignLeft, false, _leftPadding); + g_gui.theme()->drawText(Common::Rect(x+1, y+2, x+w, y+2+kLineHeight), name, hilite ? ThemeEngine::kStateHighlight : ThemeEngine::kStateEnabled, + ThemeEngine::kTextAlignLeft, false, _leftPadding); } } @@ -425,7 +425,7 @@ void PopUpWidget::drawWidget() { // Draw the label, if any if (_labelWidth > 0) - g_gui.theme()->drawText(Common::Rect(_x+2,_y+3,_x+2+_labelWidth, _y+3+g_gui.theme()->getFontHeight()), _label, _state, Theme::kTextAlignRight); + g_gui.theme()->drawText(Common::Rect(_x+2,_y+3,_x+2+_labelWidth, _y+3+g_gui.theme()->getFontHeight()), _label, _state, ThemeEngine::kTextAlignRight); Common::String sel; if (_selectedItem >= 0) diff --git a/gui/ScrollBarWidget.cpp b/gui/ScrollBarWidget.cpp index 52af9c97b5..2838ce19ee 100644 --- a/gui/ScrollBarWidget.cpp +++ b/gui/ScrollBarWidget.cpp @@ -187,15 +187,15 @@ void ScrollBarWidget::drawWidget() { if (_draggingPart != kNoPart) _part = _draggingPart; - Theme::ScrollbarState state = Theme::kScrollbarStateNo; + ThemeEngine::ScrollbarState state = ThemeEngine::kScrollbarStateNo; if (_numEntries <= _entriesPerPage) { - state = Theme::kScrollbarStateSinglePage; + state = ThemeEngine::kScrollbarStateSinglePage; } else if (_part == kUpArrowPart) { - state = Theme::kScrollbarStateUp; + state = ThemeEngine::kScrollbarStateUp; } else if (_part == kDownArrowPart) { - state = Theme::kScrollbarStateDown; + state = ThemeEngine::kScrollbarStateDown; } else if (_part == kSliderPart) { - state = Theme::kScrollbarStateSlider; + state = ThemeEngine::kScrollbarStateSlider; } g_gui.theme()->drawScrollbar(Common::Rect(_x, _y, _x+_w, _y+_h), _sliderPos, _sliderHeight, state, _state); diff --git a/gui/ThemeData.cpp b/gui/ThemeData.cpp new file mode 100644 index 0000000000..2bde70f18c --- /dev/null +++ b/gui/ThemeData.cpp @@ -0,0 +1,143 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "common/util.h" +#include "common/system.h" + +#include "graphics/surface.h" +#include "graphics/colormasks.h" +#include "graphics/imageman.h" +#include "graphics/cursorman.h" +#include "graphics/VectorRenderer.h" + +#include "gui/ThemeEngine.h" +#include "gui/ThemeData.h" + +namespace GUI { + +/********************************************************** + * Data definitions for theme engine elements + *********************************************************/ +const ThemeEngine::DrawDataInfo ThemeEngine::kDrawDataDefaults[] = { + {kDDMainDialogBackground, "mainmenu_bg", true, kDDNone}, + {kDDSpecialColorBackground, "special_bg", true, kDDNone}, + {kDDPlainColorBackground, "plain_bg", true, kDDNone}, + {kDDDefaultBackground, "default_bg", true, kDDNone}, + {kDDTextSelectionBackground, "text_selection", false, kDDNone}, + + {kDDWidgetBackgroundDefault, "widget_default", true, kDDNone}, + {kDDWidgetBackgroundSmall, "widget_small", true, kDDNone}, + {kDDWidgetBackgroundEditText, "widget_textedit", true, kDDNone}, + {kDDWidgetBackgroundSlider, "widget_slider", true, kDDNone}, + + {kDDButtonIdle, "button_idle", true, kDDWidgetBackgroundSlider}, + {kDDButtonHover, "button_hover", false, kDDButtonIdle}, + {kDDButtonDisabled, "button_disabled", true, kDDNone}, + + {kDDSliderFull, "slider_full", false, kDDNone}, + {kDDSliderHover, "slider_hover", false, kDDNone}, + {kDDSliderDisabled, "slider_disabled", true, kDDNone}, + + {kDDCheckboxDefault, "checkbox_default", true, kDDNone}, + {kDDCheckboxDisabled, "checkbox_disabled", true, kDDNone}, + {kDDCheckboxSelected, "checkbox_selected", false, kDDCheckboxDefault}, + + {kDDTabActive, "tab_active", false, kDDTabInactive}, + {kDDTabInactive, "tab_inactive", true, kDDNone}, + {kDDTabBackground, "tab_background", true, kDDNone}, + + {kDDScrollbarBase, "scrollbar_base", true, kDDNone}, + + {kDDScrollbarButtonIdle, "scrollbar_button_idle", true, kDDNone}, + {kDDScrollbarButtonHover, "scrollbar_button_hover", false, kDDScrollbarButtonIdle}, + + {kDDScrollbarHandleIdle, "scrollbar_handle_idle", false, kDDNone}, + {kDDScrollbarHandleHover, "scrollbar_handle_hover", false, kDDScrollbarBase}, + + {kDDPopUpIdle, "popup_idle", true, kDDNone}, + {kDDPopUpHover, "popup_hover", false, kDDPopUpIdle}, + + {kDDCaret, "caret", false, kDDNone}, + {kDDSeparator, "separator", true, kDDNone}, +}; + +const ThemeEngine::TextDataInfo ThemeEngine::kTextDataDefaults[] = { + {kTextDataDefault, "text_default"}, + {kTextDataHover, "text_hover"}, + {kTextDataDisabled, "text_disabled"}, + {kTextDataInverted, "text_inverted"}, + {kTextDataButton, "text_button"}, + {kTextDataButtonHover, "text_button_hover"}, + {kTextDataNormalFont, "text_normal"} +}; + + +/********************************************************** + * ThemeItem functions for drawing queues. + *********************************************************/ +void ThemeItemDrawData::drawSelf(bool draw, bool restore) { + + Common::Rect extendedRect = _area; + extendedRect.grow(_engine->kDirtyRectangleThreshold + _data->_backgroundOffset); + + if (restore) + _engine->restoreBackground(extendedRect); + + if (draw) { + Common::List<Graphics::DrawStep>::const_iterator step; + for (step = _data->_steps.begin(); step != _data->_steps.end(); ++step) + _engine->renderer()->drawStep(_area, *step, _dynamicData); + } + + _engine->addDirtyRect(extendedRect); +} + +void ThemeItemTextData::drawSelf(bool draw, bool restore) { + if (_restoreBg || restore) + _engine->restoreBackground(_area); + + if (draw) { + _engine->renderer()->setFgColor(_data->_color.r, _data->_color.g, _data->_color.b); + _engine->renderer()->drawString(_data->_fontPtr, _text, _area, _alignH, _alignV, _deltax, _ellipsis); + } + + _engine->addDirtyRect(_area); +} + +void ThemeItemBitmap::drawSelf(bool draw, bool restore) { + if (restore) + _engine->restoreBackground(_area); + + if (draw) { + if (_alpha) + _engine->renderer()->blitAlphaBitmap(_bitmap, _area); + else + _engine->renderer()->blitSubSurface(_bitmap, _area); + } + + _engine->addDirtyRect(_area); +} + +}
\ No newline at end of file diff --git a/gui/ThemeData.h b/gui/ThemeData.h new file mode 100644 index 0000000000..d2995e44a4 --- /dev/null +++ b/gui/ThemeData.h @@ -0,0 +1,130 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef GUI_THEME_DATA_H +#define GUI_THEME_DATA_H + + +namespace GUI { + +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<Graphics::DrawStep> _steps; + + int _textDataId; + GUI::ThemeEngine::TextAlign _textAlignH; + GUI::ThemeEngine::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::ThemeEngine::TextAlign alignH, GUI::ThemeEngine::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::ThemeEngine::TextAlign _alignH; + GUI::ThemeEngine::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; +}; + +} + +#endif
\ No newline at end of file diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 755d322816..6a0a8c406c 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -40,110 +40,60 @@ #include "gui/ThemeEngine.h" #include "gui/ThemeEval.h" #include "gui/ThemeParser.h" +#include "gui/ThemeData.h" #define GUI_ENABLE_BUILTIN_THEME namespace GUI { -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<Graphics::DrawStep> _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; +/********************************************************** + * ThemeEngine class + *********************************************************/ +ThemeEngine::ThemeEngine(Common::String fileName, GraphicsMode mode) : + _system(0), _vectorRenderer(0), _screen(0), _backBuffer(0), + _buffering(false), _bytesPerPixel(0), _graphicsMode(kGfxDisabled), + _font(0), _initOk(false), _themeOk(false), _enabled(false), _cursor(0), + _loadedThemeX(0), _loadedThemeY(0) { + + _system = g_system; + _parser = new ThemeParser(this); + _themeEval = new GUI::ThemeEval(); - ~WidgetDrawData() { - _steps.clear(); + _useCursor = false; - if (_surfaceCache) { - _surfaceCache->free(); - delete _surfaceCache; - } + for (int i = 0; i < kDrawDataMAX; ++i) { + _widgets[i] = 0; } -}; - -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; -}; + for (int i = 0; i < kTextDataMAX; ++i) { + _texts[i] = 0; + } -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; -}; + _graphicsMode = mode; + _themeFileName = fileName; + _initOk = false; +} -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) {} +ThemeEngine::~ThemeEngine() { + freeRenderer(); + freeScreen(); + freeBackbuffer(); + unloadTheme(); + delete _parser; + delete _themeEval; + delete[] _cursor; - void drawSelf(bool draw, bool restore); + for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) + ImageMan.unregisterSurface(i->_key); +} -protected: - const Graphics::Surface *_bitmap; - bool _alpha; -}; +/********************************************************** + * Rendering mode management + *********************************************************/ const ThemeEngine::Renderer ThemeEngine::_rendererModes[] = { { "Disabled GFX", "none", kGfxDisabled }, { "Standard Renderer (16bpp)", "normal_16bpp", kGfxStandard16bit }, @@ -179,149 +129,8 @@ const char *ThemeEngine::findModeConfigName(GraphicsMode mode) { return findModeConfigName(kGfxDisabled); } -/********************************************************** - * ThemeItem functions for drawing queues. - *********************************************************/ -void ThemeItemDrawData::drawSelf(bool draw, bool restore) { - - Common::Rect extendedRect = _area; - extendedRect.grow(_engine->kDirtyRectangleThreshold + _data->_backgroundOffset); - - if (restore) - _engine->restoreBackground(extendedRect); - - if (draw) { - Common::List<Graphics::DrawStep>::const_iterator step; - for (step = _data->_steps.begin(); step != _data->_steps.end(); ++step) - _engine->renderer()->drawStep(_area, *step, _dynamicData); - } - - _engine->addDirtyRect(extendedRect); -} - -void ThemeItemTextData::drawSelf(bool draw, bool restore) { - if (_restoreBg || restore) - _engine->restoreBackground(_area); - - if (draw) { - _engine->renderer()->setFgColor(_data->_color.r, _data->_color.g, _data->_color.b); - _engine->renderer()->drawString(_data->_fontPtr, _text, _area, _alignH, _alignV, _deltax, _ellipsis); - } - - _engine->addDirtyRect(_area); -} - -void ThemeItemBitmap::drawSelf(bool draw, bool restore) { - if (restore) - _engine->restoreBackground(_area); - - if (draw) { - if (_alpha) - _engine->renderer()->blitAlphaBitmap(_bitmap, _area); - else - _engine->renderer()->blitSubSurface(_bitmap, _area); - } - - _engine->addDirtyRect(_area); -} - - - -/********************************************************** - * Data definitions for theme engine elements - *********************************************************/ -const ThemeEngine::DrawDataInfo ThemeEngine::kDrawDataDefaults[] = { - {kDDMainDialogBackground, "mainmenu_bg", true, kDDNone}, - {kDDSpecialColorBackground, "special_bg", true, kDDNone}, - {kDDPlainColorBackground, "plain_bg", true, kDDNone}, - {kDDDefaultBackground, "default_bg", true, kDDNone}, - {kDDTextSelectionBackground, "text_selection", false, kDDNone}, - - {kDDWidgetBackgroundDefault, "widget_default", true, kDDNone}, - {kDDWidgetBackgroundSmall, "widget_small", true, kDDNone}, - {kDDWidgetBackgroundEditText, "widget_textedit", true, kDDNone}, - {kDDWidgetBackgroundSlider, "widget_slider", true, kDDNone}, - - {kDDButtonIdle, "button_idle", true, kDDWidgetBackgroundSlider}, - {kDDButtonHover, "button_hover", false, kDDButtonIdle}, - {kDDButtonDisabled, "button_disabled", true, kDDNone}, - - {kDDSliderFull, "slider_full", false, kDDNone}, - {kDDSliderHover, "slider_hover", false, kDDNone}, - {kDDSliderDisabled, "slider_disabled", true, kDDNone}, - - {kDDCheckboxDefault, "checkbox_default", true, kDDNone}, - {kDDCheckboxDisabled, "checkbox_disabled", true, kDDNone}, - {kDDCheckboxSelected, "checkbox_selected", false, kDDCheckboxDefault}, - - {kDDTabActive, "tab_active", false, kDDTabInactive}, - {kDDTabInactive, "tab_inactive", true, kDDNone}, - {kDDTabBackground, "tab_background", true, kDDNone}, - - {kDDScrollbarBase, "scrollbar_base", true, kDDNone}, - - {kDDScrollbarButtonIdle, "scrollbar_button_idle", true, kDDNone}, - {kDDScrollbarButtonHover, "scrollbar_button_hover", false, kDDScrollbarButtonIdle}, - - {kDDScrollbarHandleIdle, "scrollbar_handle_idle", false, kDDNone}, - {kDDScrollbarHandleHover, "scrollbar_handle_hover", false, kDDScrollbarBase}, - - {kDDPopUpIdle, "popup_idle", true, kDDNone}, - {kDDPopUpHover, "popup_hover", false, kDDPopUpIdle}, - - {kDDCaret, "caret", false, kDDNone}, - {kDDSeparator, "separator", true, kDDNone}, -}; - -const ThemeEngine::TextDataInfo ThemeEngine::kTextDataDefaults[] = { - {kTextDataDefault, "text_default"}, - {kTextDataHover, "text_hover"}, - {kTextDataDisabled, "text_disabled"}, - {kTextDataInverted, "text_inverted"}, - {kTextDataButton, "text_button"}, - {kTextDataButtonHover, "text_button_hover"}, - {kTextDataNormalFont, "text_normal"} -}; - - -/********************************************************** - * ThemeEngine class - *********************************************************/ -ThemeEngine::ThemeEngine(Common::String fileName, GraphicsMode mode) : - _system(0), _vectorRenderer(0), _screen(0), _backBuffer(0), - _buffering(false), _bytesPerPixel(0), _graphicsMode(kGfxDisabled), - _font(0), _initOk(false), _themeOk(false), _enabled(false), _cursor(0) { - _system = g_system; - _parser = new ThemeParser(this); - _themeEval = new GUI::ThemeEval(); - - _useCursor = false; - - for (int i = 0; i < kDrawDataMAX; ++i) { - _widgets[i] = 0; - } - - for (int i = 0; i < kTextDataMAX; ++i) { - _texts[i] = 0; - } - _graphicsMode = mode; - _themeFileName = fileName; - _initOk = false; -} - -ThemeEngine::~ThemeEngine() { - freeRenderer(); - freeScreen(); - freeBackbuffer(); - unloadTheme(); - delete _parser; - delete _themeEval; - delete[] _cursor; - for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) - ImageMan.unregisterSurface(i->_key); -} /********************************************************** @@ -515,6 +324,18 @@ void ThemeEngine::restoreBackground(Common::Rect r, bool special) { _vectorRenderer->blitSurface(_backBuffer, r); } +bool ThemeEngine::isThemeLoadingRequired() { + int x = g_system->getOverlayWidth(), y = g_system->getOverlayHeight(); + + if (_loadedThemeX == x && _loadedThemeY == y) + return false; + + _loadedThemeX = x; + _loadedThemeY = y; + + return true; +} + @@ -677,8 +498,7 @@ bool ThemeEngine::loadThemeXML(const Common::String &themeName) { if (!node.exists() || !node.isReadable()) return false; - // FIXME: Should this be initialized to something else than NULL? - Common::Archive *archive = NULL; + Common::Archive *archive = 0; if (node.getName().hasSuffix(".zip") && !node.isDirectory()) { #ifdef USE_ZLIB @@ -693,7 +513,9 @@ bool ThemeEngine::loadThemeXML(const Common::String &themeName) { #endif } else if (node.isDirectory()) { - warning("Don't know how to open theme '%s'", themeName.c_str()); + +// FIXME: This warning makes no sense whatsoever. Who added this? +// warning("Don't know how to open theme '%s'", themeName.c_str()); archive = new Common::FSDirectory(node); } @@ -701,8 +523,6 @@ bool ThemeEngine::loadThemeXML(const Common::String &themeName) { return false; Common::File themercFile; - // FIXME: Possibly dereferencing a NULL pointer here if the node's - // name doesn't have a ".zip" suffix and the node is not a directory. themercFile.open("THEMERC", *archive); if (!themercFile.isOpen()) { delete archive; @@ -1215,6 +1035,11 @@ bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int return true; } + +/********************************************************** + * Legacy GUI::Theme support functions + *********************************************************/ + const Graphics::Font *ThemeEngine::getFont(FontStyle font) const { return _texts[fontStyleToData(font)]->_fontPtr; } @@ -1236,4 +1061,148 @@ ThemeEngine::TextData ThemeEngine::getTextData(DrawData ddId) { } + +/********************************************************** + * External data loading + *********************************************************/ + +const Graphics::Font *ThemeEngine::loadFontFromArchive(const Common::String &filename) { + Common::Archive *arch = 0; + const Graphics::NewFont *font = 0; + + if (getThemeFileName().hasSuffix(".zip")) { +#ifdef USE_ZLIB + Common::ZipArchive *zip = new Common::ZipArchive(getThemeFileName()); + if (!zip || !zip->isOpen()) + return 0; + + arch = zip; +#else + return 0; +#endif + } else { + Common::FSDirectory *dir = new Common::FSDirectory(getThemeFileName()); + if (!dir || !dir->getFSNode().isDirectory()) + return 0; + + arch = dir; + } + + Common::SeekableReadStream *stream(arch->openFile(filename)); + if (stream) { + font = Graphics::NewFont::loadFromCache(*stream); + delete stream; + } + + delete arch; + return font; +} + +const Graphics::Font *ThemeEngine::loadFont(const Common::String &filename) { + const Graphics::Font *font = 0; + Common::String cacheFilename = genCacheFilename(filename.c_str()); + Common::File fontFile; + + if (!cacheFilename.empty()) { + if (fontFile.open(cacheFilename)) + font = Graphics::NewFont::loadFromCache(fontFile); + + if (font) + return font; + + if ((font = loadFontFromArchive(cacheFilename))) + return font; + } + + // normal open + if (fontFile.open(filename)) { + font = Graphics::NewFont::loadFont(fontFile); + } + + if (!font) { + font = loadFontFromArchive(filename); + } + + if (font) { + if (!cacheFilename.empty()) { + if (!Graphics::NewFont::cacheFontData(*(const Graphics::NewFont*)font, cacheFilename)) { + warning("Couldn't create cache file for font '%s'", filename.c_str()); + } + } + } + + return font; +} + +Common::String ThemeEngine::genCacheFilename(const char *filename) { + Common::String cacheName(filename); + for (int i = cacheName.size() - 1; i >= 0; --i) { + if (cacheName[i] == '.') { + while ((uint)i < cacheName.size() - 1) { + cacheName.deleteLastChar(); + } + + cacheName += "fcc"; + return cacheName; + } + } + + return ""; +} + + +/********************************************************** + * Static Theme XML functions + *********************************************************/ + +bool ThemeEngine::themeConfigParseHeader(Common::String header, Common::String &themeName) { + header.trim(); + + if (header.empty()) + return false; + + if (header[0] != '[' || header.lastChar() != ']') + return false; + + header.deleteChar(0); + header.deleteLastChar(); + + Common::StringTokenizer tok(header, ":"); + + if (tok.nextToken() != SCUMMVM_THEME_VERSION_STR) + return false; + + themeName = tok.nextToken(); + Common::String author = tok.nextToken(); + + return tok.empty(); +} + +bool ThemeEngine::themeConfigUseable(const Common::FSNode &node, Common::String &themeName) { + Common::File stream; + bool foundHeader = false; + + if (node.getName().hasSuffix(".zip") && !node.isDirectory()) { +#ifdef USE_ZLIB + Common::ZipArchive zipArchive(node); + if (zipArchive.hasFile("THEMERC")) { + stream.open("THEMERC", zipArchive); + } +#endif + } else if (node.isDirectory()) { + Common::FSNode headerfile = node.getChild("THEMERC"); + if (!headerfile.exists() || !headerfile.isReadable() || headerfile.isDirectory()) + return false; + stream.open(headerfile); + } + + if (stream.isOpen()) { + Common::String stxHeader = stream.readLine(); + foundHeader = themeConfigParseHeader(stxHeader, themeName); + } + + return foundHeader; +} + + } // end of namespace GUI. diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index cc55e0cb34..b812d7a2b2 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -28,11 +28,11 @@ #include "common/scummsys.h" #include "common/system.h" - +#include "common/fs.h" #include "graphics/surface.h" #include "graphics/fontman.h" -#include "gui/theme.h" +#define SCUMMVM_THEME_VERSION_STR "SCUMMVM_STX0.3" namespace Graphics { struct DrawStep; @@ -50,7 +50,7 @@ class ThemeEval; class ThemeItem; class ThemeParser; -class ThemeEngine : public Theme { +class ThemeEngine { protected: typedef Common::HashMap<Common::String, Graphics::Surface*> ImagesMap; @@ -137,8 +137,80 @@ protected: const char *name; } kTextDataDefaults[]; - public: + //! Defined the align of the text + enum TextAlign { + kTextAlignLeft, //!< Text should be aligned to the left + kTextAlignCenter, //!< Text should be centered + kTextAlignRight //!< Text should be aligned to the right + }; + + //! Vertical alignment of the text. + enum TextAlignVertical { + kTextAlignVBottom, + kTextAlignVCenter, + kTextAlignVTop + }; + + //! Widget background type + enum WidgetBackground { + kWidgetBackgroundNo, //!< No background at all + kWidgetBackgroundPlain, //!< Simple background, this may not include borders + kWidgetBackgroundBorder, //!< Same as kWidgetBackgroundPlain just with a border + kWidgetBackgroundBorderSmall, //!< Same as kWidgetBackgroundPlain just with a small border + kWidgetBackgroundEditText, //!< Background used for edit text fields + kWidgetBackgroundSlider //!< Background used for sliders + }; + + //! Dialog background type + enum DialogBackground { + kDialogBackgroundMain, + kDialogBackgroundSpecial, + kDialogBackgroundPlain, + kDialogBackgroundDefault + }; + + //! State of the widget to be drawn + enum State { + kStateDisabled, //!< Indicates that the widget is disabled, that does NOT include that it is invisible + kStateEnabled, //!< Indicates that the widget is enabled + kStateHighlight //!< Indicates that the widget is highlighted by the user + }; + + typedef State WidgetStateInfo; + + enum ScrollbarState { + kScrollbarStateNo, + kScrollbarStateUp, + kScrollbarStateDown, + kScrollbarStateSlider, + kScrollbarStateSinglePage + }; + + //! Font style selector + enum FontStyle { + kFontStyleBold = 0, //!< A bold font. This is also the default font. + kFontStyleNormal = 1, //!< A normal font. + kFontStyleItalic = 2, //!< Italic styled font. + kFontStyleFixedNormal = 3, //!< Fixed size font. + kFontStyleFixedBold = 4, //!< Fixed size bold font. + kFontStyleFixedItalic = 5, //!< Fixed size italic font. + kFontStyleMax + }; + + //! Function used to process areas other than the current dialog + enum ShadingStyle { + kShadingNone, //!< No special post processing + kShadingDim, //!< Dimming unused areas + kShadingLuminance //!< Converting colors to luminance for unused areas + }; + + //! Special image ids for images used in the GUI + enum kThemeImages { + kImageLogo = 0, //!< ScummVM Logo used in the launcher + kImageLogoSmall //!< ScummVM logo used in the GMM + }; + /** Graphics mode enumeration. * Each item represents a set of BPP and Renderer modes for a given * surface. @@ -148,7 +220,7 @@ public: kGfxStandard16bit, /** 2BPP with the standard (aliased) renderer. */ kGfxAntialias16bit /** 2BPP with the optimized AA renderer. */ }; - + /** Constant value to expand dirty rectangles, to make sure they are fully copied */ static const int kDirtyRectangleThreshold = 1; @@ -441,8 +513,6 @@ public: */ bool isWidgetCached(DrawData type, const Common::Rect &r); -public: - const Common::String &getThemeName() const { return _themeName; } const Common::String &getThemeFileName() const { return _themeFileName; } int getGraphicsMode() const { return _graphicsMode; } @@ -549,19 +619,63 @@ protected: void queueBitmap(const Graphics::Surface *bitmap, const Common::Rect &r, bool alpha); /** - * DEBUG: Draws a white square around the given position and writes the given next to it. + * DEBUG: Draws a white square and writes some text next to it. */ void debugWidgetPosition(const char *name, const Common::Rect &r); +public: + + /** + * LEGACY: Old GUI::Theme API + */ + + bool needThemeReload() { + return ((_loadedThemeX != g_system->getOverlayWidth()) || + (_loadedThemeY != g_system->getOverlayHeight())); + } const Graphics::Font *loadFont(const Common::String &filename); const Graphics::Font *loadFontFromArchive(const Common::String &filename); Common::String genCacheFilename(const char *filename); + + Graphics::TextAlignment convertAligment(TextAlign align) const { + switch (align) { + case kTextAlignLeft: + return Graphics::kTextAlignLeft; + break; + + case kTextAlignRight: + return Graphics::kTextAlignRight; + break; + + default: + break; + }; + return Graphics::kTextAlignCenter; + } + + TextAlign convertAligment(Graphics::TextAlignment align) const { + switch (align) { + case Graphics::kTextAlignLeft: + return kTextAlignLeft; + break; + + case Graphics::kTextAlignRight: + return kTextAlignRight; + break; + + default: + break; + } + return kTextAlignCenter; + } + + + bool isThemeLoadingRequired(); + + static bool themeConfigUseable(const Common::FSNode &node, Common::String &themeName); + static bool themeConfigParseHeader(Common::String header, Common::String &themeName); -public: - /** - * Default values from GUI::Theme - */ int getTabSpacing() const { return 0; } int getTabPadding() const { return 3; } @@ -633,6 +747,7 @@ protected: bool _needPaletteUpdates; uint _cursorWidth, _cursorHeight; byte _cursorPal[4*MAX_CURS_COLORS]; + int _loadedThemeX, _loadedThemeY; }; } // end of namespace GUI. diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 5d1ca7ff1c..1663efc404 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -177,23 +177,23 @@ bool ThemeParser::parserCallback_bitmap(ParserNode *node) { } bool ThemeParser::parserCallback_text(ParserNode *node) { - GUI::Theme::TextAlign alignH; - GUI::Theme::TextAlignVertical alignV; + GUI::ThemeEngine::TextAlign alignH; + GUI::ThemeEngine::TextAlignVertical alignV; if (node->values["horizontal_align"] == "left") - alignH = GUI::Theme::kTextAlignLeft; + alignH = GUI::ThemeEngine::kTextAlignLeft; else if (node->values["horizontal_align"] == "right") - alignH = GUI::Theme::kTextAlignRight; + alignH = GUI::ThemeEngine::kTextAlignRight; else if (node->values["horizontal_align"] == "center") - alignH = GUI::Theme::kTextAlignCenter; + alignH = GUI::ThemeEngine::kTextAlignCenter; else return parserError("Invalid value for text alignment."); if (node->values["vertical_align"] == "top") - alignV = GUI::Theme::kTextAlignVTop; + alignV = GUI::ThemeEngine::kTextAlignVTop; else if (node->values["vertical_align"] == "center") - alignV = GUI::Theme::kTextAlignVCenter; + alignV = GUI::ThemeEngine::kTextAlignVCenter; else if (node->values["vertical_align"] == "bottom") - alignV = GUI::Theme::kTextAlignVBottom; + alignV = GUI::ThemeEngine::kTextAlignVBottom; else return parserError("Invalid value for text alignment."); if (!_theme->addTextData(getParentNode(node)->values["id"], node->values["font"], alignH, alignV)) diff --git a/gui/about.cpp b/gui/about.cpp index 1c1e3a3355..7749533925 100644 --- a/gui/about.cpp +++ b/gui/about.cpp @@ -218,29 +218,29 @@ void AboutDialog::drawDialog() { for (int line = firstLine; line < lastLine; line++) { const char *str = _lines[line].c_str(); - Theme::TextAlign align = Theme::kTextAlignCenter; - Theme::WidgetStateInfo state = Theme::kStateEnabled; + ThemeEngine::TextAlign align = ThemeEngine::kTextAlignCenter; + ThemeEngine::WidgetStateInfo state = ThemeEngine::kStateEnabled; while (str[0] == '\\') { switch (str[1]) { case 'C': - align = Theme::kTextAlignCenter; + align = ThemeEngine::kTextAlignCenter; break; case 'L': - align = Theme::kTextAlignLeft; + align = ThemeEngine::kTextAlignLeft; break; case 'R': - align = Theme::kTextAlignRight; + align = ThemeEngine::kTextAlignRight; break; case 'c': switch (str[2]) { case '0': - state = Theme::kStateEnabled; + state = ThemeEngine::kStateEnabled; break; case '1': - state = Theme::kStateHighlight; + state = ThemeEngine::kStateHighlight; break; case '2': - state = Theme::kStateDisabled; + state = ThemeEngine::kStateDisabled; break; case '3': warning("Need state for color 3"); @@ -262,7 +262,7 @@ void AboutDialog::drawDialog() { str += 2; } // Trim leading whitespaces if center mode is on - if (align == Theme::kTextAlignCenter) + if (align == ThemeEngine::kTextAlignCenter) while (*str && *str == ' ') str++; diff --git a/gui/browser.cpp b/gui/browser.cpp index 36969d9c54..02af47ee7c 100644 --- a/gui/browser.cpp +++ b/gui/browser.cpp @@ -150,7 +150,7 @@ BrowserDialog::BrowserDialog(const char *title, bool dirBrowser) _fileList->setNumberingMode(kListNumberingOff); _fileList->setEditable(false); - _backgroundType = GUI::Theme::kDialogBackgroundPlain; + _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; // Buttons new ButtonWidget(this, "Browser.Up", "Go up", kGoUpCmd, 0); diff --git a/gui/console.cpp b/gui/console.cpp index 4b3d41ece1..cad65b03d6 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -170,7 +170,7 @@ void ConsoleDialog::close() { } void ConsoleDialog::drawDialog() { - g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x + _w, _y + _h), Theme::kDialogBackgroundPlain/*_backgroundType*/); + g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x + _w, _y + _h), ThemeEngine::kDialogBackgroundPlain/*_backgroundType*/); // FIXME: for the old theme the frame around the console vanishes // when any action is processed if we enable this // _drawingHints &= ~THEME_HINT_FIRST_DRAW; diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 3b302ff36a..b11bf5bf26 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -45,12 +45,12 @@ namespace GUI { Dialog::Dialog(int x, int y, int w, int h) : GuiObject(x, y, w, h), _mouseWidget(0), _focusedWidget(0), _dragWidget(0), _visible(false), - _backgroundType(GUI::Theme::kDialogBackgroundDefault) {} + _backgroundType(GUI::ThemeEngine::kDialogBackgroundDefault) {} Dialog::Dialog(const Common::String &name) : GuiObject(name), _mouseWidget(0), _focusedWidget(0), _dragWidget(0), _visible(false), - _backgroundType(GUI::Theme::kDialogBackgroundDefault) { + _backgroundType(GUI::ThemeEngine::kDialogBackgroundDefault) { // It may happen that we have 3x scaler in launcher (960xY) and then 640x480 // game will be forced to 1x. At this stage GUI will not be aware of diff --git a/gui/dialog.h b/gui/dialog.h index 281bcd7258..26e71cc600 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -49,7 +49,7 @@ protected: Widget *_dragWidget; bool _visible; - Theme::DialogBackground _backgroundType; + ThemeEngine::DialogBackground _backgroundType; private: int _result; diff --git a/gui/editable.cpp b/gui/editable.cpp index 57723bcbcd..f82f06f4ce 100644 --- a/gui/editable.cpp +++ b/gui/editable.cpp @@ -47,7 +47,7 @@ void EditableWidget::init() { _editScrollOffset = 0; - _font = Theme::kFontStyleBold; + _font = ThemeEngine::kFontStyleBold; } EditableWidget::~EditableWidget() { diff --git a/gui/editable.h b/gui/editable.h index c8ef8a80cb..e09c4a3df4 100644 --- a/gui/editable.h +++ b/gui/editable.h @@ -50,7 +50,7 @@ protected: int _editScrollOffset; - Theme::FontStyle _font; + ThemeEngine::FontStyle _font; public: EditableWidget(GuiObject *boss, int x, int y, int w, int h); @@ -79,7 +79,7 @@ protected: bool adjustOffset(); void makeCaretVisible(); - void setFontStyle(Theme::FontStyle font) { _font = font; } + void setFontStyle(ThemeEngine::FontStyle font) { _font = font; } virtual bool tryInsertChar(byte c, int pos); }; diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 39d8acffbd..ca41dacbe8 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -477,7 +477,7 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel) : Dialog("ScummSaveLoad"), _delSupport(0), _list(0), _chooseButton(0), _deleteButton(0), _gfxWidget(0) { _delSupport = _metaInfoSupport = _thumbnailSupport = _saveDateSupport = _playTimeSupport = false; - _backgroundType = Theme::kDialogBackgroundSpecial; + _backgroundType = ThemeEngine::kDialogBackgroundSpecial; new StaticTextWidget(this, "ScummSaveLoad.Title", title); @@ -794,7 +794,7 @@ void SaveLoadChooser::updateSaveList() { LauncherDialog::LauncherDialog() : Dialog(0, 0, 320, 200) { - _backgroundType = GUI::Theme::kDialogBackgroundMain; + _backgroundType = GUI::ThemeEngine::kDialogBackgroundMain; const int screenW = g_system->getOverlayWidth(); const int screenH = g_system->getOverlayHeight(); @@ -807,7 +807,7 @@ LauncherDialog::LauncherDialog() if (g_gui.xmlEval()->getVar("Globals.ShowLauncherLogo") == 1 && g_gui.theme()->supportsImages()) { _logo = new GraphicsWidget(this, "Launcher.Logo"); _logo->useThemeTransparency(true); - _logo->setGfx(g_gui.theme()->getImageSurface(Theme::kImageLogo)); + _logo->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageLogo)); new StaticTextWidget(this, "Launcher.Version", gScummVMVersionDate); } else @@ -1257,7 +1257,7 @@ void LauncherDialog::reflowLayout() { if (!_logo) _logo = new GraphicsWidget(this, "Launcher.Logo"); _logo->useThemeTransparency(true); - _logo->setGfx(g_gui.theme()->getImageSurface(Theme::kImageLogo)); + _logo->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageLogo)); } else { StaticTextWidget *ver = (StaticTextWidget*)findWidget("Launcher.Version"); if (ver) { diff --git a/gui/module.mk b/gui/module.mk index b84ced51b4..c7b7d8b87c 100644 --- a/gui/module.mk +++ b/gui/module.mk @@ -19,10 +19,10 @@ MODULE_OBJS := \ PopUpWidget.o \ ScrollBarWidget.o \ TabWidget.o \ - theme.o \ themebrowser.o \ ThemeEngine.o \ ThemeEval.o \ + ThemeData.o \ ThemeLayout.o \ ThemeParser.o \ widget.o diff --git a/gui/newgui.cpp b/gui/newgui.cpp index eca71c2d7a..d8c3a8212e 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -141,7 +141,7 @@ void NewGui::redraw() { _theme->updateScreen(); case kRedrawOpenDialog: - _theme->openDialog(true, (Theme::ShadingStyle)xmlEval()->getVar("Dialog." + _dialogStack.top()->_name + ".Shading", 0)); + _theme->openDialog(true, (ThemeEngine::ShadingStyle)xmlEval()->getVar("Dialog." + _dialogStack.top()->_name + ".Shading", 0)); _dialogStack.top()->drawDialog(); _theme->finishBuffering(); break; diff --git a/gui/newgui.h b/gui/newgui.h index d4143db178..c87b4fd177 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -30,7 +30,7 @@ #include "common/stack.h" #include "common/str.h" #include "graphics/fontman.h" -#include "gui/theme.h" + #include "gui/widget.h" #include "gui/ThemeEngine.h" @@ -83,10 +83,10 @@ public: ThemeEval *xmlEval() { return _theme->getEvaluator(); } - const Graphics::Font &getFont(Theme::FontStyle style = Theme::kFontStyleBold) const { return *(_theme->getFont(style)); } - int getFontHeight(Theme::FontStyle style = Theme::kFontStyleBold) const { return _theme->getFontHeight(style); } - int getStringWidth(const Common::String &str, Theme::FontStyle style = Theme::kFontStyleBold) const { return _theme->getStringWidth(str, style); } - int getCharWidth(byte c, Theme::FontStyle style = Theme::kFontStyleBold) const { return _theme->getCharWidth(c, style); } + const Graphics::Font &getFont(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return *(_theme->getFont(style)); } + int getFontHeight(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getFontHeight(style); } + int getStringWidth(const Common::String &str, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getStringWidth(str, style); } + int getCharWidth(byte c, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getCharWidth(c, style); } WidgetSize getWidgetSize(); diff --git a/gui/theme.cpp b/gui/theme.cpp deleted file mode 100644 index 36bf9c5191..0000000000 --- a/gui/theme.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include "gui/theme.h" -#include "common/file.h" -#include "common/archive.h" -#include "common/unzip.h" - -#include "gui/ThemeEngine.h" - -namespace GUI { - -Theme::Theme() : _loadedThemeX(0), _loadedThemeY(0) {} - -Theme::~Theme() {} - -const Graphics::Font *ThemeEngine::loadFontFromArchive(const Common::String &filename) { - Common::Archive *arch = 0; - const Graphics::NewFont *font = 0; - - if (getThemeFileName().hasSuffix(".zip")) { -#ifdef USE_ZLIB - Common::ZipArchive *zip = new Common::ZipArchive(getThemeFileName()); - if (!zip || !zip->isOpen()) - return 0; - - arch = zip; -#else - return 0; -#endif - } else { - Common::FSDirectory *dir = new Common::FSDirectory(getThemeFileName()); - if (!dir || !dir->getFSNode().isDirectory()) - return 0; - - arch = dir; - } - - Common::SeekableReadStream *stream(arch->openFile(filename)); - if (stream) { - font = Graphics::NewFont::loadFromCache(*stream); - delete stream; - } - - delete arch; - return font; -} - -const Graphics::Font *ThemeEngine::loadFont(const Common::String &filename) { - const Graphics::Font *font = 0; - Common::String cacheFilename = genCacheFilename(filename.c_str()); - Common::File fontFile; - - if (!cacheFilename.empty()) { - if (fontFile.open(cacheFilename)) - font = Graphics::NewFont::loadFromCache(fontFile); - - if (font) - return font; - - if ((font = loadFontFromArchive(cacheFilename))) - return font; - } - - // normal open - if (fontFile.open(filename)) { - font = Graphics::NewFont::loadFont(fontFile); - } - - if (!font) { - font = loadFontFromArchive(filename); - } - - if (font) { - if (!cacheFilename.empty()) { - if (!Graphics::NewFont::cacheFontData(*(const Graphics::NewFont*)font, cacheFilename)) { - warning("Couldn't create cache file for font '%s'", filename.c_str()); - } - } - } - - return font; -} - -Common::String ThemeEngine::genCacheFilename(const char *filename) { - Common::String cacheName(filename); - for (int i = cacheName.size() - 1; i >= 0; --i) { - if (cacheName[i] == '.') { - while ((uint)i < cacheName.size() - 1) { - cacheName.deleteLastChar(); - } - - cacheName += "fcc"; - return cacheName; - } - } - - return ""; -} - -bool Theme::isThemeLoadingRequired() { - int x = g_system->getOverlayWidth(), y = g_system->getOverlayHeight(); - - if (_loadedThemeX == x && _loadedThemeY == y) - return false; - - _loadedThemeX = x; - _loadedThemeY = y; - - return true; -} - -bool Theme::themeConfigParseHeader(Common::String header, Common::String &themeName) { - header.trim(); - - if (header.empty()) - return false; - - if (header[0] != '[' || header.lastChar() != ']') - return false; - - header.deleteChar(0); - header.deleteLastChar(); - - Common::StringTokenizer tok(header, ":"); - - if (tok.nextToken() != SCUMMVM_THEME_VERSION_STR) - return false; - - themeName = tok.nextToken(); - Common::String author = tok.nextToken(); - - return tok.empty(); -} - -bool Theme::themeConfigUseable(const Common::FSNode &node, Common::String &themeName) { - Common::File stream; - bool foundHeader = false; - - if (node.getName().hasSuffix(".zip") && !node.isDirectory()) { -#ifdef USE_ZLIB - Common::ZipArchive zipArchive(node); - if (zipArchive.hasFile("THEMERC")) { - stream.open("THEMERC", zipArchive); - } -#endif - } else if (node.isDirectory()) { - Common::FSNode headerfile = node.getChild("THEMERC"); - if (!headerfile.exists() || !headerfile.isReadable() || headerfile.isDirectory()) - return false; - stream.open(headerfile); - } - - if (stream.isOpen()) { - Common::String stxHeader = stream.readLine(); - foundHeader = themeConfigParseHeader(stxHeader, themeName); - } - - return foundHeader; -} - -} // End of namespace GUI - diff --git a/gui/theme.h b/gui/theme.h deleted file mode 100644 index 2b4ec83e7b..0000000000 --- a/gui/theme.h +++ /dev/null @@ -1,348 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#ifndef GUI_THEME_H -#define GUI_THEME_H - -#include "common/system.h" -#include "common/rect.h" -#include "common/str.h" -#include "common/fs.h" -#include "common/config-file.h" - -#include "graphics/surface.h" -#include "graphics/fontman.h" - -#define THEME_VERSION 24 -#define SCUMMVM_THEME_VERSION_STR "SCUMMVM_STX0.3" - -namespace GUI { - -class ThemeEval; - -/** - * Our theme renderer class. - * - * It is used to draw the different widgets and - * getting the layout of the widgets for different - * resolutions. - */ -class Theme { -public: - Theme(); - - virtual ~Theme(); - - //! Defined the align of the text - enum TextAlign { - kTextAlignLeft, //!< Text should be aligned to the left - kTextAlignCenter, //!< Text should be centered - kTextAlignRight //!< Text should be aligned to the right - }; - - //! Vertical alignment of the text. - enum TextAlignVertical { - kTextAlignVBottom, - kTextAlignVCenter, - kTextAlignVTop - }; - - //! Widget background type - enum WidgetBackground { - kWidgetBackgroundNo, //!< No background at all - kWidgetBackgroundPlain, //!< Simple background, this may not include borders - kWidgetBackgroundBorder, //!< Same as kWidgetBackgroundPlain just with a border - kWidgetBackgroundBorderSmall, //!< Same as kWidgetBackgroundPlain just with a small border - kWidgetBackgroundEditText, //!< Background used for edit text fields - kWidgetBackgroundSlider //!< Background used for sliders - }; - - //! Dialog background type - enum DialogBackground { - kDialogBackgroundMain, - kDialogBackgroundSpecial, - kDialogBackgroundPlain, - kDialogBackgroundDefault - }; - - //! State of the widget to be drawn - enum State { - kStateDisabled, //!< Indicates that the widget is disabled, that does NOT include that it is invisible - kStateEnabled, //!< Indicates that the widget is enabled - kStateHighlight //!< Indicates that the widget is highlighted by the user - }; - - typedef State WidgetStateInfo; - - enum ScrollbarState { - kScrollbarStateNo, - kScrollbarStateUp, - kScrollbarStateDown, - kScrollbarStateSlider, - kScrollbarStateSinglePage - }; - - //! Font style selector - enum FontStyle { - kFontStyleBold = 0, //!< A bold font. This is also the default font. - kFontStyleNormal = 1, //!< A normal font. - kFontStyleItalic = 2, //!< Italic styled font. - kFontStyleFixedNormal = 3, //!< Fixed size font. - kFontStyleFixedBold = 4, //!< Fixed size bold font. - kFontStyleFixedItalic = 5, //!< Fixed size italic font. - kFontStyleMax - }; - - //! Function used to process areas other than the current dialog - enum ShadingStyle { - kShadingNone, //!< No special post processing - kShadingDim, //!< Dimming unused areas - kShadingLuminance //!< Converting colors to luminance for unused areas - }; - - /** - * This initializes all the data needed by the theme renderer. - * It should just be called *once*, when first using the renderer. - * - * Other functions of the renderer should just be used after - * calling this function, else the result is undefined. - * - * If used again it should just be used after deinit, - * if there is need to use the renderer again. - * - * @see deinit - */ -// virtual bool init() = 0; - - /** - * Unloads all data used by the theme renderer. - */ -// virtual void deinit() = 0; - - /** - * Updates the renderer to changes to resolution, - * bit depth and other video related configuration. - */ -// virtual void refresh() = 0; - - /** - * Checks if the theme supplies its own cursor. - * - * @return true if using an own cursor - */ -// virtual bool ownCursor() const { return false; } - - /** - * Enables the theme renderer for use. - * - * This for examples displays the overlay, clears the - * renderer's temporary screen buffers and does other - * things to make the renderer for use. - * - * This will NOT back up the data on the overlay. - * So if you've got data in the overlay save it before - * calling this. - * - * Unlike init, this makes the renderer ready to draw - * something to the screen. And of course it relies on the data - * loaded by init. - * - * @see disable - * @see init - */ -// virtual void enable() = 0; - - /** - * Disables the theme renderer. - * - * This for example hides the overlay and undoes - * other things done by enable. - * - * Unlike uninit, this just makes the renderer unable - * to do any screen drawing, but still keeps all data - * loaded into memory. - * - * @see enable - * @see uninit - */ -// virtual void disable() = 0; - - /** - * Tells the theme renderer that a new dialog is opened. - * - * This can be used for internal caching and marking - * area of all but the not top dialog in a special way. - * - * TODO: This needs serious reworking, since at least for - * normal usage, a dialog opened with openDialog should always - * be the top dialog. Currently our themes have no good enough - * implementation to handle a single open dialog though, so we - * have to stay this way until we implement proper dialog - * 'caching'/handling. - * - * @param topDialog if true it indicates that this is the top dialog - * - * @see closeAllDialogs - */ -// virtual void openDialog(bool topDialog, ShadingStyle shading = kShadingNone) = 0; - - /** - * This indicates that all dialogs have been closed. - * - * @see openDialog - */ -// virtual void closeAllDialogs() = 0; - - /** - * Closes the topmost dialog, and redraws the screen - * accordingly. - * - * TODO: Make this purely virtual by making ThemeClassic - * and ThemeModern implement it too. - * - * @returns True if the dialog was sucessfully closed. - * If we weren't able to restore the screen after closing - * the dialog, we return false, which means we need to redraw - * the dialog stack from scratch. - */ -// virtual void startBuffering() = 0; -// virtual void finishBuffering() = 0; - - /** - * Clear the complete GUI screen. - */ -// virtual void clearAll() = 0; - - /** - * Update the GUI screen aka overlay. - * - * This does NOT call OSystem::updateScreen, - * it just copies all (changed) data to the overlay. - */ -// virtual void updateScreen() = 0; - -/* - virtual const Graphics::Font *getFont(FontStyle font = kFontStyleBold) const = 0; - virtual int getFontHeight(FontStyle font = kFontStyleBold) const = 0; - virtual int getStringWidth(const Common::String &str, FontStyle font = kFontStyleBold) const = 0; - virtual int getCharWidth(byte c, FontStyle font = kFontStyleBold) const = 0; - - virtual void drawDialogBackground(const Common::Rect &r, DialogBackground type, WidgetStateInfo state = kStateEnabled) = 0; - virtual void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, TextAlign align = kTextAlignCenter, bool inverted = false, int deltax = 0, bool useEllipsis = true, FontStyle 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, WidgetStateInfo state = kStateEnabled) = 0; - - virtual void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background = kWidgetBackgroundPlain, WidgetStateInfo state = kStateEnabled) = 0; - virtual void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, uint16 hints = 0) = 0; - virtual void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state = kStateEnabled, int alpha = 256, bool themeTrans = false) = 0; - virtual void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled) = 0; - virtual void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state = kStateEnabled) = 0; - virtual void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state = kStateEnabled) = 0; - virtual void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state = kStateEnabled) = 0; - virtual void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state = kStateEnabled, TextAlign align = kTextAlignLeft) = 0; - virtual void drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state = kStateEnabled) = 0; - virtual void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state = kStateEnabled) = 0; - - virtual void restoreBackground(Common::Rect r, bool special = false) = 0; - virtual bool addDirtyRect(Common::Rect r, bool save = false, bool special = false) = 0; - - virtual int getTabSpacing() const = 0; - virtual int getTabPadding() const = 0; -*/ - Graphics::TextAlignment convertAligment(TextAlign align) const { - switch (align) { - case kTextAlignLeft: - return Graphics::kTextAlignLeft; - break; - - case kTextAlignRight: - return Graphics::kTextAlignRight; - break; - - default: - break; - }; - return Graphics::kTextAlignCenter; - } - - TextAlign convertAligment(Graphics::TextAlignment align) const { - switch (align) { - case Graphics::kTextAlignLeft: - return kTextAlignLeft; - break; - - case Graphics::kTextAlignRight: - return kTextAlignRight; - break; - - default: - break; - } - return kTextAlignCenter; - } - - - bool isThemeLoadingRequired(); -// virtual ThemeEval *getEvaluator() = 0; - - static bool themeConfigUseable(const Common::FSNode &node, Common::String &themeName); - static bool themeConfigParseHeader(Common::String header, Common::String &themeName); - -// virtual const Common::String &getThemeFileName() const = 0; -// virtual const Common::String &getThemeName() const = 0; -// virtual int getGraphicsMode() const = 0; - - /** - * Checks if the theme renderer supports drawing of images. - * - * @return true on support, else false - */ -// virtual bool supportsImages() const { return false; } - - //! Special image ids for images used in the GUI - enum kThemeImages { - kImageLogo = 0, //!< ScummVM Logo used in the launcher - kImageLogoSmall //!< ScummVM logo used in the GMM - }; - - /** - * Returns the given image. - * - * @param n id of the image, see kThemeImages - * @return 0 if no such image exists for the theme, else pointer to the image - * - * @see kThemeImages - */ -// virtual const Graphics::Surface *getImageSurface(const kThemeImages n) const { return 0; } - -public: - bool needThemeReload() { return ((_loadedThemeX != g_system->getOverlayWidth()) || - (_loadedThemeY != g_system->getOverlayHeight())); } - -private: - int _loadedThemeX, _loadedThemeY; -}; -} // end of namespace GUI - -#endif // GUI_THEME_H diff --git a/gui/themebrowser.cpp b/gui/themebrowser.cpp index 19ac97ada3..d19aa09142 100644 --- a/gui/themebrowser.cpp +++ b/gui/themebrowser.cpp @@ -25,7 +25,8 @@ #include "gui/themebrowser.h" #include "gui/ListWidget.h" #include "gui/widget.h" -#include "gui/theme.h" +#include "common/config-manager.h" + #include "common/fs.h" #ifdef MACOSX @@ -54,7 +55,7 @@ ThemeBrowser::ThemeBrowser() : Dialog("Browser") { _fileList->setNumberingMode(kListNumberingOff); _fileList->setEditable(false); - _backgroundType = GUI::Theme::kDialogBackgroundPlain; + _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; // Buttons new ButtonWidget(this, "Browser.Cancel", "Cancel", kCloseCmd, 0); @@ -196,7 +197,7 @@ bool ThemeBrowser::isTheme(const Common::FSNode &node, Entry &out) { return false; #endif - if (!Theme::themeConfigUseable(node, out.name)) + if (!ThemeEngine::themeConfigUseable(node, out.name)) return false; return true; diff --git a/gui/widget.cpp b/gui/widget.cpp index 1fcf7bc357..433c58dd58 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -34,13 +34,13 @@ namespace GUI { Widget::Widget(GuiObject *boss, int x, int y, int w, int h) : GuiObject(x, y, w, h), _type(0), _boss(boss), - _id(0), _flags(0), _hasFocus(false), _state(Theme::kStateEnabled) { + _id(0), _flags(0), _hasFocus(false), _state(ThemeEngine::kStateEnabled) { init(); } Widget::Widget(GuiObject *boss, const Common::String &name) : GuiObject(name), _type(0), _boss(boss), - _id(0), _flags(0), _hasFocus(false), _state(Theme::kStateDisabled) { + _id(0), _flags(0), _hasFocus(false), _state(ThemeEngine::kStateDisabled) { init(); } @@ -74,11 +74,11 @@ void Widget::clearFlags(int flags) { void Widget::updateState(int oldFlags, int newFlags) { if (newFlags & WIDGET_ENABLED) { - _state = Theme::kStateEnabled; + _state = ThemeEngine::kStateEnabled; if (newFlags & WIDGET_HILITED) - _state = Theme::kStateHighlight; + _state = ThemeEngine::kStateHighlight; } else { - _state = Theme::kStateDisabled; + _state = ThemeEngine::kStateDisabled; } } @@ -96,7 +96,7 @@ void Widget::draw() { // Draw border if (_flags & WIDGET_BORDER) { - gui->theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), 0, Theme::kWidgetBackgroundBorder); + gui->theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), 0, ThemeEngine::kWidgetBackgroundBorder); _x += 4; _y += 4; _w -= 8; @@ -386,7 +386,7 @@ ContainerWidget::ContainerWidget(GuiObject *boss, const Common::String &name) : } void ContainerWidget::drawWidget() { - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, Theme::kWidgetBackgroundBorder); + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, ThemeEngine::kWidgetBackgroundBorder); } } // End of namespace GUI diff --git a/gui/widget.h b/gui/widget.h index 705c232da9..f2a6bca751 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -94,7 +94,7 @@ protected: Widget *_next; uint16 _id; bool _hasFocus; - Theme::WidgetStateInfo _state; + ThemeEngine::WidgetStateInfo _state; private: uint16 _flags; |