00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/widgets/tab.h"
00023
00024 #include "gui/widgets/tabbedarea.h"
00025
00026 #include "gui/palette.h"
00027
00028 #include "configuration.h"
00029 #include "graphics.h"
00030
00031 #include "resources/image.h"
00032 #include "resources/resourcemanager.h"
00033
00034 #include "utils/dtor.h"
00035
00036 #include <guichan/widgets/label.hpp>
00037
00038 int Tab::mInstances = 0;
00039 float Tab::mAlpha = 1.0;
00040
00041 enum {
00042 TAB_STANDARD,
00043 TAB_HIGHLIGHTED,
00044 TAB_SELECTED,
00045 TAB_UNUSED,
00046 TAB_COUNT
00047 };
00048
00049 struct TabData
00050 {
00051 char const *file;
00052 int gridX;
00053 int gridY;
00054 };
00055
00056 static TabData const data[TAB_COUNT] = {
00057 { "graphics/gui/tab.png", 0, 0 },
00058 { "graphics/gui/tab.png", 9, 4 },
00059 { "graphics/gui/tabselected.png", 16, 19 },
00060 { "graphics/gui/tab.png", 25, 23 }
00061 };
00062
00063 ImageRect Tab::tabImg[TAB_COUNT];
00064
00065 Tab::Tab() : gcn::Tab(),
00066 mTabColor(guiPalette->getColor(Palette::TEXT))
00067 {
00068 init();
00069 }
00070
00071 Tab::~Tab()
00072 {
00073 mInstances--;
00074
00075 if (mInstances == 0)
00076 {
00077 for (int mode = 0; mode < TAB_COUNT; mode++)
00078 {
00079 for_each(tabImg[mode].grid, tabImg[mode].grid + 9, dtor<Image*>());
00080 }
00081 }
00082 }
00083
00084 void Tab::init()
00085 {
00086 setFrameSize(0);
00087 mHighlighted = false;
00088
00089 if (mInstances == 0)
00090 {
00091
00092 ResourceManager *resman = ResourceManager::getInstance();
00093 Image *tab[TAB_COUNT];
00094
00095 int a, x, y, mode;
00096
00097 for (mode = 0; mode < TAB_COUNT; mode++)
00098 {
00099 tab[mode] = resman->getImage(data[mode].file);
00100 a = 0;
00101 for (y = 0; y < 3; y++)
00102 {
00103 for (x = 0; x < 3; x++)
00104 {
00105 tabImg[mode].grid[a] = tab[mode]->getSubImage(
00106 data[x].gridX, data[y].gridY,
00107 data[x + 1].gridX - data[x].gridX + 1,
00108 data[y + 1].gridY - data[y].gridY + 1);
00109 tabImg[mode].grid[a]->setAlpha(mAlpha);
00110 a++;
00111 }
00112 }
00113 tab[mode]->decRef();
00114 }
00115 }
00116 mInstances++;
00117 }
00118
00119 void Tab::draw(gcn::Graphics *graphics)
00120 {
00121 int mode = TAB_STANDARD;
00122
00123
00124 if (mTabbedArea)
00125 {
00126 if (mTabbedArea->isTabSelected(this))
00127 {
00128 mode = TAB_SELECTED;
00129
00130 mLabel->setForegroundColor(mTabColor);
00131 mHighlighted = false;
00132 }
00133 else if (mHighlighted)
00134 {
00135 mode = TAB_HIGHLIGHTED;
00136 mLabel->setForegroundColor(guiPalette->getColor(Palette::TAB_HIGHLIGHT));
00137 }
00138 else
00139 {
00140 mLabel->setForegroundColor(mTabColor);
00141 }
00142 }
00143
00144 if (config.getValue("guialpha", 0.8) != mAlpha)
00145 {
00146 mAlpha = config.getValue("guialpha", 0.8);
00147 for (int a = 0; a < 9; a++)
00148 {
00149 tabImg[TAB_SELECTED].grid[a]->setAlpha(mAlpha);
00150 tabImg[TAB_STANDARD].grid[a]->setAlpha(mAlpha);
00151 }
00152 }
00153
00154
00155 static_cast<Graphics*>(graphics)->
00156 drawImageRect(0, 0, getWidth(), getHeight(), tabImg[mode]);
00157
00158
00159 drawChildren(graphics);
00160 }
00161
00162 void Tab::setTabColor(const gcn::Color &color)
00163 {
00164 mTabColor = color;
00165 }
00166
00167 void Tab::setHighlighted(bool high)
00168 {
00169 mHighlighted = high;
00170 }