summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsniper <sniper@livecd.janhome.net>2009-03-11 15:35:54 +0100
committerJared Adams <jaxad0127@gmail.com>2009-03-12 18:53:16 -0600
commit4260cb92571842c6336537bf0d0c47c4f011ac0f (patch)
tree6c9ce9d69dc6914bb9948b152171d216a801f7c9
parentf3796c231d5bcac6850fb9afc8db652361e3fceb (diff)
downloadmana-client-4260cb92571842c6336537bf0d0c47c4f011ac0f.tar.gz
mana-client-4260cb92571842c6336537bf0d0c47c4f011ac0f.tar.bz2
mana-client-4260cb92571842c6336537bf0d0c47c4f011ac0f.tar.xz
mana-client-4260cb92571842c6336537bf0d0c47c4f011ac0f.zip
Extending the internal handling of colors
The internal storage for colors was in the file color.h/color.cpp. It mainly managed the colors in the chat. The Color class was extended to be more generic now and it stores gcn::Color objects instead of integers now. A lot of new colortypes are now available, though not many of them are used for now, that will come in the next patches. The Color class was renamed to Palette and color.{h,cpp} to palette.{h,cpp} to better describe its purpose. The color config gui now lists the new colors, even changes them, but the result is not displayed properly for now.
-rw-r--r--src/Makefile.am4
-rw-r--r--src/gui/browserbox.cpp21
-rw-r--r--src/gui/color.cpp146
-rw-r--r--src/gui/color.h136
-rw-r--r--src/gui/listbox.cpp11
-rw-r--r--src/gui/palette.cpp315
-rw-r--r--src/gui/palette.h296
-rw-r--r--src/gui/setup_colors.cpp55
-rw-r--r--src/gui/setup_colors.h2
-rw-r--r--src/gui/shoplistbox.cpp33
-rw-r--r--src/gui/table.cpp33
-rw-r--r--src/gui/widgets/dropdown.cpp21
-rw-r--r--src/main.cpp8
13 files changed, 700 insertions, 381 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4982c215..06c392db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,8 +31,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \
gui/chatinput.h \
gui/checkbox.cpp \
gui/checkbox.h \
- gui/color.cpp \
- gui/color.h \
+ gui/palette.cpp \
+ gui/palette.h \
gui/confirm_dialog.cpp \
gui/confirm_dialog.h \
gui/connection.cpp \
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index 7bdbcbef..596174cc 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -24,8 +24,8 @@
#include <guichan/graphics.hpp>
#include "browserbox.h"
-#include "color.h"
#include "linkhandler.h"
+#include "palette.h"
#include "truetypefont.h"
BrowserBox::BrowserBox(unsigned int mode, bool opaque):
@@ -249,16 +249,15 @@ void BrowserBox::draw(gcn::Graphics *graphics)
if (mOpaque)
{
- graphics->setColor(gcn::Color(BGCOLOR));
+ graphics->setColor(guiPalette->getColor(Palette::BACKGROUND));
graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
}
if (mSelectedLink >= 0)
{
- bool valid;
if ((mHighMode & BACKGROUND))
{
- graphics->setColor(gcn::Color(textColor->getColor('H', valid)));
+ graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT));
graphics->fillRectangle(gcn::Rectangle(
mLinks[mSelectedLink].x1,
mLinks[mSelectedLink].y1,
@@ -269,7 +268,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
if ((mHighMode & UNDERLINE))
{
- graphics->setColor(gcn::Color(textColor->getColor('<', valid)));
+ graphics->setColor(guiPalette->getColor(Palette::HYPERLINK));
graphics->drawLine(
mLinks[mSelectedLink].x1,
mLinks[mSelectedLink].y2,
@@ -283,11 +282,11 @@ void BrowserBox::draw(gcn::Graphics *graphics)
int link = 0;
TrueTypeFont *font = static_cast<TrueTypeFont*>(getFont());
- graphics->setColor(BLACK);
+ graphics->setColor(guiPalette->getColor(Palette::TEXT));
for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++)
{
- int selColor = BLACK;
- int prevColor = selColor;
+ const gcn::Color *selColor = &guiPalette->getColor(Palette::TEXT);
+ const gcn::Color *prevColor = selColor;
std::string row = *(i);
bool wrapped = false;
x = 0;
@@ -335,7 +334,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
else
{
bool valid;
- int rgb = textColor->getColor(c, valid);
+ const gcn::Color *col = &guiPalette->getColor(c, valid);
if (c == '<')
{
const int size = mLinks[link].x2 - mLinks[link].x1;
@@ -348,7 +347,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
}
if (valid)
{
- selColor = rgb;
+ selColor = col;
}
}
start += 3;
@@ -358,7 +357,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
break;
}
}
- graphics->setColor(gcn::Color(selColor));
+ graphics->setColor(*selColor);
}
std::string::size_type len =
diff --git a/src/gui/color.cpp b/src/gui/color.cpp
deleted file mode 100644
index f9b89857..00000000
--- a/src/gui/color.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Configurable text colors
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "color.h"
-
-#include "../configuration.h"
-
-#include "../utils/gettext.h"
-#include "../utils/stringutils.h"
-
-Color::Color()
-{
- addColor('C', 0x000000, _("Chat"));
- addColor('G', 0xff0000, _("GM"));
- addColor('H', 0xebc873, _("Highlight"));
- addColor('Y', 0x1fa052, _("Player"));
- addColor('W', 0x0000ff, _("Whisper"));
- addColor('I', 0xa08527, _("Is"));
- addColor('P', 0xff00d8, _("Party"));
- addColor('S', 0x8415e2, _("Server"));
- addColor('L', 0x919191, _("Logger"));
- addColor('<', 0xe50d0d, _("Hyperlink"));
- commit();
-}
-
-Color::~Color()
-{
- for (ColVector::iterator col = mColVector.begin(),
- colEnd = mColVector.end();
- col != colEnd;
- ++col)
- {
- config.setValue("Color" + col->text, toString(col->rgb));
- }
-}
-
-void Color::setColor(char c, int rgb)
-{
- for (ColVector::iterator col = mColVector.begin(),
- colEnd = mColVector.end();
- col != colEnd;
- ++col)
- {
- if (col->ch == c)
- {
- col->rgb = rgb;
- return;
- }
- }
-}
-
-int Color::getColor(char c, bool &valid) const
-{
- for (ColVector::const_iterator col = mColVector.begin(),
- colEnd = mColVector.end();
- col != colEnd;
- ++col)
- {
- if (col->ch == c)
- {
- valid = true;
- return col->rgb;
- }
- }
- valid = false;
- return 0x000000;
-}
-
-std::string Color::getElementAt(int i)
-{
- if (i < 0 || i >= getNumberOfElements())
- {
- return "";
- }
- return mColVector[i].text;
-}
-
-char Color::getColorCharAt(int i)
-{
- if (i < 0 || i >= getNumberOfElements())
- {
- return 'C';
- }
- return mColVector[i].ch;
-}
-
-void Color::addColor(char c, int rgb, const std::string &text)
-{
- int trueRgb = (int) config.getValue("Color" + text, rgb);
- mColVector.push_back(ColorElem(c, trueRgb, text));
-}
-
-int Color::getColorAt(int i)
-{
- if (i < 0 || i >= getNumberOfElements())
- {
- return 0;
- }
- return mColVector[i].rgb;
-}
-
-void Color::setColorAt(int i, int rgb)
-{
- if (i >= 0 && i < getNumberOfElements())
- {
- mColVector[i].rgb = rgb;
- }
-}
-
-void Color::commit()
-{
- for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
- i != iEnd;
- ++i)
- {
- i->committedRgb = i->rgb;
- }
-}
-
-void Color::rollback()
-{
- for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
- i != iEnd;
- ++i)
- {
- i->rgb = i->committedRgb;
- }
-}
diff --git a/src/gui/color.h b/src/gui/color.h
deleted file mode 100644
index 2816cedc..00000000
--- a/src/gui/color.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Configurable text colors
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef COLOR_H
-#define COLOR_H
-
-#include <string>
-#include <vector>
-
-#include <guichan/listmodel.hpp>
-
-class Color : public gcn::ListModel
-{
- public:
- /**
- * Constructor
- */
- Color();
-
- /**
- * Destructor
- */
- ~Color();
-
- /**
- * Define the color replacement for a character
- *
- * @param c charater to be replaced
- * @param rgb color to replace character
- */
- void setColor(char c, int rgb);
-
- /**
- * Define the color replacement for a character
- *
- * @param c character to be replaced
- * @param r red component
- * @param g green component
- * @param b blue component
- */
- void setColor(char c, int r, int g, int b)
- {
- setColor(c, (r << 16) | (g << 8) | b);
- }
-
- /**
- * Return the color associated with a character, if exists
- *
- * @param c character requested
- * @param valid indicate whether character is known
- */
- int getColor(char c, bool &valid) const;
-
- /**
- * Return the number of colors known
- */
- int getNumberOfElements() { return mColVector.size(); }
-
- /**
- * Return the name of the ith color
- *
- * @param i index of color interested in
- */
- std::string getElementAt(int i);
-
- /**
- * Get the color for the element at index i in the current color
- * model
- */
- int getColorAt(int i);
-
- /**
- * Get the character used by the color for the element at index i in
- * the current color model
- */
- char getColorCharAt(int i);
-
- /**
- * Set the color for the element at index i
- */
- void setColorAt(int i, int rgb);
-
- /**
- * Commit the colors
- */
- void commit();
-
- /**
- * Rollback the colors
- */
- void rollback();
-
- private:
- struct ColorElem
- {
- ColorElem(char c, int rgb, const std::string &text) :
- ch(c), rgb(rgb), text(text) {}
- char ch;
- int rgb;
- int committedRgb;
- std::string text;
- };
- typedef std::vector<ColorElem> ColVector;
- ColVector mColVector;
-
- /**
- * Initialise color
- *
- * @param c character that needs initialising
- * @param rgb default color if not found in config
- * @param text identifier of color
- */
- void addColor(char c, int rgb, const std::string &text);
-};
-
-extern Color *textColor;
-
-#endif
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index cd5aa736..23d43066 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -24,8 +24,8 @@
#include <guichan/key.hpp>
#include <guichan/listmodel.hpp>
-#include "color.h"
#include "listbox.h"
+#include "palette.h"
#include "../configuration.h"
@@ -44,13 +44,8 @@ void ListBox::draw(gcn::Graphics *graphics)
if (config.getValue("guialpha", 0.8) != mAlpha)
mAlpha = config.getValue("guialpha", 0.8);
- bool valid;
- const int red = (textColor->getColor('H', valid) >> 16) & 0xFF;
- const int green = (textColor->getColor('H', valid) >> 8) & 0xFF;
- const int blue = textColor->getColor('H', valid) & 0xFF;
- const int alpha = (int)(mAlpha * 255.0f);
-
- graphics->setColor(gcn::Color(red, green, blue, alpha));
+ graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT,
+ (int)(mAlpha * 255.0f)));
graphics->setFont(getFont());
const int fontHeight = getFont()->getHeight();
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
new file mode 100644
index 00000000..0298953c
--- /dev/null
+++ b/src/gui/palette.cpp
@@ -0,0 +1,315 @@
+/*
+ * Configurable text colors
+ * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <math.h>
+
+#include "palette.h"
+#include "gui.h"
+
+#include "../configuration.h"
+#include "../game.h"
+
+#include "../utils/gettext.h"
+#include "../utils/stringutils.h"
+
+const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0);
+
+const gcn::Color Palette::RAINBOW_COLORS[8] = {
+ gcn::Color(255, 0, 0),
+ gcn::Color(255, 153, 0),
+ gcn::Color(255, 255, 0),
+ gcn::Color(0, 153, 0),
+ gcn::Color(0, 204, 204),
+ gcn::Color(51, 0, 153),
+ gcn::Color(153, 0, 153)
+};
+/** Number of Elemets of RAINBOW_COLORS */
+const int Palette::RAINBOW_COLOR_COUNT = 7;
+
+std::string Palette::getConfigName(const std::string& typeName)
+{
+ std::string res = "Color" + typeName;
+
+ int pos = 5;
+ for (int i = 0; i < typeName.length(); i++)
+ {
+ if (i==0 || typeName[i] == '_')
+ {
+ if (i > 0)
+ {
+ i++;
+ }
+ res[pos] = typeName[i];
+ }
+ else
+ {
+ res[pos] = tolower(typeName[i]);
+ }
+ pos++;
+ }
+ res.erase(pos, res.length() - pos);
+
+ return res;
+}
+
+DEFENUMNAMES(ColorType, COLOR_TYPE);
+
+const int Palette::GRADIENT_DELAY = 20;
+
+Palette::Palette() : mColVector(ColVector(TYPE_COUNT)), mGradVector(),
+ mRainbowTime(tick_time)
+{
+ std::string indent = " ";
+ addColor(TEXT, 0x000000, STATIC, _("Text"));
+ addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow"), 0);
+ addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"), 0);
+
+ addColor(BACKGROUND, 0xffffff, STATIC, _("Background"));
+
+ addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H');
+ addColor(SHOP_WARNING, 0x910000, STATIC, indent +
+ _("Item too expensive"));
+
+ addColor(CHAT, 0x000000, STATIC, _("Chat"), 'C');
+ addColor(GM, 0xff0000, STATIC, indent + _("GM"), 'G');
+ addColor(PLAYER, 0x1fa052, STATIC, indent + _("Player"), 'Y');
+ addColor(WHISPER, 0x0000ff, STATIC, indent + _("Whisper"), 'W');
+ addColor(IS, 0xa08527, STATIC, indent + _("Is"), 'I');
+ addColor(PARTY, 0xff00d8, STATIC, indent + _("Party"), 'P');
+ addColor(SERVER, 0x8415e2, STATIC, indent + _("Server"), 'S');
+ addColor(LOGGER, 0x919191, STATIC, indent + _("Logger"), 'L');
+ addColor(HYPERLINK, 0xe50d0d, STATIC, indent + _("Hyperlink"), '<');
+
+ addColor(BEING, 0xffffff, STATIC, _("Being"), 0);
+ addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names"), 0);
+ addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"), 0);
+ addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"), 0);
+ addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"), 0);
+ addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"), 0);
+
+ addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0);
+ addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"),
+ 0);
+ addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"),0);
+ addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC,
+ indent + _("Player hits Monster"), 0);
+ addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC,
+ indent + _("Monster hits Player"), 0);
+ addColor(HIT_CRITICAL, 0xff0000, RAINBOW,
+ indent + _("Critical Hit"), 0);
+ addColor(MISS, 0xffff00, STATIC, indent + _("Misses"), 0);
+ commit(true);
+}
+
+Palette::~Palette()
+{
+ const std::string *configName;
+ for (ColVector::iterator col = mColVector.begin(),
+ colEnd = mColVector.end();
+ col != colEnd; ++col)
+ {
+ configName = &ColorTypeNames[col->type];
+ config.setValue(*configName + "Gradient", col->grad);
+ if (col->grad == STATIC)
+ {
+ config.setValue(*configName, toString(col->getRGB()));
+ }
+ }
+}
+
+const gcn::Color& Palette::getColor(char c, bool &valid)
+ {
+ for (ColVector::const_iterator col = mColVector.begin(),
+ colEnd = mColVector.end(); col != colEnd; ++col)
+ {
+ if (col->ch == c)
+ {
+ valid = true;
+ return col->color;
+ }
+ }
+ valid = false;
+ return BLACK;
+}
+
+void Palette::setColor(ColorType type, int r, int g, int b)
+{
+ mColVector[type].color.r = r;
+ mColVector[type].color.g = g;
+ mColVector[type].color.b = b;
+}
+
+void Palette::setGradient(ColorType type, GradientType grad)
+{
+ ColorElem *elem = &mColVector[type];
+ if (elem->grad != STATIC && grad == STATIC)
+ {
+ for (int i = 0; i < mGradVector.size(); i++)
+ {
+ if (mGradVector[i] == elem)
+ {
+ mGradVector.erase(mGradVector.begin() + i);
+ break;
+ }
+ }
+ }
+ else if (elem->grad == STATIC && grad != STATIC)
+ {
+ mGradVector.push_back(elem);
+ }
+
+ if (elem->grad != grad)
+ {
+ elem->grad = grad;
+ }
+}
+
+std::string Palette::getElementAt(int i)
+{
+ if (i < 0 || i >= getNumberOfElements())
+ {
+ return "";
+ }
+ return mColVector[i].text;
+}
+
+Palette::ColorType Palette::getColorTypeAt(int i)
+{
+ if (i < 0 || i >= getNumberOfElements())
+ {
+ return CHAT;
+ }
+ return mColVector[i].type;
+}
+
+void Palette::commit(bool commitNonStatic)
+{
+ for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
+ i != iEnd; ++i)
+ {
+ i->committedGrad = i->grad;
+ if (commitNonStatic || i->grad == STATIC)
+ {
+ i->committedColor = i->color;
+ }
+ }
+}
+
+void Palette::rollback()
+{
+ for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
+ i != iEnd;
+ ++i)
+ {
+ i->grad = i->committedGrad;
+ if (i->grad == STATIC)
+ {
+ i->color = i->committedColor;
+ }
+ }
+}
+
+void Palette::addColor(Palette::ColorType type, int rgb,
+ Palette::GradientType grad,
+ const std::string &text, char c)
+{
+ 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);
+ if (grad != STATIC)
+ {
+ mGradVector.push_back(&mColVector[type]);
+ }
+}
+
+void Palette::advanceGradient ()
+{
+ if (get_elapsed_time(mRainbowTime) > 5)
+ {
+ int pos, colIndex, colVal;
+ // For slower systems, advance can be greater than one (adcanve > 1
+ // skips advance-1 steps). Should make gradient look the same
+ // independent of the framerate.
+ int advance = get_elapsed_time(mRainbowTime) / 5;
+ double startColVal, destColVal;
+
+ for (int i = 0; i < mGradVector.size(); i++)
+ {
+ mGradVector[i]->gradientIndex =
+ (mGradVector[i]->gradientIndex + advance) %
+ (GRADIENT_DELAY *
+ ((mGradVector[i]->grad == SPECTRUM) ? 6 :
+ RAINBOW_COLOR_COUNT));
+
+ pos = mGradVector[i]->gradientIndex % GRADIENT_DELAY;
+ colIndex = mGradVector[i]->gradientIndex / GRADIENT_DELAY;
+
+ if (mGradVector[i]->grad == SPECTRUM)
+ {
+ if (colIndex % 2)
+ { // falling curve
+ 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);
+ }
+
+ mGradVector[i]->color.r =
+ (colIndex == 0 || colIndex == 5) ? 255 :
+ (colIndex == 1 || colIndex == 4) ? colVal : 0;
+ mGradVector[i]->color.g =
+ (colIndex == 1 || colIndex == 2) ? 255 :
+ (colIndex == 0 || colIndex == 3) ? colVal : 0;
+ mGradVector[i]->color.b =
+ (colIndex == 3 || colIndex == 4) ? 255 :
+ (colIndex == 2 || colIndex == 5) ? colVal : 0;
+ }
+ else
+ {
+ const gcn::Color* startCol = &RAINBOW_COLORS[colIndex];
+ const gcn::Color* destCol =
+ &RAINBOW_COLORS[(colIndex + 1) % RAINBOW_COLOR_COUNT];
+
+ startColVal = (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2;
+ destColVal = 1 - startColVal;
+
+ mGradVector[i]->color.r =(int)(
+ startColVal * startCol->r +
+ destColVal * destCol->r);
+
+ mGradVector[i]->color.g =(int)(
+ startColVal * startCol->g +
+ destColVal * destCol->g);
+
+ mGradVector[i]->color.b =(int)(
+ startColVal * startCol->b +
+ destColVal * destCol->b);
+ }
+ }
+
+ mRainbowTime = tick_time;
+ }
+}
diff --git a/src/gui/palette.h b/src/gui/palette.h
new file mode 100644
index 00000000..c32fbc8a
--- /dev/null
+++ b/src/gui/palette.h
@@ -0,0 +1,296 @@
+/*
+ * Configurable text colors
+ * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
+ *
+ * This file is part of The Mana World.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALETTE_H
+#define PALETTE_H
+
+#include <cstdlib>
+#include <string>
+#include <vector>
+
+#include <guichan/listmodel.hpp>
+#include <guichan/color.hpp>
+
+// Generate strings from an enum ... some preprocessor fun.
+#define EDEF(a) a,
+#define ECONFIGSTR(a) Palette::getConfigName(#a),
+
+#define TEXTENUM(name,def)\
+ enum name { def(EDEF) };\
+ static const std::string name ## Names[];
+#define DEFENUMNAMES(name,def)\
+ const std::string Palette::name ## Names[] = { def(ECONFIGSTR) "" };
+
+/**
+ * Class controlling the game's color palette.
+ */
+class Palette : public gcn::ListModel
+{
+ public:
+ /** List of all colors that are configurable. */
+ #define COLOR_TYPE(ENTRY)\
+ ENTRY(TEXT)\
+ ENTRY(SHADOW)\
+ ENTRY(OUTLINE)\
+ ENTRY(BACKGROUND)\
+ ENTRY(HIGHLIGHT)\
+ ENTRY(SHOP_WARNING)\
+ ENTRY(CHAT)\
+ ENTRY(GM)\
+ ENTRY(PLAYER)\
+ ENTRY(WHISPER)\
+ ENTRY(IS)\
+ ENTRY(PARTY)\
+ ENTRY(SERVER)\
+ ENTRY(LOGGER)\
+ ENTRY(HYPERLINK)\
+ ENTRY(BEING)\
+ ENTRY(PC)\
+ ENTRY(SELF)\
+ ENTRY(GM_NAME)\
+ ENTRY(NPC)\
+ ENTRY(MONSTER)\
+ ENTRY(PARTICLE)\
+ ENTRY(EXP_INFO)\
+ ENTRY(PICKUP_INFO)\
+ ENTRY(HIT_PLAYER_MONSTER)\
+ ENTRY(HIT_MONSTER_PLAYER)\
+ ENTRY(HIT_CRITICAL)\
+ ENTRY(MISS)\
+ ENTRY(TYPE_COUNT)\
+
+ TEXTENUM(ColorType, COLOR_TYPE);
+
+ /** Colors can be static or can alter over time. */
+ enum GradientType {
+ STATIC,
+ SPECTRUM,
+ RAINBOW
+ };
+
+ /**
+ * Constructor
+ */
+ Palette();
+
+ /**
+ * Destructor
+ */
+ ~Palette();
+
+ /**
+ * Returns the color associated with a character, if it exists. Returns
+ * Palette::BLACK if the character is not found.
+ *
+ * @param c character requested
+ * @param valid indicate whether character is known
+ *
+ * @return the requested color or Palette::BLACK
+ */
+ const gcn::Color& getColor(char c, bool &valid);
+
+ /**
+ * Gets the color with the associated type. Sets the alpha channel
+ * before returning.
+ *
+ * @param type the color type requested
+ * @param alpha alpha channel to use
+ *
+ * @return the requested color
+ */
+ inline const gcn::Color& getColor(ColorType type, int alpha = 255)
+ {
+ gcn::Color* col = &mColVector[type].color;
+ col->a = alpha;
+ return *col;
+ }
+
+ /**
+ * Gets the GradientType used by the specified color.
+ *
+ * @param type the color type of the color
+ *
+ * @return the gradient type of the color with the given index
+ */
+ inline GradientType getGradientType(ColorType type)
+ {
+ return mColVector[type].grad;
+ }
+
+ /**
+ * Get the character used by the specified color.
+ *
+ * @param type the color type of the color
+ *
+ * @return the color char of the color with the given index
+ */
+ inline char getColorChar(ColorType type)
+ {
+ return mColVector[type].ch;
+ }
+
+ /**
+ * Sets the color for the specified type.
+ *
+ * @param type color to be set
+ * @param r red component
+ * @param g green component
+ * @param b blue component
+ */
+ void setColor(ColorType type, int r, int g, int b);
+
+ /**
+ * Sets the gradient type for the specified color.
+ *
+ * @param grad gradient type to set
+ */
+ void setGradient(ColorType type, GradientType grad);
+
+ /**
+ * Returns the number of colors known.
+ *
+ * @return the number of colors known
+ */
+ inline int getNumberOfElements() { return mColVector.size(); }
+
+ /**
+ * Returns the name of the ith color.
+ *
+ * @param i index of color interested in
+ *
+ * @return the name of the color
+ */
+ std::string getElementAt(int i);
+
+ /**
+ * Gets the ColorType used by the color for the element at index i in
+ * the current color model.
+ *
+ * @param i the index of the color
+ *
+ * @return the color type of the color with the given index
+ */
+ ColorType getColorTypeAt(int i);
+
+ /**
+ * Commit the colors
+ */
+ inline void commit()
+ {
+ commit(false);
+ }
+
+ /**
+ * Rollback the colors
+ */
+ void rollback();
+
+ /**
+ * Updates all colors, that are non-static.
+ */
+ void advanceGradient();
+
+ private:
+ /** Black Color Constant */
+ static const gcn::Color BLACK;
+
+ /** Colors used for the rainbow gradient */
+ static const gcn::Color RAINBOW_COLORS[];
+ static const int RAINBOW_COLOR_COUNT;
+ /** Parameter to control the speed of the gradient */
+ static const int GRADIENT_DELAY;
+ /** Time tick, that gradient-type colors were updated the last time. */
+ int mRainbowTime;
+
+ /**
+ * Define a color replacement.
+ *
+ * @param i the index of the color to replace
+ * @param r red component
+ * @param g green component
+ * @param b blue component
+ */
+ void setColorAt(int i, int r, int g, int b);
+
+ /**
+ * Commit the colors. Commit the non-static color values, if
+ * commitNonStatic is true. Only needed in the constructor.
+ */
+ void commit(bool commitNonStatic);
+
+ struct ColorElem
+ {
+ ColorType type;
+ gcn::Color color;
+ gcn::Color committedColor;
+ std::string text;
+ char ch;
+ GradientType grad;
+ GradientType committedGrad;
+ int gradientIndex;
+
+ void set(ColorType type, gcn::Color& color, GradientType grad,
+ const std::string &text, char c)
+ {
+ ColorElem::type = type;
+ ColorElem::color = color;
+ ColorElem::text = text;
+ ColorElem::ch = c;
+ ColorElem::grad = grad;
+ ColorElem::gradientIndex = rand();
+ }
+
+ inline int getRGB() {
+ return (committedColor.r << 16) | (committedColor.g << 8) |
+ committedColor.b;
+ }
+ };
+ typedef std::vector<ColorElem> ColVector;
+ /** Vector containing the colors. */
+ ColVector mColVector;
+ std::vector<ColorElem*> mGradVector;
+
+ /**
+ * Initialise color
+ *
+ * @param c character that needs initialising
+ * @param rgb default color if not found in config
+ * @param text identifier of color
+ */
+ void addColor(ColorType type, int rgb, GradientType grad,
+ const std::string &text, char c = 0);
+
+ /**
+ * Prefixes the given string with "Color", lowercases all letters but
+ * the first and all following a '_'. All '_'s will be removed.
+ *
+ * E.g.: HIT_PLAYER_MONSTER -> HitPlayerMonster
+ *
+ * @param typeName string to transform
+ *
+ * @return the transformed string
+ */
+ static std::string getConfigName(const std::string& typeName);
+};
+
+extern Palette *guiPalette;
+
+#endif
diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp
index 2610be03..6f1da525 100644
--- a/src/gui/setup_colors.cpp
+++ b/src/gui/setup_colors.cpp
@@ -27,9 +27,9 @@
#include <guichan/widgets/slider.hpp>
#include "browserbox.h"
-#include "color.h"
#include "itemlinkhandler.h"
#include "listbox.h"
+#include "palette.h"
#include "scrollarea.h"
#include "setup_colors.h"
#include "slider.h"
@@ -42,12 +42,14 @@
#include "../utils/gettext.h"
#include "../utils/stringutils.h"
+const std::string Setup_Colors::rawmsg = _("This is what the color looks like");
+
Setup_Colors::Setup_Colors() :
mSelected(-1)
{
setOpaque(false);
- mColorBox = new ListBox(textColor);
+ mColorBox = new ListBox(guiPalette);
mColorBox->setActionEventId("color_box");
mColorBox->addActionListener(this);
@@ -130,6 +132,9 @@ Setup_Colors::Setup_Colors() :
Setup_Colors::~Setup_Colors()
{
+ delete mPreview;
+ delete mPreviewBox;
+
delete mRedLabel;
delete mRedSlider;
delete mRedText;
@@ -142,6 +147,7 @@ Setup_Colors::~Setup_Colors()
delete mBlueSlider;
delete mBlueText;
+ delete mColorBox;
delete mScroll;
}
@@ -150,22 +156,22 @@ void Setup_Colors::action(const gcn::ActionEvent &event)
if (event.getId() == "color_box")
{
mSelected = mColorBox->getSelected();
- int col = textColor->getColorAt(mSelected);
- char ch = textColor->getColorCharAt(mSelected);
+ Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
+ const gcn::Color *col = &guiPalette->getColor(type);
+
std::string msg;
+ mPreview->clearRows();
+ char ch = guiPalette->getColorChar(type);
if (ch == '<')
- msg = toString("@@|") +
- _("This is what the color looks like") + "@@";
+ msg = toString("@@|") + rawmsg + "@@";
else
- msg = "##" + toString(ch) +
- _("This is what the color looks like");
-
- mPreview->clearRows();
+ msg = "##" + toString(ch) + rawmsg;
mPreview->addRow(msg);
- setEntry(mRedSlider, mRedText, col >> 16);
- setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff);
- setEntry(mBlueSlider, mBlueText, col & 0xff);
+
+ setEntry(mRedSlider, mRedText, col->r);
+ setEntry(mGreenSlider, mGreenText, col->g);
+ setEntry(mBlueSlider, mBlueText, col->b);
return;
}
@@ -201,16 +207,17 @@ void Setup_Colors::setEntry(gcn::Slider *s, TextField *t, int value)
void Setup_Colors::apply()
{
- textColor->commit();
+ guiPalette->commit();
}
void Setup_Colors::cancel()
{
- textColor->rollback();
- int col = textColor->getColorAt(mSelected);
- setEntry(mRedSlider, mRedText, col >> 16);
- setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff);
- setEntry(mBlueSlider, mBlueText, col & 0xff);
+ guiPalette->rollback();
+ Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
+ const gcn::Color *col = &guiPalette->getColor(type);
+ setEntry(mRedSlider, mRedText, col->r);
+ setEntry(mGreenSlider, mGreenText, col->g);
+ setEntry(mBlueSlider, mBlueText, col->b);
}
void Setup_Colors::listen(const TextField *tf)
@@ -241,8 +248,10 @@ void Setup_Colors::updateColor()
{
return;
}
- int rgb = static_cast<int>(mRedSlider->getValue()) << 16 |
- static_cast<int>(mGreenSlider->getValue()) << 8 |
- static_cast<int>(mBlueSlider->getValue());
- textColor->setColorAt(mSelected, rgb);
+
+ Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
+ guiPalette->setColor(type,
+ static_cast<int>(mRedSlider->getValue()),
+ static_cast<int>(mGreenSlider->getValue()),
+ static_cast<int>(mBlueSlider->getValue()));
}
diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h
index 2831297f..050ea638 100644
--- a/src/gui/setup_colors.h
+++ b/src/gui/setup_colors.h
@@ -48,6 +48,8 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener,
void listen(const TextField *tf);
private:
+ static const std::string rawmsg;
+
gcn::ListBox *mColorBox;
gcn::ScrollArea *mScroll;
BrowserBox *mPreview;
diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp
index 64c97246..19c8a7b4 100644
--- a/src/gui/shoplistbox.cpp
+++ b/src/gui/shoplistbox.cpp
@@ -22,7 +22,7 @@
#include <guichan/font.hpp>
#include <guichan/listmodel.hpp>
-#include "color.h"
+#include "palette.h"
#include "shop.h"
#include "shoplistbox.h"
@@ -63,11 +63,9 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
if (config.getValue("guialpha", 0.8) != mAlpha)
mAlpha = config.getValue("guialpha", 0.8);
- bool valid;
- const int red = (textColor->getColor('H', valid) >> 16) & 0xFF;
- const int green = (textColor->getColor('H', valid) >> 8) & 0xFF;
- const int blue = textColor->getColor('H', valid) & 0xFF;
- const int alpha = (int)(mAlpha * 255.0f);
+ int alpha = (int)(mAlpha * 255.0f);
+ const gcn::Color* highlightColor =
+ &guiPalette->getColor(Palette::HIGHLIGHT, alpha);
Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
@@ -78,18 +76,27 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
i < mListModel->getNumberOfElements();
++i, y += mRowHeight)
{
- gcn::Color backgroundColor = gcn::Color(255, 255, 255, alpha);
+ gcn::Color temp;
+ const gcn::Color* backgroundColor =
+ &guiPalette->getColor(Palette::BACKGROUND, alpha);
if (mShopItems &&
mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck)
- if (i == mSelected)
- backgroundColor = gcn::Color(145, 0, 0, alpha);
+ if (i != mSelected)
+ backgroundColor = &guiPalette->getColor(Palette::SHOP_WARNING,
+ alpha);
else
- backgroundColor = gcn::Color(145, 145, 145, alpha);
+ {
+ temp = guiPalette->getColor(Palette::SHOP_WARNING, alpha);
+ temp.r = (temp.r + highlightColor->r) / 2;
+ temp.g = (temp.g + highlightColor->g) / 2;
+ temp.b = (temp.g + highlightColor->b) / 2;
+ backgroundColor = &temp;
+ }
else if (i == mSelected)
- backgroundColor = gcn::Color(red, green, blue, alpha);
+ backgroundColor = highlightColor;
- graphics->setColor(backgroundColor);
+ graphics->setColor(*backgroundColor);
graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight));
if (mShopItems)
@@ -100,7 +107,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
graphics->drawImage(icon, 1, y);
}
}
- graphics->setColor(gcn::Color(0, 0, 0));
+ graphics->setColor(guiPalette->getColor(Palette::TEXT));
graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5,
y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2);
}
diff --git a/src/gui/table.cpp b/src/gui/table.cpp
index 274f9a48..ece470b1 100644
--- a/src/gui/table.cpp
+++ b/src/gui/table.cpp
@@ -23,7 +23,7 @@
#include <guichan/graphics.hpp>
#include <guichan/key.hpp>
-#include "color.h"
+#include "palette.h"
#include "table.h"
#include "../configuration.h"
@@ -273,11 +273,8 @@ void GuiTable::draw(gcn::Graphics* graphics)
if (mOpaque)
{
- const int red = getBackgroundColor().r;
- const int green = getBackgroundColor().g;
- const int blue = getBackgroundColor().b;
- const int alpha = (int)(mAlpha * 255.0f);
- graphics->setColor(gcn::Color(red, green, blue, alpha));
+ graphics->setColor(guiPalette->getColor(Palette::BACKGROUND,
+ (int)(mAlpha * 255.0f)));
graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
}
@@ -324,15 +321,8 @@ void GuiTable::draw(gcn::Graphics* graphics)
if (!mLinewiseMode && c == mSelectedColumn && r == mSelectedRow)
{
- bool valid;
- const int red =
- (textColor->getColor('H', valid) >> 16) & 0xFF;
- const int green =
- (textColor->getColor('H', valid) >> 8) & 0xFF;
- const int blue = textColor->getColor('H', valid) & 0xFF;
- const int alpha = (int)(mAlpha * 127.0f);
-
- graphics->setColor(gcn::Color(red, green, blue, alpha));
+ graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT,
+ (int)(mAlpha * 127.0f)));
graphics->fillRectangle(bounds);
}
@@ -346,17 +336,8 @@ void GuiTable::draw(gcn::Graphics* graphics)
if (mLinewiseMode && r == mSelectedRow)
{
- bool valid;
- const int red =
- (textColor->getColor('H', valid) >> 16) & 0xFF;
- const int green =
- (textColor->getColor('H', valid) >> 8) & 0xFF;
- const int blue = textColor->getColor('H', valid) & 0xFF;
- const int alpha = (int)(mAlpha * 127.0f);
-
- graphics->setColor(gcn::Color(red, green, blue, alpha));
- graphics->fillRectangle(gcn::Rectangle(0, y_offset,
- x_offset, height));
+ graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT,
+ (int)(mAlpha * 127.0f)));
}
y_offset += height;
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index c91a8524..022da0f0 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -23,8 +23,8 @@
#include "dropdown.h"
-#include "../color.h"
#include "../listbox.h"
+#include "../palette.h"
#include "../scrollarea.h"
#include "../../configuration.h"
@@ -139,27 +139,24 @@ void DropDown::draw(gcn::Graphics* graphics)
}
}
- bool valid;
+// bool valid;
const int alpha = (int)(mAlpha * 255.0f);
gcn::Color faceColor = getBaseColor();
faceColor.a = alpha;
- gcn::Color highlightColor = textColor->getColor('H', valid);
- highlightColor.a = alpha;
+ gcn::Color highlightColor = guiPalette->getColor(Palette::HIGHLIGHT, alpha);
gcn::Color shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
if (mOpaque)
{
- int red = getBackgroundColor().r;
- int green = getBackgroundColor().g;
- int blue = getBackgroundColor().b;
- graphics->setColor(gcn::Color(red, green, blue, alpha));
+ gcn::Color col = getBackgroundColor();
+ col.a = alpha;
+ graphics->setColor(col);
graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h));
- red = getForegroundColor().r;
- green = getForegroundColor().g;
- blue = getForegroundColor().b;
- graphics->setColor(gcn::Color(red, green, blue, alpha));
+ col = getForegroundColor();
+ col.a = alpha;
+ graphics->setColor(col);
}
graphics->setFont(getFont());
diff --git a/src/main.cpp b/src/main.cpp
index f1424096..dddf53d0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -57,10 +57,10 @@
#include "gui/button.h"
#include "gui/char_server.h"
#include "gui/char_select.h"
-#include "gui/color.h"
#include "gui/gui.h"
#include "gui/login.h"
#include "gui/ok_dialog.h"
+#include "gui/palette.h"
#include "gui/progressbar.h"
#include "gui/register.h"
#include "gui/sdlinput.h"
@@ -135,7 +135,7 @@ CharServerHandler charServerHandler;
LoginData loginData;
LockedArray<LocalPlayer*> charInfo(MAX_SLOT + 1);
-Color *textColor;
+Palette *guiPalette;
// This anonymous namespace hides whatever is inside from other modules.
namespace {
@@ -774,7 +774,7 @@ int main(int argc, char *argv[])
unsigned int oldstate = !state; // We start with a status change.
// Needs to be created in main, as the updater uses it
- textColor = new Color;
+ guiPalette = new Palette;
Game *game = NULL;
Window *currentDialog = NULL;
@@ -1111,7 +1111,7 @@ int main(int argc, char *argv[])
usleep(50000);
}
- delete textColor;
+ delete guiPalette;
#ifdef PACKAGE_VERSION
delete versionLabel;
#endif