[Scummvm-cvs-logs] CVS: scummvm/gui TabWidget.cpp,1.1,1.2 TabWidget.h,1.1,1.2 dialog.cpp,1.35,1.36 object.h,1.2,1.3 widget.cpp,1.21,1.22 widget.h,1.25,1.26

Max Horn fingolfin at users.sourceforge.net
Sun Nov 2 14:32:09 CET 2003


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv10751

Modified Files:
	TabWidget.cpp TabWidget.h dialog.cpp object.h widget.cpp 
	widget.h 
Log Message:
more changes to allow widget nesting to fully work

Index: TabWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/TabWidget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TabWidget.cpp	2 Nov 2003 19:11:03 -0000	1.1
+++ TabWidget.cpp	2 Nov 2003 22:31:19 -0000	1.2
@@ -42,16 +42,23 @@
 	
 	// TODO: Dummy for now
 	addTab("Tab 1");
+	new ButtonWidget(this, 10, 20, kButtonWidth, 16, "Foo", 0, 0);
 	addTab("Tab 2");
+	new ButtonWidget(this, 20, 30, kButtonWidth, 16, "Bar", 0, 0);
 	addTab("Tab 3");
-	setActiveTab(1);
+	new PushButtonWidget(this, 30, 10, kButtonWidth, 16, "Qux", 0, 0);
+}
+
+int16 TabWidget::getChildY() const {
+	return getAbsY() + kTabHeight;
 }
 
 int TabWidget::addTab(const String &title) {
 	// TODO
 	Tab newTab = { title, NULL };
 	_tabs.push_back(newTab);
-	return _tabs.size() - 1;
+	setActiveTab(_tabs.size() - 1);
+	return _activeTab;
 }
 
 /*
@@ -63,9 +70,12 @@
 void TabWidget::setActiveTab(int tabID) {
 	assert(0 <= tabID && tabID < _tabs.size());
 	if (_activeTab != tabID) {
+		// Exchange the widget lists, and switch to the new tab
+		if (_activeTab != -1)
+			_tabs[_activeTab].firstWidget = _firstWidget;
 		_activeTab = tabID;
 		_firstWidget = _tabs[tabID].firstWidget;
-		draw();
+		_boss->draw();
 	}
 }
 
@@ -95,7 +105,6 @@
 	return Widget::handleKeyDown(ascii, keycode, modifiers);
 }
 
-
 void TabWidget::drawWidget(bool hilite) {
 	// TODO
 
@@ -126,6 +135,6 @@
 		return this;
 	} else {
 		// Iterate over all child widgets and find the one which was clicked
-		return Widget::findWidgetInChain(_firstWidget, x, y);
+		return Widget::findWidgetInChain(_firstWidget, x, y - kTabHeight);
 	}
 }

Index: TabWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/TabWidget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TabWidget.h	2 Nov 2003 19:11:03 -0000	1.1
+++ TabWidget.h	2 Nov 2003 22:31:19 -0000	1.2
@@ -40,6 +40,8 @@
 public:
 	TabWidget(GuiObject *boss, int x, int y, int w, int h);
 	
+	virtual int16	getChildY() const;
+
 // use Dialog::releaseFocus() when changing to another tab
 
 // Problem: how to add items to a tab?

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- dialog.cpp	2 Nov 2003 18:57:20 -0000	1.35
+++ dialog.cpp	2 Nov 2003 22:31:19 -0000	1.36
@@ -97,7 +97,6 @@
 }
 
 void Dialog::drawDialog() {
-	Widget *w = _firstWidget;
 	
 	if (!isVisible())
 		return;
@@ -105,11 +104,14 @@
 	g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor);
 	g_gui.box(_x, _y, _w, _h, g_gui._color, g_gui._shadowcolor);
 
+	// Draw all children
+	Widget *w = _firstWidget;
 	while (w) {
 		w->draw();
 		w = w->_next;
 	}
 
+	// Flag the draw area as dirty
 	g_gui.addDirtyRect(_x, _y, _w, _h);
 }
 

Index: object.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/object.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- object.h	2 Nov 2003 17:41:01 -0000	1.2
+++ object.h	2 Nov 2003 22:31:19 -0000	1.3
@@ -60,12 +60,16 @@
 public:
 	GuiObject(int x, int y, int w, int h) : _x(x), _y(y), _w(w), _h(h), _firstWidget(0) { }
 
-	virtual bool 	isVisible() const = 0;
-
 	virtual int16	getAbsX() const		{ return _x; }
 	virtual int16	getAbsY() const		{ return _y; }
+	virtual int16	getChildX() const	{ return getAbsX(); }
+	virtual int16	getChildY() const	{ return getAbsY(); }
 	virtual uint16	getWidth() const	{ return _w; }
 	virtual uint16	getHeight() const	{ return _h; }
+
+	virtual bool 	isVisible() const = 0;
+
+	virtual void	draw() = 0;
 
 protected:
 	virtual void	releaseFocus() = 0;

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- widget.cpp	2 Nov 2003 18:57:19 -0000	1.21
+++ widget.cpp	2 Nov 2003 22:31:20 -0000	1.22
@@ -38,10 +38,12 @@
 
 	if (!isVisible() || !_boss->isVisible())
 		return;
+	
+	int oldX = _x, oldY = _y;
 
 	// Account for our relative position in the dialog
-	_x += _boss->getAbsX();
-	_y += _boss->getAbsY();
+	_x = getAbsX();
+	_y = getAbsY();
 
 	// Clear background (unless alpha blending is enabled)
 	if (_flags & WIDGET_CLEARBG)
@@ -74,8 +76,15 @@
 	// Flag the draw area as dirty
 	gui->addDirtyRect(_x, _y, _w, _h);
 
-	_x -= _boss->getAbsX();
-	_y -= _boss->getAbsY();
+	_x = oldX;
+	_y = oldY;
+
+	// Draw all children
+	Widget *w = _firstWidget;
+	while (w) {
+		w->draw();
+		w = w->_next;
+	}
 }
 
 Widget *Widget::findWidgetInChain(Widget *w, int x, int y) {

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- widget.h	2 Nov 2003 18:57:20 -0000	1.25
+++ widget.h	2 Nov 2003 22:31:20 -0000	1.26
@@ -79,8 +79,8 @@
 	Widget(GuiObject *boss, int x, int y, int w, int h);
 	virtual ~Widget() {}
 
-	virtual int16	getAbsX() const	{ return _x + _boss->getAbsX(); }
-	virtual int16	getAbsY() const	{ return _y + _boss->getAbsY(); }
+	virtual int16	getAbsX() const	{ return _x + _boss->getChildX(); }
+	virtual int16	getAbsY() const	{ return _y + _boss->getChildY(); }
 
 	virtual void handleMouseDown(int x, int y, int button, int clickCount) {}
 	virtual void handleMouseUp(int x, int y, int button, int clickCount) {}
@@ -91,6 +91,7 @@
 	virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers) { return false; }	// Return true if the event was handled
 	virtual bool handleKeyUp(uint16 ascii, int keycode, int modifiers) { return false; }	// Return true if the event was handled
 	virtual void handleTickle() {}
+
 	void draw();
 	void receivedFocus() { _hasFocus = true; receivedFocusWidget(); }
 	void lostFocus() { _hasFocus = false; lostFocusWidget(); }





More information about the Scummvm-git-logs mailing list