From ef13037435c671b76c75c3ecefbad83dbdc578f2 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 15 Apr 2009 19:42:07 +0200 Subject: 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. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ira Rice Signed-off-by: Bjørn Lindeijer --- src/gui/palette.cpp | 62 +++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'src/gui/palette.cpp') 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 + -- cgit v1.2.3-70-g09d2