summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-03-14 20:54:35 -0600
committerIra Rice <irarice@gmail.com>2009-03-14 20:54:35 -0600
commit6d6fd0cec10601a51cab67e623a579a14af775fc (patch)
treebbe8182819b363f0ae22e6422d8a802eeac3f250 /src
parent8fb5276dcc5c527a3daf99c18826d6d9bf9802be (diff)
downloadmana-6d6fd0cec10601a51cab67e623a579a14af775fc.tar.gz
mana-6d6fd0cec10601a51cab67e623a579a14af775fc.tar.bz2
mana-6d6fd0cec10601a51cab67e623a579a14af775fc.tar.xz
mana-6d6fd0cec10601a51cab67e623a579a14af775fc.zip
Made the slider editable when pulse gradient is selected.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/palette.cpp34
-rw-r--r--src/gui/palette.h20
-rw-r--r--src/gui/setup_colors.cpp15
3 files changed, 56 insertions, 13 deletions
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
index 412550c7..5b98f403 100644
--- a/src/gui/palette.cpp
+++ b/src/gui/palette.cpp
@@ -52,12 +52,11 @@ std::string Palette::getConfigName(const std::string& typeName)
int pos = 5;
for (unsigned int i = 0; i < typeName.length(); i++)
{
- if (i==0 || typeName[i] == '_')
+ if (i == 0 || typeName[i] == '_')
{
if (i > 0)
- {
i++;
- }
+
res[pos] = typeName[i];
}
else
@@ -144,7 +143,7 @@ Palette::~Palette()
{
configName = &ColorTypeNames[col->type];
config.setValue(*configName + "Gradient", col->committedGrad);
- if (col->grad == STATIC)
+ if (col->grad == STATIC || col->grad == PULSE)
{
config.setValue(*configName, toString(col->getRGB()));
}
@@ -154,7 +153,7 @@ Palette::~Palette()
const gcn::Color& Palette::getColor(char c, bool &valid)
{
for (ColVector::const_iterator col = mColVector.begin(),
- colEnd = mColVector.end(); col != colEnd; ++col)
+ colEnd = mColVector.end(); col != colEnd; ++col)
{
if (col->ch == c)
{
@@ -222,10 +221,14 @@ void Palette::commit(bool commitNonStatic)
i != iEnd; ++i)
{
i->committedGrad = i->grad;
- if (commitNonStatic || i->grad == STATIC || i->grad == PULSE)
+ if (commitNonStatic || i->grad == STATIC)
{
i->committedColor = i->color;
}
+ else if (i->grad == PULSE)
+ {
+ i->committedColor = i->testColor;
+ }
}
}
@@ -240,7 +243,13 @@ void Palette::rollback()
setGradient(i->type, i->committedGrad);
}
setColor(i->type, i->committedColor.r, i->committedColor.g,
- i->committedColor.b);
+ i->committedColor.b);
+ if (i->grad == PULSE)
+ {
+ i->testColor.r = i->committedColor.r;
+ i->testColor.g = i->committedColor.g;
+ i->testColor.b = i->committedColor.b;
+ }
}
}
@@ -282,9 +291,10 @@ void Palette::advanceGradient ()
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 *
+ (mGradVector[i]->gradientIndex) / 255) + 1) / 2);
- const gcn::Color* col = &mGradVector[i]->committedColor;
+ const gcn::Color* col = &mGradVector[i]->testColor;
mGradVector[i]->color.r = (colVal) % (col->r + 1);
mGradVector[i]->color.g = (colVal) % (col->g + 1);
@@ -294,11 +304,13 @@ 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 / GRADIENT_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 * (GRADIENT_DELAY-pos) /
+ GRADIENT_DELAY) + 1) / 2);
}
mGradVector[i]->color.r =
diff --git a/src/gui/palette.h b/src/gui/palette.h
index 0947aa58..ccef231e 100644
--- a/src/gui/palette.h
+++ b/src/gui/palette.h
@@ -151,6 +151,25 @@ class Palette : public gcn::ListModel
{ return mColVector[type].committedColor; }
/**
+ * Gets the test color associated with the specified type.
+ *
+ * @param type the color type requested
+ *
+ * @return the requested test color
+ */
+ inline const gcn::Color& getTestColor(ColorType type)
+ { return mColVector[type].testColor; }
+
+ /**
+ * Sets the test color associated with the specified type.
+ *
+ * @param type the color type requested
+ * @param color the color that should be tested
+ */
+ inline void setTestColor(ColorType type, gcn::Color color)
+ { mColVector[type].testColor = color; }
+
+ /**
* Gets the GradientType associated with the specified type.
*
* @param type the color type of the color
@@ -259,6 +278,7 @@ class Palette : public gcn::ListModel
{
ColorType type;
gcn::Color color;
+ gcn::Color testColor;
gcn::Color committedColor;
std::string text;
char ch;
diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp
index 79c4fcb5..760fdc1f 100644
--- a/src/gui/setup_colors.cpp
+++ b/src/gui/setup_colors.cpp
@@ -275,11 +275,15 @@ void Setup_Colors::action(const gcn::ActionEvent &event)
break;
}
- if (grad != Palette::STATIC)
+ if (grad != Palette::STATIC && grad != Palette::PULSE)
{ // If nonstatic color, don't display the current, but the committed
// color at the sliders
col = &guiPalette->getCommittedColor(type);
}
+ else if (grad == Palette::PULSE)
+ {
+ col = &guiPalette->getTestColor(type);
+ }
setEntry(mRedSlider, mRedText, col->r);
setEntry(mGreenSlider, mGreenText, col->g);
@@ -381,7 +385,7 @@ void Setup_Colors::updateGradType()
(grad == Palette::PULSE) ? _("Pulse") :
(grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum"));
- bool enable = (grad == Palette::STATIC);
+ bool enable = (grad == Palette::STATIC || grad == Palette::PULSE);
mRedText->setEnabled(enable);
mRedSlider->setEnabled(enable);
mGreenText->setEnabled(enable);
@@ -407,4 +411,11 @@ void Setup_Colors::updateColor()
static_cast<int>(mGreenSlider->getValue()),
static_cast<int>(mBlueSlider->getValue()));
}
+ else if (grad == Palette::PULSE)
+ {
+ guiPalette->setTestColor(type, gcn::Color(
+ static_cast<int>(mRedSlider->getValue()),
+ static_cast<int>(mGreenSlider->getValue()),
+ static_cast<int>(mBlueSlider->getValue())));
+ }
}