2003-11-02 19:11:03 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2002-2005 The ScummVM project
|
2003-11-02 19:11:03 +00:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-11-02 19:11:03 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
#include "gui/TabWidget.h"
|
|
|
|
#include "gui/dialog.h"
|
|
|
|
#include "gui/newgui.h"
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2003-11-02 19:11:03 +00:00
|
|
|
enum {
|
2003-11-19 23:46:39 +00:00
|
|
|
kTabHeight = 16,
|
2005-05-17 06:19:42 +00:00
|
|
|
kBigTabHeight = 21,
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2003-11-02 19:11:03 +00:00
|
|
|
kTabLeftOffset = 4,
|
2003-11-03 00:18:33 +00:00
|
|
|
kTabSpacing = 2,
|
|
|
|
kTabPadding = 3
|
2003-11-02 19:11:03 +00:00
|
|
|
};
|
|
|
|
|
2005-05-17 06:19:42 +00:00
|
|
|
TabWidget::TabWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws)
|
|
|
|
: Widget(boss, x, y, w, h), _ws(ws) {
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2003-11-02 19:11:03 +00:00
|
|
|
_flags = WIDGET_ENABLED;
|
|
|
|
_type = kTabWidget;
|
|
|
|
_activeTab = -1;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2003-11-03 00:18:33 +00:00
|
|
|
_tabWidth = 40;
|
2005-05-17 06:19:42 +00:00
|
|
|
|
2005-06-03 12:00:38 +00:00
|
|
|
if (_ws == kBigWidgetSize) {
|
2005-05-17 06:19:42 +00:00
|
|
|
_tabHeight = kBigTabHeight;
|
2005-06-03 12:00:38 +00:00
|
|
|
} else {
|
2005-05-17 06:19:42 +00:00
|
|
|
_tabHeight = kTabHeight;
|
|
|
|
}
|
2003-11-02 22:31:20 +00:00
|
|
|
}
|
|
|
|
|
2003-11-07 14:50:32 +00:00
|
|
|
TabWidget::~TabWidget() {
|
2004-02-05 00:19:57 +00:00
|
|
|
for (uint i = 0; i < _tabs.size(); ++i) {
|
2003-11-07 14:50:32 +00:00
|
|
|
delete _tabs[i].firstWidget;
|
|
|
|
_tabs[i].firstWidget = 0;
|
|
|
|
}
|
|
|
|
_tabs.clear();
|
|
|
|
}
|
|
|
|
|
2003-11-02 22:31:20 +00:00
|
|
|
int16 TabWidget::getChildY() const {
|
2005-05-17 06:19:42 +00:00
|
|
|
return getAbsY() + _tabHeight;
|
2003-11-02 19:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int TabWidget::addTab(const String &title) {
|
2003-11-03 00:18:33 +00:00
|
|
|
// Add a new tab page
|
2003-11-03 14:55:36 +00:00
|
|
|
Tab newTab;
|
2005-05-17 06:19:42 +00:00
|
|
|
newTab.title = title;
|
|
|
|
newTab.firstWidget = 0;
|
2003-11-03 14:55:36 +00:00
|
|
|
|
2003-11-02 19:11:03 +00:00
|
|
|
_tabs.push_back(newTab);
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2003-11-03 00:18:33 +00:00
|
|
|
int numTabs = _tabs.size();
|
|
|
|
|
|
|
|
// Determine the new tab width
|
2005-06-03 12:00:38 +00:00
|
|
|
int newWidth = g_gui.getStringWidth(title) + 2 * kTabPadding;
|
2003-11-03 00:18:33 +00:00
|
|
|
if (_tabWidth < newWidth)
|
|
|
|
_tabWidth = newWidth;
|
|
|
|
int maxWidth = (_w - kTabLeftOffset) / numTabs - kTabLeftOffset;
|
|
|
|
if (_tabWidth > maxWidth)
|
|
|
|
_tabWidth = maxWidth;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2003-11-03 00:18:33 +00:00
|
|
|
// Activate the new tab
|
|
|
|
setActiveTab(numTabs - 1);
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2003-11-02 22:31:20 +00:00
|
|
|
return _activeTab;
|
2003-11-02 19:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::setActiveTab(int tabID) {
|
2004-02-05 00:19:57 +00:00
|
|
|
assert(0 <= tabID && tabID < (int)_tabs.size());
|
2003-11-02 19:11:03 +00:00
|
|
|
if (_activeTab != tabID) {
|
2003-11-02 22:31:20 +00:00
|
|
|
// Exchange the widget lists, and switch to the new tab
|
2005-04-04 17:57:40 +00:00
|
|
|
if (_activeTab != -1) {
|
2003-11-02 22:31:20 +00:00
|
|
|
_tabs[_activeTab].firstWidget = _firstWidget;
|
2005-04-04 17:57:40 +00:00
|
|
|
releaseFocus();
|
|
|
|
}
|
2003-11-02 19:11:03 +00:00
|
|
|
_activeTab = tabID;
|
|
|
|
_firstWidget = _tabs[tabID].firstWidget;
|
2003-11-02 22:31:20 +00:00
|
|
|
_boss->draw();
|
2003-11-02 19:11:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TabWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
2005-05-17 06:19:42 +00:00
|
|
|
assert(y < _tabHeight);
|
2003-11-02 19:11:03 +00:00
|
|
|
|
|
|
|
// Determine which tab was clicked
|
|
|
|
int tabID = -1;
|
|
|
|
x -= kTabLeftOffset;
|
|
|
|
if (x >= 0 && x % (_tabWidth + kTabSpacing) < _tabWidth) {
|
|
|
|
tabID = x / (_tabWidth + kTabSpacing);
|
2004-02-05 00:19:57 +00:00
|
|
|
if (tabID >= (int)_tabs.size())
|
2003-11-02 19:11:03 +00:00
|
|
|
tabID = -1;
|
|
|
|
}
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2003-11-02 19:11:03 +00:00
|
|
|
// If a tab was clicked, switch to that pane
|
|
|
|
if (tabID >= 0) {
|
|
|
|
setActiveTab(tabID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TabWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
|
|
|
|
// TODO: maybe there should be a way to switch between tabs
|
|
|
|
// using the keyboard? E.g. Alt-Shift-Left/Right-Arrow or something
|
|
|
|
// like that.
|
|
|
|
return Widget::handleKeyDown(ascii, keycode, modifiers);
|
|
|
|
}
|
|
|
|
|
2004-12-25 21:56:26 +00:00
|
|
|
static void box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB, bool omitBottom) {
|
|
|
|
NewGui &gui = g_gui;
|
|
|
|
|
|
|
|
gui.hLine(x + 1, y, x + width - 2, colorA);
|
|
|
|
gui.hLine(x, y + 1, x + width - 1, colorA);
|
|
|
|
gui.vLine(x, y + 1, y + height - (omitBottom ? 1 : 2), colorA);
|
|
|
|
gui.vLine(x + 1, y, y + height - (omitBottom ? 2 : 1), colorA);
|
|
|
|
|
|
|
|
if (!omitBottom) {
|
|
|
|
gui.hLine(x + 1, y + height - 2, x + width - 1, colorB);
|
|
|
|
gui.hLine(x + 1, y + height - 1, x + width - 2, colorB);
|
|
|
|
}
|
|
|
|
gui.vLine(x + width - 1, y + 1, y + height - (omitBottom ? 1 : 2), colorB);
|
|
|
|
gui.vLine(x + width - 2, y + 1, y + height - (omitBottom ? 2 : 1), colorB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-02 19:11:03 +00:00
|
|
|
void TabWidget::drawWidget(bool hilite) {
|
|
|
|
NewGui *gui = &g_gui;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-25 21:56:26 +00:00
|
|
|
const int left1 = _x + 1;
|
|
|
|
const int right1 = _x + kTabLeftOffset + _activeTab * (_tabWidth + kTabSpacing);
|
|
|
|
const int left2 = right1 + _tabWidth;
|
|
|
|
const int right2 = _x + _w - 2;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-11-02 19:11:03 +00:00
|
|
|
// Draw horizontal line
|
2005-05-17 06:19:42 +00:00
|
|
|
gui->hLine(left1, _y + _tabHeight - 2, right1, gui->_shadowcolor);
|
|
|
|
gui->hLine(left2, _y + _tabHeight - 2, right2, gui->_shadowcolor);
|
2003-11-02 19:11:03 +00:00
|
|
|
|
|
|
|
// Iterate over all tabs and draw them
|
|
|
|
int i, x = _x + kTabLeftOffset;
|
2004-02-05 00:19:57 +00:00
|
|
|
for (i = 0; i < (int)_tabs.size(); ++i) {
|
2004-02-28 12:58:13 +00:00
|
|
|
OverlayColor color = (i == _activeTab) ? gui->_color : gui->_shadowcolor;
|
2005-07-30 21:11:48 +00:00
|
|
|
int yOffset = (i == _activeTab) ? 0 : 2;
|
2005-05-17 06:19:42 +00:00
|
|
|
box(x, _y + yOffset, _tabWidth, _tabHeight - yOffset, color, color, (i == _activeTab));
|
2005-06-03 12:00:38 +00:00
|
|
|
gui->drawString(_tabs[i].title, x + kTabPadding, _y + yOffset / 2 + (_tabHeight - gui->getFontHeight() - 3), _tabWidth - 2 * kTabPadding, gui->_textcolor, kTextAlignCenter);
|
2003-11-02 19:11:03 +00:00
|
|
|
x += _tabWidth + kTabSpacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw more horizontal lines
|
2005-05-17 06:19:42 +00:00
|
|
|
gui->hLine(left1, _y + _tabHeight - 1, right1, gui->_color);
|
|
|
|
gui->hLine(left2, _y + _tabHeight - 1, right2, gui->_color);
|
2003-11-02 19:11:03 +00:00
|
|
|
gui->hLine(_x+1, _y + _h - 2, _x + _w - 2, gui->_shadowcolor);
|
|
|
|
gui->hLine(_x+1, _y + _h - 1, _x + _w - 2, gui->_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget *TabWidget::findWidget(int x, int y) {
|
2005-05-17 06:19:42 +00:00
|
|
|
if (y < _tabHeight) {
|
2003-11-02 19:11:03 +00:00
|
|
|
// Click was in the tab area
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
// Iterate over all child widgets and find the one which was clicked
|
2005-05-17 06:19:42 +00:00
|
|
|
return Widget::findWidgetInChain(_firstWidget, x, y - _tabHeight);
|
2003-11-02 19:11:03 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-10 23:40:48 +00:00
|
|
|
|
|
|
|
} // End of namespace GUI
|