diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/gui/connection.cpp | 31 | ||||
-rw-r--r-- | src/gui/connection.h | 13 |
3 files changed, 21 insertions, 25 deletions
@@ -1,6 +1,8 @@ 2007-10-22 Guillaume Melquiond <guillaume.melquiond@gmail.com> * src/particle.cpp: Plugged memory leak. + * src/gui/connection.cpp, src/gui/connection.h: Simplified code. + Plugged memory leak. 2007-10-21 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index 17b397ba..e7923b9a 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -23,8 +23,6 @@ #include "connection.h" -#include <guichan/actionlistener.hpp> - #include <guichan/widgets/label.hpp> #include "button.h" @@ -34,30 +32,12 @@ #include "../utils/gettext.h" -namespace { - struct ConnectionActionListener : public gcn::ActionListener - { - ConnectionActionListener(unsigned char previousState): - mPreviousState(previousState) {}; - - void action(const gcn::ActionEvent &event) { - state = mPreviousState; - } - - unsigned char mPreviousState; - }; -} - -ConnectionDialog::ConnectionDialog(unsigned char previousState): - Window("Info"), mProgress(0) +ConnectionDialog::ConnectionDialog(int previousState): + Window("Info"), mProgress(0), mPreviousState(previousState) { setContentSize(200, 100); - ConnectionActionListener *connectionListener = - new ConnectionActionListener(previousState); - - Button *cancelButton = new Button(_("Cancel"), "cancelButton", - connectionListener); + Button *cancelButton = new Button(_("Cancel"), "cancelButton", this); mProgressBar = new ProgressBar(0.0, 200 - 10, 20, 128, 128, 128); gcn::Label *label = new gcn::Label(_("Connecting...")); @@ -73,6 +53,11 @@ ConnectionDialog::ConnectionDialog(unsigned char previousState): setVisible(true); } +void ConnectionDialog::action(gcn::ActionEvent const &) +{ + state = mPreviousState; +} + void ConnectionDialog::logic() { mProgress += 0.005f; diff --git a/src/gui/connection.h b/src/gui/connection.h index 4b3187f6..51ad5467 100644 --- a/src/gui/connection.h +++ b/src/gui/connection.h @@ -24,6 +24,8 @@ #ifndef _TMW_CONNECTION_H #define _TMW_CONNECTION_H +#include <guichan/actionlistener.hpp> + #include "window.h" class ProgressBar; @@ -33,7 +35,7 @@ class ProgressBar; * * \ingroup Interface */ -class ConnectionDialog : public Window +class ConnectionDialog : public Window, gcn::ActionListener { public: /** @@ -41,13 +43,20 @@ class ConnectionDialog : public Window * * @see Window::Window */ - ConnectionDialog(unsigned char previousState); + ConnectionDialog(int previousState); + + /** + * Called when the user presses Cancel. Restores the global state to + * the previous one. + */ + void action(gcn::ActionEvent const &); void logic(); private: ProgressBar *mProgressBar; float mProgress; + int mPreviousState; }; #endif |