diff options
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 39 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.h | 12 | ||||
-rw-r--r-- | src/gui/widgets/chattab.cpp | 37 | ||||
-rw-r--r-- | src/gui/widgets/chattab.h | 10 |
4 files changed, 94 insertions, 4 deletions
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index d553312b..8c678805 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -37,6 +37,8 @@ BrowserBox::BrowserBox(unsigned int mode, bool opaque): gcn::Widget(), mMode(mode), mHighMode(UNDERLINE | BACKGROUND), + mShadows(false), + mOutline(false), mOpaque(opaque), mUseLinksAndUserColors(true), mSelectedLink(-1), @@ -304,8 +306,6 @@ void BrowserBox::draw(gcn::Graphics *graphics) } } - gcn::Font *font = getFont(); - for (LinePartIterator i = mLineParts.begin(); i != mLineParts.end(); i ++) @@ -315,8 +315,41 @@ void BrowserBox::draw(gcn::Graphics *graphics) continue; if (part.getY() > yEnd) break; + + // Use the correct font + graphics->setFont(getFont()); + + // Handle text shadows + if (mShadows) + { + graphics->setColor(Theme::getThemeColor(Theme::SHADOW, + part.getColor().a / 2)); + if (mOutline) + { + graphics->drawText(part.getText(), part.getX() + 2, + part.getY() + 2); + } + else + { + graphics->drawText(part.getText(), part.getX() + 1, + part.getY() + 1); + } + } + + if (mOutline) + { + // Text outline + graphics->setColor(Theme::getThemeColor(Theme::OUTLINE, + part.getColor().a / 4)); + graphics->drawText(part.getText(), part.getX() + 1, part.getY()); + graphics->drawText(part.getText(), part.getX() - 1, part.getY()); + graphics->drawText(part.getText(), part.getX(), part.getY() + 1); + graphics->drawText(part.getText(), part.getX(), part.getY() - 1); + } + + // the main text graphics->setColor(part.getColor()); - font->drawString(graphics, part.getText(), part.getX(), part.getY()); + graphics->drawText(part.getText(), part.getX(), part.getY()); } return; diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 28ec734a..1be74a0f 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -92,6 +92,16 @@ class BrowserBox : public gcn::Widget, void setHighlightMode(unsigned int highMode); /** + * Sets whether the font will use a shadow for text. + */ + void setShadowedText(bool shadows) { mShadows = shadows; } + + /** + * Sets whether the font will use a shadow for text. + */ + void setOutlinedText(bool outline) { mOutline = outline; } + + /** * Sets the maximum numbers of rows in the browser box. 0 = no limit. */ void setMaxRow(unsigned max) {mMaxRows = max; }; @@ -197,6 +207,8 @@ class BrowserBox : public gcn::Widget, LinkHandler *mLinkHandler; unsigned int mMode; unsigned int mHighMode; + bool mShadows; + bool mOutline; bool mOpaque; bool mUseLinksAndUserColors; int mSelectedLink; diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index c86eb2ea..bd4c5910 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -27,6 +27,7 @@ #include "configuration.h" #include "localplayer.h" +#include "gui/gui.h" #include "gui/recorder.h" #include "gui/widgets/browserbox.h" @@ -63,6 +64,11 @@ ChatTab::ChatTab(const std::string &name) : Tab() mScrollArea->setOpaque(false); chatWindow->addTab(this); + + listen(Event::ConfigChannel); + + // Initiate the text format + updateTextFormat(((Window*)getParent())->getGuiAlpha()); } ChatTab::~ChatTab() @@ -74,6 +80,37 @@ ChatTab::~ChatTab() delete mScrollArea; } +void ChatTab::updateTextFormat(int alpha) +{ + if (alpha > 200) + { + mTextOutput->setOutlinedText(false); + mTextOutput->setShadowedText(false); + } + else if (alpha <= 200 && alpha > 100) + { + mTextOutput->setOutlinedText(false); + mTextOutput->setShadowedText(true); + } + else + { + mTextOutput->setOutlinedText(true); + mTextOutput->setShadowedText(false); + } +} + +void ChatTab::event(Event::Channel channel, const Event &event) +{ + // Update the text outline and shadow according to the gui opacity. + if (channel == Event::ConfigChannel && + event.getType() == Event::ConfigOptionChanged && + event.getString("option") == "guialpha") + { + int alpha = ((Window*)getParent())->getGuiAlpha(); + updateTextFormat(alpha); + } +} + void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) { // Trim whitespace diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h index bc139079..1b666da1 100644 --- a/src/gui/widgets/chattab.h +++ b/src/gui/widgets/chattab.h @@ -34,7 +34,7 @@ class ScrollArea; /** * A tab for the chat window. This is special to ease chat handling. */ -class ChatTab : public Tab, public AutoCompleteLister +class ChatTab : public Tab, public AutoCompleteLister, public EventListener { public: ChatTab(const std::string &name); @@ -102,6 +102,8 @@ class ChatTab : public Tab, public AutoCompleteLister virtual void saveToLogFile(std::string &msg); + void event(Event::Channel channel, const Event &event); + protected: friend class ChatWindow; friend class WhisperWindow; @@ -112,6 +114,12 @@ class ChatTab : public Tab, public AutoCompleteLister virtual void handleCommand(const std::string &msg); + /** + * Adapts the text format to the current gui opacity, + * for better readability. + */ + void updateTextFormat(int alpha); + void addRow(std::string &line); ScrollArea *mScrollArea; |