[Scummvm-cvs-logs] SF.net SVN: scummvm:[35548] scummvm/trunk/gui

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Dec 26 02:08:49 CET 2008


Revision: 35548
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35548&view=rev
Author:   fingolfin
Date:     2008-12-26 01:08:49 +0000 (Fri, 26 Dec 2008)

Log Message:
-----------
Merged ThemeLayoutHorizontal and ThemeLayoutVertical into a new class ThemeLayoutStacked (suggestions for a better name are welcome); stored padding data in a Common::Rect

Modified Paths:
--------------
    scummvm/trunk/gui/ThemeEval.cpp
    scummvm/trunk/gui/ThemeLayout.cpp
    scummvm/trunk/gui/ThemeLayout.h

Modified: scummvm/trunk/gui/ThemeEval.cpp
===================================================================
--- scummvm/trunk/gui/ThemeEval.cpp	2008-12-26 00:57:30 UTC (rev 35547)
+++ scummvm/trunk/gui/ThemeEval.cpp	2008-12-26 01:08:49 UTC (rev 35548)
@@ -127,10 +127,7 @@
 	if (spacing == -1)
 		spacing = getVar("Globals.Layout.Spacing", 4);
 
-	if (type == ThemeLayout::kLayoutVertical)
-		layout = new ThemeLayoutVertical(_curLayout.top(), spacing, center);
-	else if (type == ThemeLayout::kLayoutHorizontal)
-		layout = new ThemeLayoutHorizontal(_curLayout.top(), spacing, center);
+	layout = new ThemeLayoutStacked(_curLayout.top(), type, spacing, center);
 
 	assert(layout);
 

