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
|
|
|
|
|
|
|
#include "gui/InterfaceManager.h"
|
|
|
|
#include "graphics/VectorRenderer.h"
|
|
|
|
|
2008-06-09 21:16:26 +00:00
|
|
|
DECLARE_SINGLETON(GUI::InterfaceManager);
|
|
|
|
|
2008-05-25 11:20:28 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2008-05-28 15:03:30 +00:00
|
|
|
using namespace Graphics;
|
|
|
|
|
2008-06-24 19:48:01 +00:00
|
|
|
const char *InterfaceManager::kDrawDataStrings[] = {
|
|
|
|
"mainmenu_bg",
|
|
|
|
"special_bg",
|
|
|
|
"plain_bg",
|
|
|
|
"default_bg",
|
|
|
|
|
|
|
|
"button_idle",
|
|
|
|
"button_hover",
|
|
|
|
|
|
|
|
"surface",
|
|
|
|
|
|
|
|
"slider_full",
|
|
|
|
"slider_empty",
|
|
|
|
|
|
|
|
"checkbox_enabled",
|
|
|
|
"checkbox_disabled",
|
|
|
|
|
|
|
|
"tab",
|
|
|
|
|
|
|
|
"scrollbar_base",
|
|
|
|
"scrollbar_top",
|
|
|
|
"scrollbar_bottom",
|
|
|
|
"scrollbar_handle",
|
|
|
|
|
|
|
|
"popup",
|
|
|
|
"caret",
|
|
|
|
"separator"
|
|
|
|
};
|
|
|
|
|
2008-06-09 21:16:26 +00:00
|
|
|
InterfaceManager::InterfaceManager() :
|
|
|
|
_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled),
|
2008-06-25 22:30:28 +00:00
|
|
|
_screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false) {
|
2008-06-09 21:16:26 +00:00
|
|
|
_system = g_system;
|
2008-06-25 22:30:28 +00:00
|
|
|
_parser = new ThemeParser();
|
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-06-09 21:16:26 +00:00
|
|
|
setGraphicsMode(kGfxStandard16bit);
|
|
|
|
}
|
|
|
|
|
2008-05-28 14:27:22 +00:00
|
|
|
template<typename PixelType>
|
|
|
|
void InterfaceManager::screenInit() {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceManager::setGraphicsMode(Graphics_Mode mode) {
|
|
|
|
if (mode == _graphicsMode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_graphicsMode = mode;
|
|
|
|
|
|
|
|
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-06-18 00:15:21 +00:00
|
|
|
void InterfaceManager::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-06-24 19:48:01 +00:00
|
|
|
bool InterfaceManager::addDrawData(DrawData data_id, bool cached) {
|
|
|
|
assert(data_id >= 0 && data_id < kDrawDataMAX);
|
|
|
|
|
|
|
|
if (_widgets[data_id] != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_widgets[data_id] = new WidgetDrawData;
|
|
|
|
_widgets[data_id]->_cached = cached;
|
|
|
|
_widgets[data_id]->_type = data_id;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2008-06-18 00:15:21 +00:00
|
|
|
|
2008-06-25 22:30:28 +00:00
|
|
|
bool InterfaceManager::loadTheme(Common::String &themeName) {
|
|
|
|
if (!loadThemeXML(themeName)) {
|
|
|
|
warning("Could not parse custom theme '%s'.", themeName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InterfaceManager::loadThemeXML(Common::String &themeName) {
|
|
|
|
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-06-09 21:16:26 +00:00
|
|
|
bool InterfaceManager::init() {
|
|
|
|
return false;
|
2008-06-07 20:50:39 +00:00
|
|
|
}
|
|
|
|
|
2008-06-12 11:26:11 +00:00
|
|
|
bool InterfaceManager::isWidgetCached(DrawData type, const Common::Rect &r) {
|
|
|
|
return _widgets[type] && _widgets[type]->_cached &&
|
|
|
|
_widgets[type]->_surfaceCache->w == r.width() &&
|
|
|
|
_widgets[type]->_surfaceCache->h == r.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceManager::drawCached(DrawData type, const Common::Rect &r) {
|
|
|
|
assert(_widgets[type]->_surfaceCache->bytesPerPixel == _screen->bytesPerPixel);
|
|
|
|
_vectorRenderer->blitSurface(_widgets[type]->_surfaceCache, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceManager::drawDD(DrawData type, const Common::Rect &r) {
|
|
|
|
if (isWidgetCached(type, r)) {
|
|
|
|
drawCached(type, r);
|
|
|
|
} else {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceManager::drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints) {
|
|
|
|
if (!_initOk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (state == kStateEnabled)
|
|
|
|
drawDD(kDDButtonIdle, r);
|
|
|
|
else if (state == kStateHighlight)
|
|
|
|
drawDD(kDDButtonHover, r);
|
|
|
|
|
|
|
|
// TODO: Add text drawing.
|
|
|
|
|
|
|
|
addDirtyRect(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceManager::drawLineSeparator(const Common::Rect &r, WidgetStateInfo state) {
|
|
|
|
if (!_initOk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drawDD(kDDSeparator, r);
|
|
|
|
addDirtyRect(r);
|
|
|
|
}
|
|
|
|
|
2008-06-12 19:06:37 +00:00
|
|
|
void InterfaceManager::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state) {
|
|
|
|
if (!_initOk)
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceManager::drawSlider(const Common::Rect &r, int width, WidgetStateInfo state) {
|
|
|
|
if (!_initOk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drawDD(kDDSliderEmpty, r);
|
|
|
|
|
|
|
|
Common::Rect r2 = r;
|
|
|
|
r2.setWidth(MIN((int16)width, r.width()));
|
|
|
|
|
|
|
|
drawDD(kDDSliderFull, r2);
|
|
|
|
|
|
|
|
addDirtyRect(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceManager::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState sb_state, WidgetStateInfo state) {
|
|
|
|
if (!_initOk)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-28 14:27:22 +00:00
|
|
|
int InterfaceManager::runGUI() {
|
|
|
|
Common::EventManager *eventMan = _system->getEventManager();
|
|
|
|
_system->showOverlay();
|
|
|
|
|
|
|
|
Graphics::DrawStep *steps = new Graphics::DrawStep[5];
|
|
|
|
|
2008-06-16 23:38:21 +00:00
|
|
|
steps[0].gradColor1.r = 214;
|
|
|
|
steps[0].gradColor1.g = 113;
|
|
|
|
steps[0].gradColor1.b = 8;
|
|
|
|
steps[0].gradColor2.r = 240;
|
|
|
|
steps[0].gradColor2.g = 200;
|
|
|
|
steps[0].gradColor2.b = 25;
|
|
|
|
steps[0].fillMode = VectorRenderer::kFillGradient;
|
|
|
|
steps[0].drawingCall = &VectorRenderer::drawCallback_FILLSURFACE;
|
2008-05-28 14:27:22 +00:00
|
|
|
|
2008-06-16 23:38:21 +00:00
|
|
|
steps[1].gradColor1.r = 206;
|
|
|
|
steps[1].gradColor1.g = 121;
|
|
|
|
steps[1].gradColor1.b = 99;
|
|
|
|
steps[1].gradColor2.r = 173;
|
|
|
|
steps[1].gradColor2.g = 40;
|
|
|
|
steps[1].gradColor2.b = 8;
|
2008-06-10 19:57:38 +00:00
|
|
|
steps[1].radius = 8; // radius
|
2008-06-16 23:38:21 +00:00
|
|
|
steps[1].fillArea = true;
|
|
|
|
steps[1].drawingCall = &VectorRenderer::drawCallback_ROUNDSQ;
|
2008-06-10 19:57:38 +00:00
|
|
|
steps[1].scale = (1 << 16);
|
|
|
|
|
|
|
|
steps[2].radius = 8; // radius
|
2008-06-16 23:38:21 +00:00
|
|
|
steps[2].fillArea = false;
|
2008-06-10 19:57:38 +00:00
|
|
|
steps[2].x.relative = true;
|
|
|
|
steps[2].x.pos = 32;
|
|
|
|
steps[2].y.relative = false;
|
|
|
|
steps[2].y.pos = 32;
|
|
|
|
steps[2].w = 128;
|
|
|
|
steps[2].h = 32;
|
2008-06-16 23:38:21 +00:00
|
|
|
steps[2].drawingCall = &VectorRenderer::drawCallback_ROUNDSQ;
|
2008-06-10 19:57:38 +00:00
|
|
|
steps[2].scale = (1 << 16);
|
2008-05-28 14:27:22 +00:00
|
|
|
|
2008-06-16 23:38:21 +00:00
|
|
|
steps[3].fgColor.r = 255;
|
|
|
|
steps[3].fgColor.g = 255;
|
|
|
|
steps[3].fgColor.b = 255;
|
2008-06-18 00:15:21 +00:00
|
|
|
steps[3].drawingCall = &VectorRenderer::drawCallback_VOID;
|
2008-05-28 14:27:22 +00:00
|
|
|
|
2008-06-10 19:57:38 +00:00
|
|
|
Common::Rect area = Common::Rect(32, 32, 256, 256);
|
|
|
|
|
2008-05-28 14:27:22 +00:00
|
|
|
bool running = true;
|
|
|
|
while (running) { // draw!!
|
|
|
|
|
2008-06-13 17:47:56 +00:00
|
|
|
_vectorRenderer->drawStep(Common::Rect(), steps[0]);
|
2008-06-14 17:45:26 +00:00
|
|
|
_vectorRenderer->drawStep(Common::Rect(), steps[3]);
|
2008-06-13 17:47:56 +00:00
|
|
|
_vectorRenderer->drawStep(area, steps[1]);
|
|
|
|
_vectorRenderer->drawStep(area, steps[2]);
|
2008-06-10 11:25:00 +00:00
|
|
|
// _vectorRenderer->drawStep(Common::Rect(32, 32, 256, 256), &steps[3]);
|
2008-06-07 20:50:39 +00:00
|
|
|
|
2008-05-28 14:27:22 +00:00
|
|
|
_vectorRenderer->copyFrame(_system);
|
|
|
|
|
|
|
|
Common::Event event;
|
|
|
|
_system->delayMillis(100);
|
|
|
|
while (eventMan->pollEvent(event)) {
|
|
|
|
if (event.type == Common::EVENT_QUIT)
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_system->hideOverlay();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-25 11:20:28 +00:00
|
|
|
|
|
|
|
|
2008-05-25 17:06:10 +00:00
|
|
|
} // end of namespace GUI.
|