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/textparticle.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/textparticle.cpp') diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 8a8948f4..a065eadd 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -22,10 +22,12 @@ #include -#include "graphics.h" -#include "textparticle.h" #include +#include "textparticle.h" + +#include "gui/textrenderer.h" + TextParticle::TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, gcn::Font *font, bool outline): @@ -61,24 +63,8 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const alpha /= mFadeIn; } - graphics->setFont(mTextFont); - if (mOutline) - { - graphics->setColor(gcn::Color(0, 0, 0, (int)(alpha/4))); - // Text outline - graphics->setColor(gcn::Color(0, 0, 0, (int)alpha)); - graphics->drawText(mText, screenX + 1, screenY, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX - 1, screenY, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX, screenY + 1, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX, screenY - 1, - gcn::Graphics::CENTER); - } - graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); - graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); + TextRenderer::renderText(graphics, mText, + screenX, screenY, gcn::Graphics::CENTER, + &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, + (int) alpha); } -- cgit v1.2.3-60-g2f50 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/textparticle.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-60-g2f50 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/textparticle.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-60-g2f50