summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-03-18 18:37:19 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-03-18 18:37:19 +0100
commit1231406e5c9ac43d60c6ffb0ae664970b0e4eee0 (patch)
tree45af35e9a6ee56b71f06d76efa7706bf16eaec9a /src/gui
parent04c189cf7e3e8a393c81bfb3e11058ceace8802a (diff)
parent4bd8d3fd96fab681ee4520b6a6f2a6ee73f6eb97 (diff)
downloadmana-1231406e5c9ac43d60c6ffb0ae664970b0e4eee0.tar.gz
mana-1231406e5c9ac43d60c6ffb0ae664970b0e4eee0.tar.bz2
mana-1231406e5c9ac43d60c6ffb0ae664970b0e4eee0.tar.xz
mana-1231406e5c9ac43d60c6ffb0ae664970b0e4eee0.zip
Merge branch 'master' of git@gitorious.org:tmw/eathena
Diffstat (limited to 'src/gui')
-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/emotecontainer.cpp2
-rw-r--r--src/gui/emotecontainer.h2
-rw-r--r--src/gui/emoteshortcutcontainer.cpp4
-rw-r--r--src/gui/emoteshortcutcontainer.h2
-rw-r--r--src/gui/gui.cpp8
-rw-r--r--src/gui/listbox.cpp13
-rw-r--r--src/gui/palette.cpp314
-rw-r--r--src/gui/palette.h308
-rw-r--r--src/gui/setup_colors.cpp216
-rw-r--r--src/gui/setup_colors.h10
-rw-r--r--src/gui/shoplistbox.cpp33
-rw-r--r--src/gui/speechbubble.cpp5
-rw-r--r--src/gui/speechbubble.h4
-rw-r--r--src/gui/table.cpp31
-rw-r--r--src/gui/textbox.cpp5
-rw-r--r--src/gui/textbox.h15
-rw-r--r--src/gui/textrenderer.h81
-rw-r--r--src/gui/truetypefont.h4
-rw-r--r--src/gui/widgets/dropdown.cpp21
-rw-r--r--src/gui/widgets/textpreview.cpp55
-rw-r--r--src/gui/widgets/textpreview.h114
24 files changed, 1139 insertions, 411 deletions
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/emotecontainer.cpp b/src/gui/emotecontainer.cpp
index ad3f5c83..ececd9aa 100644
--- a/src/gui/emotecontainer.cpp
+++ b/src/gui/emotecontainer.cpp
@@ -53,7 +53,7 @@ EmoteContainer::EmoteContainer():
// Setup emote sprites
for (int i = 0; i <= EmoteDB::getLast(); i++)
{
- mEmoteImg.push_back(player_node->getEmote(i));
+ mEmoteImg.push_back(EmoteDB::getAnimation(i));
}
mSelImg = resman->getImage("graphics/gui/selection.png");
diff --git a/src/gui/emotecontainer.h b/src/gui/emotecontainer.h
index fefce793..88df29fc 100644
--- a/src/gui/emotecontainer.h
+++ b/src/gui/emotecontainer.h
@@ -121,7 +121,7 @@ class EmoteContainer : public gcn::Widget,
*/
void distributeValueChangedEvent(void);
- std::vector<AnimatedSprite*> mEmoteImg;
+ std::vector<const AnimatedSprite*> mEmoteImg;
Image *mSelImg;
int mSelectedEmoteIndex;
diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp
index df1bf74c..c96ea855 100644
--- a/src/gui/emoteshortcutcontainer.cpp
+++ b/src/gui/emoteshortcutcontainer.cpp
@@ -59,7 +59,7 @@ EmoteShortcutContainer::EmoteShortcutContainer():
// Setup emote sprites
for (int i = 0; i <= EmoteDB::getLast(); i++)
{
- mEmoteImg.push_back(player_node->getEmote(i));
+ mEmoteImg.push_back(EmoteDB::getAnimation(i));
}
mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS;
@@ -112,7 +112,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
if (mEmoteMoved)
{
// Draw the emote image being dragged by the cursor.
- AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1];
+ const AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1];
if (sprite)
{
const int tPosX = mCursorPosX - (sprite->getWidth() / 2);
diff --git a/src/gui/emoteshortcutcontainer.h b/src/gui/emoteshortcutcontainer.h
index d32a9f79..2997cb09 100644
--- a/src/gui/emoteshortcutcontainer.h
+++ b/src/gui/emoteshortcutcontainer.h
@@ -68,7 +68,7 @@ class EmoteShortcutContainer : public ShortcutContainer
void mouseReleased(gcn::MouseEvent &event);
private:
- std::vector<AnimatedSprite*> mEmoteImg;
+ std::vector<const AnimatedSprite*> mEmoteImg;
bool mEmoteClicked;
int mEmoteMoved;
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 6d6ccbdf..4081eeac 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -25,6 +25,7 @@
#include "focushandler.h"
#include "gui.h"
+#include "palette.h"
#include "sdlinput.h"
#include "truetypefont.h"
#include "viewport.h"
@@ -46,11 +47,6 @@ Gui *gui = 0;
Viewport *viewport = 0; /**< Viewport on the map. */
SDLInput *guiInput = 0;
-// Fonts used in showing hits
-gcn::Font *hitRedFont = 0;
-gcn::Font *hitBlueFont = 0;
-gcn::Font *hitYellowFont = 0;
-
// Bolded font
gcn::Font *boldFont = 0;
@@ -175,6 +171,8 @@ void Gui::logic()
else
mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f);
+ guiPalette->advanceGradient();
+
gcn::Gui::logic();
}
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index cd5aa736..7ba84ee7 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();
@@ -61,7 +56,7 @@ void ListBox::draw(gcn::Graphics *graphics)
getWidth(), fontHeight));
// Draw the list elements
- graphics->setColor(gcn::Color(0, 0, 0, 255));
+ graphics->setColor(guiPalette->getColor(Palette::TEXT));
for (int i = 0, y = 0; i < mListModel->getNumberOfElements();
++i, y += fontHeight)
{
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
new file mode 100644
index 00000000..bb2245ce
--- /dev/null
+++ b/src/gui/palette.cpp
@@ -0,0 +1,314 @@
+/*
+ * 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"));
+ addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"));
+
+ 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"));
+ addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names"));
+ addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"));
+ addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"));
+ addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"));
+ addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"));
+
+ addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"));
+ addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"));
+ addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"));
+ addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC,
+ indent + _("Player hits Monster"));
+ addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC,
+ indent + _("Monster hits Player"));
+ addColor(HIT_CRITICAL, 0xff0000, RAINBOW, indent + _("Critical Hit"));
+ addColor(MISS, 0xffff00, STATIC, indent + _("Misses"));
+ 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->committedGrad);
+ 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)
+ {
+ if (i->grad != i->committedGrad)
+ {
+ setGradient(i->type, i->committedGrad);
+ }
+ setColor(i->type, i->committedColor.r, i->committedColor.g,
+ i->committedColor.b);
+ }
+}
+
+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..77ead4f6
--- /dev/null
+++ b/src/gui/palette.h
@@ -0,0 +1,308 @@
+/*
+ * 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 associated with the 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 committed color associated with the specified type.
+ *
+ * @param type the color type requested
+ *
+ * @return the requested committed color
+ */
+ inline const gcn::Color& getCommittedColor(ColorType type)
+ {
+ return mColVector[type].committedColor;
+ }
+
+ /**
+ * Gets the GradientType associated with the specified type.
+ *
+ * @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..b786a7fa 100644
--- a/src/gui/setup_colors.cpp
+++ b/src/gui/setup_colors.cpp
@@ -27,9 +27,10 @@
#include <guichan/widgets/slider.hpp>
#include "browserbox.h"
-#include "color.h"
+#include "gui.h"
#include "itemlinkhandler.h"
#include "listbox.h"
+#include "palette.h"
#include "scrollarea.h"
#include "setup_colors.h"
#include "slider.h"
@@ -42,20 +43,24 @@
#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);
mScroll = new ScrollArea(mColorBox);
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+ mTextPreview = new TextPreview(&rawmsg);
+
mPreview = new BrowserBox(BrowserBox::AUTO_WRAP);
- mPreview->setOpaque(false);
+ mPreview->setOpaque(true);
// don't do anything with links
mPreview->setLinkHandler(NULL);
@@ -65,6 +70,17 @@ Setup_Colors::Setup_Colors() :
mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER,
gcn::ScrollArea::SHOW_NEVER);
+ mGradTypeLabel = new gcn::Label(_("Type: "));
+
+ mGradTypeSlider = new Slider(0, 2);
+ mGradTypeSlider->setWidth(160);
+ mGradTypeSlider->setActionEventId("slider_grad");
+ mGradTypeSlider->setValue(0);
+ mGradTypeSlider->addActionListener(this);
+ mGradTypeSlider->setEnabled(false);
+
+ mGradTypeText = new gcn::Label();
+
mRedLabel = new gcn::Label(_("Red: "));
mRedText = new TextField;
@@ -72,12 +88,14 @@ Setup_Colors::Setup_Colors() :
mRedText->setRange(0, 255);
mRedText->setNumeric(true);
mRedText->addListener(this);
+ mRedText->setEnabled(false);
mRedSlider = new Slider(0, 255);
mRedSlider->setWidth(160);
mRedSlider->setValue(mRedText->getValue());
mRedSlider->setActionEventId("slider_red");
mRedSlider->addActionListener(this);
+ mRedSlider->setEnabled(false);
mGreenLabel = new gcn::Label(_("Green: "));
@@ -86,12 +104,14 @@ Setup_Colors::Setup_Colors() :
mGreenText->setRange(0, 255);
mGreenText->setNumeric(true);
mGreenText->addListener(this);
+ mGreenText->setEnabled(false);
mGreenSlider = new Slider(0, 255);
mGreenSlider->setWidth(160);
mGreenSlider->setValue(mGreenText->getValue());
mGreenSlider->setActionEventId("slider_green");
mGreenSlider->addActionListener(this);
+ mGreenSlider->setEnabled(false);
mBlueLabel = new gcn::Label(_("Blue: "));
@@ -100,12 +120,14 @@ Setup_Colors::Setup_Colors() :
mBlueText->setRange(0, 255);
mBlueText->setNumeric(true);
mBlueText->addListener(this);
+ mBlueText->setEnabled(false);
mBlueSlider = new Slider(0, 255);
mBlueSlider->setWidth(160);
mBlueSlider->setValue(mBlueText->getValue());
mBlueSlider->setActionEventId("slider_blue");
mBlueSlider->addActionListener(this);
+ mBlueSlider->setEnabled(false);
setOpaque(false);
@@ -113,8 +135,11 @@ Setup_Colors::Setup_Colors() :
LayoutHelper h(this);
ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 4, 7).setPadding(2);
- place(0, 7, mPreviewBox, 4).setPadding(2);
+ place(0, 0, mScroll, 4, 6).setPadding(2);
+ place(0, 6, mPreviewBox, 4).setPadding(2);
+ place(0, 7, mGradTypeLabel, 2);
+ place(2, 7, mGradTypeSlider);
+ place(3, 7, mGradTypeText);
place(0, 8, mRedLabel, 2);
place(2, 8, mRedSlider);
place(3, 8, mRedText).setPadding(1);
@@ -130,19 +155,14 @@ Setup_Colors::Setup_Colors() :
Setup_Colors::~Setup_Colors()
{
- delete mRedLabel;
- delete mRedSlider;
- delete mRedText;
-
- delete mGreenLabel;
- delete mGreenSlider;
- delete mGreenText;
-
- delete mBlueLabel;
- delete mBlueSlider;
- delete mBlueText;
-
- delete mScroll;
+ if (mPreviewBox->getContent() == mPreview)
+ {
+ delete mTextPreview;
+ }
+ else
+ {
+ delete mPreview;
+ }
}
void Setup_Colors::action(const gcn::ActionEvent &event)
@@ -150,22 +170,102 @@ 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);
- std::string msg;
+ Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
+ const gcn::Color *col = &guiPalette->getColor(type);
+ Palette::GradientType grad = guiPalette->getGradientType(type);
- if (ch == '<')
- msg = toString("@@|") +
- _("This is what the color looks like") + "@@";
- else
- msg = "##" + toString(ch) +
- _("This is what the color looks like");
+ std::string msg;
+ char ch = guiPalette->getColorChar(type);
mPreview->clearRows();
- mPreview->addRow(msg);
- setEntry(mRedSlider, mRedText, col >> 16);
- setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff);
- setEntry(mBlueSlider, mBlueText, col & 0xff);
+ mPreviewBox->setContent(mTextPreview);
+ mTextPreview->setFont(gui->getFont());
+ mTextPreview->setTextColor(
+ &guiPalette->getColor(Palette::TEXT));
+ mTextPreview->setTextBGColor(NULL);
+ mTextPreview->setShadow(true);
+ mTextPreview->setOutline(true);
+
+ switch (type)
+ {
+ case Palette::TEXT:
+ case Palette::SHADOW:
+ case Palette::OUTLINE:
+ mTextPreview->setFont(gui->getFont());
+ mTextPreview->setOutline(true);
+ mTextPreview->setShadow(type == Palette::SHADOW);
+ mTextPreview->setOutline(type == Palette::OUTLINE);
+ break;
+ case Palette::BACKGROUND:
+ case Palette::HIGHLIGHT:
+ case Palette::SHOP_WARNING:
+ mTextPreview->setTextBGColor(col);
+ mTextPreview->setOutline(false);
+ mTextPreview->setShadow(false);
+ mPreview->addRow(rawmsg);
+ break;
+ case Palette::CHAT:
+ case Palette::GM:
+ case Palette::PLAYER:
+ case Palette::WHISPER:
+ case Palette::IS:
+ case Palette::PARTY:
+ case Palette::SERVER:
+ case Palette::LOGGER:
+ case Palette::HYPERLINK:
+ mPreviewBox->setContent(mPreview);
+ mPreview->clearRows();
+
+ if (ch == '<')
+ {
+ msg = toString("@@|") + rawmsg + "@@";
+ }
+ else
+ {
+ msg = "##" + toString(ch) + rawmsg;
+ }
+ mPreview->addRow(msg);
+ break;
+ case Palette::PARTICLE:
+ case Palette::EXP_INFO:
+ case Palette::PICKUP_INFO:
+ case Palette::HIT_PLAYER_MONSTER:
+ case Palette::HIT_MONSTER_PLAYER:
+ case Palette::HIT_CRITICAL:
+ case Palette::MISS:
+ mTextPreview->setShadow(false);
+ case Palette::BEING:
+ case Palette::PC:
+ case Palette::SELF:
+ case Palette::GM_NAME:
+ case Palette::NPC:
+ case Palette::MONSTER:
+ mTextPreview->setFont(boldFont);
+ mTextPreview->setTextColor(col);
+ break;
+ }
+
+ if (grad != Palette::STATIC)
+ { // If nonstatic color, don't display the current, but the committed
+ // color at the sliders
+ col = &guiPalette->getCommittedColor(type);
+ }
+
+ setEntry(mRedSlider, mRedText, col->r);
+ setEntry(mGreenSlider, mGreenText, col->g);
+ setEntry(mBlueSlider, mBlueText, col->b);
+
+ mGradTypeSlider->setValue(grad);
+ updateGradType();
+ mGradTypeSlider->setEnabled(true);
+
+ return;
+ }
+
+ if (event.getId() == "slider_grad")
+ {
+ updateGradType();
+ updateColor();
return;
}
@@ -201,16 +301,18 @@ 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);
+ mGradTypeSlider->setValue(guiPalette->getGradientType(type));
+ setEntry(mRedSlider, mRedText, col->r);
+ setEntry(mGreenSlider, mGreenText, col->g);
+ setEntry(mBlueSlider, mBlueText, col->b);
}
void Setup_Colors::listen(const TextField *tf)
@@ -235,14 +337,46 @@ void Setup_Colors::listen(const TextField *tf)
}
}
+void Setup_Colors::updateGradType() {
+ if (mSelected == -1)
+ {
+ return;
+ }
+
+ mSelected = mColorBox->getSelected();
+ Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
+ Palette::GradientType grad = guiPalette->getGradientType(type);
+
+ mGradTypeText->setCaption(
+ (grad == Palette::STATIC) ? _("Static") :
+ (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum"));
+
+ bool enable = (grad == Palette::STATIC);
+ mRedText->setEnabled(enable);
+ mRedSlider->setEnabled(enable);
+ mGreenText->setEnabled(enable);
+ mGreenSlider->setEnabled(enable);
+ mBlueText->setEnabled(enable);
+ mBlueSlider->setEnabled(enable);
+}
+
void Setup_Colors::updateColor()
{
if (mSelected == -1)
{
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);
+ Palette::GradientType grad =
+ static_cast<Palette::GradientType>(mGradTypeSlider->getValue());
+ guiPalette->setGradient(type, grad);
+
+ if (grad == Palette::STATIC)
+ {
+ 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..52d3f727 100644
--- a/src/gui/setup_colors.h
+++ b/src/gui/setup_colors.h
@@ -34,6 +34,8 @@
#include "../guichanfwd.h"
+#include "widgets/textpreview.h"
+
class BrowserBox;
class Setup_Colors : public SetupTab, public gcn::ActionListener,
@@ -48,12 +50,19 @@ 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;
+ TextPreview *mTextPreview;
gcn::ScrollArea *mPreviewBox;
int mSelected;
+ gcn::Label *mGradTypeLabel;
+ gcn::Slider *mGradTypeSlider;
+ gcn::Label *mGradTypeText;
+
gcn::Label *mRedLabel;
gcn::Slider *mRedSlider;
TextField *mRedText;
@@ -71,5 +80,6 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener,
void setEntry(gcn::Slider *s, TextField *t, int value);
void updateColor();
+ void updateGradType();
};
#endif
diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp
index 64c97246..aa42c294 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/speechbubble.cpp b/src/gui/speechbubble.cpp
index 9ee91166..5f05971d 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -45,6 +45,7 @@ SpeechBubble::SpeechBubble():
mSpeechBox = new TextBox;
mSpeechBox->setEditable(false);
mSpeechBox->setOpaque(false);
+ mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT));
mSpeechArea = new ScrollArea(mSpeechBox);
@@ -60,11 +61,11 @@ SpeechBubble::SpeechBubble():
setLocationRelativeTo(getParent());
}
-void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color)
+void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color)
{
mCaption->setCaption(name);
mCaption->adjustSize();
- mCaption->setForegroundColor(color);
+ mCaption->setForegroundColor(*color);
}
void SpeechBubble::setText(std::string text, bool showName)
diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h
index 573e61f0..34e00722 100644
--- a/src/gui/speechbubble.h
+++ b/src/gui/speechbubble.h
@@ -22,6 +22,7 @@
#ifndef SPEECHBUBBLE_H
#define SPEECHBUBBLE_H
+#include "palette.h"
#include "window.h"
class ScrollArea;
@@ -33,7 +34,8 @@ class SpeechBubble : public Window
SpeechBubble();
void setCaption(const std::string &name,
- const gcn::Color &color = 0x000000);
+ const gcn::Color *color =
+ &guiPalette->getColor(Palette::TEXT));
void setText(std::string text, bool showName = true);
void setLocation(int x, int y);
unsigned int getNumRows();
diff --git a/src/gui/table.cpp b/src/gui/table.cpp
index 274f9a48..5fc96dbd 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,15 +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->setColor(guiPalette->getColor(Palette::HIGHLIGHT,
+ (int)(mAlpha * 127.0f)));
graphics->fillRectangle(gcn::Rectangle(0, y_offset,
x_offset, height));
}
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp
index a4024de3..10f727e3 100644
--- a/src/gui/textbox.cpp
+++ b/src/gui/textbox.cpp
@@ -23,10 +23,11 @@
#include <guichan/font.hpp>
+#include "palette.h"
#include "textbox.h"
-TextBox::TextBox():
- gcn::TextBox()
+TextBox::TextBox() :
+ gcn::TextBox(), mTextColor(&guiPalette->getColor(Palette::TEXT))
{
setOpaque(false);
setFrameSize(0);
diff --git a/src/gui/textbox.h b/src/gui/textbox.h
index 10a81fc0..5884e11c 100644
--- a/src/gui/textbox.h
+++ b/src/gui/textbox.h
@@ -39,6 +39,11 @@ class TextBox : public gcn::TextBox
*/
TextBox();
+ inline void setTextColor(const gcn::Color* color)
+ {
+ mTextColor = color;
+ }
+
/**
* Sets the text after wrapping it to the current width of the widget.
*/
@@ -49,8 +54,18 @@ class TextBox : public gcn::TextBox
*/
int getMinWidth() { return mMinWidth; }
+ /**
+ * Draws the text.
+ */
+ inline void draw(gcn::Graphics *graphics)
+ {
+ setForegroundColor(*mTextColor);
+ gcn::TextBox::draw(graphics);
+ }
+
private:
int mMinWidth;
+ const gcn::Color* mTextColor;
};
#endif
diff --git a/src/gui/textrenderer.h b/src/gui/textrenderer.h
new file mode 100644
index 00000000..0381f766
--- /dev/null
+++ b/src/gui/textrenderer.h
@@ -0,0 +1,81 @@
+/*
+ * Text Renderer
+ * Copyright (C) 2009 The Mana World Development Team
+ *
+ * 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 TEXT_RENDERER_H
+#define TEXT_RENDERER_H
+
+#include "graphics.h"
+#include "palette.h"
+
+/**
+ * Class for text rendering. Used by the TextParticle, the Text and FlashText
+ * objects and the Preview in the color dialog.
+ */
+class TextRenderer
+{
+ public:
+ /**
+ * Renders a specified text.
+ */
+ static inline void renderText(gcn::Graphics *graphics, const std::string&
+ text, int x, int y, gcn::Graphics::Alignment align,
+ const gcn::Color* color, gcn::Font *font, bool outline = false,
+ bool shadow = false, int alpha = 255)
+ {
+ graphics->setFont(font);
+
+ // Text shadow
+ if (shadow)
+ {
+ graphics->setColor(guiPalette->getColor(Palette::SHADOW,
+ alpha / 2));
+ if (outline)
+ {
+ graphics->drawText(text, x + 2, y + 2, align);
+ }
+ else
+ {
+ graphics->drawText(text, x + 1, y + 1, align);
+ }
+ }
+
+ if (outline) {
+/* graphics->setColor(guiPalette->getColor(Palette::OUTLINE,
+ alpha/4));
+ // TODO: Reanable when we can draw it nicely in software mode
+ graphics->drawText(text, x + 2, y + 2, align);
+ graphics->drawText(text, x + 1, y + 2, align);
+ graphics->drawText(text, x + 2, y + 1, align);*/
+
+ // Text outline
+ graphics->setColor(guiPalette->getColor(Palette::OUTLINE, alpha));
+ graphics->drawText(text, x + 1, y, align);
+ graphics->drawText(text, x - 1, y, align);
+ graphics->drawText(text, x, y + 1, align);
+ graphics->drawText(text, x, y - 1, align);
+ }
+
+ graphics->setColor(*color);
+ graphics->drawText(text, x, y, align);
+ }
+};
+
+#endif
diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h
index de146087..1cf6c2c8 100644
--- a/src/gui/truetypefont.h
+++ b/src/gui/truetypefont.h
@@ -26,8 +26,8 @@
#include <string>
#include <guichan/font.hpp>
-#ifndef __APPLE__
-#include <SDL/SDL_ttf.h>
+#ifdef __APPLE__
+#include <SDL_ttf/SDL_ttf.h>
#else
#include <SDL_ttf.h>
#endif
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index c91a8524..b736591c 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,20 @@ void DropDown::draw(gcn::Graphics* graphics)
}
}
- 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;
+ const 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));
+ graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, alpha));
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));
+ graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha));
}
graphics->setFont(getFont());
@@ -171,7 +164,7 @@ void DropDown::draw(gcn::Graphics* graphics)
if (isFocused())
{
- graphics->setColor(highlightColor);
+ graphics->setColor(*highlightColor);
graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h));
}
@@ -183,7 +176,7 @@ void DropDown::draw(gcn::Graphics* graphics)
// Draw two lines separating the ListBox with selected
// element view.
- graphics->setColor(highlightColor);
+ graphics->setColor(*highlightColor);
graphics->drawLine(0, h, getWidth(), h);
graphics->setColor(shadowColor);
graphics->drawLine(0, h + 1, getWidth(), h + 1);
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
new file mode 100644
index 00000000..4fcaa4a7
--- /dev/null
+++ b/src/gui/widgets/textpreview.cpp
@@ -0,0 +1,55 @@
+/*
+ * The Mana World
+ * Copyright (C) 2006 The Mana World Development Team
+ *
+ * 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 <typeinfo>
+
+#include "textpreview.h"
+
+#include "../gui.h"
+#include "../palette.h"
+#include "../textrenderer.h"
+#include "../truetypefont.h"
+
+TextPreview::TextPreview(const std::string* text)
+{
+ mText = text;
+ mFont = gui->getFont();
+ mTextColor = &guiPalette->getColor(Palette::TEXT);
+ mTextBGColor = NULL;
+ mBGColor = &guiPalette->getColor(Palette::BACKGROUND);
+}
+
+void TextPreview::draw(gcn::Graphics* graphics)
+{
+ graphics->setColor(*mBGColor);
+ graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+
+ if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont)) {
+ TrueTypeFont *font = static_cast<TrueTypeFont*>(mFont);
+ graphics->setColor(*mTextBGColor);
+ int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0);
+ int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0);
+ graphics->fillRectangle(gcn::Rectangle(1, 1, x, y));
+ }
+
+ TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT,
+ mTextColor, mFont, mOutline, mShadow);
+}
diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h
new file mode 100644
index 00000000..1c1fa1e4
--- /dev/null
+++ b/src/gui/widgets/textpreview.h
@@ -0,0 +1,114 @@
+/*
+ * The Mana World
+ * Copyright (C) 2006 The Mana World Development Team
+ *
+ * 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 TEXTPREVIEW_H
+#define TEXTPREVIEW_H
+
+#include <guichan/color.hpp>
+#include <guichan/font.hpp>
+#include <guichan/widget.hpp>
+
+/**
+ * Preview widget for particle colors, etc.
+ */
+class TextPreview : public gcn::Widget {
+ public:
+ TextPreview(const std::string* text);
+
+ /**
+ * Sets the color the text is printed in.
+ *
+ * @param color the color to set
+ */
+ inline void setTextColor(const gcn::Color* color)
+ {
+ mTextColor = color;
+ }
+
+ /**
+ * Sets the color the text background is drawn in. This is only the
+ * rectangle directly behind the text, not to full widget.
+ *
+ * @param color the color to set
+ */
+ inline void setTextBGColor(const gcn::Color* color)
+ {
+ mTextBGColor = color;
+ }
+
+ /**
+ * Sets the background color of the widget.
+ *
+ * @param color the color to set
+ */
+ inline void setBGColor(const gcn::Color* color)
+ {
+ mBGColor = color;
+ }
+
+ /**
+ * Sets the font to render the text in.
+ *
+ * @param font the font to use.
+ */
+ inline void setFont(gcn::Font *font)
+ {
+ mFont = font;
+ }
+
+ /**
+ * Sets whether to use a shadow while rendering.
+ *
+ * @param shadow true, if a shadow is wanted, false else
+ */
+ inline void setShadow(bool shadow)
+ {
+ mShadow = shadow;
+ }
+
+ /**
+ * Sets whether to use an outline while rendering.
+ *
+ * @param outline true, if an outline is wanted, false else
+ */
+ inline void setOutline(bool outline)
+ {
+ mOutline = outline;
+ }
+
+ /**
+ * Widget's draw method. Does the actual job.
+ *
+ * @param graphics graphics to draw into
+ */
+ void draw(gcn::Graphics *graphics);
+
+ private:
+ gcn::Font *mFont;
+ const std::string* mText;
+ const gcn::Color* mTextColor;
+ const gcn::Color* mBGColor;
+ const gcn::Color* mTextBGColor;
+ bool mShadow;
+ bool mOutline;
+};
+
+#endif