From 2d452dd8faf2529fda01913b0ab26f4a1f22ef3d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 5 Dec 2011 21:45:05 +0300 Subject: A bit improve speed in getting color from theme. --- src/gui/palette.cpp | 12 +++++------- src/gui/palette.h | 3 +++ src/gui/theme.cpp | 12 ++++++++++++ src/gui/widgets/browserbox.cpp | 5 +++-- 4 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index f3046264f..348f97de8 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -65,15 +65,13 @@ Palette::~Palette() const gcn::Color& Palette::getColor(char c, bool &valid) { - for (Colors::const_iterator col = mColors.begin(), - colEnd = mColors.end(); col != colEnd; ++col) + CharColors::const_iterator it = mCharColors.find(c); + if (it != mCharColors.end()) { - if (col->ch == c) - { - valid = true; - return col->color; - } + valid = true; + return mColors[(*it).second].color; } + valid = false; return BLACK; } diff --git a/src/gui/palette.h b/src/gui/palette.h index 645260280..d46a3c57c 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -200,8 +201,10 @@ class Palette } }; typedef std::vector Colors; + typedef std::map CharColors; /** Vector containing the colors. */ Colors mColors; + CharColors mCharColors; std::vector mGradVector; }; diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 9aa6bb956..b3b28bffa 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -162,6 +162,18 @@ Theme::Theme(): mColors[SERVER].ch = 'S'; mColors[LOGGER].ch = 'L'; mColors[HYPERLINK].ch = '<'; + mCharColors['H'] = HIGHLIGHT; + mCharColors['C'] = CHAT; + mCharColors['G'] = GM; + mCharColors['Y'] = PLAYER; + mCharColors['W'] = WHISPER; + mCharColors['w'] = WHISPER_OFFLINE; + mCharColors['I'] = IS; + mCharColors['P'] = PARTY_CHAT_TAB; + mCharColors['U'] = GUILD_CHAT_TAB; + mCharColors['S'] = SERVER; + mCharColors['L'] = LOGGER; + mCharColors['<'] = HYPERLINK; } Theme::~Theme() diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 4af38bf67..7d30c10bf 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -79,6 +79,7 @@ BrowserBox::BrowserBox(unsigned int mode, bool opaque): mColors[PURPLE] = Theme::getThemeColor(Theme::PURPLE); mColors[GRAY] = Theme::getThemeColor(Theme::GRAY); mColors[BROWN] = Theme::getThemeColor(Theme::BROWN); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } BrowserBox::~BrowserBox() @@ -406,8 +407,8 @@ int BrowserBox::calcHeight() char const *hyphen = "~"; int hyphenWidth = font->getWidth(hyphen); - gcn::Color selColor = Theme::getThemeColor(Theme::TEXT); - const gcn::Color textColor = Theme::getThemeColor(Theme::TEXT); + gcn::Color selColor = getForegroundColor(); + const gcn::Color textColor = getForegroundColor(); ResourceManager *resman = ResourceManager::getInstance(); mLineParts.clear(); -- cgit v1.2.3-70-g09d2