summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-17 23:38:30 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-17 23:38:30 +0300
commit59dc4ad66d2552ae1809555abd3c1e0faf99209f (patch)
tree3601d11524a489ec47ce5847a3a8d20e72032751 /src
parent3ba28f181216a150b3a59d912a8bbd9f8392f901 (diff)
downloadplus-59dc4ad66d2552ae1809555abd3c1e0faf99209f.tar.gz
plus-59dc4ad66d2552ae1809555abd3c1e0faf99209f.tar.bz2
plus-59dc4ad66d2552ae1809555abd3c1e0faf99209f.tar.xz
plus-59dc4ad66d2552ae1809555abd3c1e0faf99209f.zip
improve palette class.
Diffstat (limited to 'src')
-rw-r--r--src/gui/palette.cpp34
-rw-r--r--src/gui/palette.h17
2 files changed, 24 insertions, 27 deletions
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
index df77a8fe7..bc363bb35 100644
--- a/src/gui/palette.cpp
+++ b/src/gui/palette.cpp
@@ -49,7 +49,6 @@ const gcn::Color Palette::RAINBOW_COLORS[7] =
gcn::Color(153, 0, 153)
};
-/** Number of Elemets of RAINBOW_COLORS */
const int Palette::RAINBOW_COLOR_COUNT = 7;
Palette::Palette(const int size) :
@@ -66,7 +65,7 @@ Palette::~Palette()
mInstances.erase(this);
}
-const gcn::Color& Palette::getCharColor(const signed char c, bool &valid)
+const gcn::Color& Palette::getCharColor(const signed char c, bool &valid) const
{
const CharColors::const_iterator it = mCharColors.find(c);
if (it != mCharColors.end())
@@ -79,7 +78,7 @@ const gcn::Color& Palette::getCharColor(const signed char c, bool &valid)
return BLACK;
}
-int Palette::getIdByChar(const signed char c, bool &valid)
+int Palette::getIdByChar(const signed char c, bool &valid) const
{
const CharColors::const_iterator it = mCharColors.find(c);
if (it != mCharColors.end())
@@ -102,7 +101,6 @@ void Palette::advanceGradient()
{
if (get_elapsed_time(mRainbowTime) > 5)
{
- int pos, colIndex, colVal, delay, numOfColors;
// For slower systems, advance can be greater than one (advance > 1
// skips advance-1 steps). Should make gradient look the same
// independent of the framerate.
@@ -111,30 +109,32 @@ void Palette::advanceGradient()
for (size_t i = 0, sz = mGradVector.size(); i < sz; i++)
{
- if (!mGradVector[i])
+ ColorElem *const elem = mGradVector[i];
+ if (!elem)
continue;
- delay = mGradVector[i]->delay;
+ int delay = elem->delay;
- if (mGradVector[i]->grad == PULSE)
+ if (elem->grad == PULSE)
delay = delay / 20;
- numOfColors = (mGradVector[i]->grad == SPECTRUM ? 6 :
- mGradVector[i]->grad == PULSE ? 127 :
- RAINBOW_COLOR_COUNT);
+ const int numOfColors = (elem->grad == SPECTRUM ? 6 :
+ elem->grad == PULSE ? 127 :
+ RAINBOW_COLOR_COUNT);
- mGradVector[i]->gradientIndex =
- (mGradVector[i]->gradientIndex + advance) %
- (delay * numOfColors);
+ elem->gradientIndex = (elem->gradientIndex + advance)
+ % (delay * numOfColors);
- pos = mGradVector[i]->gradientIndex % delay;
+ const int gradIndex = elem->gradientIndex;
+ const int pos = gradIndex % delay;
+ int colIndex;
if (delay)
- colIndex = mGradVector[i]->gradientIndex / delay;
+ colIndex = gradIndex / delay;
else
- colIndex = mGradVector[i]->gradientIndex;
+ colIndex = gradIndex;
- ColorElem *const elem = mGradVector[i];
gcn::Color &color = elem->color;
+ int colVal;
if (elem->grad == PULSE)
{
diff --git a/src/gui/palette.h b/src/gui/palette.h
index 300df1f45..e842b23a5 100644
--- a/src/gui/palette.h
+++ b/src/gui/palette.h
@@ -68,9 +68,9 @@ class Palette
* @return the requested color or Palette::BLACK
*/
const gcn::Color &getCharColor(const signed char c,
- bool &valid) A_WARN_UNUSED;
+ bool &valid) const A_WARN_UNUSED;
- int getIdByChar(const signed char c, bool &valid) A_WARN_UNUSED;
+ int getIdByChar(const signed char c, bool &valid) const A_WARN_UNUSED;
/**
* Gets the color associated with the type. Sets the alpha channel
@@ -82,7 +82,7 @@ class Palette
* @return the requested color
*/
inline const gcn::Color &getColor(int type,
- int alpha = 255) A_WARN_UNUSED
+ const int alpha = 255) A_WARN_UNUSED
{
if (type >= static_cast<signed>(mColors.size()) || type < 0)
{
@@ -95,7 +95,8 @@ class Palette
return *col;
}
- inline const gcn::Color &getColorWithAlpha(int type) A_WARN_UNUSED
+ inline const gcn::Color &getColorWithAlpha(const int type)
+ A_WARN_UNUSED
{
gcn::Color* col = &mColors[type].color;
col->a = mColors[type].delay;
@@ -119,7 +120,7 @@ class Palette
*
* @return the color char of the color with the given index
*/
- inline char getColorChar(int type) const A_WARN_UNUSED
+ inline char getColorChar(const int type) const A_WARN_UNUSED
{ return mColors[type].ch; }
/**
@@ -129,7 +130,7 @@ class Palette
*
* @return the gradient delay of the color with the given index
*/
- inline int getGradientDelay(int type) const A_WARN_UNUSED
+ inline int getGradientDelay(const int type) const A_WARN_UNUSED
{ return mColors[type].delay; }
/**
@@ -137,9 +138,6 @@ class Palette
*/
static void advanceGradients();
- static gcn::Color produceHPColor(int hp, int maxHp,
- int alpha = 255) A_WARN_UNUSED;
-
protected:
/** Colors used for the rainbow gradient */
static const gcn::Color RAINBOW_COLORS[];
@@ -211,7 +209,6 @@ class Palette
};
typedef std::vector<ColorElem> Colors;
typedef std::map<unsigned char, int> CharColors;
- /** Vector containing the colors. */
Colors mColors;
CharColors mCharColors;
std::vector<ColorElem*> mGradVector;