summaryrefslogtreecommitdiff
path: root/src/gui/palette.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-04-15 19:42:07 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-15 19:43:35 +0200
commitef13037435c671b76c75c3ecefbad83dbdc578f2 (patch)
tree18f75b4e1a72d0453e9d9ae621ced87066123d7c /src/gui/palette.cpp
parentfc4a12470adde2502f37f22b86f58560e416f3e4 (diff)
downloadmana-ef13037435c671b76c75c3ecefbad83dbdc578f2.tar.gz
mana-ef13037435c671b76c75c3ecefbad83dbdc578f2.tar.bz2
mana-ef13037435c671b76c75c3ecefbad83dbdc578f2.tar.xz
mana-ef13037435c671b76c75c3ecefbad83dbdc578f2.zip
Exposed delay values to the user, but made it so that the delay is color
based, instead of global, so that the user can specify different delays for different types of actions. Signed-off-by: Ira Rice <irarice@gmail.com> Signed-off-by: Bjørn Lindeijer <bjorn@lindeijer.nl>
Diffstat (limited to 'src/gui/palette.cpp')
-rw-r--r--src/gui/palette.cpp62
1 files changed, 34 insertions, 28 deletions
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
index 92a2aea5..d06d589f 100644
--- a/src/gui/palette.cpp
+++ b/src/gui/palette.cpp
@@ -73,8 +73,6 @@ std::string Palette::getConfigName(const std::string &typeName)
DEFENUMNAMES(ColorType, COLOR_TYPE);
-const int Palette::GRADIENT_DELAY = 40;
-
Palette::Palette() :
mRainbowTime(tick_time),
mColVector(ColVector(TYPE_COUNT))
@@ -149,10 +147,12 @@ Palette::~Palette()
{
configName = &ColorTypeNames[col->type];
config.setValue(*configName + "Gradient", col->committedGrad);
+
+ if (col->grad != STATIC)
+ config.setValue(*configName + "Delay", col->delay);
+
if (col->grad == STATIC || col->grad == PULSE)
- {
config.setValue(*configName, toString(col->getRGB()));
- }
}
}
@@ -227,6 +227,7 @@ void Palette::commit(bool commitNonStatic)
i != iEnd; ++i)
{
i->committedGrad = i->grad;
+ i->committedDelay = i->delay;
if (commitNonStatic || i->grad == STATIC)
{
i->committedColor = i->color;
@@ -241,13 +242,13 @@ void Palette::commit(bool commitNonStatic)
void Palette::rollback()
{
for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
- i != iEnd;
- ++i)
+ i != iEnd; ++i)
{
if (i->grad != i->committedGrad)
{
setGradient(i->type, i->committedGrad);
}
+ setGradientDelay(i->type, i->committedDelay);
setColor(i->type, i->committedColor.r, i->committedColor.g,
i->committedColor.b);
if (i->grad == PULSE)
@@ -260,24 +261,24 @@ void Palette::rollback()
}
void Palette::addColor(Palette::ColorType type, int rgb,
- Palette::GradientType grad,
- const std::string &text, char c)
+ Palette::GradientType grad, const std::string &text,
+ char c, int delay)
{
const std::string *configName = &ColorTypeNames[type];
- gcn::Color trueCol = (int)config.getValue(*configName, rgb);
- grad = (GradientType)config.getValue(*configName + "Gradient", grad);
- mColVector[type].set(type, trueCol, grad, text, c);
+ gcn::Color trueCol = (int) config.getValue(*configName, rgb);
+ grad = (GradientType) config.getValue(*configName + "Gradient", grad);
+ delay = (int) config.getValue(*configName + "Delay", delay);
+ mColVector[type].set(type, trueCol, grad, text, c, delay);
+
if (grad != STATIC)
- {
mGradVector.push_back(&mColVector[type]);
- }
}
void Palette::advanceGradient ()
{
if (get_elapsed_time(mRainbowTime) > 5)
{
- int pos, colIndex, colVal;
+ 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.
@@ -286,19 +287,25 @@ void Palette::advanceGradient ()
for (size_t i = 0; i < mGradVector.size(); i++)
{
+ delay = mGradVector[i]->delay;
+
+ if (mGradVector[i]->grad == PULSE)
+ delay = delay / 20;
+
+ numOfColors = (mGradVector[i]->grad == SPECTRUM ? 6 :
+ mGradVector[i]->grad == PULSE ? 127 :
+ RAINBOW_COLOR_COUNT);
+
mGradVector[i]->gradientIndex =
- (mGradVector[i]->gradientIndex + advance) %
- (GRADIENT_DELAY * ((mGradVector[i]->grad == SPECTRUM) ?
- (mGradVector[i]->grad == PULSE) ? 255 : 6 :
- RAINBOW_COLOR_COUNT));
+ (mGradVector[i]->gradientIndex + advance) %
+ (delay * numOfColors);
- pos = mGradVector[i]->gradientIndex % GRADIENT_DELAY;
- colIndex = mGradVector[i]->gradientIndex / GRADIENT_DELAY;
+ pos = mGradVector[i]->gradientIndex % delay;
+ colIndex = mGradVector[i]->gradientIndex / delay;
if (mGradVector[i]->grad == PULSE)
{
- colVal = (int) (255.0 * (sin(M_PI *
- (mGradVector[i]->gradientIndex) / 255) + 1) / 2);
+ colVal = (int) (255.0 * sin(M_PI * colIndex / numOfColors));
const gcn::Color* col = &mGradVector[i]->testColor;
@@ -310,13 +317,12 @@ void Palette::advanceGradient ()
{
if (colIndex % 2)
{ // falling curve
- colVal = (int)(255.0 * (cos(M_PI * pos / GRADIENT_DELAY) +
- 1) / 2);
+ colVal = (int)(255.0 * (cos(M_PI * pos / delay) + 1) / 2);
}
else
{ // ascending curve
- colVal = (int)(255.0 * (cos(M_PI * (GRADIENT_DELAY-pos) /
- GRADIENT_DELAY) + 1) / 2);
+ colVal = (int)(255.0 * (cos(M_PI * (delay - pos) / delay) +
+ 1) / 2);
}
mGradVector[i]->color.r =
@@ -333,9 +339,9 @@ void Palette::advanceGradient ()
{
const gcn::Color* startCol = &RAINBOW_COLORS[colIndex];
const gcn::Color* destCol =
- &RAINBOW_COLORS[(colIndex + 1) % RAINBOW_COLOR_COUNT];
+ &RAINBOW_COLORS[(colIndex + 1) % numOfColors];
- startColVal = (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2;
+ startColVal = (cos(M_PI * pos / delay) + 1) / 2;
destColVal = 1 - startColVal;
mGradVector[i]->color.r =(int)(startColVal * startCol->r +