From 393c1085ed1cb24092778594d2945a39428e41ad Mon Sep 17 00:00:00 2001 From: sniper Date: Wed, 11 Mar 2009 17:19:31 +0100 Subject: Added a class for rendering of floating text This is a header only-class that merges the textrendering of the TextParticle and Text classes. It is done to reduce code duplication and to prepare some color configuration gui. --- src/text.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'src/text.cpp') diff --git a/src/text.cpp b/src/text.cpp index e5e40235..c167701a 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -26,6 +26,8 @@ #include "textmanager.h" #include "gui/gui.h" +#include "gui/palette.h" +#include "gui/textrenderer.h" int Text::mInstances = 0; @@ -76,23 +78,9 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) { graphics->setFont(boldFont); - // Text shadow - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawText(mText, mX - xOff + 1, mY - yOff + 1, - gcn::Graphics::LEFT); - - // Text outline - graphics->drawText(mText, mX - xOff + 1, mY - yOff, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff - 1, mY - yOff, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff, mY - yOff + 1, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff, mY - yOff - 1, - gcn::Graphics::LEFT); - - graphics->setColor(mColor); - graphics->drawText(mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT); + TextRenderer::renderText(graphics, mText, + mX - xOff, mY - yOff, gcn::Graphics::LEFT, + &mColor, boldFont, !mIsSpeech, true); } FlashText::FlashText(const std::string &text, int x, int y, @@ -107,9 +95,7 @@ void FlashText::draw(gcn::Graphics *graphics, int xOff, int yOff) if (mTime) { if ((--mTime & 4) == 0) - { return; - } } Text::draw(graphics, xOff, yOff); } -- cgit v1.2.3-70-g09d2 From 7d20381b7b9abdf0934ee0fbbb196c788ea93a0d Mon Sep 17 00:00:00 2001 From: sniper Date: Wed, 11 Mar 2009 15:35:54 +0100 Subject: 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. --- aethyra.cbp | 5 +- src/CMakeLists.txt | 5 +- src/Makefile.am | 5 +- src/gui/browserbox.cpp | 21 ++- src/gui/listbox.cpp | 11 +- src/gui/palette.cpp | 317 +++++++++++++++++++++++++++++++++++++++++++ src/gui/palette.h | 297 ++++++++++++++++++++++++++++++++++++++++ src/gui/setup_colors.cpp | 55 ++++---- src/gui/setup_colors.h | 2 + src/gui/shoplistbox.cpp | 40 +++--- src/gui/table.cpp | 31 +---- src/gui/widgets/dropdown.cpp | 21 ++- src/main.cpp | 8 +- src/text.cpp | 2 +- 14 files changed, 714 insertions(+), 106 deletions(-) create mode 100644 src/gui/palette.cpp create mode 100644 src/gui/palette.h (limited to 'src/text.cpp') diff --git a/aethyra.cbp b/aethyra.cbp index aa1737b7..b9e80430 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -132,8 +132,6 @@ - - @@ -191,6 +189,8 @@ + + @@ -256,6 +256,7 @@ + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9fdca23a..6565a1b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,8 +81,6 @@ SET(SRCS gui/chatinput.h gui/checkbox.cpp gui/checkbox.h - gui/color.cpp - gui/color.h gui/confirm_dialog.cpp gui/confirm_dialog.h gui/connection.cpp @@ -140,6 +138,8 @@ SET(SRCS gui/npc_text.h gui/ok_dialog.cpp gui/ok_dialog.h + gui/palette.cpp + gui/palette.h gui/passwordfield.cpp gui/passwordfield.h gui/playerbox.cpp @@ -205,6 +205,7 @@ SET(SRCS gui/textbox.h gui/textfield.cpp gui/textfield.h + gui/textrenderer.h gui/trade.cpp gui/trade.h gui/truetypefont.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c4265dec..b3bdde9d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,8 +31,6 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/chatinput.h \ gui/checkbox.cpp \ gui/checkbox.h \ - gui/color.cpp \ - gui/color.h \ gui/confirm_dialog.cpp \ gui/confirm_dialog.h \ gui/connection.cpp \ @@ -90,6 +88,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/npc_text.h \ gui/ok_dialog.cpp \ gui/ok_dialog.h \ + gui/palette.cpp \ + gui/palette.h \ gui/passwordfield.cpp \ gui/passwordfield.h \ gui/playerbox.cpp \ @@ -155,6 +155,7 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/textbox.h \ gui/textfield.cpp \ gui/textfield.h \ + gui/textrenderer.h \ gui/trade.cpp \ gui/trade.h \ gui/truetypefont.cpp \ diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 2b690b21..46c8bdf1 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -25,8 +25,8 @@ #include #include "browserbox.h" -#include "color.h" #include "linkhandler.h" +#include "palette.h" #include "truetypefont.h" BrowserBox::BrowserBox(unsigned int mode, bool opaque): @@ -250,16 +250,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, @@ -270,7 +269,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, @@ -284,11 +283,11 @@ void BrowserBox::draw(gcn::Graphics *graphics) int link = 0; TrueTypeFont *font = static_cast(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; @@ -336,7 +335,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; @@ -349,7 +348,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) } if (valid) { - selColor = rgb; + selColor = col; } } start += 3; @@ -359,7 +358,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/listbox.cpp b/src/gui/listbox.cpp index 82011239..e53a1652 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -25,8 +25,8 @@ #include #include -#include "color.h" #include "listbox.h" +#include "palette.h" #include "../configuration.h" @@ -45,13 +45,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..a79f2050 --- /dev/null +++ b/src/gui/palette.cpp @@ -0,0 +1,317 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of Aethyra. + * + * 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 + +#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 (unsigned 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() : + mRainbowTime(tick_time), + mColVector(ColVector(TYPE_COUNT)), + mGradVector() +{ + 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 (unsigned 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 (unsigned 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..a372d6cd --- /dev/null +++ b/src/gui/palette.h @@ -0,0 +1,297 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of Aethyra. + * + * 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 +#include +#include + +#include +#include + +// 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 ColVector; + /** Vector containing the colors. */ + ColVector mColVector; + std::vector 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 31b56b51..4f017e15 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -27,9 +27,9 @@ #include #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); @@ -131,6 +133,9 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { + delete mPreview; + delete mPreviewBox; + delete mRedLabel; delete mRedSlider; delete mRedText; @@ -143,6 +148,7 @@ Setup_Colors::~Setup_Colors() delete mBlueSlider; delete mBlueText; + delete mColorBox; delete mScroll; } @@ -151,22 +157,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; } @@ -202,16 +208,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) @@ -242,8 +249,10 @@ void Setup_Colors::updateColor() { return; } - int rgb = static_cast(mRedSlider->getValue()) << 16 | - static_cast(mGreenSlider->getValue()) << 8 | - static_cast(mBlueSlider->getValue()); - textColor->setColorAt(mSelected, rgb); + + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + guiPalette->setColor(type, + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue())); } diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 98a2d18b..6cf59b6d 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 776f26bc..74209122 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -23,7 +23,7 @@ #include #include -#include "color.h" +#include "palette.h" #include "shop.h" #include "shoplistbox.h" @@ -64,11 +64,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(gcnGraphics); @@ -79,19 +77,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 (i == mSelected) - { - backgroundColor = gcn::Color(red, green, blue, alpha); - } - else if (mShopItems && + if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) - { - backgroundColor = gcn::Color(145, 145, 145, alpha); - } + if (i != mSelected) + backgroundColor = &guiPalette->getColor(Palette::SHOP_WARNING, + alpha); + else + { + 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 = highlightColor; - graphics->setColor(backgroundColor); + graphics->setColor(*backgroundColor); graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight)); if (mShopItems) @@ -102,7 +108,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 b2571495..144e7e21 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -24,7 +24,7 @@ #include #include -#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/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 7036c2ee..076a167f 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -24,8 +24,8 @@ #include "dropdown.h" -#include "../color.h" #include "../listbox.h" +#include "../palette.h" #include "../scrollarea.h" #include "../../configuration.h" @@ -140,27 +140,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 fab7ed95..bed297de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,10 +56,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" @@ -134,7 +134,7 @@ CharServerHandler charServerHandler; LoginData loginData; LockedArray charInfo(MAX_SLOT + 1); -Color *textColor; +Palette *guiPalette; // This anonymous namespace hides whatever is inside from other modules. namespace { @@ -767,7 +767,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; @@ -1108,7 +1108,7 @@ int main(int argc, char *argv[]) usleep(50000); } - delete textColor; + delete guiPalette; #ifdef PACKAGE_VERSION delete versionLabel; #endif diff --git a/src/text.cpp b/src/text.cpp index c167701a..2d96152b 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -80,7 +80,7 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - &mColor, boldFont, !mIsSpeech, true); + &mColor, boldFont, true, true); } FlashText::FlashText(const std::string &text, int x, int y, -- cgit v1.2.3-70-g09d2 From f0d5e3da15a308fcc962590330e7d8e39e8874b9 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 12 Mar 2009 22:42:42 +0100 Subject: Make use of the new available colors This patch lets all being derivatives use the palette to set their name's colors. Text Particle Effects all respect the new settings. Some widgets were updated to use the colors. --- src/being.cpp | 41 ++++++++++++++++------------------------- src/being.h | 2 +- src/gui/listbox.cpp | 2 +- src/gui/shoplistbox.cpp | 2 +- src/gui/speechbubble.cpp | 5 +++-- src/gui/speechbubble.h | 4 +++- src/gui/textbox.cpp | 5 +++-- src/gui/textbox.h | 15 +++++++++++++++ src/gui/widgets/dropdown.cpp | 16 ++++++---------- src/localplayer.cpp | 19 ++++++++++--------- src/monster.cpp | 7 +++++-- src/npc.cpp | 6 ++++-- src/particle.cpp | 17 +++++------------ src/particle.h | 14 ++++++-------- src/player.cpp | 13 +++++++++---- src/text.cpp | 10 ++++++---- src/text.h | 8 +++++--- src/textparticle.cpp | 11 +++-------- src/textparticle.h | 7 +++---- 19 files changed, 105 insertions(+), 99 deletions(-) (limited to 'src/text.cpp') diff --git a/src/being.cpp b/src/being.cpp index 64972912..3a772fbd 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -47,6 +47,7 @@ #include "resources/resourcemanager.h" #include "gui/gui.h" +#include "gui/palette.h" #include "gui/speechbubble.h" #include "utils/dtor.h" @@ -91,7 +92,7 @@ Being::Being(int id, int job, Map *map): mSpeechBubble = new SpeechBubble(); mSpeech = ""; - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::CHAT); mText = 0; } @@ -192,17 +193,14 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) gcn::Font *font; std::string damage = amount ? toString(amount) : type == FLEE ? "dodge" : "miss"; - - int red, green, blue; + const gcn::Color* color; font = gui->getInfoParticleFont(); // Selecting the right color if (type == CRITICAL || type == FLEE) { - red = 255; - green = 128; - blue = 0; + color = &guiPalette->getColor(Palette::HIT_CRITICAL); } else if (!amount) { @@ -210,39 +208,31 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) { // This is intended to be the wrong direction to visually // differentiate between hits and misses - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } else { - red = 255; - green = 255; - blue = 0; - } - } + color = &guiPalette->getColor(Palette::MISS); + } + } else if (getType() == MONSTER) { - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_PLAYER_MONSTER); } else { - red = 255; - green = 50; - blue = 50; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } if (amount > 0 && type == CRITICAL) { - particleEngine->addTextSplashEffect("crit!", red, green, blue, font, - mPx + 16, mPy + 16, true); + particleEngine->addTextSplashEffect("crit!", mPx + 16, mPy + 16, + color, font, true); } // Show damage number - particleEngine->addTextSplashEffect(damage, red, green, blue, font, - mPx + 16, mPy + 16, true); + particleEngine->addTextSplashEffect(damage, mPx + 16, mPy + 16, + color, font, true); } void Being::handleAttack(Being *victim, int damage, AttackType type) @@ -503,7 +493,8 @@ void Being::drawSpeech(int offsetX, int offsetY) delete mText; mText = new Text(mSpeech, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET, - gcn::Graphics::CENTER, gcn::Color(255, 255, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::PARTICLE)); } else if (speech == NO_SPEECH) { diff --git a/src/being.h b/src/being.h index 4b30b6c5..689eda02 100644 --- a/src/being.h +++ b/src/being.h @@ -428,7 +428,7 @@ class Being : public Sprite Gender mGender; int mPx, mPy; /**< Pixel coordinates */ - gcn::Color mNameColor; + const gcn::Color* mNameColor; std::vector mSprites; std::vector mSpriteIDs; diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index e53a1652..71e92eaf 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -57,7 +57,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/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 74209122..5c55069f 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -79,7 +79,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) { gcn::Color temp; const gcn::Color* backgroundColor = - &guiPalette->getColor(Palette::BACKGROUND, alpha); + &guiPalette->getColor(Palette::BACKGROUND, alpha); if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index d342328e..cb1724c8 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -46,6 +46,7 @@ SpeechBubble::SpeechBubble(): mSpeechBox = new TextBox(); mSpeechBox->setEditable(false); mSpeechBox->setOpaque(false); + mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT)); mSpeechArea = new ScrollArea(mSpeechBox); @@ -61,11 +62,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 a1a597c1..d356dac1 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -23,6 +23,7 @@ #ifndef SPEECHBUBBLE_H #define SPEECHBUBBLE_H +#include "palette.h" #include "popup.h" class ScrollArea; @@ -34,7 +35,8 @@ class SpeechBubble : public Popup 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/textbox.cpp b/src/gui/textbox.cpp index 589986cd..51a8efc6 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -24,10 +24,11 @@ #include +#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 33ea42f9..20f4ebe2 100644 --- a/src/gui/textbox.h +++ b/src/gui/textbox.h @@ -40,6 +40,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. */ @@ -50,8 +55,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/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 076a167f..0015beed 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -140,24 +140,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 = guiPalette->getColor(Palette::HIGHLIGHT, alpha); + const gcn::Color* highlightColor = &guiPalette->getColor(Palette::HIGHLIGHT, + alpha); gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (mOpaque) { - gcn::Color col = getBackgroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, alpha)); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - col = getForegroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha)); } graphics->setFont(getFont()); @@ -169,7 +165,7 @@ void DropDown::draw(gcn::Graphics* graphics) if (isFocused()) { - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); } @@ -181,7 +177,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/localplayer.cpp b/src/localplayer.cpp index d6acc48f..f72aa59a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -37,6 +37,7 @@ #include "text.h" #include "gui/gui.h" +#include "gui/palette.h" #include "gui/storagewindow.h" #include "net/messageout.h" @@ -201,7 +202,9 @@ void LocalPlayer::logic() void LocalPlayer::setGM() { mIsGM = !mIsGM; - mNameColor = mIsGM ? 0x009000: 0x202020; + mNameColor = mIsGM ? + &guiPalette->getColor(Palette::GM) : + &guiPalette->getColor(Palette::PLAYER); setName(getName()); config.setValue(getName() + "GMassert", mIsGM); } @@ -608,10 +611,9 @@ void LocalPlayer::setXp(int xp) const std::string text = toString(xp - mXp) + " xp"; // Show XP number - particleEngine->addTextRiseFadeOutEffect(text, - gui->getInfoParticleFont(), - mPx + 16, mPy - 16, - 255, 255, 0, true); + particleEngine->addTextRiseFadeOutEffect(text, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::EXP_INFO), + gui->getInfoParticleFont(), true); } mXp = xp; } @@ -621,10 +623,9 @@ void LocalPlayer::pickedUp(std::string item) if (mMap) { // Show pickup notification - particleEngine->addTextRiseFadeOutEffect(item, - gui->getInfoParticleFont (), - mPx + 16, mPy - 16, - 40, 220, 40, true); + particleEngine->addTextRiseFadeOutEffect(item, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::PICKUP_INFO), + gui->getInfoParticleFont (), true); } } diff --git a/src/monster.cpp b/src/monster.cpp index 45d2fbeb..f71457df 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -28,6 +28,8 @@ #include "sound.h" #include "text.h" +#include "gui/palette.h" + #include "resources/monsterdb.h" #include "resources/monsterinfo.h" @@ -72,7 +74,7 @@ Monster::Monster(int id, Uint16 job, Map *map): } } - mNameColor = 0xff2020; + mNameColor = &guiPalette->getColor(Palette::MONSTER); } Monster::~Monster() @@ -196,7 +198,8 @@ void Monster::showName(bool show) { mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET - getHeight(), - gcn::Graphics::CENTER, gcn::Color(255, 32, 32)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::MONSTER)); } else { diff --git a/src/npc.cpp b/src/npc.cpp index c9250415..a6d60dbb 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -27,6 +27,7 @@ #include "text.h" #include "gui/npc_text.h" +#include "gui/palette.h" #include "net/messageout.h" #include "net/protocol.h" @@ -72,7 +73,7 @@ NPC::NPC(int id, Uint16 job, Map *map, Network *network): } mName = 0; - mNameColor = 0x21bbbb; + mNameColor = &guiPalette->getColor(Palette::NPC); } NPC::~NPC() @@ -86,7 +87,8 @@ void NPC::setName(const std::string &name) delete mName; mName = new Text(displayName, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, - gcn::Graphics::CENTER, gcn::Color(200, 200, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::NPC)); Being::setName(displayName + " (NPC)"); } diff --git a/src/particle.cpp b/src/particle.cpp index 8bc764ba..e56435ed 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -325,12 +325,10 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, return newParticle; } -Particle *Particle::addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, bool outline) +Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -346,13 +344,8 @@ Particle *Particle::addTextSplashEffect(const std::string &text, } Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, - int colorR, int colorG, - int colorB, bool outline) -{ - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + int x, int y, const gcn::Color *color, gcn::Font *font, bool outline){ + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); diff --git a/src/particle.h b/src/particle.h index f03f081d..76beb8d1 100644 --- a/src/particle.h +++ b/src/particle.h @@ -106,19 +106,17 @@ class Particle : public Sprite /** * Creates a standalone text particle. */ - Particle *addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, - bool outline = false); + Particle *addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, int colorR = 255, - int colorG = 255, int colorB = 255, - bool outline = false); + int x, int y, const gcn::Color *color, gcn::Font *font, + bool outline = false); + /** * Adds an emitter to the particle. */ diff --git a/src/player.cpp b/src/player.cpp index 61e91613..b289c3e5 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -22,10 +22,13 @@ #include "animatedsprite.h" #include "game.h" +#include "localplayer.h" #include "particle.h" #include "player.h" #include "text.h" +#include "gui/palette.h" + #include "resources/colordb.h" #include "resources/itemdb.h" @@ -51,17 +54,19 @@ void Player::setName(const std::string &name) { if (mIsGM) { - mNameColor = 0x009000; + mNameColor = &guiPalette->getColor(Palette::GM); mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(0, 255, 0)); + &guiPalette->getColor(Palette::GM)); } else { - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::PLAYER); mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(255, 255, 255)); + (this == player_node) ? + &guiPalette->getColor(Palette::SELF) : + &guiPalette->getColor(Palette::PC)); } Being::setName(name); } diff --git a/src/text.cpp b/src/text.cpp index 2d96152b..420eeb8b 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -32,8 +32,9 @@ int Text::mInstances = 0; Text::Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color) : - mText(text), mColor(color) + gcn::Graphics::Alignment alignment, const gcn::Color* color) : + mText(text), + mColor(color) { if (textManager == 0) { @@ -80,11 +81,12 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - &mColor, boldFont, true, true); + mColor, boldFont, true); } FlashText::FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color) : + gcn::Graphics::Alignment alignment, + const gcn::Color *color) : Text(text, x, y, alignment, color), mTime(0) { diff --git a/src/text.h b/src/text.h index 0b53dd48..cf0aac48 100644 --- a/src/text.h +++ b/src/text.h @@ -39,7 +39,8 @@ class Text * Constructor creates a text object to display on the screen. */ Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color); + gcn::Graphics::Alignment alignment, + const gcn::Color *color); /** * Destructor. The text is removed from the screen. @@ -64,14 +65,15 @@ class Text int mXOffset; /**< The offset of mX from the desired x. */ static int mInstances; /**< Instances of text. */ std::string mText; /**< The text to display. */ - gcn::Color mColor; /**< The color of the text. */ + const gcn::Color *mColor; /**< The color of the text. */ }; class FlashText : public Text { public: FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color); + gcn::Graphics::Alignment alignment, + const gcn::Color* color); /** * Remove the text from the screen diff --git a/src/textparticle.cpp b/src/textparticle.cpp index a065eadd..865c6764 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -22,21 +22,17 @@ #include -#include - #include "textparticle.h" #include "gui/textrenderer.h" TextParticle::TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), - mColorR(colorR), - mColorG(colorG), - mColorB(colorB), + mColor(color), mOutline(outline) { } @@ -65,6 +61,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, - (int) alpha); + mColor, mTextFont, mOutline, false, (int) alpha); } diff --git a/src/textparticle.h b/src/textparticle.h index 26b92a50..1a49b5ef 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -33,7 +33,7 @@ class TextParticle : public Particle * Constructor. */ TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline = false); /** @@ -48,9 +48,8 @@ class TextParticle : public Particle private: std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ - int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ - bool mOutline; /**< Make the text readable - draw it the way - a Text is usually drawn: with outline */ + const gcn::Color* mColor; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text better readable */ }; #endif -- cgit v1.2.3-70-g09d2 From 20ad38045482254b9875ee80de44a9b6f9367d2d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 14:28:26 -0600 Subject: Exposed the progress bar colors to the color management tab. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 1 + src/gui/palette.h | 1 + src/gui/progressbar.cpp | 13 ++++++++++--- src/gui/setup_colors.cpp | 27 ++++++++++++++++++--------- src/gui/textrenderer.h | 7 +++---- src/gui/widgets/textpreview.cpp | 10 +++++++++- src/gui/widgets/textpreview.h | 11 +++++++++++ src/gui/window.cpp | 6 ++++++ src/gui/window.h | 5 +++++ src/text.cpp | 2 +- src/textparticle.cpp | 2 +- 11 files changed, 66 insertions(+), 19 deletions(-) (limited to 'src/text.cpp') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index c155cfe2..a3d654be 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -84,6 +84,7 @@ Palette::Palette() : addColor(TEXT, 0x000000, STATIC, _("Text")); addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow")); addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline")); + addColor(PROGRESS_BAR, 0xffffff, STATIC, indent + _("Progress Bar Labels")); addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); diff --git a/src/gui/palette.h b/src/gui/palette.h index 4d8f7f11..f0a3d541 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -51,6 +51,7 @@ class Palette : public gcn::ListModel ENTRY(TEXT)\ ENTRY(SHADOW)\ ENTRY(OUTLINE)\ + ENTRY(PROGRESS_BAR)\ ENTRY(BACKGROUND)\ ENTRY(HIGHLIGHT)\ ENTRY(TAB_HIGHLIGHT)\ diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index bec86bb1..025e0ec5 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -23,6 +23,7 @@ #include #include "gui.h" +#include "palette.h" #include "progressbar.h" #include "../configuration.h" @@ -133,18 +134,24 @@ void ProgressBar::draw(gcn::Graphics *graphics) const int textX = getWidth() / 2; const int textY = (getHeight() - f->getHeight()) / 2; + gcn::Color tempColor = guiPalette->getColor(Palette::OUTLINE); + graphics->setFont(f); - graphics->setColor(gcn::Color(0, 0, 0, alpha)); + graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, + (int) tempColor.b, alpha)); graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(255, 255, 255, alpha)); + tempColor = guiPalette->getColor(Palette::PROGRESS_BAR); + + graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, + (int) tempColor.b, alpha)); graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(0, 0, 0)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); } } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 09c6a3a9..b7c408d1 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -177,12 +177,12 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mPreview->clearRows(); mPreviewBox->setContent(mTextPreview); mTextPreview->setFont(gui->getFont()); - mTextPreview->setTextColor( - &guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextColor(&guiPalette->getColor(Palette::TEXT)); mTextPreview->setTextBGColor(NULL); - mTextPreview->setOpaque(false); + mTextPreview->setOpaque(false); mTextPreview->setShadow(true); mTextPreview->setOutline(true); + mTextPreview->useTextAlpha(false); switch (type) { @@ -190,10 +190,16 @@ void Setup_Colors::action(const gcn::ActionEvent &event) 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::PROGRESS_BAR: + mTextPreview->useTextAlpha(true); + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(true); + mTextPreview->setShadow(false); + break; case Palette::TAB_HIGHLIGHT: mTextPreview->setFont(gui->getFont()); mTextPreview->setTextColor(col); @@ -201,8 +207,13 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setShadow(false); break; case Palette::BACKGROUND: - case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: + mTextPreview->setBGColor(col); + mTextPreview->setOpaque(true); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; + case Palette::HIGHLIGHT: mTextPreview->setTextBGColor(col); mTextPreview->setOutline(false); mTextPreview->setShadow(false); @@ -221,13 +232,10 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mPreview->clearRows(); if (ch == '<') - { msg = toString("@@|") + rawmsg + "@@"; - } else - { msg = "##" + toString(ch) + rawmsg; - } + mPreview->addRow(msg); break; case Palette::UNKNOWN_ITEM: @@ -246,6 +254,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setFont(boldFont); mTextPreview->setOutline(false); mTextPreview->setShadow(false); + break; case Palette::PARTICLE: case Palette::EXP_INFO: case Palette::PICKUP_INFO: diff --git a/src/gui/textrenderer.h b/src/gui/textrenderer.h index 599e85a3..c0f5a0e9 100644 --- a/src/gui/textrenderer.h +++ b/src/gui/textrenderer.h @@ -37,7 +37,7 @@ class TextRenderer */ 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, + const gcn::Color color, gcn::Font *font, bool outline = false, bool shadow = false, int alpha = 255) { graphics->setFont(font); @@ -45,8 +45,7 @@ class TextRenderer // Text shadow if (shadow) { - graphics->setColor(guiPalette->getColor(Palette::SHADOW, - alpha / 2)); + graphics->setColor(guiPalette->getColor(Palette::SHADOW, alpha / 2)); if (outline) { graphics->drawText(text, x + 2, y + 2, align); @@ -73,7 +72,7 @@ class TextRenderer graphics->drawText(text, x, y - 1, align); } - graphics->setColor(*color); + graphics->setColor(color); graphics->drawText(text, x, y, align); } }; diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index e34bb5cb..5408eebe 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -35,6 +35,7 @@ float TextPreview::mAlpha = config.getValue("guialpha", 0.8); TextPreview::TextPreview(const std::string* text) { mText = text; + mTextAlpha = false; mFont = gui->getFont(); mTextColor = &guiPalette->getColor(Palette::TEXT); mTextBGColor = NULL; @@ -47,6 +48,11 @@ void TextPreview::draw(gcn::Graphics* graphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); + int alpha = (int) (mAlpha * 255.0f); + + if (!mTextAlpha) + alpha = 255; + if (mOpaque) { graphics->setColor(gcn::Color((int) mBGColor->r, @@ -69,5 +75,7 @@ void TextPreview::draw(gcn::Graphics* graphics) } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, - mTextColor, mFont, mOutline, mShadow); + gcn::Color(mTextColor->r, mTextColor->g, + mTextColor->b, alpha), + mFont, mOutline, mShadow, alpha); } diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index a73eb638..8e116262 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -44,6 +44,16 @@ class TextPreview : public gcn::Widget mTextColor = color; } + /** + * Sets the text to use the set alpha value. + * + * @param alpha whether to use alpha values for the text or not + */ + inline void useTextAlpha(bool alpha) + { + mTextAlpha = alpha; + } + /** * Sets the color the text background is drawn in. This is only the * rectangle directly behind the text, not to full widget. @@ -123,6 +133,7 @@ class TextPreview : public gcn::Widget const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; static float mAlpha; + bool mTextAlpha; bool mOpaque; bool mShadow; bool mOutline; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 144357ca..e6e79b45 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -675,6 +675,12 @@ void Window::setGuiAlpha() mAlphaChanged = false; } +int Window::getGuiAlpha() +{ + float alpha = config.getValue("guialpha", 0.8); + return (int) (alpha * 255.0f); +} + Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; diff --git a/src/gui/window.h b/src/gui/window.h index d573d85f..e04fcfc3 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -300,6 +300,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ virtual void close(); + /** + * Gets the alpha value used by the window, in a GUIChan usable format. + */ + int getGuiAlpha(); + private: enum ResizeHandles { diff --git a/src/text.cpp b/src/text.cpp index 420eeb8b..4e697f15 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -81,7 +81,7 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - mColor, boldFont, true); + *mColor, boldFont, true); } FlashText::FlashText(const std::string &text, int x, int y, diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 865c6764..957d67c0 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -61,5 +61,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - mColor, mTextFont, mOutline, false, (int) alpha); + *mColor, mTextFont, mOutline, false, (int) alpha); } -- cgit v1.2.3-70-g09d2