scummvm/backends/platform/wince/CEgui/ToolbarHandler.cpp

126 lines
2.9 KiB
C++
Raw Normal View History

/* 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.
*
*/
#include "backends/platform/sdl/sdl-sys.h"
#include "ToolbarHandler.h"
namespace CEGUI {
2010-10-31 17:11:43 +00:00
ToolbarHandler::ToolbarHandler():
_current(""), _active(NULL) {
2010-10-31 17:11:43 +00:00
}
2010-10-31 17:11:43 +00:00
bool ToolbarHandler::add(const String &name, const Toolbar &toolbar) {
_toolbarMap[name] = (Toolbar *)&toolbar;
2010-10-31 17:11:43 +00:00
if (!_active) {
_active = &((Toolbar &)toolbar);
2010-10-31 17:11:43 +00:00
_current = name;
}
2010-10-31 17:11:43 +00:00
return true;
}
2010-10-31 17:11:43 +00:00
String ToolbarHandler::activeName() {
return _current;
}
bool ToolbarHandler::setActive(const String &name) {
if (!_toolbarMap.contains(name))
return false;
if (_current == name)
return true;
_active->action(0, 0, false); // make sure any items are unpushed when changing toolbars (e.g. forced VK->main panel)
2010-10-31 17:11:43 +00:00
_current = name;
_active = _toolbarMap[name];
_active->forceRedraw();
return true;
}
2010-10-31 17:11:43 +00:00
bool ToolbarHandler::action(int x, int y, bool pushed) {
if (_active && _active->visible()) {
// FIXME !
if (_offset > 240)
return _active->action(x / 2, (y - _offset) / 2, pushed);
else
2010-10-31 17:11:43 +00:00
return _active->action(x, y - _offset, pushed);
} else
2010-10-31 17:11:43 +00:00
return false;
}
2010-10-31 17:11:43 +00:00
void ToolbarHandler::setVisible(bool visible) {
if (_active)
_active->setVisible(visible);
}
2010-10-31 17:11:43 +00:00
bool ToolbarHandler::visible() {
if (_active)
return _active->visible();
else
return false;
}
2010-10-31 17:11:43 +00:00
void ToolbarHandler::forceRedraw() {
if (_active)
_active->forceRedraw();
}
2010-10-31 17:11:43 +00:00
bool ToolbarHandler::drawn() {
if (_active)
return _active->drawn();
else
return false;
}
2010-10-31 17:11:43 +00:00
bool ToolbarHandler::draw(SDL_Surface *surface, SDL_Rect *rect) {
if (_active) {
bool result = _active->draw(surface);
if (result) {
rect->x = _active->getX();
rect->y = _active->getY();
rect->w = _active->getWidth();
rect->h = _active->getHeight();
}
2010-10-31 17:11:43 +00:00
return result;
} else
return false;
}
2010-10-31 17:11:43 +00:00
void ToolbarHandler::setOffset(int offset) {
_offset = offset;
}
2010-10-31 17:11:43 +00:00
int ToolbarHandler::getOffset() {
return _offset;
}
Toolbar *ToolbarHandler::active() {
2010-10-31 17:11:43 +00:00
return _active;
}
2010-10-31 17:11:43 +00:00
ToolbarHandler::~ToolbarHandler() {
_toolbarMap.clear();
2005-06-24 16:08:31 +00:00
}
2010-10-31 17:11:43 +00:00
} // End of namespace CEGUI