summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/popup.cpp23
-rw-r--r--src/gui/widgets/popup.h8
-rw-r--r--src/gui/widgets/window.cpp21
-rw-r--r--src/gui/widgets/window.h6
-rw-r--r--src/gui/widgets/windowcontainer.cpp39
-rw-r--r--src/gui/widgets/windowcontainer.h59
6 files changed, 144 insertions, 12 deletions
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index 1bfd7fd2..970b21ec 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -29,6 +29,8 @@
#include "gui/skin.h"
#include "gui/viewport.h"
+#include "gui/widgets/windowcontainer.h"
+
#include "resources/image.h"
#include <guichan/exception.hpp>
@@ -43,16 +45,16 @@ Popup::Popup(const std::string &name, const std::string &skin):
{
logger->log("Popup::Popup(\"%s\")", name.c_str());
- if (!viewport)
- throw GCN_EXCEPTION("Popup::Popup(): no viewport set");
+ if (!windowContainer)
+ throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set");
setPadding(3);
// Loads the skin
mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath);
- // Add this window to the viewport
- viewport->add(this);
+ // Add this window to the window container
+ windowContainer->add(this);
// Popups are invisible by default
setVisible(false);
@@ -67,6 +69,11 @@ Popup::~Popup()
mSkin->instances--;
}
+void Popup::setWindowContainer(WindowContainer *wc)
+{
+ windowContainer = wc;
+}
+
void Popup::loadPopupConfiguration()
{
if (mPopupName.empty())
@@ -161,7 +168,7 @@ void Popup::setMaxHeight(int height)
void Popup::scheduleDelete()
{
- viewport->scheduleDelete(this);
+ windowContainer->scheduleDelete(this);
}
void Popup::position(int x, int y)
@@ -180,3 +187,9 @@ void Popup::position(int x, int y)
setVisible(true);
requestMoveToTop();
}
+
+void Popup::mouseMoved(gcn::MouseEvent &event)
+{
+ if (viewport)
+ viewport->hideBeingPopup();
+}
diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h
index dfa9b2fa..5c9164f6 100644
--- a/src/gui/widgets/popup.h
+++ b/src/gui/widgets/popup.h
@@ -31,6 +31,7 @@
#include <guichan/mouselistener.hpp>
class Skin;
+class WindowContainer;
/**
* A light version of the Window class. Particularly suited for popup type
@@ -64,6 +65,11 @@ class Popup : public Container, public gcn::MouseListener
~Popup();
/**
+ * Sets the window container to be used by new popups.
+ */
+ static void setWindowContainer(WindowContainer *windowContainer);
+
+ /**
* Changes the popup's skin to use the skin defined in the saved
* configuration file.
*/
@@ -90,6 +96,8 @@ class Popup : public Container, public gcn::MouseListener
*/
void setLocationRelativeTo(gcn::Widget *widget);
+ void mouseMoved(gcn::MouseEvent &event);
+
/**
* Sets the minimum width of the popup.
*/
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 4d70df84..83c918cf 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -31,6 +31,7 @@
#include "gui/widgets/layout.h"
#include "gui/widgets/resizegrip.h"
+#include "gui/widgets/windowcontainer.h"
#include "resources/image.h"
@@ -62,8 +63,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
{
logger->log("Window::Window(\"%s\")", caption.c_str());
- if (!viewport)
- throw GCN_EXCEPTION("Window::Window(): no viewport set");
+ if (!windowContainer)
+ throw GCN_EXCEPTION("Window::Window(): no windowContainer set");
instances++;
@@ -74,8 +75,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
// Loads the skin
mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath);
- // Add this window to the viewport
- viewport->add(this);
+ // Add this window to the window container
+ windowContainer->add(this);
if (mModal)
{
@@ -87,8 +88,6 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
setVisible(false);
addWidgetListener(this);
-
- setFocusable(true);
}
Window::~Window()
@@ -109,6 +108,11 @@ Window::~Window()
mSkin->instances--;
}
+void Window::setWindowContainer(WindowContainer *wc)
+{
+ windowContainer = wc;
+}
+
void Window::draw(gcn::Graphics *graphics)
{
Graphics *g = static_cast<Graphics*>(graphics);
@@ -332,7 +336,7 @@ void Window::setVisible(bool visible, bool forceSticky)
void Window::scheduleDelete()
{
- viewport->scheduleDelete(this);
+ windowContainer->scheduleDelete(this);
}
void Window::mousePressed(gcn::MouseEvent &event)
@@ -427,6 +431,9 @@ void Window::mouseMoved(gcn::MouseEvent &event)
default:
gui->setCursorType(Gui::CURSOR_POINTER);
}
+
+ if (viewport)
+ viewport->hideBeingPopup();
}
void Window::mouseDragged(gcn::MouseEvent &event)
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index 3c458efe..b72be9d4 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -34,6 +34,7 @@ class Layout;
class LayoutCell;
class ResizeGrip;
class Skin;
+class WindowContainer;
/**
* A window. This window can be dragged around and has a title bar. Windows are
@@ -64,6 +65,11 @@ class Window : public gcn::Window, gcn::WidgetListener
~Window();
/**
+ * Sets the window container to be used by new windows.
+ */
+ static void setWindowContainer(WindowContainer *windowContainer);
+
+ /**
* Draws the window.
*/
void draw(gcn::Graphics *graphics);
diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp
new file mode 100644
index 00000000..7d5ecd37
--- /dev/null
+++ b/src/gui/widgets/windowcontainer.cpp
@@ -0,0 +1,39 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ *
+ * This file is part of The Mana 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/windowcontainer.h"
+
+#include "utils/dtor.h"
+
+WindowContainer *windowContainer = NULL;
+
+void WindowContainer::logic()
+{
+ delete_all(mDeathList);
+ mDeathList.clear();
+
+ gcn::Container::logic();
+}
+
+void WindowContainer::scheduleDelete(gcn::Widget *widget)
+{
+ mDeathList.push_back(widget);
+}
diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h
new file mode 100644
index 00000000..2ec65d15
--- /dev/null
+++ b/src/gui/widgets/windowcontainer.h
@@ -0,0 +1,59 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ *
+ * This file is part of The Mana 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 WINDOWCONTAINER_H
+#define WINDOWCONTAINER_H
+
+#include "gui/widgets/container.h"
+
+/**
+ * A window container. This container adds functionality for more convenient
+ * widget (windows in particular) destruction.
+ *
+ * \ingroup GUI
+ */
+class WindowContainer : public Container
+{
+ public:
+ /**
+ * Do GUI logic. This functions adds automatic deletion of objects that
+ * volunteered to be deleted.
+ */
+ void logic();
+
+ /**
+ * Schedule a widget for deletion. It will be deleted at the start of
+ * the next logic update.
+ */
+ void scheduleDelete(gcn::Widget *widget);
+
+ private:
+ /**
+ * List of widgets that are scheduled to be deleted.
+ */
+ typedef std::list<gcn::Widget*> Widgets;
+ typedef Widgets::iterator WidgetIterator;
+ Widgets mDeathList;
+};
+
+extern WindowContainer *windowContainer;
+
+#endif