From a928798a9326de1e6781e14c8ccf5abec1232385 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 24 Jan 2009 19:43:26 +0100 Subject: Use standard GUI font also for speech and names The speech bitmap font can't handle unicode, so it has now been replaced by the standard GUI font, drawn with a shadow for chat and with a full outline for names. --- src/being.cpp | 2 +- src/gui/gui.cpp | 29 ++++++-------------------- src/gui/gui.h | 4 ---- src/gui/ministatus.cpp | 8 -------- src/monster.cpp | 4 +--- src/npc.cpp | 4 +--- src/player.cpp | 3 +-- src/text.cpp | 55 +++++++++++++++++++++++++++++++++++++++++--------- src/text.h | 5 ++--- 9 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/being.cpp b/src/being.cpp index 5782c423..7036b8cd 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -156,7 +156,7 @@ void Being::setSpeech(const std::string &text, Uint32 time) delete mSpeech; mSpeech = new Text(text, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET, - gcn::Graphics::CENTER, speechFont, + gcn::Graphics::CENTER, gcn::Color(255, 255, 255), true); mSpeechTime = 500; } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 722779ca..22d94791 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -43,16 +43,14 @@ #include "../resources/imageloader.h" // Guichan stuff -Gui *gui; -Viewport *viewport; /**< Viewport on the map. */ -SDLInput *guiInput; +Gui *gui = 0; +Viewport *viewport = 0; /**< Viewport on the map. */ +SDLInput *guiInput = 0; // Fonts used in showing hits -gcn::Font *hitRedFont; -gcn::Font *hitBlueFont; -gcn::Font *hitYellowFont; -// Font used to display speech and player names -gcn::Font *speechFont; +gcn::Font *hitRedFont = 0; +gcn::Font *hitBlueFont = 0; +gcn::Font *hitYellowFont = 0; class GuiConfigListener : public ConfigListener { @@ -116,20 +114,6 @@ Gui::Gui(Graphics *graphics): + e.getMessage()); } - // Set speech font - try { - speechFont = new gcn::ImageFont("graphics/gui/rpgfont_wider.png", - " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789.,!?-+/():;%&`'*#=[]\"<>{}^~|_@$\\" - "áÁéÉíÍóÓúÚç륣¢¡¿àãõêñÑöüäÖÜÄßøèÈåÅ" - ); - } - catch (gcn::Exception e) - { - logger->error(std::string("Unable to load rpgfont_wider.png: ") - + e.getMessage()); - } - gcn::Widget::setGlobalFont(mGuiFont); // Load hits' colourful fonts @@ -173,7 +157,6 @@ Gui::~Gui() mMouseCursors->decRef(); delete mGuiFont; - delete speechFont; delete viewport; delete getTop(); diff --git a/src/gui/gui.h b/src/gui/gui.h index 6af0a26a..c153b8e1 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -124,9 +124,5 @@ extern SDLInput *guiInput; /**< GUI input */ extern gcn::Font *hitRedFont; extern gcn::Font *hitBlueFont; extern gcn::Font *hitYellowFont; -/** - * Font used to display speech and player names - */ -extern gcn::Font *speechFont; #endif diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 7a10ed3f..fa4f75da 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -55,14 +55,6 @@ MiniStatusWindow::MiniStatusWindow(): mMpLabel->setDimension(mMpBar->getDimension()); mXpLabel->setDimension(mXpBar->getDimension()); - mHpLabel->setForegroundColor(gcn::Color(255, 255, 255)); - mMpLabel->setForegroundColor(gcn::Color(255, 255, 255)); - mXpLabel->setForegroundColor(gcn::Color(255, 255, 255)); - - mHpLabel->setFont(speechFont); - mMpLabel->setFont(speechFont); - mXpLabel->setFont(speechFont); - mHpLabel->setAlignment(gcn::Graphics::CENTER); mMpLabel->setAlignment(gcn::Graphics::CENTER); mXpLabel->setAlignment(gcn::Graphics::CENTER); diff --git a/src/monster.cpp b/src/monster.cpp index 65049c9e..b6e6fc35 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -28,8 +28,6 @@ #include "text.h" #include "localplayer.h" -#include "gui/gui.h" - #include "resources/monsterdb.h" #include "utils/tostring.h" @@ -179,7 +177,7 @@ void Monster::showName(bool show) mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET - getHeight(), gcn::Graphics::CENTER, - speechFont, gcn::Color(255, 32, 32)); + gcn::Color(255, 64, 64)); } else { diff --git a/src/npc.cpp b/src/npc.cpp index 3de1228f..aed6d87b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -30,8 +30,6 @@ #include "net/protocol.h" #include "resources/npcdb.h" -#include "gui/gui.h" - NPC *current_npc = 0; static const int NAME_X_OFFSET = 15; @@ -76,7 +74,7 @@ void NPC::setName(const std::string &name) { delete mName; mName = new Text(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, - gcn::Graphics::CENTER, speechFont, + gcn::Graphics::CENTER, gcn::Color(200, 200, 255)); } diff --git a/src/player.cpp b/src/player.cpp index 22efc711..27820acf 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -31,7 +31,6 @@ #include "utils/strprintf.h" -#include "gui/gui.h" #include static const int NAME_X_OFFSET = 15; @@ -57,7 +56,7 @@ void Player::setName(const std::string &name) { mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - speechFont, gcn::Color(255, 255, 255)); + gcn::Color(255, 255, 255)); Being::setName(name); } } diff --git a/src/text.cpp b/src/text.cpp index d256b82d..0e458c9f 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -30,12 +30,14 @@ #include "resources/resourcemanager.h" #include "resources/image.h" +#include "gui/gui.h" + int Text::mInstances = 0; ImageRect Text::mBubble; Image *Text::mBubbleArrow; Text::Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Font *font, + gcn::Graphics::Alignment alignment, gcn::Color colour, bool isSpeech) : mText(text), mColour(colour), @@ -57,7 +59,7 @@ Text::Text(const std::string &text, int x, int y, mBubble.grid[7] = sbImage->getSubImage(5, 10, 5, 5); mBubble.grid[8] = sbImage->getSubImage(10, 10, 5, 5); mBubbleArrow = sbImage->getSubImage(0, 15, 15, 10); - double bubbleAlpha = config.getValue("speechBubbleAlpha", 0.4); + const float bubbleAlpha = config.getValue("speechBubbleAlpha", 1.0); for (int i = 0; i < 9; i++) { mBubble.grid[i]->setAlpha(bubbleAlpha); @@ -66,8 +68,8 @@ Text::Text(const std::string &text, int x, int y, sbImage->decRef(); } ++mInstances; - mHeight = font->getHeight(); - mWidth = font->getWidth(text); + mHeight = gui->getFont()->getHeight(); + mWidth = gui->getFont()->getWidth(text); switch (alignment) { @@ -84,7 +86,6 @@ Text::Text(const std::string &text, int x, int y, mX = x - mXOffset; mY = y; textManager->addText(this); - mFont = font; } Text::~Text() @@ -114,29 +115,63 @@ void Text::adviseXY(int x, int y) void Text::draw(Graphics *graphics, int xOff, int yOff) { - graphics->setFont(mFont); - graphics->setColor(mColour); + graphics->setFont(gui->getFont()); if (mIsSpeech) { static_cast(graphics)->drawImageRect( mX - xOff - 5, mY - yOff - 5, mWidth + 10, mHeight + 10, mBubble); - + /* if (mWidth >= 15) { static_cast(graphics)->drawImage( mBubbleArrow, mX - xOff - 7 + mWidth / 2, mY - yOff + mHeight + 4); } + */ + } + + // Text shadow + graphics->setColor(gcn::Color(0, 0, 0)); + graphics->drawText(mText, mX - xOff + 1, mY - yOff + 1, + gcn::Graphics::LEFT); + + if (!mIsSpeech) { + graphics->setColor(gcn::Color(0, 0, 0, 64)); + /* + // TODO: Reanable when we can draw it nicely in software mode + graphics->drawText(mText, mX - xOff + 2, mY - yOff + 2, + gcn::Graphics::LEFT); + graphics->drawText(mText, mX - xOff + 1, mY - yOff + 2, + gcn::Graphics::LEFT); + graphics->drawText(mText, mX - xOff + 2, mY - yOff + 1, + gcn::Graphics::LEFT); + */ + + // Text outline + graphics->setColor(gcn::Color(0, 0, 0)); + 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(mColour); graphics->drawText(mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT); } FlashText::FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Font *font, + gcn::Graphics::Alignment alignment, gcn::Color colour) : - Text(text, x, y, alignment, font, colour), mTime(0) + Text(text, x, y, alignment, colour), + mTime(0) { } diff --git a/src/text.h b/src/text.h index cdf91fb9..0c6f072a 100644 --- a/src/text.h +++ b/src/text.h @@ -37,7 +37,7 @@ 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::Font *font, + gcn::Graphics::Alignment alignment, gcn::Color colour, bool isSpeech = false); /** @@ -62,7 +62,6 @@ class Text int mHeight; /**< The height of the text. */ int mXOffset; /**< The offset of mX from the desired x. */ static int mInstances; /**< Instances of text. */ - gcn::Font *mFont; /**< The font used. */ std::string mText; /**< The text to display. */ gcn::Color mColour; /**< The colour of the text. */ bool mIsSpeech; /**< Is this text a speech bubble? */ @@ -76,7 +75,7 @@ class FlashText : public Text { public: FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Font *font, + gcn::Graphics::Alignment alignment, gcn::Color colour); /** -- cgit v1.2.3-70-g09d2