2008-05-25 11:20:28 +00:00
|
|
|
/* 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 "graphics/surface.h"
|
|
|
|
#include "graphics/colormasks.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/events.h"
|
2008-06-25 22:30:28 +00:00
|
|
|
#include "common/config-manager.h"
|
2008-05-25 11:20:28 +00:00
|
|
|
|
2008-07-01 15:57:30 +00:00
|
|
|
#include "gui/launcher.h"
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
#include "gui/ThemeRenderer.h"
|
2008-05-25 11:20:28 +00:00
|
|
|
#include "graphics/VectorRenderer.h"
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
2008-05-28 15:03:30 +00:00
|
|
|
using namespace Graphics;
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
const char *ThemeRenderer::kDrawDataStrings[] = {
|
2008-06-24 19:48:01 +00:00
|
|
|
"mainmenu_bg",
|
|
|
|
"special_bg",
|
|
|
|
"plain_bg",
|
|
|
|
"default_bg",
|
|
|
|
|
|
|
|
"button_idle",
|
|
|
|
"button_hover",
|
2008-07-03 19:42:04 +00:00
|
|
|
"button_disabled",
|
2008-06-24 19:48:01 +00:00
|
|
|
|
|
|
|
"surface",
|
|
|
|
|
|
|
|
"slider_full",
|
|
|
|
"slider_empty",
|
|
|
|
|
|
|
|
"checkbox_enabled",
|
|
|
|
"checkbox_disabled",
|
|
|
|
|
|
|
|
"tab",
|
|
|
|
|
|
|
|
"scrollbar_base",
|
|
|
|
"scrollbar_top",
|
|
|
|
"scrollbar_bottom",
|
|
|
|
"scrollbar_handle",
|
|
|
|
|
|
|
|
"popup",
|
|
|
|
"caret",
|
|
|
|
"separator"
|
|
|
|
};
|
|
|
|
|
2008-07-03 10:26:55 +00:00
|
|
|
ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :
|
2008-06-09 21:16:26 +00:00
|
|
|
_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled),
|
2008-07-03 19:42:04 +00:00
|
|
|
_screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false), _enabled(false) {
|
2008-06-09 21:16:26 +00:00
|
|
|
_system = g_system;
|
2008-07-01 15:57:30 +00:00
|
|
|
_parser = new ThemeParser(this);
|
2008-06-09 21:16:26 +00:00
|
|
|
|
2008-06-24 19:48:01 +00:00
|
|
|
for (int i = 0; i < kDrawDataMAX; ++i) {
|
|
|
|
_widgets[i] = 0;
|
|
|
|
}
|
|
|
|
|
2008-07-03 10:26:55 +00:00
|
|
|
_graphicsMode = mode;
|
|
|
|
setGraphicsMode(_graphicsMode);
|
|
|
|
|
2008-07-03 19:42:04 +00:00
|
|
|
loadConfigFile("classic");
|
2008-07-03 10:26:55 +00:00
|
|
|
|
|
|
|
_initOk = true;
|
|
|
|
_themeName = themeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ThemeRenderer::init() {
|
|
|
|
// reset everything and reload the graphics
|
|
|
|
deinit();
|
|
|
|
setGraphicsMode(_graphicsMode);
|
|
|
|
|
|
|
|
if (_screen->pixels) {
|
|
|
|
_initOk = true;
|
|
|
|
clearAll();
|
|
|
|
resetDrawArea();
|
|
|
|
}
|
|
|
|
|
2008-07-03 19:42:04 +00:00
|
|
|
if (!_themeOk || isThemeLoadingRequired()) {
|
2008-07-03 10:26:55 +00:00
|
|
|
loadTheme(_themeName);
|
|
|
|
|
2008-07-03 19:42:04 +00:00
|
|
|
Theme::loadTheme(_defaultConfig);
|
|
|
|
Theme::loadTheme(_configFile, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_fontName.empty()) {
|
|
|
|
if (_screen->w >= 400 && _screen->h >= 300) {
|
|
|
|
_font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
|
|
|
|
} else {
|
|
|
|
_font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 10:26:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeRenderer::deinit() {
|
|
|
|
if (_initOk) {
|
|
|
|
_system->hideOverlay();
|
|
|
|
freeRenderer();
|
|
|
|
freeScreen();
|
|
|
|
_initOk = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeRenderer::clearAll() {
|
|
|
|
if (!_initOk)
|
|
|
|
return;
|
|
|
|
|
2008-07-03 19:42:04 +00:00
|
|
|
_system->clearOverlay();
|
|
|
|
_system->grabOverlay((OverlayColor*)_screen->pixels, _screen->w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeRenderer::enable() {
|
|
|
|
init();
|
|
|
|
resetDrawArea();
|
|
|
|
_system->showOverlay();
|
|
|
|
clearAll();
|
|
|
|
_enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeRenderer::disable() {
|
|
|
|
_system->hideOverlay();
|
|
|
|
_enabled = false;
|
2008-06-09 21:16:26 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 14:27:22 +00:00
|
|
|
template<typename PixelType>
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::screenInit() {
|
2008-05-28 14:27:22 +00:00
|
|
|
freeScreen();
|
|
|
|
|
2008-05-28 15:03:30 +00:00
|
|
|
_screen = new Surface;
|
2008-05-28 14:27:22 +00:00
|
|
|
_screen->create(_system->getOverlayWidth(), _system->getOverlayHeight(), sizeof(PixelType));
|
|
|
|
_system->clearOverlay();
|
|
|
|
}
|
|
|
|
|
2008-07-03 10:26:55 +00:00
|
|
|
void ThemeRenderer::setGraphicsMode(GraphicsMode mode) {
|
2008-05-28 14:27:22 +00:00
|
|
|
switch (mode) {
|
2008-05-28 15:03:30 +00:00
|
|
|
case kGfxStandard16bit:
|
|
|
|
case kGfxAntialias16bit:
|
2008-05-28 14:27:22 +00:00
|
|
|
_bytesPerPixel = sizeof(uint16);
|
|
|
|
screenInit<uint16>();
|
|
|
|
break;
|
2008-05-28 14:30:51 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2008-05-28 14:27:22 +00:00
|
|
|
}
|
|
|
|
|
2008-06-10 11:25:00 +00:00
|
|
|
freeRenderer();
|
2008-05-28 15:03:30 +00:00
|
|
|
_vectorRenderer = createRenderer(mode);
|
2008-05-28 14:27:22 +00:00
|
|
|
_vectorRenderer->setSurface(_screen);
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::addDrawStep(Common::String &drawDataId, Graphics::DrawStep *step) {
|
2008-06-24 19:48:01 +00:00
|
|
|
DrawData id = getDrawDataId(drawDataId);
|
|
|
|
|
|
|
|
assert(_widgets[id] != 0);
|
|
|
|
_widgets[id]->_steps.push_back(step);
|
2008-06-18 00:15:21 +00:00
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
bool ThemeRenderer::addDrawData(DrawData data_id, bool cached) {
|
2008-06-24 19:48:01 +00:00
|
|
|
assert(data_id >= 0 && data_id < kDrawDataMAX);
|
|
|
|
|
|
|
|
if (_widgets[data_id] != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_widgets[data_id] = new WidgetDrawData;
|
|
|
|
_widgets[data_id]->_cached = cached;
|
2008-07-03 10:26:55 +00:00
|
|
|
_widgets[data_id]->_surfaceCache = 0;
|
2008-06-24 19:48:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2008-06-18 00:15:21 +00:00
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
bool ThemeRenderer::loadTheme(Common::String themeName) {
|
2008-06-29 12:08:53 +00:00
|
|
|
unloadTheme();
|
|
|
|
|
2008-06-25 22:30:28 +00:00
|
|
|
if (!loadThemeXML(themeName)) {
|
2008-06-26 13:50:16 +00:00
|
|
|
warning("Could not parse custom theme '%s'.\nFalling back to default theme", themeName.c_str());
|
|
|
|
|
|
|
|
if (!loadDefaultXML()) // if we can't load the embeded theme, this is a complete failure
|
2008-06-28 00:02:54 +00:00
|
|
|
error("Could not load default embeded theme");
|
2008-06-25 22:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < kDrawDataMAX; ++i) {
|
|
|
|
if (_widgets[i] == 0) {
|
|
|
|
#ifdef REQUIRE_ALL_DD_SETS
|
|
|
|
warning("Error when parsing custom theme '%s': Missing data assets.", themeName.c_str());
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
} else if (_widgets[i]->_cached) {
|
|
|
|
// draw the cached widget to the cache surface
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_themeOk = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
bool ThemeRenderer::loadThemeXML(Common::String themeName) {
|
2008-06-25 22:30:28 +00:00
|
|
|
assert(_parser);
|
|
|
|
|
|
|
|
if (ConfMan.hasKey("themepath"))
|
|
|
|
Common::File::addDefaultDirectory(ConfMan.get("themepath"));
|
|
|
|
|
|
|
|
#ifdef DATA_PATH
|
|
|
|
Common::File::addDefaultDirectoryRecursive(DATA_PATH);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ConfMan.hasKey("extrapath"))
|
|
|
|
Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
|
|
|
|
|
|
|
|
if (!parser()->loadFile(themeName + ".xml"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return parser()->parse();
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
bool ThemeRenderer::isWidgetCached(DrawData type, const Common::Rect &r) {
|
2008-06-12 11:26:11 +00:00
|
|
|
return _widgets[type] && _widgets[type]->_cached &&
|
|
|
|
_widgets[type]->_surfaceCache->w == r.width() &&
|
|
|
|
_widgets[type]->_surfaceCache->h == r.height();
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::drawCached(DrawData type, const Common::Rect &r) {
|
2008-06-12 11:26:11 +00:00
|
|
|
assert(_widgets[type]->_surfaceCache->bytesPerPixel == _screen->bytesPerPixel);
|
|
|
|
_vectorRenderer->blitSurface(_widgets[type]->_surfaceCache, r);
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::drawDD(DrawData type, const Common::Rect &r) {
|
2008-06-12 11:26:11 +00:00
|
|
|
if (isWidgetCached(type, r)) {
|
|
|
|
drawCached(type, r);
|
2008-07-03 19:42:04 +00:00
|
|
|
} else if (_widgets[type] != 0) {
|
2008-06-18 00:15:21 +00:00
|
|
|
for (uint i = 0; i < _widgets[type]->_steps.size(); ++i)
|
2008-06-13 17:47:56 +00:00
|
|
|
_vectorRenderer->drawStep(r, *_widgets[type]->_steps[i]);
|
2008-06-12 11:26:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints) {
|
2008-06-28 16:49:39 +00:00
|
|
|
if (!ready())
|
2008-06-12 11:26:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (state == kStateEnabled)
|
|
|
|
drawDD(kDDButtonIdle, r);
|
|
|
|
else if (state == kStateHighlight)
|
|
|
|
drawDD(kDDButtonHover, r);
|
2008-07-03 19:42:04 +00:00
|
|
|
else if (state == kStateDisabled)
|
|
|
|
drawDD(kDDButtonDisabled, r);
|
2008-06-12 11:26:11 +00:00
|
|
|
|
|
|
|
// TODO: Add text drawing.
|
|
|
|
|
|
|
|
addDirtyRect(r);
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::drawLineSeparator(const Common::Rect &r, WidgetStateInfo state) {
|
2008-06-28 16:49:39 +00:00
|
|
|
if (!ready())
|
2008-06-12 11:26:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
drawDD(kDDSeparator, r);
|
|
|
|
addDirtyRect(r);
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state) {
|
2008-06-28 16:49:39 +00:00
|
|
|
if (!ready())
|
2008-06-12 19:06:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
drawDD(checked ? kDDCheckboxEnabled : kDDCheckboxDisabled, r);
|
|
|
|
|
|
|
|
Common::Rect r2 = r;
|
|
|
|
r2.left += 16; // TODO: add variable for checkbox text offset.
|
|
|
|
|
|
|
|
// TODO: text drawing
|
|
|
|
// getFont()->drawString(&_screen, str, r2.left, r2.top, r2.width(), getColor(state), Graphics::kTextAlignLeft, 0, false);
|
|
|
|
|
|
|
|
addDirtyRect(r);
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::drawSlider(const Common::Rect &r, int width, WidgetStateInfo state) {
|
2008-06-28 16:49:39 +00:00
|
|
|
if (!ready())
|
2008-06-12 19:06:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
drawDD(kDDSliderEmpty, r);
|
|
|
|
|
|
|
|
Common::Rect r2 = r;
|
|
|
|
r2.setWidth(MIN((int16)width, r.width()));
|
|
|
|
|
|
|
|
drawDD(kDDSliderFull, r2);
|
|
|
|
|
|
|
|
addDirtyRect(r);
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState sb_state, WidgetStateInfo state) {
|
2008-06-28 16:49:39 +00:00
|
|
|
if (!ready())
|
2008-06-12 19:06:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-03 19:42:04 +00:00
|
|
|
void ThemeRenderer::updateScreen() {
|
|
|
|
// renderDirtyScreen();
|
|
|
|
_vectorRenderer->copyWholeFrame(_system);
|
|
|
|
}
|
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
void ThemeRenderer::renderDirtyScreen() {
|
|
|
|
// TODO: This isn't really optimized. Check dirty squares for collisions
|
|
|
|
// and all that.
|
|
|
|
if (_dirtyScreen.empty())
|
|
|
|
return;
|
2008-06-28 16:49:39 +00:00
|
|
|
|
2008-07-02 18:11:41 +00:00
|
|
|
for (uint i = 0; i < _dirtyScreen.size(); ++i)
|
|
|
|
_vectorRenderer->copyFrame(_system, _dirtyScreen[i]);
|
2008-05-28 14:27:22 +00:00
|
|
|
|
2008-07-03 19:42:04 +00:00
|
|
|
// _system->updateScreen();
|
2008-07-02 18:11:41 +00:00
|
|
|
_dirtyScreen.clear();
|
2008-05-28 14:27:22 +00:00
|
|
|
}
|
|
|
|
|
2008-05-25 17:06:10 +00:00
|
|
|
} // end of namespace GUI.
|