summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-03-09 03:22:25 +0300
committerAndrei Karas <akaras@inbox.ru>2012-03-09 03:22:25 +0300
commite11249023c8945fb817469b3b4362dcd8c2fd9f0 (patch)
treefcb062710863e27321475dfc029b79976786097c /src
parent117a35dc9450a134038818a925168de757fb3136 (diff)
downloadmanaplus-e11249023c8945fb817469b3b4362dcd8c2fd9f0.tar.gz
manaplus-e11249023c8945fb817469b3b4362dcd8c2fd9f0.tar.bz2
manaplus-e11249023c8945fb817469b3b4362dcd8c2fd9f0.tar.xz
manaplus-e11249023c8945fb817469b3b4362dcd8c2fd9f0.zip
Add new dye mode S.
It simple colors replace dye method. Dye palate should be in format: source1,destination1,source2,destination2 etc
Diffstat (limited to 'src')
-rw-r--r--src/resources/dye.cpp38
-rw-r--r--src/resources/dye.h14
2 files changed, 43 insertions, 9 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index eec5916c4..3b2d20054 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -205,9 +205,32 @@ void DyePalette::getColor(double intensity, int color[3]) const
color[2] = static_cast<int>(rest * b1 + intensity * b2);
}
+void DyePalette::replaceColor(int color[3]) const
+{
+ std::vector<Color>::const_iterator it = mColors.begin();
+ std::vector<Color>::const_iterator it_end = mColors.end();
+ while (it != it_end)
+ {
+ const Color &col = *it;
+ ++ it;
+ if (it == it_end)
+ return;
+ const Color &col2 = *it;
+ if (color[0] == col.value[0] && color[1] == col.value[1]
+ && color[2] == col.value[2])
+ {
+ color[0] = col2.value[0];
+ color[1] = col2.value[1];
+ color[2] = col2.value[2];
+ return;
+ }
+ ++ it;
+ }
+}
+
Dye::Dye(const std::string &description)
{
- for (int i = 0; i < 7; ++i)
+ for (int i = 0; i < dyePalateSize; ++i)
mDyePalettes[i] = nullptr;
if (description.empty())
@@ -239,6 +262,7 @@ Dye::Dye(const std::string &description)
case 'M': i = 4; break;
case 'C': i = 5; break;
case 'W': i = 6; break;
+ case 'S': i = 7; break;
default:
logger->log("Error, invalid dye: %s", description.c_str());
return;
@@ -252,7 +276,7 @@ Dye::Dye(const std::string &description)
Dye::~Dye()
{
- for (int i = 0; i < 7; ++i)
+ for (int i = 0; i < dyePalateSize; ++i)
{
delete mDyePalettes[i];
mDyePalettes[i] = nullptr;
@@ -261,6 +285,12 @@ Dye::~Dye()
void Dye::update(int color[3]) const
{
+ if (mDyePalettes[dyePalateSize - 1])
+ {
+ mDyePalettes[dyePalateSize - 1]->replaceColor(color);
+ return;
+ }
+
int cmax = std::max(color[0], std::max(color[1], color[2]));
if (cmax == 0)
return;
@@ -268,8 +298,8 @@ void Dye::update(int color[3]) const
int cmin = std::min(color[0], std::min(color[1], color[2]));
int intensity = color[0] + color[1] + color[2];
- if (cmin != cmax &&
- (cmin != 0 || (intensity != cmax && intensity != 2 * cmax)))
+ if (cmin != cmax && (cmin != 0 || (intensity != cmax
+ && intensity != 2 * cmax)))
{
// not pure
return;
diff --git a/src/resources/dye.h b/src/resources/dye.h
index 94bee3b58..34afcf8ed 100644
--- a/src/resources/dye.h
+++ b/src/resources/dye.h
@@ -26,6 +26,8 @@
#include <string>
#include <vector>
+const int dyePalateSize = 8;
+
/**
* Class for performing a linear interpolation between colors.
*/
@@ -57,11 +59,13 @@ class DyePalette
*/
void getColor(double intensity, int color[3]) const;
- private:
+ void replaceColor(int color[3]) const;
- struct Color { unsigned char value[3]; };
+ private:
+ struct Color
+ { unsigned char value[3]; };
- std::vector< Color > mColors;
+ std::vector<Color> mColors;
};
/**
@@ -100,9 +104,9 @@ class Dye
/**
* The order of the palettes, as well as their uppercase letter, is:
*
- * Red, Green, Yellow, Blue, Magenta, White (or rather gray).
+ * Red, Green, Yellow, Blue, Magenta, White (or rather gray), Simple.
*/
- DyePalette *mDyePalettes[7];
+ DyePalette *mDyePalettes[dyePalateSize];
};
#endif