From 7a7018c517948c2cc567d28d221c5cd8a91f2c12 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 7 Aug 2009 14:49:27 -0600 Subject: Clear tab data from SkillDialog --- src/gui/skilldialog.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/gui/skilldialog.cpp') diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index a27a2775..2f970184 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -47,7 +47,6 @@ #include "utils/xml.h" #include -#include class SkillEntry; @@ -104,7 +103,8 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - //delete_all(mTabs); + // Clear gui + loadSkills(""); } void SkillDialog::action(const gcn::ActionEvent &event) @@ -182,9 +182,21 @@ void SkillDialog::update() void SkillDialog::loadSkills(const std::string &file) { // TODO: mTabs->clear(); + while (mTabs->getSelectedTabIndex() != -1) + { + mTabs->removeTabWithIndex(mTabs->getSelectedTabIndex()); + } + + for (SkillMap::iterator it = mSkills.begin(); it != mSkills.end(); it++) + { + delete (*it).second->display; + } delete_all(mSkills); mSkills.clear(); + if (file.length() == 0) + return; + XML::Document doc(file); xmlNodePtr root = doc.rootNode(); -- cgit v1.2.3-70-g09d2 From 9af6e761373f25b56e815f1f75b44473474cf280 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 10 Aug 2009 20:28:23 -0600 Subject: Fix TabbedArea and ScrollArea to resize contents Also remove that code from SkillDialog. I tried to do the same with ChatWindow, but it kept segfaulting. Will try again later. --- src/gui/skilldialog.cpp | 22 ---------------------- src/gui/skilldialog.h | 8 -------- src/gui/widgets/scrollarea.cpp | 5 +++++ src/gui/widgets/scrollarea.h | 5 ++++- src/gui/widgets/tabbedarea.cpp | 11 +++++++++++ src/gui/widgets/tabbedarea.h | 5 ++++- 6 files changed, 24 insertions(+), 32 deletions(-) (limited to 'src/gui/skilldialog.cpp') diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index a0bfaf53..01b6e5ae 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -122,25 +122,6 @@ void SkillDialog::action(const gcn::ActionEvent &event) } } -void SkillDialog::adjustTabSize() -{ - gcn::Widget *content = mTabs->getCurrentWidget(); - if (content) { - int width = mTabs->getWidth() - 2 * content->getFrameSize() - 2 * mTabs->getFrameSize(); - int height = mTabs->getContainerHeight() - 2 * content->getFrameSize(); - content->setSize(width, height); - content->setVisible(true); - content->logic(); - } -} - -void SkillDialog::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - - adjustTabSize(); -} - void SkillDialog::logic() { Window::logic(); @@ -148,7 +129,6 @@ void SkillDialog::logic() Tab *tab = dynamic_cast(mTabs->getSelectedTab()); if (tab != mCurrentTab) { mCurrentTab = tab; - adjustTabSize(); } } @@ -248,8 +228,6 @@ void SkillDialog::loadSkills(const std::string &file) } } } - - adjustTabSize(); update(); } diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 6ad28be4..8fa7443d 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -54,12 +54,6 @@ class SkillDialog : public Window, public gcn::ActionListener */ void action(const gcn::ActionEvent &event); - /** - * Called when the widget changes size. Used for adapting the size of - * the tabbed area. - */ - void widgetResized(const gcn::Event &event); - void logic(); /** @@ -77,8 +71,6 @@ class SkillDialog : public Window, public gcn::ActionListener void setModifiable(int id, bool modifiable); private: - void adjustTabSize(); - typedef std::map SkillMap; SkillMap mSkills; Tab *mCurrentTab; diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 52322b05..6cf27bb6 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -42,6 +42,7 @@ ScrollArea::ScrollArea(): mY(0), mOpaque(true) { + addWidgetListener(this); init(); } @@ -346,3 +347,7 @@ void ScrollArea::mouseExited(gcn::MouseEvent& event) mHasMouse = false; } +void ScrollArea::widgetResized(const gcn::Event &event) +{ + getContent()->setSize(getWidth() - 2 * getFrameSize(), getHeight() - 2 * getFrameSize()); +} diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 8fd92b5f..69e99b1f 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -23,6 +23,7 @@ #define SCROLLAREA_H #include +#include class Image; class ImageRect; @@ -36,7 +37,7 @@ class ImageRect; * * \ingroup GUI */ -class ScrollArea : public gcn::ScrollArea +class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener { public: /** @@ -98,6 +99,8 @@ class ScrollArea : public gcn::ScrollArea */ void mouseExited(gcn::MouseEvent& event); + void widgetResized(const gcn::Event &event); + protected: enum BUTTON_DIR { UP, diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index bb5ae9a4..2de812ed 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -27,6 +27,7 @@ TabbedArea::TabbedArea() : gcn::TabbedArea() { mWidgetContainer->setOpaque(false); + addWidgetListener(this); } int TabbedArea::getNumberOfTabs() const @@ -152,3 +153,13 @@ void TabbedArea::setSelectedTab(gcn::Tab *tab) if (newTab) newTab->setCurrent(); } + +void TabbedArea::widgetResized(const gcn::Event &event) +{ + int width = getWidth() - 2 * getFrameSize(); + int height = getHeight() - 2 * getFrameSize() - mTabContainer->getHeight(); + mWidgetContainer->setSize(width, height); + gcn::Widget *w = getCurrentWidget(); + if (w) + w->setSize(width, height); +} diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index 29ba2f76..1b61b102 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -23,6 +23,7 @@ #define TABBEDAREA_H #include +#include #include #include @@ -33,7 +34,7 @@ class Tab; /** * A tabbed area, the same as the guichan tabbed area in 0.8, but extended */ -class TabbedArea : public gcn::TabbedArea +class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener { public: /** @@ -97,6 +98,8 @@ class TabbedArea : public gcn::TabbedArea void setSelectedTab(gcn::Tab *tab); + void widgetResized(const gcn::Event &event); + private: typedef std::vector< std::pair > TabContainer; }; -- cgit v1.2.3-70-g09d2 From bb9380e68c48f901353ac22042105243c8edd250 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 10 Aug 2009 20:54:18 -0600 Subject: Fix SkillDialog's layout for points to always show --- src/gui/skilldialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/skilldialog.cpp') diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 01b6e5ae..f6ab226a 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -95,7 +95,7 @@ SkillDialog::SkillDialog(): mPointsLabel = new Label("0"); place(0, 0, mTabs, 5, 5); - place(0, 5, mPointsLabel); + place(0, 5, mPointsLabel, 2); setLocationRelativeTo(getParent()); loadWindowState(); -- cgit v1.2.3-70-g09d2 From 7f83b173354b3e9efe0b9c99879d8db5bc800e17 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 14 Aug 2009 20:31:49 -0600 Subject: Remove some uneeded code This should've been removed earlier with the layout fixes. --- src/gui/skilldialog.cpp | 10 ---------- src/gui/skilldialog.h | 3 --- src/gui/specialswindow.cpp | 10 ---------- src/gui/specialswindow.h | 3 --- 4 files changed, 26 deletions(-) (limited to 'src/gui/skilldialog.cpp') diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index f6ab226a..6e7b3e70 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -122,16 +122,6 @@ void SkillDialog::action(const gcn::ActionEvent &event) } } -void SkillDialog::logic() -{ - Window::logic(); - - Tab *tab = dynamic_cast(mTabs->getSelectedTab()); - if (tab != mCurrentTab) { - mCurrentTab = tab; - } -} - std::string SkillDialog::update(int id) { SkillMap::iterator i = mSkills.find(id); diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 8fa7443d..12cb3581 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -54,8 +54,6 @@ class SkillDialog : public Window, public gcn::ActionListener */ void action(const gcn::ActionEvent &event); - void logic(); - /** * Update the given skill's display */ @@ -73,7 +71,6 @@ class SkillDialog : public Window, public gcn::ActionListener private: typedef std::map SkillMap; SkillMap mSkills; - Tab *mCurrentTab; TabbedArea *mTabs; Label *mPointsLabel; }; diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index 5d2ab676..35839b39 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -126,16 +126,6 @@ void SpecialsWindow::action(const gcn::ActionEvent &event) } } -void SpecialsWindow::logic() -{ - Window::logic(); - - Tab *tab = dynamic_cast(mTabs->getSelectedTab()); - if (tab != mCurrentTab) { - mCurrentTab = tab; - } -} - std::string SpecialsWindow::update(int id) { // TODO diff --git a/src/gui/specialswindow.h b/src/gui/specialswindow.h index 17c29597..cc2a68b3 100644 --- a/src/gui/specialswindow.h +++ b/src/gui/specialswindow.h @@ -48,8 +48,6 @@ class SpecialsWindow : public Window, public gcn::ActionListener { */ void action(const gcn::ActionEvent &actionEvent); - void logic(); - /** * Update the given special's display */ @@ -60,7 +58,6 @@ class SpecialsWindow : public Window, public gcn::ActionListener { private: typedef std::map SpecialMap; SpecialMap mSpecials; - Tab *mCurrentTab; TabbedArea *mTabs; }; -- cgit v1.2.3-70-g09d2