diff options
author | David Athay <ko2fan@gmail.com> | 2008-05-15 14:07:19 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2008-05-15 14:07:19 +0000 |
commit | f4c0d85edfc8c6fb0d4d436f098e841bac72f5f1 (patch) | |
tree | 34a053b8ec7995dab3b54b025764ff511a0b6954 | |
parent | 96b79b905b22bfcf4b35c26e6e70065e4ce3222c (diff) | |
download | mana-client-f4c0d85edfc8c6fb0d4d436f098e841bac72f5f1.tar.gz mana-client-f4c0d85edfc8c6fb0d4d436f098e841bac72f5f1.tar.bz2 mana-client-f4c0d85edfc8c6fb0d4d436f098e841bac72f5f1.tar.xz mana-client-f4c0d85edfc8c6fb0d4d436f098e841bac72f5f1.zip |
Added tab with image based on button
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | data/graphics/gui/tab.png | bin | 0 -> 329 bytes | |||
-rw-r--r-- | data/graphics/gui/tabselected.png | bin | 0 -> 313 bytes | |||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/gui/chat.cpp | 5 | ||||
-rw-r--r-- | src/gui/guildwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/tab.cpp | 130 | ||||
-rw-r--r-- | src/gui/widgets/tab.h | 62 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 41 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.h | 24 | ||||
-rw-r--r-- | tmw.cbp | 2 |
12 files changed, 265 insertions, 14 deletions
@@ -1,3 +1,12 @@ +2008-05-15 David Athay <ko2fan@gmail.com> + + * src/gui/widgets/tabbedarea.h, src/gui/widgets/tab.cpp, + src/gui/widgets/tabbedarea.cpp, src/gui/widgets/tab.h, + src/gui/chat.cpp, src/gui/guildwindow.cpp, src/CMakeLists.txt, + src/Makefile.am, data/graphics/gui/tab.png, + data/graphics/gui/tabselected.png, tmw.cbp: Added tab with image + based on button. + 2008-05-12 David Athay <ko2fan@gmail.com> * src/Makefile.am, src/CMakeLists.txt: Fix building on other systems. diff --git a/data/graphics/gui/tab.png b/data/graphics/gui/tab.png Binary files differnew file mode 100644 index 00000000..91eadf08 --- /dev/null +++ b/data/graphics/gui/tab.png diff --git a/data/graphics/gui/tabselected.png b/data/graphics/gui/tabselected.png Binary files differnew file mode 100644 index 00000000..e2983060 --- /dev/null +++ b/data/graphics/gui/tabselected.png diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a6d07c0d..7fd5983e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,8 @@ SET(SRCS gui/widgets/resizegrip.h gui/widgets/layout.cpp gui/widgets/layout.h + gui/widgets/tab.cpp + gui/widgets/tab.h gui/widgets/tabbedarea.cpp gui/widgets/tabbedarea.h gui/box.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e012af0c..75e81951 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,6 +7,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/layout.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ + gui/widgets/tab.cpp \ + gui/widgets/tab.h \ gui/widgets/tabbedarea.cpp \ gui/widgets/tabbedarea.h \ gui/box.h \ diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index fec2394b..c15f7968 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -34,6 +34,7 @@ #include "sdlinput.h" #include "windowcontainer.h" +#include "widgets/tab.h" #include "widgets/tabbedarea.h" #include "../channelmanager.h" @@ -488,7 +489,7 @@ ChatWindow::removeChannel(Channel *channel) { if (channel) { - gcn::Tab *tab = mChatTabs->getTab(channel->getName()); + Tab *tab = mChatTabs->getTab(channel->getName()); if (!tab) return; mChatTabs->removeTab(tab); @@ -595,7 +596,7 @@ ChatWindow::setVisible(bool isVisible) bool ChatWindow::tabExists(const std::string &tabName) { - gcn::Tab *tab = mChatTabs->getTab(tabName); + Tab *tab = mChatTabs->getTab(tabName); if (tab) return true; return false; diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp index e982487c..a2b8243c 100644 --- a/src/gui/guildwindow.cpp +++ b/src/gui/guildwindow.cpp @@ -252,7 +252,7 @@ void GuildWindow::removeTab(int guildId) Guild* guild = player_node->getGuild(guildId); if (guild) { - gcn::Tab *tab = mGuildTabs->getTab(guild->getName()); + Tab *tab = mGuildTabs->getTab(guild->getName()); if (tab) { mGuildTabs->removeTab(tab); diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp new file mode 100644 index 00000000..4bb85946 --- /dev/null +++ b/src/gui/widgets/tab.cpp @@ -0,0 +1,130 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "tab.h" + +#include "tabbedarea.h" + +#include "../../graphics.h" + +#include "../../resources/image.h" +#include "../../resources/resourcemanager.h" + +#include "../../utils/dtor.h" + +int Tab::mInstances = 0; + +enum{ + TAB_STANDARD, // 0 + TAB_HIGHLIGHTED, // 1 + TAB_SELECTED, // 2 + TAB_UNUSED, // 3 + TAB_COUNT // 4 - Must be last. +}; + +struct TabData +{ + char const *file; + int gridX; + int gridY; +}; + +static TabData const data[TAB_COUNT] = { + {"graphics/gui/tab.png", 0, 0}, + {"graphics/gui/tab.png", 9, 4}, + {"graphics/gui/tabselected.png", 16, 19}, + {"graphics/gui/tab.png", 25, 23} +}; + +ImageRect Tab::tabImg[TAB_COUNT]; + +Tab::Tab() : gcn::Tab() +{ + init(); +} + +Tab::~Tab() +{ + mInstances--; + + if (mInstances == 0) + { + for (int mode = 0; mode < TAB_COUNT; mode++) + { + for_each(tabImg[mode].grid, tabImg[mode].grid + 9, dtor<Image*>()); + } + } +} + +void Tab::init() +{ + setFrameSize(0); + + if (mInstances == 0) + { + // Load the skin + ResourceManager *resman = ResourceManager::getInstance(); + Image *tab[TAB_COUNT]; + + int a, x, y, mode; + + for (mode = 0; mode < TAB_COUNT; mode++) + { + tab[mode] = resman->getImage(data[mode].file); + a = 0; + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + tabImg[mode].grid[a] = tab[mode]->getSubImage( + data[x].gridX, data[y].gridY, + data[x + 1].gridX - data[x].gridX + 1, + data[y + 1].gridY - data[y].gridY + 1); + a++; + } + } + tab[mode]->decRef(); + } + } + mInstances++; +} + +void Tab::draw(gcn::Graphics *graphics) +{ + int mode; + + // check which type of tab to draw + if (mTabbedArea && mTabbedArea->isTabSelected(this)) + { + mode = TAB_SELECTED; + } + else + { + mode = TAB_STANDARD; + } + + // draw tab + static_cast<Graphics*>(graphics)-> + drawImageRect(0, 0, getWidth(), getHeight(), tabImg[mode]); + + // draw label + drawChildren(graphics); +} diff --git a/src/gui/widgets/tab.h b/src/gui/widgets/tab.h new file mode 100644 index 00000000..b18c93e3 --- /dev/null +++ b/src/gui/widgets/tab.h @@ -0,0 +1,62 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_TAB_H +#define _TMW_TAB_H + +#include <guichan/widgets/tab.hpp> + +class ImageRect; + +/** + * A tab, the same as the guichan tab in 0.8, but extended to allow transparancy + */ +class Tab : public gcn::Tab +{ + public: + /** + * Constructor. + */ + Tab(); + + /** + * Destructor. + */ + ~Tab(); + + /** + * Draw the tabbed area. + */ + void draw(gcn::Graphics *graphics); + + private: + /** Load images if no other instances exist yet */ + void init(); + + static ImageRect tabImg[4]; /**< Tab state graphics */ + static int mInstances; /**< Number of tab instances */ +}; + +#endif + + diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 7821190b..5c9403c7 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -22,6 +22,7 @@ */ #include "tabbedarea.h" +#include "tab.h" #include <guichan/widgets/container.hpp> @@ -35,15 +36,14 @@ int TabbedArea::getNumberOfTabs() return mTabs.size(); } -gcn::Tab* TabbedArea::getTab(const std::string &name) +Tab* TabbedArea::getTab(const std::string &name) { - std::vector< std::pair<gcn::Tab*, gcn::Widget*> >::iterator itr = mTabs.begin(), - itr_end = mTabs.end(); + TabContainer::iterator itr = mTabs.begin(), itr_end = mTabs.end(); while (itr != itr_end) { if ((*itr).first->getCaption() == name) { - return (*itr).first; + return static_cast<Tab*>((*itr).first); } ++itr; } @@ -62,8 +62,7 @@ void TabbedArea::draw(gcn::Graphics *graphics) gcn::Widget* TabbedArea::getWidget(const std::string &name) { - std::vector< std::pair<gcn::Tab*, gcn::Widget*> >::iterator itr = mTabs.begin(), - itr_end = mTabs.end(); + TabContainer::iterator itr = mTabs.begin(), itr_end = mTabs.end(); while (itr != itr_end) { if ((*itr).first->getCaption() == name) @@ -76,7 +75,33 @@ gcn::Widget* TabbedArea::getWidget(const std::string &name) return NULL; } -void TabbedArea::removeTab(gcn::Tab *tab) +void TabbedArea::addTab(const std::string &caption, gcn::Widget *widget) +{ + Tab* tab = new Tab(); + tab->setCaption(caption); + mTabsToDelete.push_back(tab); + + addTab(tab, widget); +} + +void TabbedArea::addTab(Tab *tab, gcn::Widget *widget) +{ + tab->setTabbedArea(this); + tab->addActionListener(this); + + mTabContainer->add(tab); + mTabs.push_back(std::pair<Tab*, gcn::Widget*>(tab, widget)); + + if (mSelectedTab == NULL) + { + setSelectedTab(tab); + } + + adjustTabPositions(); + adjustSize(); +} + +void TabbedArea::removeTab(Tab *tab) { int tabIndexToBeSelected = 0; @@ -95,7 +120,7 @@ void TabbedArea::removeTab(gcn::Tab *tab) } } - std::vector<std::pair<gcn::Tab*, gcn::Widget*> >::iterator iter; + TabContainer::iterator iter; for (iter = mTabs.begin(); iter != mTabs.end(); iter++) { if (iter->first == tab) diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index bc623427..e24b9794 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -25,11 +25,12 @@ #define _TMW_TABBEDAREA_H #include <guichan/widget.hpp> -#include <guichan/widgets/tab.hpp> #include <guichan/widgets/tabbedarea.hpp> #include <string> +class Tab; + /** * A tabbed area, the same as the guichan tabbed area in 0.8, but extended */ @@ -54,7 +55,7 @@ class TabbedArea : public gcn::TabbedArea /** * Return tab with specified name as caption */ - gcn::Tab* getTab(const std::string &name); + Tab* getTab(const std::string &name); /** * Returns the widget with the tab that has specified caption @@ -62,9 +63,26 @@ class TabbedArea : public gcn::TabbedArea gcn::Widget* getWidget(const std::string &name); /** + * Add a tab + * @param caption The Caption to display + * @param widget The widget to show when tab is selected + */ + void addTab(const std::string &caption, gcn::Widget *widget); + + /** + * Add a tab + * @param tab The tab + * @param widget The widget to display + */ + void addTab(Tab *tab, gcn::Widget *widget); + + /** * Overload the remove tab function as its broken in guichan 0.8 */ - void removeTab(gcn::Tab *tab); + void removeTab(Tab *tab); + + private: + typedef std::vector< std::pair<gcn::Tab*, gcn::Widget*> > TabContainer; }; #endif @@ -411,6 +411,8 @@ <Unit filename="src/gui/widgets/resizegrip.h"> <Option target="default" /> </Unit> + <Unit filename="src/gui/widgets/tab.cpp" /> + <Unit filename="src/gui/widgets/tab.h" /> <Unit filename="src/gui/widgets/tabbedarea.cpp" /> <Unit filename="src/gui/widgets/tabbedarea.h" /> <Unit filename="src/gui/window.cpp" /> |