summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-14 22:09:25 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-14 22:09:25 +0300
commitffee866c7eea91d38f6a27fbd4ecf38b573d32ee (patch)
tree10d02aede21898dbe802798777e0588e87a17e92 /src
parent916a53ec6e9eda8711ae7c2e9296463728370751 (diff)
downloadmv-ffee866c7eea91d38f6a27fbd4ecf38b573d32ee.tar.gz
mv-ffee866c7eea91d38f6a27fbd4ecf38b573d32ee.tar.bz2
mv-ffee866c7eea91d38f6a27fbd4ecf38b573d32ee.tar.xz
mv-ffee866c7eea91d38f6a27fbd4ecf38b573d32ee.zip
Move layoutcell into separate file.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/widgets/layout.cpp65
-rw-r--r--src/gui/widgets/layout.h172
-rw-r--r--src/gui/widgets/layoutcell.cpp131
-rw-r--r--src/gui/widgets/layoutcell.h196
6 files changed, 334 insertions, 234 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index de9dad9f7..f831a6190 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -181,6 +181,8 @@ SET(SRCS
gui/widgets/tabs/langtab.h
gui/widgets/layout.cpp
gui/widgets/layout.h
+ gui/widgets/layoutcell.cpp
+ gui/widgets/layoutcell.h
gui/widgets/layouthelper.cpp
gui/widgets/layouthelper.h
gui/widgets/linepart.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index ca884fd03..9d3449ed7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -273,6 +273,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
gui/widgets/tabs/langtab.h \
gui/widgets/layout.cpp \
gui/widgets/layout.h \
+ gui/widgets/layoutcell.cpp \
+ gui/widgets/layoutcell.h \
gui/widgets/layouthelper.cpp \
gui/widgets/layouthelper.h \
gui/widgets/linepart.cpp \
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
index d2f09864b..eb61bd4d5 100644
--- a/src/gui/widgets/layout.cpp
+++ b/src/gui/widgets/layout.cpp
@@ -32,71 +32,6 @@
#include "debug.h"
-LayoutCell::~LayoutCell()
-{
- if (mType == ARRAY)
- delete2(mArray)
-}
-
-LayoutArray &LayoutCell::getArray()
-{
- assert(mType != WIDGET);
- if (mType == ARRAY)
- return *mArray;
-
- mArray = new LayoutArray;
- mType = ARRAY;
- mExtent[0] = 1;
- mExtent[1] = 1;
- mHPadding = 0;
- mVPadding = 0;
- mAlign[0] = FILL;
- mAlign[1] = FILL;
- return *mArray;
-}
-
-void LayoutCell::reflow(int nx, int ny, int nw, int nh)
-{
- if (mType == NONE)
- return;
-
- nx += mHPadding;
- ny += mVPadding;
- nw -= 2 * mHPadding;
- nh -= 2 * mVPadding;
- if (mType == ARRAY)
- mArray->reflow(nx, ny, nw, nh);
- else
- mWidget->setDimension(Rect(nx, ny, nw, nh));
-}
-
-void LayoutCell::computeSizes()
-{
- if (mType != ARRAY)
- return;
-
- std::vector <std::vector <LayoutCell *> >::const_iterator
- i = mArray->mCells.begin();
- const std::vector <std::vector <LayoutCell *> >::const_iterator
- i_end = mArray->mCells.end();
- while (i != i_end)
- {
- std::vector <LayoutCell *>::const_iterator j = i->begin();
- while (j != i->end())
- {
- LayoutCell *const cell = *j;
- if (cell && cell->mType == ARRAY)
- cell->computeSizes();
-
- ++j;
- }
- ++i;
- }
-
- mSize[0] = mArray->getSize(0);
- mSize[1] = mArray->getSize(1);
-}
-
LayoutArray::LayoutArray():
mCells(),
mSpacing(4)
diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h
index bf41e1c8e..c41c6570f 100644
--- a/src/gui/widgets/layout.h
+++ b/src/gui/widgets/layout.h
@@ -23,12 +23,13 @@
#ifndef GUI_WIDGETS_LAYOUT_H
#define GUI_WIDGETS_LAYOUT_H
-#include "localconsts.h"
+#include "gui/widgets/layoutcell.h"
#include <vector>
+#include "localconsts.h"
+
class BasicContainer2;
-class LayoutCell;
class Widget;
/**
@@ -121,173 +122,6 @@ class LayoutArray final
};
/**
- * This class describes the formatting of a widget in the cell of a layout
- * table. Horizontally, a widget can either fill the width of the cell (minus
- * the cell padding), or it can retain its size and be flushed left, or flush
- * right, or centered in the cell. The process is similar for the vertical
- * alignment, except that top is represented by LEFT and bottom by RIGHT.
- */
-class LayoutCell
-{
- friend class Layout;
- friend class LayoutArray;
-
- public:
- enum Alignment
- {
- LEFT = 0,
- RIGHT,
- CENTER,
- FILL
- };
-
- virtual ~LayoutCell();
-
- /**
- * Sets the padding around the cell content.
- */
- LayoutCell &setPadding(int p)
- { mHPadding = p; mVPadding = p; return *this; }
-
- /**
- * Sets the vertical padding around the cell content.
- */
- LayoutCell &setVPadding(int p)
- { mVPadding = p; return *this; }
-
- /**
- * Sets the horisontal padding around the cell content.
- */
- LayoutCell &setHPadding(int p)
- { mHPadding = p; return *this; }
-
- /**
- * Sets the horizontal alignment of the cell content.
- */
- LayoutCell &setHAlign(const Alignment a)
- { mAlign[0] = a; return *this; }
-
- /**
- * Sets the vertical alignment of the cell content.
- */
- LayoutCell &setVAlign(const Alignment a)
- { mAlign[1] = a; return *this; }
-
- /**
- * @see LayoutArray::at
- */
- LayoutCell &at(const int x, const int y) A_WARN_UNUSED
- { return getArray().at(x, y); }
-
- /**
- * @see LayoutArray::place
- */
- LayoutCell &place(Widget *wg,
- const int x, const int y,
- const int w = 1, const int h = 1)
- { return getArray().place(wg, x, y, w, h); }
-
- /**
- * @see LayoutArray::matchColWidth
- */
- void matchColWidth(const int n1, const int n2)
- { getArray().matchColWidth(n1, n2); }
-
- /**
- * @see LayoutArray::setColWidth
- */
- void setColWidth(const int n, const int w)
- { getArray().setColWidth(n, w); }
-
- /**
- * @see LayoutArray::setRowHeight
- */
- void setRowHeight(const int n, const int h)
- { getArray().setRowHeight(n, h); }
-
- /**
- * @see LayoutArray::extend.
- */
- void extend(const int x, const int y,
- const int w, const int h)
- { getArray().extend(x, y, w, h); }
-
- /**
- * Sets the minimum widths and heights of this cell and of all the
- * inner cells.
- */
- void computeSizes();
-
- void setType(int t)
- { mType = t; }
-
- int getWidth() const A_WARN_UNUSED
- { return mExtent[0]; }
-
- int getHeight() const A_WARN_UNUSED
- { return mExtent[1]; }
-
- void setWidth(const int w)
- { mExtent[0] = w; }
-
- void setHeight(const int h)
- { mExtent[1] = h; }
-
- enum
- {
- NONE = 0,
- WIDGET,
- ARRAY
- };
-
- private:
- LayoutCell():
- mWidget(nullptr),
- mHPadding(0),
- mVPadding(0),
- mType(NONE)
- {
- mExtent[0] = 0;
- mExtent[1] = 0;
- mAlign[0] = LEFT;
- mAlign[1] = LEFT;
- mNbFill[0] = 0;
- mNbFill[1] = 0;
- mSize[0] = 0;
- mSize[1] = 0;
- }
-
- // Copy not allowed, as the cell may own an array.
- explicit LayoutCell(LayoutCell const &);
- LayoutCell &operator=(LayoutCell const &);
-
- union
- {
- Widget *mWidget;
- LayoutArray *mArray;
- };
-
- /**
- * Returns the embedded array. Creates it if the cell does not contain
- * anything yet. Aborts if it contains a widget.
- */
- LayoutArray &getArray();
-
- /**
- * @see LayoutArray::reflow
- */
- void reflow(int nx, int ny, int nw, int nh);
-
- int mSize[2];
- int mHPadding;
- int mVPadding;
- int mExtent[2];
- Alignment mAlign[2];
- int mNbFill[2];
- int mType;
-};
-
-/**
* This class is an helper for setting the position of widgets. They are
* positioned along the cells of some rectangular tables. The layout may either
* be a single table or a tree of nested tables.
diff --git a/src/gui/widgets/layoutcell.cpp b/src/gui/widgets/layoutcell.cpp
new file mode 100644
index 000000000..58ba6976e
--- /dev/null
+++ b/src/gui/widgets/layoutcell.cpp
@@ -0,0 +1,131 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2007-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/widgets/layoutcell.h"
+
+#include "gui/widgets/layout.h"
+#include "gui/widgets/widget.h"
+
+#include "utils/delete2.h"
+
+#include "debug.h"
+
+static LayoutArray tempArray;
+
+LayoutCell::~LayoutCell()
+{
+ if (mType == ARRAY)
+ delete2(mArray)
+}
+
+LayoutArray &LayoutCell::getArray()
+{
+ if (mType == WIDGET)
+ return tempArray;
+ if (mType == ARRAY)
+ return *mArray;
+
+ mArray = new LayoutArray;
+ mType = ARRAY;
+ mExtent[0] = 1;
+ mExtent[1] = 1;
+ mHPadding = 0;
+ mVPadding = 0;
+ mAlign[0] = FILL;
+ mAlign[1] = FILL;
+ return *mArray;
+}
+
+void LayoutCell::reflow(int nx, int ny, int nw, int nh)
+{
+ if (mType == NONE)
+ return;
+
+ nx += mHPadding;
+ ny += mVPadding;
+ nw -= 2 * mHPadding;
+ nh -= 2 * mVPadding;
+ if (mType == ARRAY)
+ mArray->reflow(nx, ny, nw, nh);
+ else
+ mWidget->setDimension(Rect(nx, ny, nw, nh));
+}
+
+void LayoutCell::computeSizes()
+{
+ if (mType != ARRAY)
+ return;
+
+ std::vector <std::vector <LayoutCell *> >::const_iterator
+ i = mArray->mCells.begin();
+ const std::vector <std::vector <LayoutCell *> >::const_iterator
+ i_end = mArray->mCells.end();
+ while (i != i_end)
+ {
+ std::vector <LayoutCell *>::const_iterator j = i->begin();
+ while (j != i->end())
+ {
+ LayoutCell *const cell = *j;
+ if (cell && cell->mType == ARRAY)
+ cell->computeSizes();
+
+ ++j;
+ }
+ ++i;
+ }
+
+ mSize[0] = mArray->getSize(0);
+ mSize[1] = mArray->getSize(1);
+}
+
+LayoutCell &LayoutCell::at(const int x, const int y)
+{
+ return getArray().at(x, y);
+}
+
+LayoutCell &LayoutCell::place(Widget *wg,
+ const int x, const int y,
+ const int w, const int h)
+{
+ return getArray().place(wg, x, y, w, h);
+}
+
+void LayoutCell::matchColWidth(const int n1, const int n2)
+{
+ getArray().matchColWidth(n1, n2);
+}
+
+void LayoutCell::setColWidth(const int n, const int w)
+{
+ getArray().setColWidth(n, w);
+}
+
+void LayoutCell::setRowHeight(const int n, const int h)
+{
+ getArray().setRowHeight(n, h);
+}
+
+void LayoutCell::extend(const int x, const int y,
+ const int w, const int h)
+{
+ getArray().extend(x, y, w, h);
+}
diff --git a/src/gui/widgets/layoutcell.h b/src/gui/widgets/layoutcell.h
new file mode 100644
index 000000000..f262ebb05
--- /dev/null
+++ b/src/gui/widgets/layoutcell.h
@@ -0,0 +1,196 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2007-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_WIDGETS_LAYOUTCELL_H
+#define GUI_WIDGETS_LAYOUTCELL_H
+
+#include "localconsts.h"
+
+#include <vector>
+
+class BasicContainer2;
+class LayoutArray;
+class LayoutCell;
+class Widget;
+
+/**
+ * This class describes the formatting of a widget in the cell of a layout
+ * table. Horizontally, a widget can either fill the width of the cell (minus
+ * the cell padding), or it can retain its size and be flushed left, or flush
+ * right, or centered in the cell. The process is similar for the vertical
+ * alignment, except that top is represented by LEFT and bottom by RIGHT.
+ */
+class LayoutCell
+{
+ friend class Layout;
+ friend class LayoutArray;
+
+ public:
+ enum Alignment
+ {
+ LEFT = 0,
+ RIGHT,
+ CENTER,
+ FILL
+ };
+
+ virtual ~LayoutCell();
+
+ /**
+ * Sets the padding around the cell content.
+ */
+ LayoutCell &setPadding(int p)
+ { mHPadding = p; mVPadding = p; return *this; }
+
+ /**
+ * Sets the vertical padding around the cell content.
+ */
+ LayoutCell &setVPadding(int p)
+ { mVPadding = p; return *this; }
+
+ /**
+ * Sets the horisontal padding around the cell content.
+ */
+ LayoutCell &setHPadding(int p)
+ { mHPadding = p; return *this; }
+
+ /**
+ * Sets the horizontal alignment of the cell content.
+ */
+ LayoutCell &setHAlign(const Alignment a)
+ { mAlign[0] = a; return *this; }
+
+ /**
+ * Sets the vertical alignment of the cell content.
+ */
+ LayoutCell &setVAlign(const Alignment a)
+ { mAlign[1] = a; return *this; }
+
+ /**
+ * @see LayoutArray::at
+ */
+ LayoutCell &at(const int x, const int y) A_WARN_UNUSED;
+
+ /**
+ * @see LayoutArray::place
+ */
+ LayoutCell &place(Widget *wg,
+ const int x, const int y,
+ const int w = 1, const int h = 1);
+
+ /**
+ * @see LayoutArray::matchColWidth
+ */
+ void matchColWidth(const int n1, const int n2);
+
+ /**
+ * @see LayoutArray::setColWidth
+ */
+ void setColWidth(const int n, const int w);
+
+ /**
+ * @see LayoutArray::setRowHeight
+ */
+ void setRowHeight(const int n, const int h);
+
+ /**
+ * @see LayoutArray::extend.
+ */
+ void extend(const int x, const int y,
+ const int w, const int h);
+
+ /**
+ * Sets the minimum widths and heights of this cell and of all the
+ * inner cells.
+ */
+ void computeSizes();
+
+ void setType(int t)
+ { mType = t; }
+
+ int getWidth() const A_WARN_UNUSED
+ { return mExtent[0]; }
+
+ int getHeight() const A_WARN_UNUSED
+ { return mExtent[1]; }
+
+ void setWidth(const int w)
+ { mExtent[0] = w; }
+
+ void setHeight(const int h)
+ { mExtent[1] = h; }
+
+ enum
+ {
+ NONE = 0,
+ WIDGET,
+ ARRAY
+ };
+
+ private:
+ LayoutCell():
+ mWidget(nullptr),
+ mHPadding(0),
+ mVPadding(0),
+ mType(NONE)
+ {
+ mExtent[0] = 0;
+ mExtent[1] = 0;
+ mAlign[0] = LEFT;
+ mAlign[1] = LEFT;
+ mNbFill[0] = 0;
+ mNbFill[1] = 0;
+ mSize[0] = 0;
+ mSize[1] = 0;
+ }
+
+ // Copy not allowed, as the cell may own an array.
+ explicit LayoutCell(LayoutCell const &);
+ LayoutCell &operator=(LayoutCell const &);
+
+ union
+ {
+ Widget *mWidget;
+ LayoutArray *mArray;
+ };
+
+ /**
+ * Returns the embedded array. Creates it if the cell does not contain
+ * anything yet. Aborts if it contains a widget.
+ */
+ LayoutArray &getArray();
+
+ /**
+ * @see LayoutArray::reflow
+ */
+ void reflow(int nx, int ny, int nw, int nh);
+
+ int mSize[2];
+ int mHPadding;
+ int mVPadding;
+ int mExtent[2];
+ Alignment mAlign[2];
+ int mNbFill[2];
+ int mType;
+};
+
+#endif // GUI_WIDGETS_LAYOUTCELL_H