summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-14 22:10:31 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-14 22:10:31 +0300
commita2c06346e1830d888a72ccdb2e224686319af014 (patch)
tree23dac39f0ca04563c42dd2750135bee53a169012 /src/gui/widgets
parentf6751cdc1e3a60f31889eacabf3751f23dfdcb0b (diff)
downloadplus-a2c06346e1830d888a72ccdb2e224686319af014.tar.gz
plus-a2c06346e1830d888a72ccdb2e224686319af014.tar.bz2
plus-a2c06346e1830d888a72ccdb2e224686319af014.tar.xz
plus-a2c06346e1830d888a72ccdb2e224686319af014.zip
add support for icon in tabs.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/tab.cpp51
-rw-r--r--src/gui/widgets/tab.h3
-rw-r--r--src/gui/widgets/tabbedarea.cpp9
-rw-r--r--src/gui/widgets/tabbedarea.h3
4 files changed, 57 insertions, 9 deletions
diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp
index 813ae0ef8..bce4ae11f 100644
--- a/src/gui/widgets/tab.cpp
+++ b/src/gui/widgets/tab.cpp
@@ -75,6 +75,7 @@ Tab::Tab(const Widget2 *const widget) :
mPlayerFlashOutlineColor(&getThemeColor(Theme::TAB_PLAYER_FLASH_OUTLINE)),
mFlash(0),
mVertexes(new ImageCollection),
+ mImage(nullptr),
mMode(0),
mRedraw(true),
mHasMouse(false)
@@ -98,6 +99,11 @@ Tab::~Tab()
delete mLabel;
mLabel = nullptr;
+ if (mImage)
+ {
+ mImage->decRef();
+ mImage = nullptr;
+ }
delete mVertexes;
mVertexes = nullptr;
}
@@ -210,26 +216,37 @@ void Tab::draw(gcn::Graphics *graphics)
updateAlpha();
+ Graphics *const g = static_cast<Graphics*>(graphics);
+
// draw tab
if (openGLMode != 2)
{
const ImageRect &rect = skin->getBorder();
- if (mRedraw || mode != mMode
- || static_cast<Graphics*>(graphics)->getRedraw())
+ if (mRedraw || mode != mMode || g->getRedraw())
{
mMode = mode;
mRedraw = false;
mVertexes->clear();
- static_cast<Graphics*>(graphics)->calcWindow(mVertexes, 0, 0,
+ g->calcWindow(mVertexes, 0, 0,
mDimension.width, mDimension.height, rect);
}
- static_cast<Graphics*>(graphics)->drawTile(mVertexes);
+ g->drawTile(mVertexes);
}
else
{
- static_cast<Graphics*>(graphics)->drawImageRect(
- 0, 0, mDimension.width, mDimension.height, skin->getBorder());
+ g->drawImageRect(0, 0,
+ mDimension.width, mDimension.height, skin->getBorder());
+ }
+
+ if (mImage)
+ {
+ const Skin *const skin1 = tabImg[TAB_STANDARD];
+ if (skin1)
+ {
+ const int padding = skin1->getPadding();
+ g->drawImage(mImage, padding, padding);
+ }
}
drawChildren(graphics);
@@ -262,10 +279,18 @@ void Tab::adjustSize()
const Skin *const skin = tabImg[TAB_STANDARD];
if (!skin)
return;
- const int padding = skin->getPadding();
+ const int pad2 = skin->getPadding() * 2;
- setSize(mLabel->getWidth() + 2 * padding,
- mLabel->getHeight() + 2 * padding);
+ if (mImage)
+ {
+ const SDL_Rect &rect = mImage->mBounds;
+ setSize(rect.w + pad2, rect.h + pad2);
+ }
+ else
+ {
+ setSize(mLabel->getWidth() + pad2,
+ mLabel->getHeight() + pad2);
+ }
if (mTabbedArea)
mTabbedArea->adjustTabPositions();
@@ -288,6 +313,14 @@ void Tab::setCaption(const std::string &caption)
adjustSize();
}
+void Tab::setImage(Image *const image)
+{
+ if (mImage)
+ mImage->decRef();
+ mImage = image;
+ adjustSize();
+}
+
const std::string &Tab::getCaption() const
{
return mLabel->getCaption();
diff --git a/src/gui/widgets/tab.h b/src/gui/widgets/tab.h
index cbc50a2ef..690db9072 100644
--- a/src/gui/widgets/tab.h
+++ b/src/gui/widgets/tab.h
@@ -145,6 +145,8 @@ class Tab : public gcn::BasicContainer,
void mouseExited(gcn::MouseEvent &mouseEvent) override;
+ void setImage(Image *const image);
+
protected:
friend class TabbedArea;
@@ -176,6 +178,7 @@ class Tab : public gcn::BasicContainer,
const gcn::Color *mPlayerFlashOutlineColor;
int mFlash;
ImageCollection *mVertexes;
+ Image *mImage;
int mMode;
bool mRedraw;
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 88d12764a..5a8b7265f 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -212,6 +212,15 @@ void TabbedArea::addTab(const std::string &caption, gcn::Widget *const widget)
addTab(tab, widget);
}
+void TabbedArea::addTab(Image *const image, gcn::Widget *const widget)
+{
+ Tab *const tab = new Tab(this);
+ tab->setImage(image);
+ mTabsToDelete.push_back(tab);
+
+ addTab(tab, widget);
+}
+
bool TabbedArea::isTabSelected(const unsigned int index) const
{
if (index >= mTabs.size())
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index ca2857709..5a97de6a6 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -32,6 +32,7 @@
#include "gui/widgets/button.h"
+class Image;
class Tab;
/**
@@ -95,6 +96,8 @@ class TabbedArea final : public Widget2,
void addTab(const std::string &caption, gcn::Widget *const widget);
+ void addTab(Image *const image, gcn::Widget *const widget);
+
bool isTabSelected(const unsigned int index) const A_WARN_UNUSED;
bool isTabSelected(Tab *const tab) const A_WARN_UNUSED;