diff options
| author | Max Horn | 2003-11-02 19:11:03 +0000 | 
|---|---|---|
| committer | Max Horn | 2003-11-02 19:11:03 +0000 | 
| commit | af19319a246100cf1164538589389258f8409d43 (patch) | |
| tree | 72d78a570e17d5253264f1c2066bd59f75822835 /gui | |
| parent | ac4b9ccdb8f0d0491c80ec026d8ed510f729cabf (diff) | |
| download | scummvm-rg350-af19319a246100cf1164538589389258f8409d43.tar.gz scummvm-rg350-af19319a246100cf1164538589389258f8409d43.tar.bz2 scummvm-rg350-af19319a246100cf1164538589389258f8409d43.zip  | |
added initial TabWidget stub (if you want to try it, I added some testing code to launcher.cpp which you just have to un-#if). This is not yet finished, obviously, but enough to 'get the idea', I hope
svn-id: r11062
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/TabWidget.cpp | 131 | ||||
| -rw-r--r-- | gui/TabWidget.h | 66 | ||||
| -rw-r--r-- | gui/launcher.cpp | 7 | ||||
| -rw-r--r-- | gui/module.mk | 1 | 
4 files changed, 205 insertions, 0 deletions
diff --git a/gui/TabWidget.cpp b/gui/TabWidget.cpp new file mode 100644 index 0000000000..4b29bd2d7b --- /dev/null +++ b/gui/TabWidget.cpp @@ -0,0 +1,131 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2002-2003 The ScummVM project + * + * 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$ + */ + +#include "stdafx.h" +#include "common/util.h" +#include "gui/TabWidget.h" +#include "gui/dialog.h" +#include "gui/newgui.h" + +enum { +	kTabHeight = 14, +	 +	kTabLeftOffset = 4, +	kTabSpacing = 2 +}; + +TabWidget::TabWidget(GuiObject *boss, int x, int y, int w, int h) +	: Widget(boss, x, y, w, h) { +	 +	_flags = WIDGET_ENABLED; +	_type = kTabWidget; +	_activeTab = -1; +	 +	_tabWidth = 50; +	 +	// TODO: Dummy for now +	addTab("Tab 1"); +	addTab("Tab 2"); +	addTab("Tab 3"); +	setActiveTab(1); +} + +int TabWidget::addTab(const String &title) { +	// TODO +	Tab newTab = { title, NULL }; +	_tabs.push_back(newTab); +	return _tabs.size() - 1; +} + +/* +void TabWidget::removeTab(int tabID) { +	// TODO +} +*/ + +void TabWidget::setActiveTab(int tabID) { +	assert(0 <= tabID && tabID < _tabs.size()); +	if (_activeTab != tabID) { +		_activeTab = tabID; +		_firstWidget = _tabs[tabID].firstWidget; +		draw(); +	} +} + + +void TabWidget::handleMouseDown(int x, int y, int button, int clickCount) { +	assert(y < kTabHeight); + +	// Determine which tab was clicked +	int tabID = -1; +	x -= kTabLeftOffset; +	if (x >= 0 && x % (_tabWidth + kTabSpacing) < _tabWidth) { +		tabID = x / (_tabWidth + kTabSpacing); +		if (tabID >= _tabs.size()) +			tabID = -1; +	} +	 +	// 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); +} + + +void TabWidget::drawWidget(bool hilite) { +	// TODO + +	NewGui *gui = &g_gui; +	 +	// Draw horizontal line +	gui->hLine(_x+1, _y + kTabHeight - 2, _x + _w - 2, gui->_shadowcolor); + +	// Iterate over all tabs and draw them +	int i, x = _x + kTabLeftOffset; +	for (i = 0; i < _tabs.size(); ++i) { +		NewGuiColor color = (i == _activeTab) ? gui->_color : gui->_shadowcolor; +		gui->box(x, _y, _tabWidth, kTabHeight, color, color); +		gui->drawString(_tabs[i].title, x, _y + 4, _tabWidth, gui->_textcolor, kTextAlignCenter); +		x += _tabWidth + kTabSpacing; +	} + +	// Draw more horizontal lines +	gui->hLine(_x+1, _y + kTabHeight - 1, _x + _w - 2, gui->_color); +	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) { +	if (y < kTabHeight) { +		// Click was in the tab area +		return this; +	} else { +		// Iterate over all child widgets and find the one which was clicked +		return Widget::findWidgetInChain(_firstWidget, x, y); +	} +} diff --git a/gui/TabWidget.h b/gui/TabWidget.h new file mode 100644 index 0000000000..76165e5b1b --- /dev/null +++ b/gui/TabWidget.h @@ -0,0 +1,66 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2002-2003 The ScummVM project + * + * 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$ + */ + +#ifndef TABWIDGET_H +#define TABWIDGET_H + +#include "widget.h" +#include "common/str.h" +#include "common/list.h" + +class TabWidget : public Widget { +	typedef Common::String String; +	struct Tab { +		String title; +		Widget *firstWidget; +	}; +	typedef Common::List<Tab> TabList; +protected: +	int _activeTab; +	TabList _tabs; +	int _tabWidth; + +public: +	TabWidget(GuiObject *boss, int x, int y, int w, int h); +	 +// use Dialog::releaseFocus() when changing to another tab + +// Problem: how to add items to a tab? +// First off, widget should allow non-dialog bosses, (i.e. also other widgets) +// Could add a common base class for Widgets and Dialogs. +// Then you add tabs using the following method, which returns a unique ID +	int addTab(const String &title); +// Maybe we need to remove tabs again? Hm +	//void removeTab(int tabID); +// Setting the active tab: +	void setActiveTab(int tabID); +// setActiveTab changes the value of _firstWidget. This means Widgets added afterwards +// will be added to the active tab. + +	virtual void handleMouseDown(int x, int y, int button, int clickCount); +	virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers); + +protected: +	virtual void drawWidget(bool hilite); + +	virtual Widget *findWidget(int x, int y); +}; + +#endif diff --git a/gui/launcher.cpp b/gui/launcher.cpp index ead4891d25..18b0e8a000 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -29,6 +29,7 @@  #include "gui/options.h"  #include "gui/EditTextWidget.h"  #include "gui/ListWidget.h" +#include "gui/TabWidget.h"  #include "backends/fs/fs.h" @@ -174,7 +175,13 @@ LauncherDialog::LauncherDialog(GameDetector &detector)  	new ButtonWidget(this, x, _h - 24, width, 16, "Start", kStartCmd, 'S'); x += space + width;  	// Add list with game titles +#if 0 +	// HACK HACK HACK FIXME +	new TabWidget(this, 0, 76, 320, 64); +	_list = new ListWidget(this, 10, 28, 300, 46); +#else  	_list = new ListWidget(this, 10, 28, 300, 112); +#endif  	_list->setEditable(false);  	_list->setNumberingMode(kListNumberingOff); diff --git a/gui/module.mk b/gui/module.mk index e04af24355..097deb8e93 100644 --- a/gui/module.mk +++ b/gui/module.mk @@ -14,6 +14,7 @@ MODULE_OBJS := \  	gui/options.o \  	gui/PopUpWidget.o \  	gui/ScrollBarWidget.o \ +	gui/TabWidget.o \  	gui/widget.o \  MODULE_DIRS += \  | 
