diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-02-27 16:31:34 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-02-27 16:31:34 +0000 |
commit | 88a86283083800443c4f5e934fface5988c42fe8 (patch) | |
tree | fa6a26c56836d8b1f148d362eb0b6b0e0ed3ce9b /src | |
parent | a064b260e2950b5a153e51c13f579095c53a9a7a (diff) | |
download | mana-88a86283083800443c4f5e934fface5988c42fe8.tar.gz mana-88a86283083800443c4f5e934fface5988c42fe8.tar.bz2 mana-88a86283083800443c4f5e934fface5988c42fe8.tar.xz mana-88a86283083800443c4f5e934fface5988c42fe8.zip |
Tabbed containers now display the button of the active tab pressed all the time.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/button.cpp | 9 | ||||
-rw-r--r-- | src/gui/button.h | 7 | ||||
-rw-r--r-- | src/gui/tabbedcontainer.cpp | 36 | ||||
-rw-r--r-- | src/gui/tabbedcontainer.h | 10 |
4 files changed, 50 insertions, 12 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 0055c89a..e607b66a 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -38,8 +38,9 @@ ImageRect Button::button[4]; int Button::mInstances = 0; Button::Button(const std::string& caption, const std::string &actionEventId, - gcn::ActionListener *listener): - gcn::Button(caption) + gcn::ActionListener *listener): + gcn::Button(caption), + mIsLogged(false) { setBorderSize(0); @@ -100,7 +101,7 @@ Button::draw(gcn::Graphics *graphics) if (!isEnabled()) { mode = 3; } - else if (isPressed()) { + else if (isPressed() || mIsLogged) { mode = 2; } else if (mHasMouse) { @@ -130,7 +131,7 @@ Button::draw(gcn::Graphics *graphics) textX = getWidth() - 4; break; default: - throw GCN_EXCEPTION("Button::draw. Uknown alignment."); + throw GCN_EXCEPTION("Button::draw. Unknown alignment."); } graphics->setFont(getFont()); diff --git a/src/gui/button.h b/src/gui/button.h index 339341ad..eb73e311 100644 --- a/src/gui/button.h +++ b/src/gui/button.h @@ -53,11 +53,16 @@ class Button : public gcn::Button { */ void draw(gcn::Graphics* graphics); - void focusLost() {} + /** + * Enable/Disable highlighting + */ + void setLogged(bool enable) + { mIsLogged = enable; } private: static ImageRect button[4]; /**< Button state graphics */ static int mInstances; /**< Number of button instances */ + bool mIsLogged; /**< Makes the button appear pressed all the time */ }; #endif diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp index 75f9f3cf..5d6d21d1 100644 --- a/src/gui/tabbedcontainer.cpp +++ b/src/gui/tabbedcontainer.cpp @@ -26,6 +26,7 @@ #include "button.h" #include "../utils/tostring.h" +#include "../utils/dtor.h" #define TABWIDTH 60 #define TABHEIGHT 20 @@ -37,10 +38,7 @@ TabbedContainer::TabbedContainer(): TabbedContainer::~TabbedContainer() { - for (WidgetIterator i = mTabs.begin(); i != mTabs.end(); i++) { - remove(*i); - delete (*i); - } + for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs)); mTabs.clear(); mContents.clear(); @@ -55,7 +53,7 @@ void TabbedContainer::addTab(gcn::Widget *widget, const std::string &caption) tab->setSize(TABWIDTH, TABHEIGHT); add(tab, TABWIDTH * tabNumber, 0); - mTabs.push_back(tab); + mTabs[caption] = tab; mContents.push_back(widget); widget->setPosition(0, TABHEIGHT); @@ -64,7 +62,18 @@ void TabbedContainer::addTab(gcn::Widget *widget, const std::string &caption) if (!mActiveContent) { mActiveContent = widget; add(mActiveContent); + tab->setLogged(true); } + + mWidgets[widget] = caption; +} + +void TabbedContainer::removeTab(const std::string &caption) +{ + gcn::ActionEvent actionEvent(this, "0"); + action(actionEvent); + remove(mTabs[caption]); + mTabs.erase(caption); } void TabbedContainer::logic() @@ -80,16 +89,21 @@ void TabbedContainer::logic() void TabbedContainer::action(const gcn::ActionEvent &event) { - std::stringstream ss(event.getId()); int tabNo; + std::stringstream ss(event.getId()); ss >> tabNo; gcn::Widget *newContent = mContents[tabNo]; + if (newContent) { if (mActiveContent) { + // Unhighlight old tab + ((Button*)mTabs[mWidgets[mActiveContent]])->setLogged(false); remove(mActiveContent); } mActiveContent = newContent; + // Highlight new tab + ((Button*)mTabs[mWidgets[mActiveContent]])->setLogged(true); add(newContent); } } @@ -98,3 +112,13 @@ void TabbedContainer::setOpaque(bool opaque) { Container::setOpaque(opaque); } + +short TabbedContainer::getNumberOfTabs() +{ + return mTabs.size(); +} + +std::string TabbedContainer::getActiveWidget() +{ + return mWidgets[mActiveContent]; +} diff --git a/src/gui/tabbedcontainer.h b/src/gui/tabbedcontainer.h index 2dc017ae..7f8deef9 100644 --- a/src/gui/tabbedcontainer.h +++ b/src/gui/tabbedcontainer.h @@ -26,6 +26,7 @@ #include <iosfwd> #include <vector> +#include <map> #include <guichan/actionlistener.hpp> @@ -41,18 +42,25 @@ class TabbedContainer : public gcn::Container, public gcn::ActionListener void addTab(gcn::Widget *widget, const std::string &caption); + void removeTab(const std::string &caption); + void logic(); void action(const gcn::ActionEvent &event); void setOpaque(bool opaque); + short getNumberOfTabs(); + + std::string getActiveWidget(); + private: typedef std::vector<gcn::Widget*> Widgets; typedef Widgets::iterator WidgetIterator; - Widgets mTabs; // The actual tabs at the top + std::map<std::string, gcn::Widget*> mTabs; // tabs mapped to their channel name Widgets mContents; // The contents of the tabs + std::map<gcn::Widget*, std::string> mWidgets; gcn::Widget *mActiveContent; }; |