diff --git a/TODO b/TODO index 7db1bc3..5429bbe 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from e5271f1ad79923ffa1810e2bc62435117d49ce9f +* Continue rebasing from 2bc3319195c94fd4ba3d87e0a9f095bca211646e * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. diff --git a/include/guisan/rectangle.hpp b/include/guisan/rectangle.hpp index 8a175a4..55c2042 100644 --- a/include/guisan/rectangle.hpp +++ b/include/guisan/rectangle.hpp @@ -112,8 +112,8 @@ namespace gcn /** * Checks if a point is inside the rectangle * - * @param x The point x coordinate of the point. - * @param y The point y coordinate of the point. + * @param x The x coordinate of the point. + * @param y The y coordinate of the point. * @return True if the point is inside the rectangle. * @since 0.1.0 */ diff --git a/include/guisan/widgets/tab.hpp b/include/guisan/widgets/tab.hpp index 25bf3b3..1e81755 100644 --- a/include/guisan/widgets/tab.hpp +++ b/include/guisan/widgets/tab.hpp @@ -129,7 +129,6 @@ namespace gcn */ const std::string& getCaption() const; - // Inherited from Widget virtual void draw(Graphics *graphics); @@ -140,7 +139,7 @@ namespace gcn virtual void mouseEntered(MouseEvent& mouseEvent); virtual void mouseExited(MouseEvent& mouseEvent); - + protected: /** * Holds the label of the tab. @@ -152,11 +151,6 @@ namespace gcn */ TabbedArea* mTabbedArea; - /** - * Holds the caption of the tab. - */ - std::string mCaption; - /** * True if the tab has the mouse, false otherwise. */ diff --git a/include/guisan/widgets/tabbedarea.hpp b/include/guisan/widgets/tabbedarea.hpp index b16d312..7d06305 100644 --- a/include/guisan/widgets/tabbedarea.hpp +++ b/include/guisan/widgets/tabbedarea.hpp @@ -71,7 +71,7 @@ namespace gcn { class Container; class Tab; - + /** * An implementation of a tabbed area where a user can display a widget by * selecting a tab. @@ -82,6 +82,8 @@ namespace gcn public KeyListener, public MouseListener { + friend class Tab; + public: /** @@ -107,7 +109,7 @@ namespace gcn * Adds a tab to the tabbed area. * * @param tab The tab widget for the tab. - * @param widget The widget to view when the tab is selected. + * @param widget The widget to view when the tab is selected. * @see removeTab, removeTabWithIndex */ virtual void addTab(Tab* tab, Widget* widget); @@ -119,7 +121,7 @@ namespace gcn * @see addTab */ virtual void removeTabWithIndex(unsigned int index); - + /** * Removes a tab from the tabbed area. * @@ -136,7 +138,7 @@ namespace gcn * @see setSelectedTab */ virtual bool isTabSelected(unsigned int index) const; - + /** * Checks if a tab is selected or not. * @@ -194,11 +196,9 @@ namespace gcn void setDimension(const Rectangle& dimension); - // Inherited from ActionListener void action(const ActionEvent& actionEvent); - // Inherited from DeathListener @@ -222,7 +222,7 @@ namespace gcn void adjustSize(); /** - * Adjusts the positions ot the tabs. + * Adjusts the positions of the tabs. */ void adjustTabPositions(); diff --git a/src/widgets/tab.cpp b/src/widgets/tab.cpp index 9538507..0c06a65 100644 --- a/src/widgets/tab.cpp +++ b/src/widgets/tab.cpp @@ -77,15 +77,20 @@ namespace gcn addMouseListener(this); } - + Tab::~Tab() { delete mLabel; } - + void Tab::adjustSize() { - setHeight(mLabel->getHeight() + 8); + setSize(mLabel->getWidth() + 8, mLabel->getHeight() + 8); + + if (mTabbedArea != NULL) + { + mTabbedArea->adjustTabPositions(); + } } void Tab::setTabbedArea(TabbedArea* tabbedArea) @@ -100,24 +105,23 @@ namespace gcn void Tab::setCaption(const std::string& caption) { - mCaption = caption; mLabel->setCaption(caption); mLabel->adjustSize(); + adjustSize(); } - + const std::string& Tab::getCaption() const { - return mCaption; + return mLabel->getCaption(); } - + void Tab::draw(Graphics *graphics) { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; - int alpha = getBaseColor().a; - highlightColor = faceColor + 0x303030; + const Color& faceColor = getBaseColor(); + const int alpha = getBaseColor().a; + Color highlightColor = faceColor + 0x303030; highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; + Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; Color borderColor; @@ -165,7 +169,7 @@ namespace gcn } graphics->popClipArea(); } - + void Tab::mouseEntered(MouseEvent& mouseEvent) { mHasMouse = true; diff --git a/src/widgets/tabbedarea.cpp b/src/widgets/tabbedarea.cpp index 77759de..3e85015 100644 --- a/src/widgets/tabbedarea.cpp +++ b/src/widgets/tabbedarea.cpp @@ -79,7 +79,7 @@ namespace gcn setFocusable(true); addKeyListener(this); addMouseListener(this); - + mTabContainer = new Container(); mTabContainer->setOpaque(false); mWidgetContainer = new Container(); @@ -92,7 +92,7 @@ namespace gcn { remove(mTabContainer); remove(mWidgetContainer); - + delete mTabContainer; delete mWidgetContainer; @@ -104,9 +104,8 @@ namespace gcn } void TabbedArea::addTab(const std::string& caption, Widget* widget) - { + { Tab* tab = new Tab(); - tab->setSize(70, 20); tab->setCaption(caption); mTabsToDelete.push_back(tab); @@ -114,14 +113,13 @@ namespace gcn } void TabbedArea::addTab(Tab* tab, Widget* widget) - { + { tab->setTabbedArea(this); - tab->addActionListener(this); + tab->addActionListener(this); - mTabContainer->add(tab); + mTabContainer->add(tab); mTabs.push_back(std::pair(tab, widget)); - if (mSelectedTab == NULL) { setSelectedTab(tab); @@ -144,11 +142,11 @@ namespace gcn void TabbedArea::removeTab(Tab* tab) { int tabIndexToBeSelected = - 1; - + if (tab == mSelectedTab) { int index = getSelectedTabIndex(); - + if (index == (int)mTabs.size() - 1 && mTabs.size() >= 2) { @@ -167,7 +165,7 @@ namespace gcn std::vector >::iterator iter; for (iter = mTabs.begin(); iter != mTabs.end(); iter++) - { + { if (iter->first == tab) { mTabContainer->remove(tab); @@ -175,7 +173,7 @@ namespace gcn break; } } - + std::vector::iterator iter2; for (iter2 = mTabsToDelete.begin(); iter2 != mTabsToDelete.end(); iter2++) { @@ -196,7 +194,7 @@ namespace gcn { setSelectedTab(tabIndexToBeSelected); } - + adjustSize(); adjustTabPositions(); } @@ -269,12 +267,11 @@ namespace gcn void TabbedArea::draw(Graphics *graphics) { - Color faceColor = getBaseColor(); - Color highlightColor, shadowColor; + const Color& faceColor = getBaseColor(); int alpha = getBaseColor().a; - highlightColor = faceColor + 0x303030; + Color highlightColor = faceColor + 0x303030; highlightColor.a = alpha; - shadowColor = faceColor - 0x303030; + Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; // Draw a border. @@ -327,12 +324,10 @@ namespace gcn } } - mTabContainer->setWidth(getWidth() - 2); - mTabContainer->setHeight(maxTabHeight); + mTabContainer->setSize(getWidth() - 2, maxTabHeight); mWidgetContainer->setPosition(1, maxTabHeight + 1); - mWidgetContainer->setWidth(getWidth() - 2); - mWidgetContainer->setHeight(getHeight() - maxTabHeight - 2); + mWidgetContainer->setSize(getWidth() - 2, getHeight() - maxTabHeight - 2); } void TabbedArea::adjustTabPositions() @@ -348,33 +343,22 @@ namespace gcn } int x = 0; - for (i = 0; i < mTabs.size(); i++) + for (i = 0; i < mTabs.size(); i++) { Tab* tab = mTabs[i].first; - tab->setX(x); + tab->setPosition(x, maxTabHeight - tab->getHeight()); - if (tab->getHeight() < maxTabHeight) - { - tab->setY(maxTabHeight - - tab->getHeight()); - } - else - { - tab->setY(0); - } - x += tab->getWidth(); } } - + void TabbedArea::setWidth(int width) { Widget::setWidth(width); adjustSize(); } - void TabbedArea::setHeight(int height) { Widget::setHeight(height); @@ -386,7 +370,7 @@ namespace gcn setWidth(width); setHeight(height); } - + void TabbedArea::setDimension(const Rectangle& dimension) { setX(dimension.x); @@ -401,12 +385,12 @@ namespace gcn { return; } - + if (keyEvent.getKey().getValue() == Key::LEFT) { int index = getSelectedTabIndex(); index--; - + if (index < 0) { return; @@ -415,7 +399,7 @@ namespace gcn { setSelectedTab(mTabs[index].first); } - + keyEvent.consume(); } else if (keyEvent.getKey().getValue() == Key::RIGHT) @@ -431,11 +415,10 @@ namespace gcn { setSelectedTab(mTabs[index].first); } - + keyEvent.consume(); } } - void TabbedArea::mousePressed(MouseEvent& mouseEvent) { @@ -444,7 +427,7 @@ namespace gcn { return; } - + if (mouseEvent.getButton() == MouseEvent::LEFT) { Widget* widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY());