summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-08-16 18:25:55 +0200
committerPhilipp Sehmisch <crush@themanaworld.org>2009-08-16 18:25:55 +0200
commit4263962e947b4914de8d1750f21cc7cc82567b4d (patch)
tree32340098913c302fdb33f88ffea65fb36920db75 /src/gui/widgets
parentdd0844b6ac01293e7afd0dd85e695b8d77b8e4be (diff)
parent7e2673a3b9460fdcd646e23c3bd9039de854565f (diff)
downloadmana-client-4263962e947b4914de8d1750f21cc7cc82567b4d.tar.gz
mana-client-4263962e947b4914de8d1750f21cc7cc82567b4d.tar.bz2
mana-client-4263962e947b4914de8d1750f21cc7cc82567b4d.tar.xz
mana-client-4263962e947b4914de8d1750f21cc7cc82567b4d.zip
More merges and conflict resolves
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/flowcontainer.cpp78
-rw-r--r--src/gui/widgets/flowcontainer.h68
-rw-r--r--src/gui/widgets/scrollarea.cpp5
-rw-r--r--src/gui/widgets/scrollarea.h5
-rw-r--r--src/gui/widgets/tabbedarea.cpp20
-rw-r--r--src/gui/widgets/tabbedarea.h13
6 files changed, 187 insertions, 2 deletions
diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp
new file mode 100644
index 00000000..6ce4284b
--- /dev/null
+++ b/src/gui/widgets/flowcontainer.cpp
@@ -0,0 +1,78 @@
+/*
+ * The Mana World
+ * Copyright (C) 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "flowcontainer.h"
+
+FlowContainer::FlowContainer(int boxWidth, int boxHeight):
+ mBoxWidth(boxWidth), mBoxHeight(boxHeight),
+ mGridWidth(1), mGridHeight(1)
+{
+ addWidgetListener(this);
+}
+
+void FlowContainer::widgetResized(const gcn::Event &event)
+{
+ if (getWidth() < mBoxWidth)
+ {
+ setWidth(mBoxWidth);
+ return;
+ }
+
+ int itemCount = mWidgets.size();
+
+ mGridWidth = getWidth() / mBoxWidth;
+
+ if (mGridWidth < 1)
+ mGridWidth = 1;
+
+ mGridHeight = itemCount / mGridWidth;
+
+ if (itemCount % mGridWidth != 0 || mGridHeight < 1)
+ ++mGridHeight;
+
+ int height = mGridHeight * mBoxHeight;
+
+ if (getHeight() != height)
+ {
+ setHeight(height);
+ return;
+ }
+
+ int i = 0;
+ height = 0;
+ for (WidgetList::iterator it = mWidgets.begin(); it != mWidgets.end(); it++)
+ {
+ int x = i % mGridWidth * mBoxWidth;
+ (*it)->setPosition(x, height);
+
+ i++;
+
+ if (i % mGridWidth == 0)
+ height += mBoxHeight;
+ }
+}
+
+void FlowContainer::add(gcn::Widget *widget)
+{
+ Container::add(widget);
+ widget->setSize(mBoxWidth, mBoxHeight);
+ widgetResized(NULL);
+}
diff --git a/src/gui/widgets/flowcontainer.h b/src/gui/widgets/flowcontainer.h
new file mode 100644
index 00000000..afecde25
--- /dev/null
+++ b/src/gui/widgets/flowcontainer.h
@@ -0,0 +1,68 @@
+/*
+ * The Mana World
+ * Copyright (C) 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef FLOWCONTAINER_H
+#define FLOWCONTAINER_H
+
+#include "container.h"
+
+#include <guichan/widgetlistener.hpp>
+
+/**
+ * A container that arranges its contents like words on a page.
+ *
+ * \ingroup GUI
+ */
+class FlowContainer : public Container,
+ public gcn::WidgetListener
+{
+ public:
+ /**
+ * Constructor. Initializes the shortcut container.
+ */
+ FlowContainer(int boxWidth, int boxHeight);
+
+ /**
+ * Destructor.
+ */
+ ~FlowContainer() {}
+
+ /**
+ * Invoked when a widget changes its size. This is used to determine
+ * the new height of the container.
+ */
+ void widgetResized(const gcn::Event &event);
+
+ int getBoxWidth() const
+ { return mBoxWidth; }
+
+ int getBoxHeight() const
+ { return mBoxHeight; }
+
+ void add(gcn::Widget *widget);
+
+ private:
+ int mBoxWidth;
+ int mBoxHeight;
+ int mGridWidth, mGridHeight;
+};
+
+#endif
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 52322b05..6cf27bb6 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -42,6 +42,7 @@ ScrollArea::ScrollArea():
mY(0),
mOpaque(true)
{
+ addWidgetListener(this);
init();
}
@@ -346,3 +347,7 @@ void ScrollArea::mouseExited(gcn::MouseEvent& event)
mHasMouse = false;
}
+void ScrollArea::widgetResized(const gcn::Event &event)
+{
+ getContent()->setSize(getWidth() - 2 * getFrameSize(), getHeight() - 2 * getFrameSize());
+}
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 8fd92b5f..69e99b1f 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -23,6 +23,7 @@
#define SCROLLAREA_H
#include <guichan/widgets/scrollarea.hpp>
+#include <guichan/widgetlistener.hpp>
class Image;
class ImageRect;
@@ -36,7 +37,7 @@ class ImageRect;
*
* \ingroup GUI
*/
-class ScrollArea : public gcn::ScrollArea
+class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener
{
public:
/**
@@ -98,6 +99,8 @@ class ScrollArea : public gcn::ScrollArea
*/
void mouseExited(gcn::MouseEvent& event);
+ void widgetResized(const gcn::Event &event);
+
protected:
enum BUTTON_DIR {
UP,
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index bb5ae9a4..13bb884b 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -27,6 +27,7 @@
TabbedArea::TabbedArea() : gcn::TabbedArea()
{
mWidgetContainer->setOpaque(false);
+ addWidgetListener(this);
}
int TabbedArea::getNumberOfTabs() const
@@ -79,6 +80,15 @@ gcn::Widget *TabbedArea::getCurrentWidget()
return NULL;
}
+void TabbedArea::addTab(gcn::Tab* tab, gcn::Widget* widget)
+{
+ gcn::TabbedArea::addTab(tab, widget);
+
+ int width = getWidth() - 2 * getFrameSize();
+ int height = getHeight() - 2 * getFrameSize() - mTabContainer->getHeight();
+ widget->setSize(width, height);
+}
+
void TabbedArea::addTab(const std::string &caption, gcn::Widget *widget)
{
Tab *tab = new Tab;
@@ -152,3 +162,13 @@ void TabbedArea::setSelectedTab(gcn::Tab *tab)
if (newTab)
newTab->setCurrent();
}
+
+void TabbedArea::widgetResized(const gcn::Event &event)
+{
+ int width = getWidth() - 2 * getFrameSize();
+ int height = getHeight() - 2 * getFrameSize() - mTabContainer->getHeight();
+ mWidgetContainer->setSize(width, height);
+ gcn::Widget *w = getCurrentWidget();
+ if (w)
+ w->setSize(width, height);
+}
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index 29ba2f76..a64d855f 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -23,6 +23,7 @@
#define TABBEDAREA_H
#include <guichan/widget.hpp>
+#include <guichan/widgetlistener.hpp>
#include <guichan/widgets/container.hpp>
#include <guichan/widgets/tabbedarea.hpp>
@@ -33,7 +34,7 @@ class Tab;
/**
* A tabbed area, the same as the guichan tabbed area in 0.8, but extended
*/
-class TabbedArea : public gcn::TabbedArea
+class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener
{
public:
/**
@@ -71,6 +72,14 @@ class TabbedArea : public gcn::TabbedArea
using gcn::TabbedArea::addTab;
/**
+ * Add a tab. Overridden since it needs to size the widget.
+ *
+ * @param tab The tab widget for the tab.
+ * @param widget The widget to view when the tab is selected.
+ */
+ void addTab(gcn::Tab* tab, gcn::Widget* widget);
+
+ /**
* Add a tab. Overridden since it needs to create an instance of Tab
* instead of gcn::Tab.
*
@@ -97,6 +106,8 @@ class TabbedArea : public gcn::TabbedArea
void setSelectedTab(gcn::Tab *tab);
+ void widgetResized(const gcn::Event &event);
+
private:
typedef std::vector< std::pair<gcn::Tab*, gcn::Widget*> > TabContainer;
};