aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2008-12-26 01:08:49 +0000
committerMax Horn2008-12-26 01:08:49 +0000
commit131cb5a05ac14f1608030437aed72883f4ddd0d3 (patch)
treea600ee3f9fa8899705339119cf1e4b7eb018608a
parentc59f5919a23419203f5a7e73bb8bb658ac50b14d (diff)
downloadscummvm-rg350-131cb5a05ac14f1608030437aed72883f4ddd0d3.tar.gz
scummvm-rg350-131cb5a05ac14f1608030437aed72883f4ddd0d3.tar.bz2
scummvm-rg350-131cb5a05ac14f1608030437aed72883f4ddd0d3.zip
Merged ThemeLayoutHorizontal and ThemeLayoutVertical into a new class ThemeLayoutStacked (suggestions for a better name are welcome); stored padding data in a Common::Rect
svn-id: r35548
-rw-r--r--gui/ThemeEval.cpp5
-rw-r--r--gui/ThemeLayout.cpp35
-rw-r--r--gui/ThemeLayout.h68
3 files changed, 47 insertions, 61 deletions
diff --git a/gui/ThemeEval.cpp b/gui/ThemeEval.cpp
index 5d841c6ad7..6a0056c63b 100644
--- a/gui/ThemeEval.cpp
+++ b/gui/ThemeEval.cpp
@@ -127,10 +127,7 @@ void ThemeEval::addLayout(ThemeLayout::LayoutType type, int spacing, bool center
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);
diff --git a/gui/ThemeLayout.cpp b/gui/ThemeLayout.cpp
index 1d5239ef80..e56438aef6 100644
--- a/gui/ThemeLayout.cpp
+++ b/gui/ThemeLayout.cpp
@@ -68,7 +68,7 @@ int16 ThemeLayout::getParentW() {
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 @@ int16 ThemeLayout::getParentH() {
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 ThemeLayoutMain::reflowLayout() {
}
}
-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 @@ void ThemeLayoutVertical::reflowLayout() {
_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 @@ void ThemeLayoutVertical::reflowLayout() {
_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 ThemeLayoutVertical::reflowLayout() {
}
}
-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 @@ void ThemeLayoutHorizontal::reflowLayout() {
_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 @@ void ThemeLayoutHorizontal::reflowLayout() {
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 @@ void ThemeLayoutHorizontal::reflowLayout() {
}
}
-
-}
+} // End of namespace GUI
diff --git a/gui/ThemeLayout.h b/gui/ThemeLayout.h
index ce7131ec29..0824893441 100644
--- a/gui/ThemeLayout.h
+++ b/gui/ThemeLayout.h
@@ -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 @@ namespace GUI {
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ protected:
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 @@ public:
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 {