Modified: scummvm/trunk/gui/ThemeLayout.cpp
===================================================================
--- scummvm/trunk/gui/ThemeLayout.cpp	2008-12-26 00:57:30 UTC (rev 35547)
+++ scummvm/trunk/gui/ThemeLayout.cpp	2008-12-26 01:08:49 UTC (rev 35548)
@@ -68,7 +68,7 @@
 	int width = 0;
 
 	while (p && p->getLayoutType() != kLayoutMain) {
-		width += p->_paddingRight + p->_paddingLeft;
+		width += p->_padding.right + p->_padding.left;
 		if (p->getLayoutType() == kLayoutHorizontal) {
 			for (uint i = 0; i < p->_children.size(); ++i)
 				width += p->_children[i]->getWidth() + p->_spacing;
@@ -84,7 +84,7 @@
 	int height = 0;
 
 	while (p && p->getLayoutType() != kLayoutMain) {
-		height += p->_paddingBottom + p->_paddingTop;
+		height += p->_padding.bottom + p->_padding.top;
 		if (p->getLayoutType() == kLayoutVertical) {
 			for (uint i = 0; i < p->_children.size(); ++i)
 				height += p->_children[i]->getHeight() + p->_spacing;
@@ -143,14 +143,14 @@
 	}
 }
 
-void ThemeLayoutVertical::reflowLayout() {
+void ThemeLayoutStacked::reflowLayoutV() {
 	int curX, curY;
 	int resize[8];
 	int rescount = 0;
 
-	curX = _paddingLeft;
-	curY = _paddingTop;
-	_h = _paddingTop + _paddingBottom;
+	curX = _padding.left;
+	curY = _padding.top;
+	_h = _padding.top + _padding.bottom;
 
 	for (uint i = 0; i < _children.size(); ++i) {
 
@@ -158,7 +158,7 @@
 		_children[i]->reflowLayout();
 
 		if (_children[i]->getWidth() == -1)
-			_children[i]->setWidth((_w == -1 ? getParentW() : _w) - _paddingLeft - _paddingRight);
+			_children[i]->setWidth((_w == -1 ? getParentW() : _w) - _padding.left - _padding.right);
 
 		if (_children[i]->getHeight() == -1) {
 			resize[rescount++] = i;
@@ -173,14 +173,14 @@
 			_children[i]->setX(curX);
 
 		curY += _children[i]->getHeight() + _spacing;
-		_w = MAX(_w, (int16)(_children[i]->getWidth() + _paddingLeft + _paddingRight));
+		_w = MAX(_w, (int16)(_children[i]->getWidth() + _padding.left + _padding.right));
 		_h += _children[i]->getHeight() + _spacing;
 	}
 
 	_h -= _spacing;
 
 	if (rescount) {
-		int newh = (getParentH() - _h - _paddingBottom) / rescount;
+		int newh = (getParentH() - _h - _padding.bottom) / rescount;
 
 		for (int i = 0; i < rescount; ++i) {
 			_children[resize[i]]->setHeight(newh);
@@ -191,14 +191,14 @@
 	}
 }
 
-void ThemeLayoutHorizontal::reflowLayout() {
+void ThemeLayoutStacked::reflowLayoutH() {
 	int curX, curY;
 	int resize[8];
 	int rescount = 0;
 
-	curX = _paddingLeft;
-	curY = _paddingTop;
-	_w = _paddingLeft + _paddingRight;
+	curX = _padding.left;
+	curY = _padding.top;
+	_w = _padding.left + _padding.right;
 
 	for (uint i = 0; i < _children.size(); ++i) {
 
@@ -206,7 +206,7 @@
 		_children[i]->reflowLayout();
 
 		if (_children[i]->getHeight() == -1)
-			_children[i]->setHeight((_h == -1 ? getParentH() : _h) - _paddingTop - _paddingBottom);
+			_children[i]->setHeight((_h == -1 ? getParentH() : _h) - _padding.top - _padding.bottom);
 
 		if (_children[i]->getWidth() == -1) {
 			resize[rescount++] = i;
@@ -222,13 +222,13 @@
 
 		curX += (_children[i]->getWidth() + _spacing);
 		_w += _children[i]->getWidth() + _spacing;
-		_h = MAX(_h, (int16)(_children[i]->getHeight() + _paddingTop + _paddingBottom));
+		_h = MAX(_h, (int16)(_children[i]->getHeight() + _padding.top + _padding.bottom));
 	}
 
 	_w -= _spacing;
 
 	if (rescount) {
-		int neww = (getParentW() - _w - _paddingRight) / rescount;
+		int neww = (getParentW() - _w - _padding.right) / rescount;
 
 		for (int i = 0; i < rescount; ++i) {
 			_children[resize[i]]->setWidth(neww);
@@ -239,5 +239,4 @@
 	}
 }
 
-
-}
+} // End of namespace GUI

Modified: scummvm/trunk/gui/ThemeLayout.h
===================================================================
--- scummvm/trunk/gui/ThemeLayout.h	2008-12-26 00:57:30 UTC (rev 35547)
+++ scummvm/trunk/gui/ThemeLayout.h	2008-12-26 01:08:49 UTC (rev 35548)
@@ -26,6 +26,8 @@
 #ifndef THEME_LAYOUT_H
 #define THEME_LAYOUT_H
 
+#include "common/rect.h"
+
 #ifdef LAYOUT_DEBUG_DIALOG
 namespace Graphics {
 	class Font;
@@ -37,8 +39,7 @@
 
 class ThemeLayout {
 	friend class ThemeLayoutMain;
-	friend class ThemeLayoutVertical;
-	friend class ThemeLayoutHorizontal;
+	friend class ThemeLayoutStacked;
 	friend class ThemeLayoutSpacing;
 	friend class ThemeLayoutWidget;
 public:
@@ -51,7 +52,6 @@
 
 	ThemeLayout(ThemeLayout *p) :
 		_parent(p), _x(0), _y(0), _w(-1), _h(-1),
-		_paddingLeft(0), _paddingRight(0), _paddingTop(0), _paddingBottom(0),
 		_centered(false), _defaultW(-1), _defaultH(-1) { }
 
 	virtual ~ThemeLayout() {
@@ -66,10 +66,10 @@
 	void addChild(ThemeLayout *child) { _children.push_back(child); }
 
 	void setPadding(int8 left, int8 right, int8 top, int8 bottom) {
-		_paddingLeft = left;
-		_paddingRight = right;
-		_paddingTop = top;
-		_paddingBottom = bottom;
+		_padding.left = left;
+		_padding.right = right;
+		_padding.top = top;
+		_padding.bottom = bottom;
 	}
 
 	void setSpacing(int8 spacing) {
@@ -122,7 +122,7 @@
 protected:
 	ThemeLayout *_parent;
 	int16 _x, _y, _w, _h;
-	int8 _paddingLeft, _paddingRight, _paddingTop, _paddingBottom;
+	Common::Rect _padding;
 	int8 _spacing;
 	Common::Array<ThemeLayout *> _children;
 	bool _centered;
@@ -157,23 +157,35 @@
 	int16 _defaultY;
 };
 
-class ThemeLayoutVertical : public ThemeLayout {
+class ThemeLayoutStacked : public ThemeLayout {
 public:
-	ThemeLayoutVertical(ThemeLayout *p, int spacing, bool center) :
-		ThemeLayout(p) {
+	ThemeLayoutStacked(ThemeLayout *p, LayoutType type, int spacing, bool center) :
+		ThemeLayout(p), _type(type) {
+		assert((type == kLayoutVertical) || (type == kLayoutHorizontal));
 		_spacing = spacing;
 		_centered = center;
 	}
 
-	void reflowLayout();
+	void reflowLayout() {
+		if (_type == kLayoutVertical)
+			reflowLayoutV();
+		else
+			reflowLayoutH();
+	}
+	void reflowLayoutH();
+	void reflowLayoutV();
+
 #ifdef LAYOUT_DEBUG_DIALOG
-	const char *getName() const { return "Vertical Layout"; }
+	const char *getName() const {
+		return (_type == kLayoutVertical)
+			? "Vertical Layout" : "Horizontal Layout";
+	}
 #endif
-	LayoutType getLayoutType() { return kLayoutVertical; }
 
+	LayoutType getLayoutType() { return _type; }
 
 	ThemeLayout *makeClone(ThemeLayout *newParent) {
-		ThemeLayoutVertical *n = new ThemeLayoutVertical(*this);
+		ThemeLayoutStacked *n = new ThemeLayoutStacked(*this);
 		n->_parent = newParent;
 
 		for (uint i = 0; i < n->_children.size(); ++i)
@@ -181,31 +193,9 @@
 
 		return n;
 	}
-};
 
-class ThemeLayoutHorizontal : public ThemeLayout {
-public:
-	ThemeLayoutHorizontal(ThemeLayout *p, int spacing, bool center) :
-		ThemeLayout(p) {
-		_spacing = spacing;
-		_centered = center;
-	}
-
-	void reflowLayout();
-#ifdef LAYOUT_DEBUG_DIALOG
-	const char *getName() const { return "Horizontal Layout"; }
-#endif
-	LayoutType getLayoutType() { return kLayoutHorizontal; }
-
-	ThemeLayout *makeClone(ThemeLayout *newParent) {
-		ThemeLayoutHorizontal *n = new ThemeLayoutHorizontal(*this);
-		n->_parent = newParent;
-
-		for (uint i = 0; i < n->_children.size(); ++ i)
-			n->_children[i] = n->_children[i]->makeClone(n);
-
-		return n;
-	}
+protected:
+	const LayoutType _type;
 };
 
 class ThemeLayoutWidget : public ThemeLayout {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list