summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-16 19:28:44 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-16 19:28:44 +0300
commit3c02e309bbe285f9fb625f20f55533ff0b22b3cc (patch)
treec18db46312c4f430da82688903007682f4d69dcf
parent0ebe35be8527732a9c04a20103db6a34391efb24 (diff)
downloadmanaverse-3c02e309bbe285f9fb625f20f55533ff0b22b3cc.tar.gz
manaverse-3c02e309bbe285f9fb625f20f55533ff0b22b3cc.tar.bz2
manaverse-3c02e309bbe285f9fb625f20f55533ff0b22b3cc.tar.xz
manaverse-3c02e309bbe285f9fb625f20f55533ff0b22b3cc.zip
Improve basiccontainer.
-rw-r--r--src/gui/widgets/basiccontainer.cpp103
-rw-r--r--src/gui/widgets/basiccontainer.h30
-rw-r--r--src/gui/widgets/basiccontainer2.cpp5
-rw-r--r--src/gui/widgets/basiccontainer2.h11
-rw-r--r--src/gui/widgets/widget.h7
5 files changed, 47 insertions, 109 deletions
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp
index d3dd62fc7..1d71e976f 100644
--- a/src/gui/widgets/basiccontainer.cpp
+++ b/src/gui/widgets/basiccontainer.cpp
@@ -74,8 +74,7 @@ BasicContainer::~BasicContainer()
void BasicContainer::moveToTop(Widget* widget)
{
- for (WidgetListIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListIterator, iter, mWidgets)
{
if (*iter == widget)
{
@@ -88,8 +87,8 @@ void BasicContainer::moveToTop(Widget* widget)
void BasicContainer::moveToBottom(Widget* widget)
{
- WidgetListIterator iter;
- iter = std::find(mWidgets.begin(), mWidgets.end(), widget);
+ WidgetListIterator iter = std::find(mWidgets.begin(),
+ mWidgets.end(), widget);
if (iter == mWidgets.end())
return;
@@ -98,10 +97,10 @@ void BasicContainer::moveToBottom(Widget* widget)
mWidgets.insert(mWidgets.begin(), widget);
}
-void BasicContainer::death(const Event& event)
+void BasicContainer::death(const Event &event)
{
- WidgetListIterator iter;
- iter = std::find(mWidgets.begin(), mWidgets.end(), event.getSource());
+ WidgetListIterator iter = std::find(mWidgets.begin(),
+ mWidgets.end(), event.getSource());
if (iter == mWidgets.end())
return;
@@ -111,7 +110,7 @@ void BasicContainer::death(const Event& event)
Rect BasicContainer::getChildrenArea()
{
- return Rect(0, 0, getWidth(), getHeight());
+ return Rect(0, 0, mDimension.width, mDimension.height);
}
void BasicContainer::focusNext()
@@ -185,12 +184,13 @@ Widget *BasicContainer::getWidgetAt(int x, int y)
y -= r.y;
for (WidgetListReverseIterator it = mWidgets.rbegin();
- it != mWidgets.rend(); ++ it)
+ it != mWidgets.rend(); ++ it)
{
- if ((*it)->isVisible() && (*it)->getDimension()
+ const Widget *const widget = *it;
+ if (widget->isVisible() && widget->getDimension()
.isPointInRect(x, y))
{
- return (*it);
+ return *it;;
}
}
@@ -211,11 +211,8 @@ void BasicContainer::_setFocusHandler(FocusHandler* focusHandler)
if (mInternalFocusHandler)
return;
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
(*iter)->_setFocusHandler(focusHandler);
- }
}
void BasicContainer::add(Widget* widget)
@@ -233,8 +230,7 @@ void BasicContainer::add(Widget* widget)
void BasicContainer::remove(Widget* widget)
{
- for (WidgetListIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListIterator, iter, mWidgets)
{
if (*iter == widget)
{
@@ -249,12 +245,12 @@ void BasicContainer::remove(Widget* widget)
void BasicContainer::clear()
{
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
{
- (*iter)->_setFocusHandler(nullptr);
- (*iter)->_setParent(nullptr);
- (*iter)->removeDeathListener(this);
+ Widget *const widget = *iter;
+ widget->_setFocusHandler(nullptr);
+ widget->_setParent(nullptr);
+ widget->removeDeathListener(this);
}
mWidgets.clear();
@@ -263,21 +259,19 @@ void BasicContainer::clear()
void BasicContainer::drawChildren(Graphics* graphics)
{
BLOCK_START("BasicContainer::drawChildren")
-
graphics->pushClipArea(getChildrenArea());
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
{
Widget *const widget = *iter;
if (widget->isVisible())
{
// If the widget has a frame,
// draw it before drawing the widget
- if (widget->getFrameSize() > 0)
+ if (widget->mFrameSize > 0)
{
- Rect rec = widget->getDimension();
- const int frame = widget->getFrameSize();
+ Rect rec = widget->mDimension;
+ const int frame = widget->mFrameSize;
const int frame2 = frame * 2;
rec.x -= frame;
rec.y -= frame;
@@ -290,7 +284,7 @@ void BasicContainer::drawChildren(Graphics* graphics)
graphics->popClipArea();
}
- graphics->pushClipArea(widget->getDimension());
+ graphics->pushClipArea(widget->mDimension);
BLOCK_START("BasicContainer::drawChildren 2")
widget->draw(graphics);
BLOCK_END("BasicContainer::drawChildren 2")
@@ -305,11 +299,8 @@ void BasicContainer::drawChildren(Graphics* graphics)
void BasicContainer::logicChildren()
{
BLOCK_START("BasicContainer::logicChildren")
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
(*iter)->logic();
- }
BLOCK_END("BasicContainer::logicChildren")
}
@@ -317,34 +308,29 @@ void BasicContainer::showWidgetPart(Widget *const widget, Rect area)
{
const Rect widgetArea = getChildrenArea();
- area.x += widget->getX();
- area.y += widget->getY();
+ const int x = widget->mDimension.x;
+ const int y = widget->mDimension.y;
+ area.x += x;
+ area.y += y;
if (area.x + area.width > widgetArea.width)
- {
- widget->setX(widget->getX() - area.x
- - area.width + widgetArea.width);
- }
+ widget->setX(x - area.x - area.width + widgetArea.width);
if (area.y + area.height > widgetArea.height)
- {
- widget->setY(widget->getY() - area.y
- - area.height + widgetArea.height);
- }
+ widget->setY(y - area.y - area.height + widgetArea.height);
if (area.x < 0)
- widget->setX(widget->getX() - area.x);
+ widget->setX(x - area.x);
if (area.y < 0)
- widget->setY(widget->getY() - area.y);
+ widget->setY(y - area.y);
}
void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler)
{
Widget::setInternalFocusHandler(focusHandler);
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
{
if (!mInternalFocusHandler)
(*iter)->_setFocusHandler(_getFocusHandler());
@@ -352,26 +338,3 @@ void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler)
(*iter)->_setFocusHandler(mInternalFocusHandler);
}
}
-
-Widget* BasicContainer::findWidgetById(const std::string& id)
-{
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- if ((*iter)->getId() == id)
- return (*iter);
-
- BasicContainer *const basicContainer
- = dynamic_cast<BasicContainer *const>(*iter);
-
- if (basicContainer)
- {
- Widget *const widget = basicContainer->findWidgetById(id);
-
- if (widget)
- return widget;
- }
- }
-
- return nullptr;
-}
diff --git a/src/gui/widgets/basiccontainer.h b/src/gui/widgets/basiccontainer.h
index 6e753a445..7d7876b2f 100644
--- a/src/gui/widgets/basiccontainer.h
+++ b/src/gui/widgets/basiccontainer.h
@@ -110,28 +110,27 @@ class BasicContainer : public Widget,
// Inherited from Widget
- virtual void moveToTop(Widget* widget);
+ virtual void moveToTop(Widget* widget) override;
- virtual void moveToBottom(Widget* widget);
+ virtual void moveToBottom(Widget* widget) override;
- virtual Rect getChildrenArea() A_WARN_UNUSED;
+ virtual Rect getChildrenArea() override A_WARN_UNUSED;
- virtual void focusNext();
+ virtual void focusNext() override;
- virtual void focusPrevious();
+ virtual void focusPrevious() override;
- virtual void logic();
+ virtual void logic() override;
- virtual void _setFocusHandler(FocusHandler* focusHandler);
+ virtual void _setFocusHandler(FocusHandler* focusHandler) override;
void setInternalFocusHandler(FocusHandler* focusHandler);
- virtual Widget *getWidgetAt(int x, int y) A_WARN_UNUSED;
-
+ virtual Widget *getWidgetAt(int x, int y) override A_WARN_UNUSED;
// Inherited from DeathListener
- virtual void death(const Event& event);
+ virtual void death(const Event& event) override;
protected:
/**
@@ -171,17 +170,6 @@ class BasicContainer : public Widget,
virtual void logicChildren();
/**
- * Finds a widget given an id. This function can be useful
- * when implementing a GUI generator for Guichan, such as
- * the ability to create a Guichan GUI from an XML file.
- *
- * @param id The id to find a widget by.
- * @return The widget with the corrosponding id,
- NULL of no widget is found.
- */
- virtual Widget* findWidgetById(const std::string& id) A_WARN_UNUSED;
-
- /**
* Typedef.
*/
typedef std::vector<Widget *> WidgetList;
diff --git a/src/gui/widgets/basiccontainer2.cpp b/src/gui/widgets/basiccontainer2.cpp
index 9bd4d1593..8e6d62a67 100644
--- a/src/gui/widgets/basiccontainer2.cpp
+++ b/src/gui/widgets/basiccontainer2.cpp
@@ -122,8 +122,3 @@ void BasicContainer2::clear()
{
BasicContainer::clear();
}
-
-Widget* BasicContainer2::findWidgetById(const std::string &id)
-{
- return BasicContainer::findWidgetById(id);
-}
diff --git a/src/gui/widgets/basiccontainer2.h b/src/gui/widgets/basiccontainer2.h
index c6f1d996b..7d65d0cdf 100644
--- a/src/gui/widgets/basiccontainer2.h
+++ b/src/gui/widgets/basiccontainer2.h
@@ -149,17 +149,6 @@ class BasicContainer2: public BasicContainer
*/
virtual void clear();
- /**
- * Finds a widget given an id.
- *
- * @param id The id to find a widget by.
- * @return A widget with a corrosponding id, NULL if no widget
- * is found.
- * @see Widget::setId
- */
- virtual Widget* findWidgetById(const std::string &id);
-
-
// Inherited from Widget
virtual void draw(Graphics* graphics);
diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h
index 3af00d247..86bf0f773 100644
--- a/src/gui/widgets/widget.h
+++ b/src/gui/widgets/widget.h
@@ -76,6 +76,7 @@
#include "localconsts.h"
class ActionListener;
+class BasicContainer;
class DeathListener;
class FocusHandler;
class FocusListener;
@@ -99,6 +100,8 @@ class WidgetListener;
class Widget : public Widget2
{
public:
+ friend BasicContainer;
+
/**
* Constructor. Resets member variables. Noteable, a widget is not
* focusable as default, therefore, widgets that are supposed to be
@@ -970,7 +973,7 @@ class Widget : public Widget2
* has an id.
*
* @param id The id to set to the widget.
- * @see getId, BasicContainer::findWidgetById
+ * @see getId
* @since 0.8.0
*/
void setId(const std::string& id)
@@ -983,7 +986,7 @@ class Widget : public Widget2
* has an id.
*
* @param id The id to set to the widget.
- * @see setId, BasicContainer::findWidgetById
+ * @see setId
* @since 0.8.0
*/
const std::string& getId() const A_WARN_UNUSED