summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-20 11:33:17 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-20 11:33:17 +0000
commitce2813cb1f4988669422c6af3e8c4442776e45c8 (patch)
tree098177c279f5376bd27d4db30f913f6e61471537 /src/gui
parent5acb9213cc2ee949a252a5c08a9a9a13542b94d5 (diff)
downloadmana-ce2813cb1f4988669422c6af3e8c4442776e45c8.tar.gz
mana-ce2813cb1f4988669422c6af3e8c4442776e45c8.tar.bz2
mana-ce2813cb1f4988669422c6af3e8c4442776e45c8.tar.xz
mana-ce2813cb1f4988669422c6af3e8c4442776e45c8.zip
Added garbage collection to the ScrollArea class. Fixed slider not being updated in the item amount box when the buttons are used.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/buddywindow.cpp21
-rw-r--r--src/gui/buddywindow.h11
-rw-r--r--src/gui/buy.cpp5
-rw-r--r--src/gui/buy.h7
-rw-r--r--src/gui/char_select.cpp15
-rw-r--r--src/gui/char_select.h5
-rw-r--r--src/gui/char_server.cpp1
-rw-r--r--src/gui/chat.cpp2
-rw-r--r--src/gui/help.cpp7
-rw-r--r--src/gui/help.h8
-rw-r--r--src/gui/inventorywindow.cpp5
-rw-r--r--src/gui/inventorywindow.h5
-rw-r--r--src/gui/item_amount.cpp10
-rw-r--r--src/gui/npc.cpp37
-rw-r--r--src/gui/npc.h12
-rw-r--r--src/gui/npc_text.cpp5
-rw-r--r--src/gui/npc_text.h5
-rw-r--r--src/gui/scrollarea.cpp15
-rw-r--r--src/gui/scrollarea.h5
-rw-r--r--src/gui/sell.cpp5
-rw-r--r--src/gui/sell.h5
-rw-r--r--src/gui/setup.cpp1
-rw-r--r--src/gui/skill.cpp10
-rw-r--r--src/gui/trade.cpp3
-rw-r--r--src/gui/updatewindow.cpp1
25 files changed, 50 insertions, 156 deletions
diff --git a/src/gui/buddywindow.cpp b/src/gui/buddywindow.cpp
index 8d4c246e..c37f2a6d 100644
--- a/src/gui/buddywindow.cpp
+++ b/src/gui/buddywindow.cpp
@@ -36,23 +36,23 @@ BuddyWindow::BuddyWindow():
{
setContentSize(124, 202);
- listbox = new gcn::ListBox();
- listbox->setListModel(this);
+ mListbox = new gcn::ListBox();
+ mListbox->setListModel(this);
- scrollArea = new ScrollArea(listbox);
+ ScrollArea *scrollArea = new ScrollArea(mListbox);
scrollArea->setDimension(gcn::Rectangle(
7, 5, 110, 170));
add(scrollArea);
- talk = new Button("Talk");
+ Button *talk = new Button("Talk");
talk->setPosition(2,180);
talk->addActionListener(this);
talk->setEventId("Talk");
- remove = new Button("Remove");
+ Button *remove = new Button("Remove");
remove->addActionListener(this);
remove->setEventId("Remove");
remove->setPosition(talk->getWidth()+2,180);
- cancel = new Button("Cancel");
+ Button *cancel = new Button("Cancel");
cancel->addActionListener(this);
cancel->setEventId("Cancel");
cancel->setPosition(talk->getWidth()+remove->getWidth()+2,180);
@@ -62,15 +62,10 @@ BuddyWindow::BuddyWindow():
add(cancel);
}
-BuddyWindow::~BuddyWindow()
-{
- delete listbox;
-}
-
void BuddyWindow::action(const std::string& eventId)
{
if (eventId == "Talk") {
- int selected = listbox->getSelected();
+ int selected = mListbox->getSelected();
if ( selected > -1 )
{
std::string who = getElementAt(selected);
@@ -78,7 +73,7 @@ void BuddyWindow::action(const std::string& eventId)
}
}
else if (eventId == "Remove") {
- int selected = listbox->getSelected();
+ int selected = mListbox->getSelected();
if ( selected > -1 )
{
std::string who = getElementAt(selected);
diff --git a/src/gui/buddywindow.h b/src/gui/buddywindow.h
index 32dd2da2..82ef9935 100644
--- a/src/gui/buddywindow.h
+++ b/src/gui/buddywindow.h
@@ -47,21 +47,12 @@ class BuddyWindow : public Window, public BuddyList,
BuddyWindow();
/**
- * Destructor
- */
- ~BuddyWindow();
-
- /**
* Performs action.
*/
void action(const std::string &actionId);
private:
- gcn::ListBox *listbox;
- gcn::ScrollArea *scrollArea;
- gcn::Button *talk;
- gcn::Button *remove;
- gcn::Button *cancel;
+ gcn::ListBox *mListbox;
};
#endif /* _TMW_BUDDYWINDOW_H */
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 4414a755..1c0b2ea7 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -114,11 +114,6 @@ BuyDialog::BuyDialog():
setLocationRelativeTo(getParent());
}
-BuyDialog::~BuyDialog()
-{
- delete itemList;
-}
-
void BuyDialog::setMoney(int amount)
{
m_money = amount;
diff --git a/src/gui/buy.h b/src/gui/buy.h
index 341989c9..7e9ef069 100644
--- a/src/gui/buy.h
+++ b/src/gui/buy.h
@@ -51,11 +51,6 @@ class BuyDialog : public Window, public gcn::ActionListener,
BuyDialog();
/**
- * Destructor.
- */
- ~BuyDialog();
-
- /**
* Resets the dialog, clearing shop inventory.
*/
void reset();
@@ -110,6 +105,4 @@ class BuyDialog : public Window, public gcn::ActionListener,
int m_maxItems;
};
-extern BuyDialog *buyDialog;
-
#endif
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 0123251b..86e2b12f 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -347,21 +347,6 @@ CharCreateDialog::CharCreateDialog(Window *parent):
setLocationRelativeTo(getParent());
}
-CharCreateDialog::~CharCreateDialog()
-{
- delete nameField;
- delete nameLabel;
- delete nextHairColorButton;
- delete prevHairColorButton;
- delete hairColorLabel;
- delete nextHairStyleButton;
- delete prevHairStyleButton;
- delete hairStyleLabel;
- delete createButton;
- delete cancelButton;
- delete playerBox;
-}
-
void CharCreateDialog::action(const std::string& eventId)
{
if (eventId == "create") {
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index d36904d3..a85bb28c 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -102,11 +102,6 @@ class CharCreateDialog : public Window, public gcn::ActionListener
*/
CharCreateDialog(Window *parent = NULL);
- /**
- * Destructor.
- */
- ~CharCreateDialog();
-
void action(const std::string& eventId);
std::string getName();
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index 37e7d56f..7a9090cd 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -94,7 +94,6 @@ ServerSelectDialog::ServerSelectDialog():
ServerSelectDialog::~ServerSelectDialog()
{
- delete serverList;
delete serverListModel;
}
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 2050745e..731cc0d0 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -77,8 +77,6 @@ ChatWindow::ChatWindow(const std::string &logfile):
ChatWindow::~ChatWindow()
{
- delete textOutput;
-
chatlog_file.flush();
chatlog_file.close();
}
diff --git a/src/gui/help.cpp b/src/gui/help.cpp
index 45ed7ba4..eb30556a 100644
--- a/src/gui/help.cpp
+++ b/src/gui/help.cpp
@@ -41,7 +41,7 @@ HelpWindow::HelpWindow():
browserBox = new BrowserBox();
browserBox->setOpaque(false);
scrollArea = new ScrollArea(browserBox);
- okButton = new Button("Close");
+ Button *okButton = new Button("Close");
scrollArea->setDimension(gcn::Rectangle(
5, 5, 445, 335 - okButton->getHeight()));
@@ -60,11 +60,6 @@ HelpWindow::HelpWindow():
setLocationRelativeTo(getParent());
}
-HelpWindow::~HelpWindow()
-{
- delete browserBox;
-}
-
void HelpWindow::action(const std::string& eventId)
{
if (eventId == "close")
diff --git a/src/gui/help.h b/src/gui/help.h
index 6a0c6551..139b9397 100644
--- a/src/gui/help.h
+++ b/src/gui/help.h
@@ -46,11 +46,6 @@ class HelpWindow : public Window, public LinkHandler,
HelpWindow();
/**
- * Destructor.
- */
- ~HelpWindow();
-
- /**
* Called when receiving actions from the widgets.
*/
void action(const std::string& eventId);
@@ -67,9 +62,8 @@ class HelpWindow : public Window, public LinkHandler,
private:
void loadFile(const std::string &file);
-
+
BrowserBox* browserBox;
- gcn::Button *okButton;
gcn::ScrollArea *scrollArea;
};
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 62a0be4b..35809bdd 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -88,11 +88,6 @@ InventoryWindow::InventoryWindow():
}
-InventoryWindow::~InventoryWindow()
-{
- delete items;
-}
-
void InventoryWindow::logic()
{
Window::logic();
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 4dbda261..17c4888a 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -47,11 +47,6 @@ class InventoryWindow : public Window, gcn::ActionListener
InventoryWindow();
/**
- * Destructor.
- */
- ~InventoryWindow();
-
- /**
* Logic (updates buttons and weight information)
*/
void logic();
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index f308b7ab..d92f53e1 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -106,6 +106,7 @@ void ItemAmountWindow::resetAmount()
void ItemAmountWindow::action(const std::string& eventId)
{
+ int amount = mItemAmountTextBox->getInt();
if (eventId == "Cancel")
{
@@ -123,15 +124,18 @@ void ItemAmountWindow::action(const std::string& eventId)
}
else if (eventId == "Plus")
{
- mItemAmountTextBox->setInt(mItemAmountTextBox->getInt() + 1);
+ amount++;
}
else if (eventId == "Minus")
{
- mItemAmountTextBox->setInt(mItemAmountTextBox->getInt() - 1);
+ amount--;
}
else if (eventId == "Slide")
{
- mItemAmountTextBox->setInt((int)(mItemAmountSlide->getValue()*mItem->getQuantity()));
+ amount = (int)(mItemAmountSlide->getValue()*(mItem->getQuantity()+1));
}
+ mItemAmountTextBox->setInt(amount);
+ amount = mItemAmountTextBox->getInt(); // The textbox cares about bounds
+ mItemAmountSlide->setValue((amount-1)*1.0f/(mItem->getQuantity()-1));
}
diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp
index 2729d816..de491b73 100644
--- a/src/gui/npc.cpp
+++ b/src/gui/npc.cpp
@@ -23,6 +23,8 @@
#include "npc.h"
+#include <sstream>
+
#include "button.h"
#include "scrollarea.h"
#include "listbox.h"
@@ -35,10 +37,10 @@
NpcListDialog::NpcListDialog():
Window("NPC")
{
- itemList = new ListBox(this);
- scrollArea = new ScrollArea(itemList);
- okButton = new Button("OK");
- cancelButton = new Button("Cancel");
+ mItemList = new ListBox(this);
+ ScrollArea *scrollArea = new ScrollArea(mItemList);
+ Button *okButton = new Button("OK");
+ Button *cancelButton = new Button("Cancel");
setContentSize(260, 175);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -51,11 +53,11 @@ NpcListDialog::NpcListDialog():
cancelButton->getX() - 5 - okButton->getWidth(),
cancelButton->getY());
- itemList->setEventId("item");
+ mItemList->setEventId("item");
okButton->setEventId("ok");
cancelButton->setEventId("cancel");
- itemList->addActionListener(this);
+ mItemList->addActionListener(this);
okButton->addActionListener(this);
cancelButton->addActionListener(this);
@@ -66,11 +68,6 @@ NpcListDialog::NpcListDialog():
setLocationRelativeTo(getParent());
}
-NpcListDialog::~NpcListDialog()
-{
- delete itemList;
-}
-
int
NpcListDialog::getNumberOfElements()
{
@@ -86,16 +83,12 @@ NpcListDialog::getElementAt(int i)
void
NpcListDialog::parseItems(const std::string &itemString)
{
- char *copy = new char[itemString.length() + 1];
- strcpy(copy, itemString.c_str());
+ std::istringstream iss(itemString);
- char *token = strtok(copy, ":");
- while (token) {
- items.push_back(token);
- token = strtok(NULL, ":");
+ std::string tmp;
+ while(getline(iss, tmp, ':')) {
+ items.push_back(tmp);
}
-
- delete[] copy;
}
void
@@ -108,11 +101,11 @@ void
NpcListDialog::action(const std::string& eventId)
{
int choice = 0;
-
+
if (eventId == "ok")
{
// Send the selected index back to the server
- int selectedIndex = itemList->getSelected();
+ int selectedIndex = mItemList->getSelected();
if (selectedIndex > -1)
{
choice = selectedIndex + 1;
@@ -122,7 +115,7 @@ NpcListDialog::action(const std::string& eventId)
{
choice = 0xff; // 0xff means cancel
}
-
+
if (choice)
{
MessageOut outMsg;
diff --git a/src/gui/npc.h b/src/gui/npc.h
index e9960cd2..6ab49138 100644
--- a/src/gui/npc.h
+++ b/src/gui/npc.h
@@ -51,11 +51,6 @@ class NpcListDialog : public Window, public gcn::ActionListener,
NpcListDialog();
/**
- * Destructor.
- */
- ~NpcListDialog();
-
- /**
* Called when receiving actions from the widgets.
*/
void
@@ -88,14 +83,9 @@ class NpcListDialog : public Window, public gcn::ActionListener,
reset();
private:
- gcn::Button *okButton;
- gcn::Button *cancelButton;
- gcn::ListBox *itemList;
- gcn::ScrollArea *scrollArea;
+ gcn::ListBox *mItemList;
std::vector<std::string> items;
};
-extern NpcListDialog *npcListDialog;
-
#endif
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 12032850..f4bdfb0f 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -58,11 +58,6 @@ NpcTextDialog::NpcTextDialog():
setLocationRelativeTo(getParent());
}
-NpcTextDialog::~NpcTextDialog()
-{
- delete textBox;
-}
-
void
NpcTextDialog::setText(const char *text)
{
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index 02fae7f4..aa6aa725 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -47,11 +47,6 @@ class NpcTextDialog : public Window, public gcn::ActionListener
NpcTextDialog();
/**
- * Destructor.
- */
- ~NpcTextDialog();
-
- /**
* Called when receiving actions from the widgets.
*/
void
diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp
index 246e2ffa..d1873cb5 100644
--- a/src/gui/scrollarea.cpp
+++ b/src/gui/scrollarea.cpp
@@ -35,20 +35,27 @@ ImageRect ScrollArea::background;
ImageRect ScrollArea::vMarker;
Image *ScrollArea::buttons[4][2];
-ScrollArea::ScrollArea():
- gcn::ScrollArea()
+ScrollArea::ScrollArea(bool gc):
+ gcn::ScrollArea(),
+ mGC(gc)
{
init();
}
-ScrollArea::ScrollArea(gcn::Widget *widget):
- gcn::ScrollArea(widget)
+ScrollArea::ScrollArea(gcn::Widget *widget, bool gc):
+ gcn::ScrollArea(widget),
+ mGC(gc)
{
init();
}
ScrollArea::~ScrollArea()
{
+ // Garbage collection
+ if (mGC) {
+ delete mContent;
+ }
+
instances--;
if (instances == 0)
diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h
index d75e194a..504842cc 100644
--- a/src/gui/scrollarea.h
+++ b/src/gui/scrollarea.h
@@ -39,12 +39,12 @@ class ScrollArea : public gcn::ScrollArea {
/**
* Constructor.
*/
- ScrollArea();
+ ScrollArea(bool gc=true);
/**
* Constructor.
*/
- ScrollArea(gcn::Widget *content);
+ ScrollArea(gcn::Widget *content, bool gc=true);
/**
* Destructor.
@@ -108,6 +108,7 @@ class ScrollArea : public gcn::ScrollArea {
static Image *buttons[4][2];
bool mOpaque;
+ bool mGC;
};
#endif
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 7245c692..ea5b948f 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -116,11 +116,6 @@ SellDialog::SellDialog():
setLocationRelativeTo(getParent());
}
-SellDialog::~SellDialog()
-{
- delete itemList;
-}
-
void SellDialog::reset()
{
shopInventory.clear();
diff --git a/src/gui/sell.h b/src/gui/sell.h
index 864c5f63..9b30002a 100644
--- a/src/gui/sell.h
+++ b/src/gui/sell.h
@@ -54,11 +54,6 @@ class SellDialog : public Window, public gcn::ActionListener,
SellDialog();
/**
- * Destructor.
- */
- ~SellDialog();
-
- /**
* Resets the dialog, clearing inventory.
*/
void reset();
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 30d95dcc..d76a0542 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -214,7 +214,6 @@ Setup::Setup():
Setup::~Setup()
{
delete modeListModel;
- delete modeList;
}
void Setup::action(const std::string &eventId)
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 72790f6a..8a073bdd 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -110,13 +110,7 @@ SkillDialog::SkillDialog():
SkillDialog::~SkillDialog()
{
- delete skillListBox;
-
- for (int i = skillList.size() - 1; i >= 0; i--)
- {
- delete skillList[i];
- }
- skillList.clear();
+ cleanList();
}
void SkillDialog::action(const std::string& eventId)
@@ -210,6 +204,6 @@ void SkillDialog::cleanList()
for (int i = skillList.size() - 1; i >= 0; i--)
{
delete skillList[i];
- skillList.pop_back();
}
+ skillList.clear();
}
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index bd8b95c5..31efab2e 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -136,9 +136,6 @@ TradeWindow::TradeWindow():
TradeWindow::~TradeWindow()
{
- delete myItemContainer;
- delete partnerItemContainer;
-
delete myInventory;
delete partnerInventory;
}
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 8ad5e486..6d4f93df 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -107,7 +107,6 @@ UpdaterWindow::~UpdaterWindow()
remove((mBasePath + "/updates/download.temp").c_str());
delete[] mCurlError;
- delete mBrowserBox;
}
void UpdaterWindow::setProgress(float p)