From 34cb5e4b16c1b1f5d3263dd01848b24ab0b9b354 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 31 May 2015 18:46:22 +0300 Subject: Convert ThemeColorId enum into strong typed enum. --- src/gui/theme.cpp | 121 +++++++++++++++++++---------------- src/gui/theme.h | 15 +++-- src/gui/themecolorsidoperators.cpp | 28 ++++++++ src/gui/themecolorsidoperators.h | 28 ++++++++ src/gui/widgets/widget2.h | 18 +++--- src/gui/windows/ministatuswindow.cpp | 2 +- src/gui/windows/ministatuswindow.h | 2 +- src/gui/windows/tradewindow.cpp | 24 +++---- 8 files changed, 154 insertions(+), 84 deletions(-) create mode 100644 src/gui/themecolorsidoperators.cpp create mode 100644 src/gui/themecolorsidoperators.h (limited to 'src/gui') diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index c0a4e7bf7..9735fc05b 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -70,7 +70,7 @@ static void initDefaultThemePath() } Theme::Theme() : - Palette(ThemeColorId::THEME_COLORS_END * THEME_PALETTES), + Palette(static_cast(ThemeColorId::THEME_COLORS_END) * THEME_PALETTES), mSkins(), mMinimumOpacity(-1.0F), mProgressColors(ProgressColors(static_cast( @@ -80,56 +80,62 @@ Theme::Theme() : config.addListener("guialpha", this); - mColors[ThemeColorId::HIGHLIGHT].ch = 'H'; - mColors[ThemeColorId::CHAT].ch = 'C'; - mColors[ThemeColorId::GM].ch = 'G'; - mColors[ThemeColorId::GLOBAL].ch = 'g'; - mColors[ThemeColorId::PLAYER].ch = 'Y'; - mColors[ThemeColorId::WHISPER_TAB].ch = 'W'; - mColors[ThemeColorId::WHISPER_TAB_OFFLINE].ch = 'w'; - mColors[ThemeColorId::IS].ch = 'I'; - mColors[ThemeColorId::PARTY_CHAT_TAB].ch = 'P'; - mColors[ThemeColorId::GUILD_CHAT_TAB].ch = 'U'; - mColors[ThemeColorId::SERVER].ch = 'S'; - mColors[ThemeColorId::LOGGER].ch = 'L'; - mColors[ThemeColorId::HYPERLINK].ch = '<'; - mColors[ThemeColorId::SELFNICK].ch = 's'; - mColors[ThemeColorId::OLDCHAT].ch = 'o'; - mColors[ThemeColorId::AWAYCHAT].ch = 'a'; - mCharColors['H'] = ThemeColorId::HIGHLIGHT; - mCharColors['C'] = ThemeColorId::CHAT; - mCharColors['G'] = ThemeColorId::GM; - mCharColors['g'] = ThemeColorId::GLOBAL; - mCharColors['Y'] = ThemeColorId::PLAYER; - mCharColors['W'] = ThemeColorId::WHISPER_TAB; - mCharColors['w'] = ThemeColorId::WHISPER_TAB_OFFLINE; - mCharColors['I'] = ThemeColorId::IS; - mCharColors['P'] = ThemeColorId::PARTY_CHAT_TAB; - mCharColors['U'] = ThemeColorId::GUILD_CHAT_TAB; - mCharColors['S'] = ThemeColorId::SERVER; - mCharColors['L'] = ThemeColorId::LOGGER; - mCharColors['<'] = ThemeColorId::HYPERLINK; - mCharColors['s'] = ThemeColorId::SELFNICK; - mCharColors['o'] = ThemeColorId::OLDCHAT; - mCharColors['a'] = ThemeColorId::AWAYCHAT; + mColors[static_cast(ThemeColorId::HIGHLIGHT)].ch = 'H'; + mColors[static_cast(ThemeColorId::CHAT)].ch = 'C'; + mColors[static_cast(ThemeColorId::GM)].ch = 'G'; + mColors[static_cast(ThemeColorId::GLOBAL)].ch = 'g'; + mColors[static_cast(ThemeColorId::PLAYER)].ch = 'Y'; + mColors[static_cast(ThemeColorId::WHISPER_TAB)].ch = 'W'; + mColors[static_cast(ThemeColorId::WHISPER_TAB_OFFLINE)].ch = 'w'; + mColors[static_cast(ThemeColorId::IS)].ch = 'I'; + mColors[static_cast(ThemeColorId::PARTY_CHAT_TAB)].ch = 'P'; + mColors[static_cast(ThemeColorId::GUILD_CHAT_TAB)].ch = 'U'; + mColors[static_cast(ThemeColorId::SERVER)].ch = 'S'; + mColors[static_cast(ThemeColorId::LOGGER)].ch = 'L'; + mColors[static_cast(ThemeColorId::HYPERLINK)].ch = '<'; + mColors[static_cast(ThemeColorId::SELFNICK)].ch = 's'; + mColors[static_cast(ThemeColorId::OLDCHAT)].ch = 'o'; + mColors[static_cast(ThemeColorId::AWAYCHAT)].ch = 'a'; + mCharColors['H'] = static_cast(ThemeColorId::HIGHLIGHT); + mCharColors['C'] = static_cast(ThemeColorId::CHAT); + mCharColors['G'] = static_cast(ThemeColorId::GM); + mCharColors['g'] = static_cast(ThemeColorId::GLOBAL); + mCharColors['Y'] = static_cast(ThemeColorId::PLAYER); + mCharColors['W'] = static_cast(ThemeColorId::WHISPER_TAB); + mCharColors['w'] = static_cast(ThemeColorId::WHISPER_TAB_OFFLINE); + mCharColors['I'] = static_cast(ThemeColorId::IS); + mCharColors['P'] = static_cast(ThemeColorId::PARTY_CHAT_TAB); + mCharColors['U'] = static_cast(ThemeColorId::GUILD_CHAT_TAB); + mCharColors['S'] = static_cast(ThemeColorId::SERVER); + mCharColors['L'] = static_cast(ThemeColorId::LOGGER); + mCharColors['<'] = static_cast(ThemeColorId::HYPERLINK); + mCharColors['s'] = static_cast(ThemeColorId::SELFNICK); + mCharColors['o'] = static_cast(ThemeColorId::OLDCHAT); + mCharColors['a'] = static_cast(ThemeColorId::AWAYCHAT); // here need use outlined colors - mCharColors['H' | 0x80] = ThemeColorId::HIGHLIGHT_OUTLINE; - mCharColors['C' | 0x80] = ThemeColorId::CHAT_OUTLINE; - mCharColors['G' | 0x80] = ThemeColorId::GM_OUTLINE; - mCharColors['g' | 0x80] = ThemeColorId::GLOBAL_OUTLINE; - mCharColors['Y' | 0x80] = ThemeColorId::PLAYER_OUTLINE; - mCharColors['W' | 0x80] = ThemeColorId::WHISPER_TAB_OUTLINE; - mCharColors['w' | 0x80] = ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE; - mCharColors['I' | 0x80] = ThemeColorId::IS_OUTLINE; - mCharColors['P' | 0x80] = ThemeColorId::PARTY_CHAT_TAB_OUTLINE; - mCharColors['U' | 0x80] = ThemeColorId::GUILD_CHAT_TAB_OUTLINE; - mCharColors['S' | 0x80] = ThemeColorId::SERVER_OUTLINE; - mCharColors['L' | 0x80] = ThemeColorId::LOGGER_OUTLINE; - mCharColors['<' | 0x80] = ThemeColorId::HYPERLINK_OUTLINE; - mCharColors['s' | 0x80] = ThemeColorId::SELFNICK_OUTLINE; - mCharColors['o' | 0x80] = ThemeColorId::OLDCHAT_OUTLINE; - mCharColors['a' | 0x80] = ThemeColorId::AWAYCHAT_OUTLINE; + mCharColors['H' | 0x80] + = static_cast(ThemeColorId::HIGHLIGHT_OUTLINE); + mCharColors['C' | 0x80] = static_cast(ThemeColorId::CHAT_OUTLINE); + mCharColors['G' | 0x80] = static_cast(ThemeColorId::GM_OUTLINE); + mCharColors['g' | 0x80] = static_cast(ThemeColorId::GLOBAL_OUTLINE); + mCharColors['Y' | 0x80] = static_cast(ThemeColorId::PLAYER_OUTLINE); + mCharColors['W' | 0x80] + = static_cast(ThemeColorId::WHISPER_TAB_OUTLINE); + mCharColors['w' | 0x80] + = static_cast(ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE); + mCharColors['I' | 0x80] = static_cast(ThemeColorId::IS_OUTLINE); + mCharColors['P' | 0x80] + = static_cast(ThemeColorId::PARTY_CHAT_TAB_OUTLINE); + mCharColors['U' | 0x80] + = static_cast(ThemeColorId::GUILD_CHAT_TAB_OUTLINE); + mCharColors['S' | 0x80] = static_cast(ThemeColorId::SERVER_OUTLINE); + mCharColors['L' | 0x80] = static_cast(ThemeColorId::LOGGER_OUTLINE); + mCharColors['<' | 0x80] + = static_cast(ThemeColorId::HYPERLINK_OUTLINE); + mCharColors['s' | 0x80] = static_cast(ThemeColorId::SELFNICK_OUTLINE); + mCharColors['o' | 0x80] = static_cast(ThemeColorId::OLDCHAT_OUTLINE); + mCharColors['a' | 0x80] = static_cast(ThemeColorId::AWAYCHAT_OUTLINE); } Theme::~Theme() @@ -644,7 +650,8 @@ ImageSet *Theme::getImageSetFromTheme(const std::string &path, static int readColorType(const std::string &type) { - static const std::string colors[ThemeColorId::THEME_COLORS_END] = + static const std::string colors[static_cast( + ThemeColorId::THEME_COLORS_END)] = { "BROWSERBOX", "BROWSERBOX_OUTLINE", @@ -871,7 +878,7 @@ static int readColorType(const std::string &type) if (type.empty()) return -1; - for (int i = 0; i < ThemeColorId::THEME_COLORS_END; i++) + for (int i = 0; i < static_cast(ThemeColorId::THEME_COLORS_END); i++) { if (compareStrI(type, colors[i]) == 0) return i; @@ -1029,7 +1036,8 @@ void Theme::loadColors(std::string file) const Color color = readColor(temp); const GradientTypeT grad = readColorGradient( XML::getProperty(node, "effect", "")); - mColors[paletteId * ThemeColorId::THEME_COLORS_END + type].set( + mColors[paletteId * static_cast( + ThemeColorId::THEME_COLORS_END) + type].set( type, color, grad, 10); if (!findLast(id, "_OUTLINE")) @@ -1037,7 +1045,8 @@ void Theme::loadColors(std::string file) const int type2 = readColorType(id + "_OUTLINE"); if (type2 < 0) continue; - const int idx = paletteId * ThemeColorId::THEME_COLORS_END; + const int idx = paletteId + * static_cast(ThemeColorId::THEME_COLORS_END); mColors[idx + type2] = mColors[idx + type]; } } @@ -1216,15 +1225,15 @@ ThemeInfo *Theme::loadInfo(const std::string &themeName) return info; } -int Theme::getIdByChar(const signed char c, bool &valid) const +ThemeColorIdT Theme::getIdByChar(const signed char c, bool &valid) const { const CharColors::const_iterator it = mCharColors.find(c); if (it != mCharColors.end()) { valid = true; - return (*it).second; + return static_cast((*it).second); } valid = false; - return 0; + return ThemeColorId::BROWSERBOX; } diff --git a/src/gui/theme.h b/src/gui/theme.h index 5a9a75bb0..2b6e45812 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -26,6 +26,7 @@ #define GUI_THEME_H #include "enums/gui/progresscolorid.h" +#include "enums/gui/themecolorid.h" #include "listeners/configlistener.h" @@ -133,21 +134,23 @@ class Theme final : public Palette, * * @return the requested color */ - inline const Color &getColor(int type, + inline const Color &getColor(ThemeColorIdT type, const int alpha = 255) A_WARN_UNUSED { - if (type >= static_cast(mColors.size()) || type < 0) + if (static_cast(type) >= mColors.size()) { logger->log("incorrect color request type: %d from %u", - type, static_cast(mColors.size())); - type = 0; + static_cast(type), + static_cast(mColors.size())); + type = ThemeColorIdT::BROWSERBOX; } - Color* col = &mColors[type].color; + Color* col = &mColors[static_cast(type)].color; col->a = alpha; return *col; } - int getIdByChar(const signed char c, bool &valid) const A_WARN_UNUSED; + ThemeColorIdT getIdByChar(const signed char c, + bool &valid) const A_WARN_UNUSED; /** * Set the minimum opacity allowed to skins. diff --git a/src/gui/themecolorsidoperators.cpp b/src/gui/themecolorsidoperators.cpp new file mode 100644 index 000000000..559981d67 --- /dev/null +++ b/src/gui/themecolorsidoperators.cpp @@ -0,0 +1,28 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 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/themecolorsidoperators.h" + +#include "debug.h" + +ThemeColorIdT operator+(const ThemeColorIdT &id, const int& i) +{ + return static_cast(static_cast(id) + i); +} diff --git a/src/gui/themecolorsidoperators.h b/src/gui/themecolorsidoperators.h new file mode 100644 index 000000000..b4781ed2d --- /dev/null +++ b/src/gui/themecolorsidoperators.h @@ -0,0 +1,28 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 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 . + */ + +#ifndef GUI_THEMECOLORIDOPERATOR_H +#define GUI_THEMECOLORIDOPERATOR_H + +#include "enums/gui/themecolorid.h" + +ThemeColorIdT operator+(const ThemeColorIdT &id, const int& i); + +#endif // GUI_THEMECOLORIDOPERATOR_H diff --git a/src/gui/widgets/widget2.h b/src/gui/widgets/widget2.h index 9fad6a882..5955397fc 100644 --- a/src/gui/widgets/widget2.h +++ b/src/gui/widgets/widget2.h @@ -21,7 +21,7 @@ #ifndef GUI_WIDGETS_WIDGET2_H #define GUI_WIDGETS_WIDGET2_H -#include "enums/gui/themecolorid.h" +#include "gui/themecolorsidoperators.h" #include "gui/theme.h" @@ -34,11 +34,11 @@ class Widget2 notfinal { } - inline const Color &getThemeColor(const int type, + inline const Color &getThemeColor(const ThemeColorIdT type, const int alpha = 255) const A_WARN_UNUSED { - return theme->getColor(mPaletteOffset + type, alpha); + return theme->getColor(type + mPaletteOffset, alpha); } inline const Color &getThemeCharColor(const signed char c, @@ -47,9 +47,9 @@ class Widget2 notfinal { if (!theme) return Palette::BLACK; - const int colorId = theme->getIdByChar(c, valid); + const ThemeColorIdT colorId = theme->getIdByChar(c, valid); if (valid) - return theme->getColor(mPaletteOffset + colorId, 255); + return theme->getColor(colorId + mPaletteOffset, 255); else return Palette::BLACK; } @@ -61,15 +61,17 @@ class Widget2 notfinal void setPalette(int palette) { - mPaletteOffset = palette * ThemeColorId::THEME_COLORS_END; + mPaletteOffset = palette * static_cast( + ThemeColorId::THEME_COLORS_END); checkPalette(); setWidget2(this); } void checkPalette() { - if (mPaletteOffset < 0 || mPaletteOffset - >= THEME_PALETTES * ThemeColorId::THEME_COLORS_END) + if (mPaletteOffset < 0 || + mPaletteOffset >= THEME_PALETTES * static_cast( + ThemeColorId::THEME_COLORS_END)) { mPaletteOffset = 0; } diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp index 7d0e030b3..73663c3a7 100644 --- a/src/gui/windows/ministatuswindow.cpp +++ b/src/gui/windows/ministatuswindow.cpp @@ -175,7 +175,7 @@ MiniStatusWindow::~MiniStatusWindow() ProgressBar *MiniStatusWindow::createBar(const float progress, const int width, const int height, - const int textColor, + const ThemeColorId textColor, const ProgressColorIdT backColor, const std::string &restrict skin, const std::string &restrict skinFill, diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h index 2edb8e66e..dbe2b76e8 100644 --- a/src/gui/windows/ministatuswindow.h +++ b/src/gui/windows/ministatuswindow.h @@ -112,7 +112,7 @@ class MiniStatusWindow final : public Window, ProgressBar *createBar(const float progress, const int width, const int height, - const int textColor, + const ThemeColorId textColor, const ProgressColorIdT backColor, const std::string &restrict skin, const std::string &restrict skinFill, diff --git a/src/gui/windows/tradewindow.cpp b/src/gui/windows/tradewindow.cpp index 11d150f30..c5951a7a5 100644 --- a/src/gui/windows/tradewindow.cpp +++ b/src/gui/windows/tradewindow.cpp @@ -173,16 +173,16 @@ void TradeWindow::setMoney(const int amount) } else { - mMoneyLabel->setForegroundColorAll(getThemeColor( - static_cast(ThemeColorId::WARNING)), getThemeColor( - static_cast(ThemeColorId::WARNING_OUTLINE))); + mMoneyLabel->setForegroundColorAll( + getThemeColor(ThemeColorId::WARNING), + getThemeColor(ThemeColorId::WARNING_OUTLINE)); } } else { - mMoneyLabel->setForegroundColorAll(getThemeColor( - static_cast(ThemeColorId::LABEL)), getThemeColor( - static_cast(ThemeColorId::LABEL_OUTLINE))); + mMoneyLabel->setForegroundColorAll( + getThemeColor(ThemeColorId::LABEL), + getThemeColor(ThemeColorId::LABEL_OUTLINE)); mGotMaxMoney = amount; } @@ -277,9 +277,9 @@ void TradeWindow::reset() setMoney(0); mMoneyField->setEnabled(true); mMoneyField->setText(""); - mMoneyLabel->setForegroundColorAll(getThemeColor( - static_cast(ThemeColorId::LABEL)), getThemeColor( - static_cast(ThemeColorId::LABEL_OUTLINE))); + mMoneyLabel->setForegroundColorAll( + getThemeColor(ThemeColorId::LABEL), + getThemeColor(ThemeColorId::LABEL_OUTLINE)); mAddButton->setEnabled(true); mMoneyChangeButton->setEnabled(true); mGotMoney = 0; @@ -448,9 +448,9 @@ void TradeWindow::clear() mAutoAddAmount = 0; mGotMoney = 0; mGotMaxMoney = 0; - mMoneyLabel->setForegroundColorAll(getThemeColor( - static_cast(ThemeColorId::LABEL)), getThemeColor( - static_cast(ThemeColorId::LABEL_OUTLINE))); + mMoneyLabel->setForegroundColorAll( + getThemeColor(ThemeColorId::LABEL), + getThemeColor(ThemeColorId::LABEL_OUTLINE)); } void TradeWindow::addAutoItem(const std::string &nick, Item* const item, -- cgit v1.2.3-60-g2f50