[Scummvm-cvs-logs] CVS: scummvm/gui TabWidget.cpp,NONE,1.1 TabWidget.h,NONE,1.1 launcher.cpp,1.63,1.64 module.mk,1.7,1.8
Max Horn
fingolfin at users.sourceforge.net
Sun Nov 2 11:12:01 CET 2003
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/gui widget.cpp,1.20,1.21 widget.h,1.24,1.25 dialog.cpp,1.34,1.35 newgui.h,1.30,1.31 newgui.cpp,1.63,1.64
- Next message: [Scummvm-cvs-logs] CVS: scummvm/queen defs.h,1.22,1.23 input.cpp,1.7,1.8 input.h,1.5,1.6 queen.cpp,1.27,1.28
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv2444
Modified Files:
launcher.cpp module.mk
Added Files:
TabWidget.cpp TabWidget.h
Log Message:
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
--- NEW FILE: TabWidget.cpp ---
/* 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: /cvsroot/scummvm/scummvm/gui/TabWidget.cpp,v 1.1 2003/11/02 19:11:03 fingolfin Exp $
*/
#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);
}
}
--- NEW FILE: TabWidget.h ---
/* 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: /cvsroot/scummvm/scummvm/gui/TabWidget.h,v 1.1 2003/11/02 19:11:03 fingolfin Exp $
*/
#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
Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- launcher.cpp 2 Nov 2003 11:32:18 -0000 1.63
+++ launcher.cpp 2 Nov 2003 19:11:03 -0000 1.64
@@ -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 @@
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);
Index: module.mk
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/module.mk,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- module.mk 17 Sep 2003 21:53:11 -0000 1.7
+++ module.mk 2 Nov 2003 19:11:03 -0000 1.8
@@ -14,6 +14,7 @@
gui/options.o \
gui/PopUpWidget.o \
gui/ScrollBarWidget.o \
+ gui/TabWidget.o \
gui/widget.o \
MODULE_DIRS += \
- Previous message: [Scummvm-cvs-logs] CVS: scummvm/gui widget.cpp,1.20,1.21 widget.h,1.24,1.25 dialog.cpp,1.34,1.35 newgui.h,1.30,1.31 newgui.cpp,1.63,1.64
- Next message: [Scummvm-cvs-logs] CVS: scummvm/queen defs.h,1.22,1.23 input.cpp,1.7,1.8 input.h,1.5,1.6 queen.cpp,1.27,1.28
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list