From c632452430cb3f886da38fa315cb27a3a3a10d2c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 19 Oct 2012 20:29:23 +0300 Subject: Allow get colors from Widget2. --- src/CMakeLists.txt | 1 - src/Makefile.am | 1 - src/gui/palette.cpp | 13 +++++++++++++ src/gui/palette.h | 2 ++ src/gui/theme.cpp | 2 -- src/gui/theme.h | 5 +++++ src/gui/widgets/browserbox.cpp | 2 +- src/gui/widgets/widget2.cpp | 31 ------------------------------- src/gui/widgets/widget2.h | 35 +++++++++++++++++++++++++++++++++-- 9 files changed, 54 insertions(+), 38 deletions(-) delete mode 100644 src/gui/widgets/widget2.cpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4279ef743..5c0b2e45c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -218,7 +218,6 @@ SET(SRCS gui/widgets/vertcontainer.h gui/widgets/whispertab.cpp gui/widgets/whispertab.h - gui/widgets/widget2.cpp gui/widgets/widget2.h gui/widgets/widgetgroup.cpp gui/widgets/widgetgroup.h diff --git a/src/Makefile.am b/src/Makefile.am index e3bec2b9d..edf151089 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -220,7 +220,6 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/vertcontainer.h \ gui/widgets/whispertab.cpp \ gui/widgets/whispertab.h \ - gui/widgets/widget2.cpp \ gui/widgets/widget2.h \ gui/widgets/widgetgroup.cpp \ gui/widgets/widgetgroup.h \ diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 092a0daae..b73732e29 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -77,6 +77,19 @@ const gcn::Color& Palette::getCharColor(const signed char c, bool &valid) return BLACK; } +int Palette::getIdByChar(const signed char c, bool &valid) +{ + const CharColors::const_iterator it = mCharColors.find(c); + if (it != mCharColors.end()) + { + valid = true; + return (*it).second; + } + + valid = false; + return 0; +} + void Palette::advanceGradients() { for (Palettes::const_iterator it = mInstances.begin(), diff --git a/src/gui/palette.h b/src/gui/palette.h index 51c60cb8f..e165e8901 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -69,6 +69,8 @@ class Palette */ const gcn::Color &getCharColor(const signed char c, bool &valid); + int getIdByChar(const signed char c, bool &valid); + /** * Gets the color associated with the type. Sets the alpha channel * before returning. diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 71c864c0f..2178228fc 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -47,8 +47,6 @@ std::string Theme::mThemePath; std::string Theme::mThemeName; Theme *Theme::mInstance = nullptr; -static const int THEME_PALETTES = 5; - // Set the theme path... static void initDefaultThemePath() { diff --git a/src/gui/theme.h b/src/gui/theme.h index 26d4ba99d..1e91b46ce 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -39,6 +39,8 @@ class Image; class ImageSet; class ProgressBar; +const int THEME_PALETTES = 5; + struct ThemeInfo final { std::string name; @@ -294,6 +296,9 @@ class Theme final : public Palette, public ConfigListener bool &valid) { return mInstance->getCharColor(c, valid); } + static int getIdByChar(const signed char c, bool &valid) + { return mInstance->getIdByChar(c, valid); } + static gcn::Color getProgressColor(const int type, const float progress); diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 7d6dc3f13..f8f3de2a0 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -499,7 +499,7 @@ int BrowserBox::calcHeight() const signed char c = row.at(start + 2); bool valid; - const gcn::Color col = Theme::getThemeColor(c, valid); + const gcn::Color col = Theme::getThemeCharColor(c, valid); if (c == '>') { diff --git a/src/gui/widgets/widget2.cpp b/src/gui/widgets/widget2.cpp deleted file mode 100644 index 6b38b0cf5..000000000 --- a/src/gui/widgets/widget2.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * 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, see . - */ - -#include "gui/widgets/widget2.h" - -#include "debug.h" - -Widget2::Widget2() -{ -} - -Widget2::~Widget2() -{ -} diff --git a/src/gui/widgets/widget2.h b/src/gui/widgets/widget2.h index 68a45ae30..0bf7ae87a 100644 --- a/src/gui/widgets/widget2.h +++ b/src/gui/widgets/widget2.h @@ -21,12 +21,43 @@ #ifndef GUI_WIDGET2_H #define GUI_WIDGET2_H +#include "gui/theme.h" + class Widget2 { public: - Widget2(); + Widget2() + { + } + + ~Widget2() + { + } + + inline const gcn::Color &getThemeColor(const int type, + const int alpha = 255) + { + return Theme::getThemeColor(type * mPalette, alpha); + } + + inline const gcn::Color &getThemeCharColor(const signed char c, + bool &valid) + { + const int colorId = Theme::getIdByChar(c, valid); + if (valid) + return Theme::getThemeColor(colorId * mPalette); + else + return Palette::BLACK; + } + + void setPalette(int p) + { + if (p >= 1 && p <= THEME_PALETTES) + mPalette = p; + } - ~Widget2(); + private: + int mPalette; }; #endif -- cgit v1.2.3-60-g2f50