summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-15 23:32:28 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-15 23:37:32 +0200
commitfe25bc152de747eb64a1c1f6084f0399faf125e8 (patch)
tree83746ebff16b87ad36c71908667ed1a81489ebe6
parentddd7f8acbbfbe7cf2787279babdb5c1279c7fd73 (diff)
downloadmana-client-fe25bc152de747eb64a1c1f6084f0399faf125e8.tar.gz
mana-client-fe25bc152de747eb64a1c1f6084f0399faf125e8.tar.bz2
mana-client-fe25bc152de747eb64a1c1f6084f0399faf125e8.tar.xz
mana-client-fe25bc152de747eb64a1c1f6084f0399faf125e8.zip
Have the DropDown create its ScrollArea and ListBox
And also clean them up again. Fixes some memory leaks and simplifies the code. Also got rid of the basically unused "opaque" setting of DropDown.
-rw-r--r--src/gui/login.cpp11
-rw-r--r--src/gui/login.h8
-rw-r--r--src/gui/serverdialog.cpp11
-rw-r--r--src/gui/serverdialog.h2
-rw-r--r--src/gui/setup_players.cpp9
-rw-r--r--src/gui/widgets/dropdown.cpp25
-rw-r--r--src/gui/widgets/dropdown.h35
7 files changed, 21 insertions, 80 deletions
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index d9f31b95..92c6050c 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -28,9 +28,7 @@
#include "gui/widgets/dropdown.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
-#include "gui/widgets/listbox.h"
#include "gui/widgets/passwordfield.h"
-#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textfield.h"
#include "main.h"
@@ -61,8 +59,6 @@ LoginDialog::LoginDialog(LoginData *loginData):
dfltPort.push_back("6901");
mServerList = new DropDownList("MostRecent00", dfltServer, dfltPort,
MAX_SERVER_LIST_SIZE);
- mServerListBox = new ListBox(mServerList);
- mServerScrollArea = new ScrollArea;
#endif
mUserField = new TextField(mLoginData->username);
@@ -70,10 +66,7 @@ LoginDialog::LoginDialog(LoginData *loginData):
#ifdef EATHENA_SUPPORT
mServerField = new TextField(mServerList->getServerAt(0));
mPortField = new TextField(mServerList->getPortAt(0));
- mServerDropDown = new DropDown(mServerList,
- mServerScrollArea,
- mServerListBox);
- mServerDropDown->setOpaque(false);
+ mServerDropDown = new DropDown(mServerList);
#endif
mKeepCheck = new CheckBox(_("Remember Username"), mLoginData->remember);
@@ -161,7 +154,7 @@ void LoginDialog::action(const gcn::ActionEvent &event)
#ifdef EATHENA_SUPPORT
else if (event.getId() == "changeSelection")
{
- int selected = mServerListBox->getSelected();
+ int selected = mServerDropDown->getSelected();
mServerField->setText(mServerList->getServerAt(selected));
mPortField->setText(mServerList->getPortAt(selected));
}
diff --git a/src/gui/login.h b/src/gui/login.h
index 398fe725..7224c64d 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -34,10 +34,6 @@
#include <vector>
class LoginData;
-#ifdef EATHENA_SUPPORT
-class DropDown;
-class ScrollArea;
-#endif
/**
* The login dialog.
@@ -97,7 +93,7 @@ class LoginDialog : public Window, public gcn::ActionListener,
#ifdef EATHENA_SUPPORT
gcn::TextField *mServerField;
gcn::TextField *mPortField;
- DropDown *mServerDropDown;
+ gcn::DropDown *mServerDropDown;
#endif
gcn::CheckBox *mKeepCheck;
gcn::Button *mOkButton;
@@ -132,8 +128,6 @@ class LoginDialog : public Window, public gcn::ActionListener,
std::string getPortAt(int i);
};
DropDownList *mServerList;
- gcn::ListBox *mServerListBox;
- gcn::ScrollArea *mServerScrollArea;
#endif
};
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 35bb2f50..9fb6b6a2 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -27,8 +27,6 @@
#include "gui/widgets/dropdown.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textfield.h"
#include "configuration.h"
@@ -99,11 +97,7 @@ ServerDialog::ServerDialog(LoginData *loginData):
}
}
- mMostUsedServersListBox = new ListBox(NULL);
- mMostUsedServersListBox->setListModel(mMostUsedServersListModel);
- mMostUsedServersScrollArea = new ScrollArea;
- mMostUsedServersDropDown = new DropDown(mMostUsedServersListModel,
- mMostUsedServersScrollArea, mMostUsedServersListBox);
+ mMostUsedServersDropDown = new DropDown(mMostUsedServersListModel);
mOkButton = new Button(_("Ok"), "connect", this);
mCancelButton = new Button(_("Cancel"), "cancel", this);
@@ -142,7 +136,6 @@ ServerDialog::ServerDialog(LoginData *loginData):
ServerDialog::~ServerDialog()
{
delete mMostUsedServersListModel;
- delete mMostUsedServersScrollArea;
}
void
@@ -157,7 +150,7 @@ ServerDialog::action(const gcn::ActionEvent &event)
{
// Change the textField Values according to new selection
Server myServer = mMostUsedServersListModel->getServer
- (mMostUsedServersListBox->getSelected());
+ (mMostUsedServersDropDown->getSelected());
mServerNameField->setText(myServer.serverName);
mPortField->setText(toString(myServer.port));
}
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index 0c75cede..93903c08 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -118,8 +118,6 @@ class ServerDialog : public Window, public gcn::ActionListener
gcn::Button *mCancelButton;
DropDown *mMostUsedServersDropDown;
- gcn::ListBox *mMostUsedServersListBox;
- gcn::ScrollArea *mMostUsedServersScrollArea;
ServersListModel *mMostUsedServersListModel;
LoginData *mLoginData;
diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp
index 9f084e60..e093a5b6 100644
--- a/src/gui/setup_players.cpp
+++ b/src/gui/setup_players.cpp
@@ -29,7 +29,6 @@
#include "gui/widgets/dropdown.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
#include "configuration.h"
@@ -141,10 +140,7 @@ public:
mWidgets.push_back(widget);
gcn::ListModel *playerRelation = new PlayerRelationListModel;
- gcn::DropDown *choicebox = new DropDown(playerRelation,
- new ScrollArea,
- new ListBox(playerRelation),
- false);
+ gcn::DropDown *choicebox = new DropDown(playerRelation);
choicebox->setSelected(player_relations.getRelation(name));
mWidgets.push_back(choicebox);
}
@@ -245,8 +241,7 @@ Setup_Players::Setup_Players():
mPlayerTitleTable->setBackgroundColor(gcn::Color(0xbf, 0xbf, 0xbf));
gcn::ListModel *ignoreChoices = new IgnoreChoicesListModel;
- mIgnoreActionChoicesBox = new DropDown(ignoreChoices, new ScrollArea,
- new ListBox(ignoreChoices), false);
+ mIgnoreActionChoicesBox = new DropDown(ignoreChoices);
for (int i = 0; i < COLUMNS_NR; i++)
{
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 8dabc3f9..b5a75093 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -41,10 +41,10 @@ Image *DropDown::buttons[2][2];
ImageRect DropDown::skin;
float DropDown::mAlpha = 1.0;
-DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea,
- gcn::ListBox *listBox, bool opacity):
- gcn::DropDown::DropDown(listModel, scrollArea, listBox),
- mOpaque(opacity)
+DropDown::DropDown(gcn::ListModel *listModel):
+ gcn::DropDown::DropDown(listModel,
+ new ScrollArea,
+ new ListBox(listModel))
{
setFrameSize(2);
@@ -108,6 +108,9 @@ DropDown::~DropDown()
for_each(skin.grid, skin.grid + 9, dtor<Image*>());
}
+
+ delete mScrollArea;
+ delete mListBox;
}
void DropDown::draw(gcn::Graphics* graphics)
@@ -134,7 +137,7 @@ void DropDown::draw(gcn::Graphics* graphics)
}
}
- const int alpha = (int)(mAlpha * 255.0f);
+ const int alpha = (int) (mAlpha * 255.0f);
gcn::Color faceColor = getBaseColor();
faceColor.a = alpha;
const gcn::Color* highlightColor = &guiPalette->getColor(Palette::HIGHLIGHT,
@@ -142,18 +145,10 @@ void DropDown::draw(gcn::Graphics* graphics)
gcn::Color shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
- if (mOpaque)
- {
- graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, alpha));
- graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h));
-
- graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha));
- }
-
- graphics->setFont(getFont());
-
if (mListBox->getListModel() && mListBox->getSelected() >= 0)
{
+ graphics->setFont(getFont());
+ graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha));
graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0);
}
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
index 601d55c8..83d43f63 100644
--- a/src/gui/widgets/dropdown.h
+++ b/src/gui/widgets/dropdown.h
@@ -28,11 +28,9 @@ class Image;
class ImageRect;
/**
- * A drop down box from which you can select different values. It is one of
- * the most complicated Widgets you will find in Guichan. For drawing the
- * DroppedDown box it uses one ScrollArea and one ListBox. It also uses an
- * internal FocusHandler to handle the focus of the internal ScollArea and
- * ListBox. DropDown uses a ListModel to handle the list. To be able to use
+ * A drop down box from which you can select different values.
+ *
+ * A ListModel provides the contents of the drop down. To be able to use
* DropDown you must give DropDown an implemented ListModel which represents
* your list.
*/
@@ -47,37 +45,14 @@ class DropDown : public gcn::DropDown
* @param listBox the listBox to use.
* @see ListModel, ScrollArea, ListBox.
*/
- DropDown(gcn::ListModel *listModel = NULL,
- gcn::ScrollArea *scrollArea = NULL,
- gcn::ListBox *listBox = NULL,
- bool opacity = true);
+ DropDown(gcn::ListModel *listModel = NULL);
- /**
- * Destructor.
- */
~DropDown();
void draw(gcn::Graphics *graphics);
void drawFrame(gcn::Graphics *graphics);
- /**
- * Sets the widget to be opaque, that is sets the widget to display its
- * background.
- *
- * @param opaque True if the widget should be opaque, false otherwise.
- */
- void setOpaque(bool opaque) { mOpaque = opaque; }
-
- /**
- * Checks if the widget is opaque, that is if the widget area displays
- * its background.
- *
- * @return True if the widget is opaque, false otherwise.
- */
- bool isOpaque() const { return mOpaque; }
-
-
protected:
/**
* Draws the button with the little down arrow.
@@ -91,8 +66,6 @@ class DropDown : public gcn::DropDown
static Image *buttons[2][2];
static ImageRect skin;
static float mAlpha;
-
- bool mOpaque;
};
#endif // end DROPDOWN_H