summaryrefslogtreecommitdiff
path: root/src/resources/dye.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-03-04 22:41:19 -0700
committerJared Adams <jaxad0127@gmail.com>2010-03-12 14:49:27 -0700
commit781b3c9f17708cc5fe08eb3c9ee38d596364d97c (patch)
tree833797c9b9168ab58864ffe4cf8ed028060e44a2 /src/resources/dye.cpp
parent96b64757954f07d196599b3c1131a6603982c930 (diff)
downloadMana-781b3c9f17708cc5fe08eb3c9ee38d596364d97c.tar.gz
Mana-781b3c9f17708cc5fe08eb3c9ee38d596364d97c.tar.bz2
Mana-781b3c9f17708cc5fe08eb3c9ee38d596364d97c.tar.xz
Mana-781b3c9f17708cc5fe08eb3c9ee38d596364d97c.zip
Split Palette into Theme and UserPalette
Themes can now control the colors they use. Colors in the Viewport (being names, particles, etc) can still be changed by the user. Also make ProgressBars more easily colored. DyePalette was made more flexible in the process. Also fixes comparing strings of different lengths insensitively. Reviewed-by: Thorbjørn Lindeijer
Diffstat (limited to 'src/resources/dye.cpp')
-rw-r--r--src/resources/dye.cpp49
1 files changed, 34 insertions, 15 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 5116a134..85a87aa4 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -75,27 +75,43 @@ DyePalette::DyePalette(const std::string &description)
logger->log("Error, invalid embedded palette: %s", description.c_str());
}
+void DyePalette::addFirstColor(const int color[3])
+{
+ Color c = { {color[0], color[1], color[2]} };
+ mColors.insert(mColors.begin(), c);
+}
+
+void DyePalette::addLastColor(const int color[3])
+{
+ Color c = { {color[0], color[1], color[2]} };
+ mColors.push_back(c);
+}
+
void DyePalette::getColor(int intensity, int color[3]) const
{
- if (intensity == 0)
- {
- color[0] = 0;
- color[1] = 0;
- color[2] = 0;
+ if (mColors.size() == 0)
return;
+
+ Color c0 = mColors[0];
+
+ // Short circuit for black and single-color palettes
+ if (intensity == 0 || mColors.size() == 1)
+ {
+ color[0] = c0.value[0];
+ color[1] = c0.value[1];
+ color[2] = c0.value[2];
}
- int last = mColors.size();
- if (last == 0) return;
+ int last = mColors.size() - 1;
int i = intensity * last / 255;
int t = intensity * last % 255;
int j = t != 0 ? i : i - 1;
// Get the exact color if any, the next color otherwise.
- int r2 = mColors[j].value[0],
- g2 = mColors[j].value[1],
- b2 = mColors[j].value[2];
+ int r2 = mColors[j + 1].value[0],
+ g2 = mColors[j + 1].value[1],
+ b2 = mColors[j + 1].value[2];
if (t == 0)
{
@@ -106,13 +122,13 @@ void DyePalette::getColor(int intensity, int color[3]) const
return;
}
- // Get the previous color. First color is implicitly black.
- int r1 = 0, g1 = 0, b1 = 0;
+ // Get the previous color.
+ int r1 = c0.value[0], g1 = c0.value[1], b1 = c0.value[2];
if (i > 0)
{
- r1 = mColors[i - 1].value[0];
- g1 = mColors[i - 1].value[1];
- b1 = mColors[i - 1].value[2];
+ r1 = mColors[i].value[0];
+ g1 = mColors[i].value[1];
+ b1 = mColors[i].value[2];
}
// Perform a linear interpolation.
@@ -123,6 +139,8 @@ void DyePalette::getColor(int intensity, int color[3]) const
Dye::Dye(const std::string &description)
{
+ static const int black[3] = {0, 0, 0};
+
for (int i = 0; i < 7; ++i)
mDyePalettes[i] = 0;
@@ -161,6 +179,7 @@ Dye::Dye(const std::string &description)
}
mDyePalettes[i] = new DyePalette(description.substr(pos + 2,
next_pos - pos - 2));
+ mDyePalettes[i]->addFirstColor(black); // First color is black
++next_pos;
}
while (next_pos < length);