diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-06-01 01:08:30 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-06-01 01:08:30 +0300 |
commit | 16f6f636aee6acaf52439643502f5ff9cb4ccffc (patch) | |
tree | 9f291e5257e20b0090405d4594553f38a69767ce /src/gui | |
parent | 3fc7fd8473e545265c705504ee0d5f2a70268282 (diff) | |
download | manaverse-16f6f636aee6acaf52439643502f5ff9cb4ccffc.tar.gz manaverse-16f6f636aee6acaf52439643502f5ff9cb4ccffc.tar.bz2 manaverse-16f6f636aee6acaf52439643502f5ff9cb4ccffc.tar.xz manaverse-16f6f636aee6acaf52439643502f5ff9cb4ccffc.zip |
Convert UserColorId enum into strong typed enum.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/palette.h | 7 | ||||
-rw-r--r-- | src/gui/userpalette.cpp | 49 | ||||
-rw-r--r-- | src/gui/userpalette.h | 63 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_colors.cpp | 12 | ||||
-rw-r--r-- | src/gui/windows/minimap.cpp | 2 |
5 files changed, 80 insertions, 53 deletions
diff --git a/src/gui/palette.h b/src/gui/palette.h index aa7d2ecc8..bee83daf3 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -27,6 +27,7 @@ #include "logger.h" #include "enums/gui/gradienttype.h" +#include "enums/gui/usercolorid.h" #include "gui/color.h" @@ -132,8 +133,10 @@ class Palette notfinal int delay; int committedDelay; - void set(const int type0, const Color &color0, - const GradientTypeT grad0, const int delay0) + void set(const int type0, + const Color &color0, + const GradientTypeT grad0, + const int delay0) { type = type0; color = color0; diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index 629caca73..bb82b3b78 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -105,14 +105,14 @@ std::string UserPalette::getConfigName(const std::string &typeName) } UserPalette::UserPalette() : - Palette(UserColorId::USER_COLOR_LAST) + Palette(static_cast<int>(UserColorId::USER_COLOR_LAST)) { - mColors[UserColorId::BEING] = ColorElem(); - mColors[UserColorId::PC] = ColorElem(); - mColors[UserColorId::SELF] = ColorElem(); - mColors[UserColorId::GM] = ColorElem(); - mColors[UserColorId::NPC] = ColorElem(); - mColors[UserColorId::MONSTER] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::BEING)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::PC)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::SELF)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::GM)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::NPC)] = ColorElem(); + mColors[static_cast<size_t>(UserColorId::MONSTER)] = ColorElem(); // TRANSLATORS: palette color addColor(UserColorId::BEING, 0xffffff, GradientType::STATIC, _("Being")); @@ -248,20 +248,21 @@ UserPalette::~UserPalette() } } -void UserPalette::setColor(const int type, +void UserPalette::setColor(const UserColorIdT type, const int r, const int g, const int b) { - Color &color = mColors[type].color; + Color &color = mColors[static_cast<size_t>(type)].color; color.r = r; color.g = g; color.b = b; } -void UserPalette::setGradient(const int type, const GradientTypeT grad) +void UserPalette::setGradient(const UserColorIdT type, + const GradientTypeT grad) { - ColorElem *const elem = &mColors[type]; + ColorElem *const elem = &mColors[static_cast<size_t>(type)]; if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC) { @@ -311,12 +312,15 @@ void UserPalette::rollback() FOR_EACH (Colors::iterator, i, mColors) { if (i->grad != i->committedGrad) - setGradient(i->type, i->committedGrad); + setGradient(static_cast<UserColorIdT>(i->type), i->committedGrad); const Color &committedColor = i->committedColor; - setGradientDelay(i->type, i->committedDelay); - setColor(i->type, committedColor.r, - committedColor.g, committedColor.b); + setGradientDelay(static_cast<UserColorIdT>(i->type), + i->committedDelay); + setColor(static_cast<UserColorIdT>(i->type), + committedColor.r, + committedColor.g, + committedColor.b); if (i->grad == GradientType::PULSE) { @@ -331,12 +335,12 @@ void UserPalette::rollback() int UserPalette::getColorTypeAt(const int i) { if (i < 0 || i >= getNumberOfElements()) - return UserColorId::BEING; + return 0; return mColors[i].type; } -void UserPalette::addColor(const unsigned type, +void UserPalette::addColor(const UserColorIdT type, const unsigned rgb, GradientTypeT grad, const std::string &text, @@ -345,10 +349,10 @@ void UserPalette::addColor(const unsigned type, const unsigned maxType = sizeof(ColorTypeNames) / sizeof(ColorTypeNames[0]); - if (type >= maxType) + if (static_cast<unsigned>(type) >= maxType) return; - const std::string &configName = ColorTypeNames[type]; + const std::string &configName = ColorTypeNames[static_cast<size_t>(type)]; char buffer[20]; snprintf(buffer, sizeof(buffer), "0x%06x", rgb); buffer[19] = 0; @@ -365,11 +369,12 @@ void UserPalette::addColor(const unsigned type, configName + "Gradient", static_cast<int>(grad))); delay = config.getValueInt(configName + "Delay", delay); - mColors[type].set(type, trueCol, grad, delay); - mColors[type].text = text; + mColors[static_cast<size_t>(type)].set(static_cast<int>(type), + trueCol, grad, delay); + mColors[static_cast<size_t>(type)].text = text; if (grad != GradientType::STATIC) - mGradVector.push_back(&mColors[type]); + mGradVector.push_back(&mColors[static_cast<size_t>(type)]); } int UserPalette::getIdByChar(const signed char c, bool &valid) const diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h index 525a18492..22203560c 100644 --- a/src/gui/userpalette.h +++ b/src/gui/userpalette.h @@ -24,6 +24,8 @@ #ifndef GUI_USERPALETTE_H #define GUI_USERPALETTE_H +#include "enums/gui/usercolorid.h" + #include "gui/palette.h" #include "gui/models/listmodel.h" @@ -53,10 +55,10 @@ class UserPalette final : public Palette, public ListModel * * @return the requested committed color */ - inline const Color &getCommittedColor(const int type) + inline const Color &getCommittedColor(const UserColorIdT type) const A_WARN_UNUSED { - return mColors[type].committedColor; + return mColors[static_cast<size_t>(type)].committedColor; } /** @@ -66,8 +68,9 @@ class UserPalette final : public Palette, public ListModel * * @return the requested test color */ - inline const Color &getTestColor(const int type) const A_WARN_UNUSED - { return mColors[type].testColor; } + inline const Color &getTestColor(const UserColorIdT type) + const A_WARN_UNUSED + { return mColors[static_cast<size_t>(type)].testColor; } /** * Sets the test color associated with the specified type. @@ -75,8 +78,9 @@ class UserPalette final : public Palette, public ListModel * @param type the color type requested * @param color the color that should be tested */ - inline void setTestColor(const int type, const Color &color) - { mColors[type].testColor = color; } + inline void setTestColor(const UserColorIdT type, + const Color &color) + { mColors[static_cast<size_t>(type)].testColor = color; } /** * Sets the color for the specified type. @@ -86,22 +90,27 @@ class UserPalette final : public Palette, public ListModel * @param g green component * @param b blue component */ - void setColor(const int type, const int r, const int g, const int b); + void setColor(const UserColorIdT type, + const int r, + const int g, + const int b); /** * Sets the gradient type for the specified color. * * @param grad gradient type to set */ - void setGradient(const int type, const GradientTypeT grad); + void setGradient(const UserColorIdT type, + const GradientTypeT grad); /** * Sets the gradient delay for the specified color. * * @param grad gradient type to set */ - void setGradientDelay(const int type, const int delay) - { mColors[type].delay = delay; } + void setGradientDelay(const UserColorIdT type, + const int delay) + { mColors[static_cast<size_t>(type)].delay = delay; } /** * Returns the number of colors known. @@ -150,16 +159,17 @@ class UserPalette final : public Palette, public ListModel * * @return the requested color */ - inline const Color &getColor(int type, + inline const Color &getColor(UserColorIdT type, const int alpha = 255) A_WARN_UNUSED { - if (type >= static_cast<signed>(mColors.size()) || type < 0) + if (static_cast<size_t>(type) >= mColors.size()) { logger->log("incorrect color request type: %d from %u", - type, static_cast<unsigned int>(mColors.size())); - type = 0; + static_cast<int>(type), + static_cast<unsigned int>(mColors.size())); + type = UserColorId::BEING; } - Color* col = &mColors[type].color; + Color* col = &mColors[static_cast<size_t>(type)].color; col->a = alpha; return *col; } @@ -173,8 +183,9 @@ class UserPalette final : public Palette, public ListModel * * @return the gradient type of the color with the given index */ - inline GradientTypeT getGradientType(const int type) const A_WARN_UNUSED - { return mColors[type].grad; } + inline GradientTypeT getGradientType(const UserColorId type) + const A_WARN_UNUSED + { return mColors[static_cast<size_t>(type)].grad; } /** * Gets the gradient delay for the specified type. @@ -183,13 +194,15 @@ class UserPalette final : public Palette, public ListModel * * @return the gradient delay of the color with the given index */ - inline int getGradientDelay(const int type) const A_WARN_UNUSED - { return mColors[type].delay; } + inline int getGradientDelay(const UserColorIdT type) + const A_WARN_UNUSED + { return mColors[static_cast<size_t>(type)].delay; } - inline const Color &getColorWithAlpha(const int type) A_WARN_UNUSED + inline const Color &getColorWithAlpha(const UserColorIdT type) + A_WARN_UNUSED { - Color *const col = &mColors[type].color; - col->a = mColors[type].delay; + Color *const col = &mColors[static_cast<size_t>(type)].color; + col->a = mColors[static_cast<size_t>(type)].delay; return *col; } @@ -230,8 +243,10 @@ class UserPalette final : public Palette, public ListModel * @param rgb default color if not found in config * @param text identifier of color */ - void addColor(const unsigned type, const unsigned rgb, - GradientTypeT grad, const std::string &text, + void addColor(const UserColorIdT type, + const unsigned rgb, + GradientTypeT grad, + const std::string &text, int delay = GRADIENT_DELAY); }; diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp index 1ba6461ea..f7a2dcfd6 100644 --- a/src/gui/widgets/tabs/setup_colors.cpp +++ b/src/gui/widgets/tabs/setup_colors.cpp @@ -250,7 +250,8 @@ void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED) return; mSelected = mColorBox->getSelected(); - const int type = userPalette->getColorTypeAt(mSelected); + const UserColorIdT type = static_cast<UserColorIdT>( + userPalette->getColorTypeAt(mSelected)); const Color *col = &userPalette->getColor(type); const GradientTypeT grad = userPalette->getGradientType(type); const int delay = userPalette->getGradientDelay(type); @@ -380,7 +381,8 @@ void Setup_Colors::cancel() return; userPalette->rollback(); - const int type = userPalette->getColorTypeAt(mSelected); + const UserColorIdT type = static_cast<UserColorIdT>( + userPalette->getColorTypeAt(mSelected)); const Color *const col = &userPalette->getColor(type); mGradTypeSlider->setValue(static_cast<int>( userPalette->getGradientType(type))); @@ -397,7 +399,8 @@ void Setup_Colors::updateGradType() return; mSelected = mColorBox->getSelected(); - const int type = userPalette->getColorTypeAt(mSelected); + const UserColorIdT type = static_cast<UserColorIdT>( + userPalette->getColorTypeAt(mSelected)); const GradientTypeT grad = userPalette->getGradientType(type); mGradTypeText->setCaption( @@ -427,7 +430,8 @@ void Setup_Colors::updateColor() if (mSelected == -1 || !userPalette) return; - const int type = userPalette->getColorTypeAt(mSelected); + const UserColorIdT type = static_cast<UserColorIdT>( + userPalette->getColorTypeAt(mSelected)); const GradientTypeT grad = static_cast<GradientTypeT>( static_cast<int>(mGradTypeSlider->getValue())); const int delay = static_cast<int>(mGradDelaySlider->getValue()); diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index 2f73d50e6..ea22db3f4 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -312,7 +312,7 @@ void Minimap::draw2(Graphics *const graphics) continue; int dotSize = 2; - int type = UserColorId::PC; + UserColorIdT type = UserColorId::PC; if (being == localPlayer) { |