summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/Makefile.am4
-rw-r--r--src/gui/base/basiccontainer.cpp384
-rw-r--r--src/gui/base/widgets/container.hpp2
-rw-r--r--src/gui/base/widgets/scrollarea.cpp6
-rw-r--r--src/gui/base/widgets/scrollarea.hpp3
-rw-r--r--src/gui/widgets/basiccontainer.cpp377
-rw-r--r--src/gui/widgets/basiccontainer.h (renamed from src/gui/base/basiccontainer.hpp)135
-rw-r--r--src/gui/widgets/dropdown.cpp2
-rw-r--r--src/gui/widgets/dropdown.h4
-rw-r--r--src/gui/widgets/tabbedarea.cpp4
-rw-r--r--src/gui/widgets/tabbedarea.h2
-rw-r--r--src/gui/widgets/tabs/tab.cpp2
-rw-r--r--src/gui/widgets/tabs/tab.h4
14 files changed, 462 insertions, 471 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 054ab4823..8b4a052cf 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -790,7 +790,7 @@ SET(SRCS
walklayer.h
events/actionevent.h
listeners/actionlistener.h
- gui/base/basiccontainer.hpp
+ gui/widgets/basiccontainer.h
gui/cliprect.h
gui/color.h
listeners/deathlistener.h
@@ -821,7 +821,7 @@ SET(SRCS
gui/base/widgets/slider.hpp
gui/base/widgets/textbox.hpp
gui/base/widgets/textfield.hpp
- gui/base/basiccontainer.cpp
+ gui/widgets/basiccontainer.cpp
gui/cliprect.cpp
gui/color.cpp
gui/base/gui.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 2b1eb4c68..1e372d667 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -152,7 +152,7 @@ endif
manaplus_SOURCES += events/actionevent.h \
listeners/actionlistener.h \
- gui/base/basiccontainer.hpp \
+ gui/widgets/basiccontainer.h \
gui/cliprect.h \
gui/color.h \
listeners/deathlistener.h \
@@ -184,7 +184,7 @@ manaplus_SOURCES += events/actionevent.h \
gui/base/widgets/slider.hpp \
gui/base/widgets/textbox.hpp \
gui/base/widgets/textfield.hpp \
- gui/base/basiccontainer.cpp \
+ gui/widgets/basiccontainer.cpp \
gui/cliprect.cpp \
gui/color.cpp \
gui/base/gui.cpp \
diff --git a/src/gui/base/basiccontainer.cpp b/src/gui/base/basiccontainer.cpp
deleted file mode 100644
index f323366ad..000000000
--- a/src/gui/base/basiccontainer.cpp
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * The ManaPlus Client
- * 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/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * For comments regarding functions please see the header file.
- */
-
-#include "gui/base/basiccontainer.hpp"
-
-#include <algorithm>
-
-#include "debug.h"
-
-namespace gcn
-{
- BasicContainer::~BasicContainer()
- {
- clear();
- }
-
- void BasicContainer::moveToTop(Widget* widget)
- {
- for (WidgetListIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- if (*iter == widget)
- {
- mWidgets.erase(iter);
- mWidgets.push_back(widget);
- return;
- }
- }
- }
-
- void BasicContainer::moveToBottom(Widget* widget)
- {
- WidgetListIterator iter;
- iter = std::find(mWidgets.begin(), mWidgets.end(), widget);
-
- if (iter == mWidgets.end())
- return;
-
- mWidgets.erase(iter);
- mWidgets.insert(mWidgets.begin(), widget);
- }
-
- void BasicContainer::death(const Event& event)
- {
- WidgetListIterator iter;
- iter = std::find(mWidgets.begin(), mWidgets.end(), event.getSource());
-
- if (iter == mWidgets.end())
- return;
-
- mWidgets.erase(iter);
- }
-
- Rect BasicContainer::getChildrenArea()
- {
- return Rect(0, 0, getWidth(), getHeight());
- }
-
- void BasicContainer::focusNext()
- {
- WidgetListConstIterator it;
-
- for (it = mWidgets.begin(); it != mWidgets.end(); ++ it)
- {
- if ((*it)->isFocused())
- break;
- }
-
- WidgetListConstIterator end = it;
-
- if (it == mWidgets.end())
- it = mWidgets.begin();
-
- ++ it;
-
- for ( ; it != end; ++ it)
- {
- if (it == mWidgets.end())
- it = mWidgets.begin();
-
- if ((*it)->isFocusable())
- {
- (*it)->requestFocus();
- return;
- }
- }
- }
-
- void BasicContainer::focusPrevious()
- {
- WidgetListReverseIterator it;
-
- for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it)
- {
- if ((*it)->isFocused())
- break;
- }
-
- const WidgetListReverseIterator end = it;
-
- ++ it;
-
- if (it == mWidgets.rend())
- it = mWidgets.rbegin();
-
- for ( ; it != end; ++ it)
- {
- if (it == mWidgets.rend())
- it = mWidgets.rbegin();
-
- if ((*it)->isFocusable())
- {
- (*it)->requestFocus();
- return;
- }
- }
- }
-
- Widget *BasicContainer::getWidgetAt(int x, int y)
- {
- const Rect r = getChildrenArea();
-
- if (!r.isPointInRect(x, y))
- return nullptr;
-
- x -= r.x;
- y -= r.y;
-
- for (WidgetListReverseIterator it = mWidgets.rbegin();
- it != mWidgets.rend(); ++ it)
- {
- if ((*it)->isVisible() && (*it)->getDimension()
- .isPointInRect(x, y))
- {
- return (*it);
- }
- }
-
- return nullptr;
- }
-
- void BasicContainer::logic()
- {
- BLOCK_START("BasicContainer::logic")
- logicChildren();
- BLOCK_END("BasicContainer::logic")
- }
-
- void BasicContainer::_setFocusHandler(FocusHandler* focusHandler)
- {
- Widget::_setFocusHandler(focusHandler);
-
- if (mInternalFocusHandler)
- return;
-
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- (*iter)->_setFocusHandler(focusHandler);
- }
- }
-
- void BasicContainer::add(Widget* widget)
- {
- mWidgets.push_back(widget);
-
- if (!mInternalFocusHandler)
- widget->_setFocusHandler(_getFocusHandler());
- else
- widget->_setFocusHandler(mInternalFocusHandler);
-
- widget->_setParent(this);
- widget->addDeathListener(this);
- }
-
- void BasicContainer::remove(Widget* widget)
- {
- for (WidgetListIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- if (*iter == widget)
- {
- mWidgets.erase(iter);
- widget->_setFocusHandler(nullptr);
- widget->_setParent(nullptr);
- widget->removeDeathListener(this);
- return;
- }
- }
- }
-
- void BasicContainer::clear()
- {
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- (*iter)->_setFocusHandler(nullptr);
- (*iter)->_setParent(nullptr);
- (*iter)->removeDeathListener(this);
- }
-
- mWidgets.clear();
- }
-
- void BasicContainer::drawChildren(Graphics* graphics)
- {
- BLOCK_START("BasicContainer::drawChildren")
-
- graphics->pushClipArea(getChildrenArea());
-
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- Widget *const widget = *iter;
- if (widget->isVisible())
- {
- // If the widget has a frame,
- // draw it before drawing the widget
- if (widget->getFrameSize() > 0)
- {
- Rect rec = widget->getDimension();
- const int frame = widget->getFrameSize();
- const int frame2 = frame * 2;
- rec.x -= frame;
- rec.y -= frame;
- rec.width += frame2;
- rec.height += frame2;
- graphics->pushClipArea(rec);
- BLOCK_START("BasicContainer::drawChildren 1")
- widget->drawFrame(graphics);
- BLOCK_END("BasicContainer::drawChildren 1")
- graphics->popClipArea();
- }
-
- graphics->pushClipArea(widget->getDimension());
- BLOCK_START("BasicContainer::drawChildren 2")
- widget->draw(graphics);
- BLOCK_END("BasicContainer::drawChildren 2")
- graphics->popClipArea();
- }
- }
-
- graphics->popClipArea();
- BLOCK_END("BasicContainer::drawChildren")
- }
-
- void BasicContainer::logicChildren()
- {
- BLOCK_START("BasicContainer::logicChildren")
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- (*iter)->logic();
- }
- BLOCK_END("BasicContainer::logicChildren")
- }
-
- void BasicContainer::showWidgetPart(Widget* widget, Rect area)
- {
- const Rect widgetArea = getChildrenArea();
-
- area.x += widget->getX();
- area.y += widget->getY();
-
- if (area.x + area.width > widgetArea.width)
- {
- widget->setX(widget->getX() - area.x
- - area.width + widgetArea.width);
- }
-
- if (area.y + area.height > widgetArea.height)
- {
- widget->setY(widget->getY() - area.y
- - area.height + widgetArea.height);
- }
-
- if (area.x < 0)
- widget->setX(widget->getX() - area.x);
-
- if (area.y < 0)
- widget->setY(widget->getY() - area.y);
- }
-
- void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler)
- {
- Widget::setInternalFocusHandler(focusHandler);
-
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- if (!mInternalFocusHandler)
- (*iter)->_setFocusHandler(_getFocusHandler());
- else
- (*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;
- }
-} // namespace gcn
diff --git a/src/gui/base/widgets/container.hpp b/src/gui/base/widgets/container.hpp
index 3e6c0a587..37984bbc9 100644
--- a/src/gui/base/widgets/container.hpp
+++ b/src/gui/base/widgets/container.hpp
@@ -64,7 +64,7 @@
#ifndef GCN_CONTAINER_HPP
#define GCN_CONTAINER_HPP
-#include "gui/base/basiccontainer.hpp"
+#include "gui/widgets/basiccontainer.h"
namespace gcn
{
diff --git a/src/gui/base/widgets/scrollarea.cpp b/src/gui/base/widgets/scrollarea.cpp
index 665830ce4..3c830c239 100644
--- a/src/gui/base/widgets/scrollarea.cpp
+++ b/src/gui/base/widgets/scrollarea.cpp
@@ -72,7 +72,7 @@
namespace gcn
{
ScrollArea::ScrollArea(const Widget2 *const widget) :
- gcn::BasicContainer(widget),
+ BasicContainer(widget),
MouseListener(),
mVScroll(0),
mHScroll(0),
@@ -100,7 +100,7 @@ namespace gcn
ScrollArea::ScrollArea(const Widget2 *const widget,
Widget *const content) :
- gcn::BasicContainer(widget),
+ BasicContainer(widget),
MouseListener(),
mVScroll(0),
mHScroll(0),
@@ -131,7 +131,7 @@ namespace gcn
Widget *content,
ScrollPolicy hPolicy,
ScrollPolicy vPolicy) :
- gcn::BasicContainer(widget),
+ BasicContainer(widget),
MouseListener(),
mVScroll(0),
mHScroll(0),
diff --git a/src/gui/base/widgets/scrollarea.hpp b/src/gui/base/widgets/scrollarea.hpp
index 879792019..624debc35 100644
--- a/src/gui/base/widgets/scrollarea.hpp
+++ b/src/gui/base/widgets/scrollarea.hpp
@@ -64,7 +64,8 @@
#ifndef GCN_SCROLLAREA_HPP
#define GCN_SCROLLAREA_HPP
-#include "gui/base/basiccontainer.hpp"
+#include "gui/widgets/basiccontainer.h"
+
#include "listeners/mouselistener.h"
namespace gcn
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp
new file mode 100644
index 000000000..48ab683be
--- /dev/null
+++ b/src/gui/widgets/basiccontainer.cpp
@@ -0,0 +1,377 @@
+/*
+ * The ManaPlus Client
+ * 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/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
+ *
+ *
+ * Per Larsson a.k.a finalman
+ * Olof Naessén a.k.a jansem/yakslem
+ *
+ * Visit: http://guichan.sourceforge.net
+ *
+ * License: (BSD)
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of Guichan nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gui/widgets/basiccontainer.h"
+
+#include <algorithm>
+
+#include "debug.h"
+
+BasicContainer::~BasicContainer()
+{
+ clear();
+}
+
+void BasicContainer::moveToTop(Widget* widget)
+{
+ for (WidgetListIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ if (*iter == widget)
+ {
+ mWidgets.erase(iter);
+ mWidgets.push_back(widget);
+ return;
+ }
+ }
+}
+
+void BasicContainer::moveToBottom(Widget* widget)
+{
+ WidgetListIterator iter;
+ iter = std::find(mWidgets.begin(), mWidgets.end(), widget);
+
+ if (iter == mWidgets.end())
+ return;
+
+ mWidgets.erase(iter);
+ mWidgets.insert(mWidgets.begin(), widget);
+}
+
+void BasicContainer::death(const Event& event)
+{
+ WidgetListIterator iter;
+ iter = std::find(mWidgets.begin(), mWidgets.end(), event.getSource());
+
+ if (iter == mWidgets.end())
+ return;
+
+ mWidgets.erase(iter);
+}
+
+Rect BasicContainer::getChildrenArea()
+{
+ return Rect(0, 0, getWidth(), getHeight());
+}
+
+void BasicContainer::focusNext()
+{
+ WidgetListConstIterator it;
+
+ for (it = mWidgets.begin(); it != mWidgets.end(); ++ it)
+ {
+ if ((*it)->isFocused())
+ break;
+ }
+
+ WidgetListConstIterator end = it;
+
+ if (it == mWidgets.end())
+ it = mWidgets.begin();
+
+ ++ it;
+
+ for ( ; it != end; ++ it)
+ {
+ if (it == mWidgets.end())
+ it = mWidgets.begin();
+
+ if ((*it)->isFocusable())
+ {
+ (*it)->requestFocus();
+ return;
+ }
+ }
+}
+
+void BasicContainer::focusPrevious()
+{
+ WidgetListReverseIterator it;
+
+ for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it)
+ {
+ if ((*it)->isFocused())
+ break;
+ }
+
+ const WidgetListReverseIterator end = it;
+
+ ++ it;
+
+ if (it == mWidgets.rend())
+ it = mWidgets.rbegin();
+
+ for ( ; it != end; ++ it)
+ {
+ if (it == mWidgets.rend())
+ it = mWidgets.rbegin();
+
+ if ((*it)->isFocusable())
+ {
+ (*it)->requestFocus();
+ return;
+ }
+ }
+}
+
+Widget *BasicContainer::getWidgetAt(int x, int y)
+{
+ const Rect r = getChildrenArea();
+
+ if (!r.isPointInRect(x, y))
+ return nullptr;
+
+ x -= r.x;
+ y -= r.y;
+
+ for (WidgetListReverseIterator it = mWidgets.rbegin();
+ it != mWidgets.rend(); ++ it)
+ {
+ if ((*it)->isVisible() && (*it)->getDimension()
+ .isPointInRect(x, y))
+ {
+ return (*it);
+ }
+ }
+
+ return nullptr;
+}
+
+void BasicContainer::logic()
+{
+ BLOCK_START("BasicContainer::logic")
+ logicChildren();
+ BLOCK_END("BasicContainer::logic")
+}
+
+void BasicContainer::_setFocusHandler(FocusHandler* focusHandler)
+{
+ Widget::_setFocusHandler(focusHandler);
+
+ if (mInternalFocusHandler)
+ return;
+
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ (*iter)->_setFocusHandler(focusHandler);
+ }
+}
+
+void BasicContainer::add(Widget* widget)
+{
+ mWidgets.push_back(widget);
+
+ if (!mInternalFocusHandler)
+ widget->_setFocusHandler(_getFocusHandler());
+ else
+ widget->_setFocusHandler(mInternalFocusHandler);
+
+ widget->_setParent(this);
+ widget->addDeathListener(this);
+}
+
+void BasicContainer::remove(Widget* widget)
+{
+ for (WidgetListIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ if (*iter == widget)
+ {
+ mWidgets.erase(iter);
+ widget->_setFocusHandler(nullptr);
+ widget->_setParent(nullptr);
+ widget->removeDeathListener(this);
+ return;
+ }
+ }
+}
+
+void BasicContainer::clear()
+{
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ (*iter)->_setFocusHandler(nullptr);
+ (*iter)->_setParent(nullptr);
+ (*iter)->removeDeathListener(this);
+ }
+
+ mWidgets.clear();
+}
+
+void BasicContainer::drawChildren(Graphics* graphics)
+{
+ BLOCK_START("BasicContainer::drawChildren")
+
+ graphics->pushClipArea(getChildrenArea());
+
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ Widget *const widget = *iter;
+ if (widget->isVisible())
+ {
+ // If the widget has a frame,
+ // draw it before drawing the widget
+ if (widget->getFrameSize() > 0)
+ {
+ Rect rec = widget->getDimension();
+ const int frame = widget->getFrameSize();
+ const int frame2 = frame * 2;
+ rec.x -= frame;
+ rec.y -= frame;
+ rec.width += frame2;
+ rec.height += frame2;
+ graphics->pushClipArea(rec);
+ BLOCK_START("BasicContainer::drawChildren 1")
+ widget->drawFrame(graphics);
+ BLOCK_END("BasicContainer::drawChildren 1")
+ graphics->popClipArea();
+ }
+
+ graphics->pushClipArea(widget->getDimension());
+ BLOCK_START("BasicContainer::drawChildren 2")
+ widget->draw(graphics);
+ BLOCK_END("BasicContainer::drawChildren 2")
+ graphics->popClipArea();
+ }
+ }
+
+ graphics->popClipArea();
+ BLOCK_END("BasicContainer::drawChildren")
+}
+
+void BasicContainer::logicChildren()
+{
+ BLOCK_START("BasicContainer::logicChildren")
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ (*iter)->logic();
+ }
+ BLOCK_END("BasicContainer::logicChildren")
+}
+
+void BasicContainer::showWidgetPart(Widget* widget, Rect area)
+{
+ const Rect widgetArea = getChildrenArea();
+
+ area.x += widget->getX();
+ area.y += widget->getY();
+
+ if (area.x + area.width > widgetArea.width)
+ {
+ widget->setX(widget->getX() - area.x
+ - area.width + widgetArea.width);
+ }
+
+ if (area.y + area.height > widgetArea.height)
+ {
+ widget->setY(widget->getY() - area.y
+ - area.height + widgetArea.height);
+ }
+
+ if (area.x < 0)
+ widget->setX(widget->getX() - area.x);
+
+ if (area.y < 0)
+ widget->setY(widget->getY() - area.y);
+}
+
+void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler)
+{
+ Widget::setInternalFocusHandler(focusHandler);
+
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ if (!mInternalFocusHandler)
+ (*iter)->_setFocusHandler(_getFocusHandler());
+ else
+ (*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/base/basiccontainer.hpp b/src/gui/widgets/basiccontainer.h
index e1947c652..240e9375f 100644
--- a/src/gui/base/basiccontainer.hpp
+++ b/src/gui/widgets/basiccontainer.h
@@ -70,19 +70,17 @@
#include "listeners/deathlistener.h"
-namespace gcn
+/**
+ * A base class for containers. The class implements the most
+ * common things for a container. If you are implementing a
+ * container, consider inheriting from this class.
+ *
+ * @see Container
+ * @since 0.6.0
+ */
+class BasicContainer : public Widget,
+ public DeathListener
{
- /**
- * A base class for containers. The class implements the most
- * common things for a container. If you are implementing a
- * container, consider inheriting from this class.
- *
- * @see Container
- * @since 0.6.0
- */
- class BasicContainer : public Widget,
- public DeathListener
- {
public:
explicit BasicContainer(const Widget2 *const widget) :
Widget(widget),
@@ -93,21 +91,21 @@ namespace gcn
A_DELETE_COPY(BasicContainer)
/**
- * Destructor
- */
+ * Destructor
+ */
virtual ~BasicContainer();
/**
- * Shows a certain part of a widget in the basic container.
- * Used when widgets want a specific part to be visible in
- * its parent. An example is a TextArea that wants a specific
- * part of its text to be visible when a TextArea is a child
- * of a ScrollArea.
- *
- * @param widget The widget whom wants a specific part of
- * itself to be visible.
- * @param rectangle The rectangle to be visible.
- */
+ * Shows a certain part of a widget in the basic container.
+ * Used when widgets want a specific part to be visible in
+ * its parent. An example is a TextArea that wants a specific
+ * part of its text to be visible when a TextArea is a child
+ * of a ScrollArea.
+ *
+ * @param widget The widget whom wants a specific part of
+ * itself to be visible.
+ * @param rectangle The rectangle to be visible.
+ */
virtual void showWidgetPart(Widget* widget, Rect area);
// Inherited from Widget
@@ -137,82 +135,81 @@ namespace gcn
protected:
/**
- * Adds a widget to the basic container.
- *
- * @param widget The widget to add.
- * @see remove, clear
- */
+ * Adds a widget to the basic container.
+ *
+ * @param widget The widget to add.
+ * @see remove, clear
+ */
void add(Widget* widget);
/**
- * Removes a widget from the basic container.
- *
- * @param widget The widget to remove.
- * @see add, clear
- */
+ * Removes a widget from the basic container.
+ *
+ * @param widget The widget to remove.
+ * @see add, clear
+ */
virtual void remove(Widget* widget);
/**
- * Clears the basic container from all widgets.
- *
- * @see remove, clear
- */
+ * Clears the basic container from all widgets.
+ *
+ * @see remove, clear
+ */
virtual void clear();
/**
- * Draws the children widgets of the basic container.
- *
- * @param graphics A graphics object to draw with.
- */
+ * Draws the children widgets of the basic container.
+ *
+ * @param graphics A graphics object to draw with.
+ */
virtual void drawChildren(Graphics* graphics);
/**
- * Calls logic for the children widgets of the basic
- * container.
- */
+ * Calls logic for the children widgets of the basic
+ * container.
+ */
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.
- */
+ * 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.
+ */
typedef std::vector<Widget *> WidgetList;
- /**
- * Typedef.
- */
+ /**
+ * Typedef.
+ */
typedef WidgetList::iterator WidgetListIterator;
- /**
- * Typedef.
- */
+ /**
+ * Typedef.
+ */
typedef WidgetList::const_iterator WidgetListConstIterator;
/**
- * Typedef.
- */
+ * Typedef.
+ */
typedef WidgetList::reverse_iterator WidgetListReverseIterator;
/**
- * Typedef.
- */
+ * Typedef.
+ */
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator;
/**
- * Holds all widgets of the basic container.
- */
+ * Holds all widgets of the basic container.
+ */
WidgetList mWidgets;
- };
-} // namespace gcn
+};
#endif // end GCN_BASICCONTAINER_HPP
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index dfc17e17b..b1a3c4ac1 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -60,7 +60,7 @@ DropDown::DropDown(const Widget2 *const widget,
ActionListener *const listener,
const std::string &eventId):
ActionListener(),
- gcn::BasicContainer(widget),
+ BasicContainer(widget),
KeyListener(),
MouseListener(),
FocusListener(),
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
index 8e463a2c1..2208880b3 100644
--- a/src/gui/widgets/dropdown.h
+++ b/src/gui/widgets/dropdown.h
@@ -23,7 +23,7 @@
#ifndef GUI_WIDGETS_DROPDOWN_H
#define GUI_WIDGETS_DROPDOWN_H
-#include "gui/base/basiccontainer.hpp"
+#include "gui/widgets/basiccontainer.h"
#include "listeners/actionlistener.h"
#include "listeners/focuslistener.h"
@@ -46,7 +46,7 @@ class Skin;
* your list.
*/
class DropDown final : public ActionListener,
- public gcn::BasicContainer,
+ public BasicContainer,
public KeyListener,
public MouseListener,
public FocusListener,
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index d2bb24720..5d125cadd 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -81,7 +81,7 @@
TabbedArea::TabbedArea(const Widget2 *const widget) :
ActionListener(),
- gcn::BasicContainer(widget),
+ BasicContainer(widget),
KeyListener(),
MouseListener(),
WidgetListener(),
@@ -768,7 +768,7 @@ void TabbedArea::death(const Event &event)
if (tab)
removeTab(tab);
else
- gcn::BasicContainer::death(event);
+ BasicContainer::death(event);
}
void TabbedArea::selectNextTab()
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index dbaa4334b..11f3a46d3 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -82,7 +82,7 @@ class Tab;
* A tabbed area, the same as the guichan tabbed area in 0.8, but extended
*/
class TabbedArea final : public ActionListener,
- public gcn::BasicContainer,
+ public BasicContainer,
public KeyListener,
public MouseListener,
public WidgetListener
diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp
index 96ae76787..ede69619e 100644
--- a/src/gui/widgets/tabs/tab.cpp
+++ b/src/gui/widgets/tabs/tab.cpp
@@ -91,7 +91,7 @@ static std::string const data[Tab::TAB_COUNT] =
Skin *Tab::tabImg[Tab::TAB_COUNT];
Tab::Tab(const Widget2 *const widget) :
- gcn::BasicContainer(widget),
+ BasicContainer(widget),
MouseListener(),
WidgetListener(),
mLabel(new Label(this)),
diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h
index 1f52cde88..246d90650 100644
--- a/src/gui/widgets/tabs/tab.h
+++ b/src/gui/widgets/tabs/tab.h
@@ -66,7 +66,7 @@
#ifndef GUI_WIDGETS_TABS_TAB_H
#define GUI_WIDGETS_TABS_TAB_H
-#include "gui/base/basiccontainer.hpp"
+#include "gui/widgets/basiccontainer.h"
#include "listeners/mouselistener.h"
#include "listeners/widgetlistener.h"
@@ -81,7 +81,7 @@ class TabbedArea;
/**
* A tab, the same as the Guichan tab in 0.8, but extended
*/
-class Tab : public gcn::BasicContainer,
+class Tab : public BasicContainer,
public MouseListener,
public WidgetListener
{