diff options
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/enums/gui/gradienttype.h | 40 | ||||
-rw-r--r-- | src/gui/palette.cpp | 14 | ||||
-rw-r--r-- | src/gui/palette.h | 23 | ||||
-rw-r--r-- | src/gui/theme.cpp | 10 | ||||
-rw-r--r-- | src/gui/userpalette.cpp | 113 | ||||
-rw-r--r-- | src/gui/userpalette.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_colors.cpp | 24 |
9 files changed, 134 insertions, 96 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 22f03e4e5..df0be0da1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1127,6 +1127,7 @@ SET(SRCS gui/color.h gui/colorpair.h enums/gui/dialogtype.h + enums/gui/gradienttype.h enums/gui/progresscolorid.h enums/gui/themecolorid.h listeners/errorlistener.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e589af516..f3ef622df 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -192,6 +192,7 @@ manaplus_SOURCES += events/actionevent.h \ gui/cliprect.h \ gui/color.h \ enums/gui/dialogtype.h \ + enums/gui/gradienttype.h \ enums/gui/progresscolorid.h \ enums/gui/themecolorid.h \ listeners/errorlistener.cpp \ diff --git a/src/enums/gui/gradienttype.h b/src/enums/gui/gradienttype.h new file mode 100644 index 000000000..9ff14b4b2 --- /dev/null +++ b/src/enums/gui/gradienttype.h @@ -0,0 +1,40 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net> + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-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 <http://www.gnu.org/licenses/>. + */ + +#ifndef ENUMS_GUI_GRADIENTTYPE_H +#define ENUMS_GUI_GRADIENTTYPE_H + +namespace GradientType +{ + enum T + { + STATIC = 0, + PULSE, + SPECTRUM, + RAINBOW + }; +} // namespace GradientType + +typedef GradientType::T GradientTypeT; + +#endif // ENUMS_GUI_GRADIENTTYPE_H diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 4935ce60d..88de9d5d0 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -108,13 +108,13 @@ void Palette::advanceGradient() continue; int delay = elem->delay; - const GradientType &grad = elem->grad; + const GradientTypeT &grad = elem->grad; - if (grad == PULSE) + if (grad == GradientType::PULSE) delay = delay / 20; - const int numOfColors = (elem->grad == SPECTRUM ? 6 : - grad == PULSE ? 127 : + const int numOfColors = (elem->grad == GradientType::SPECTRUM ? 6 : + grad == GradientType::PULSE ? 127 : RAINBOW_COLOR_COUNT); elem->gradientIndex = (elem->gradientIndex + advance) @@ -131,7 +131,7 @@ void Palette::advanceGradient() Color &color = elem->color; int colVal; - if (grad == PULSE) + if (grad == GradientType::PULSE) { colVal = static_cast<int>(255.0 * sin(M_PI * colIndex / numOfColors)); @@ -142,7 +142,7 @@ void Palette::advanceGradient() color.g = ((colVal * col.g) / 255) % (col.g + 1); color.b = ((colVal * col.b) / 255) % (col.b + 1); } - else if (grad == SPECTRUM) + else if (grad == GradientType::SPECTRUM) { if (colIndex % 2) { // falling curve @@ -178,7 +178,7 @@ void Palette::advanceGradient() color.b = (colIndex == 3 || colIndex == 4) ? 255 : (colIndex == 2 || colIndex == 5) ? colVal : 0; } - else if (elem->grad == RAINBOW) + else if (elem->grad == GradientType::RAINBOW) { const Color &startCol = RAINBOW_COLORS[colIndex]; const Color &destCol diff --git a/src/gui/palette.h b/src/gui/palette.h index c8bf5de47..b42ada438 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -26,6 +26,8 @@ #include "logger.h" +#include "enums/gui/gradienttype.h" + #include "gui/color.h" #if defined __native_client__ @@ -49,15 +51,6 @@ class Palette notfinal /** Black Color Constant */ static const Color BLACK; - /** Colors can be static or can alter over time. */ - enum GradientType - { - STATIC = 0, - PULSE, - SPECTRUM, - RAINBOW - }; - A_DELETE_COPY(Palette) /** @@ -111,7 +104,7 @@ class Palette notfinal * * @return the gradient type of the color with the given index */ - inline GradientType getGradientType(const int type) const A_WARN_UNUSED + inline GradientTypeT getGradientType(const int type) const A_WARN_UNUSED { return mColors[type].grad; } /** @@ -171,8 +164,8 @@ class Palette notfinal committedColor(0), text(), ch(0), - grad(STATIC), - committedGrad(STATIC), + grad(GradientType::STATIC), + committedGrad(GradientType::STATIC), gradientIndex(0), delay(0), committedDelay(0) @@ -185,14 +178,14 @@ class Palette notfinal Color committedColor; std::string text; signed char ch; - GradientType grad; - GradientType committedGrad; + GradientTypeT grad; + GradientTypeT committedGrad; int gradientIndex; int delay; int committedDelay; void set(const int type0, const Color &color0, - const GradientType grad0, const int delay0) + const GradientTypeT grad0, const int delay0) { type = type0; color = color0; diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 477da5fb0..d9740de3b 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -913,7 +913,7 @@ static Color readColor(const std::string &description) return Color(v); } -static Palette::GradientType readColorGradient(const std::string &grad) +static GradientTypeT readColorGradient(const std::string &grad) { static const std::string grads[] = { @@ -924,15 +924,15 @@ static Palette::GradientType readColorGradient(const std::string &grad) }; if (grad.empty()) - return Palette::STATIC; + return GradientType::STATIC; for (int i = 0; i < 4; i++) { if (compareStrI(grad, grads[i])) - return static_cast<Palette::GradientType>(i); + return static_cast<GradientTypeT>(i); } - return Palette::STATIC; + return GradientType::STATIC; } static int readProgressType(const std::string &type) @@ -1018,7 +1018,7 @@ void Theme::loadColors(std::string file) continue; const Color color = readColor(temp); - const GradientType grad = readColorGradient( + const GradientTypeT grad = readColorGradient( XML::getProperty(node, "effect", "")); mColors[paletteId * ThemeColorId::THEME_COLORS_END + type].set( type, color, grad, 10); diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index 7163cb396..38cf4cfe1 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -113,116 +113,116 @@ UserPalette::UserPalette() : mColors[MONSTER] = ColorElem(); // TRANSLATORS: palette color - addColor(BEING, 0xffffff, STATIC, _("Being")); + addColor(BEING, 0xffffff, GradientType::STATIC, _("Being")); // TRANSLATORS: palette color - addColor(FRIEND, 0xb0ffb0, STATIC, _("Friend names")); + addColor(FRIEND, 0xb0ffb0, GradientType::STATIC, _("Friend names")); // TRANSLATORS: palette color - addColor(DISREGARDED, 0xa00000, STATIC, _("Disregarded names")); + addColor(DISREGARDED, 0xa00000, GradientType::STATIC, _("Disregarded names")); // TRANSLATORS: palette color - addColor(IGNORED, 0xff0000, STATIC, _("Ignored names")); + addColor(IGNORED, 0xff0000, GradientType::STATIC, _("Ignored names")); // TRANSLATORS: palette color - addColor(ERASED, 0xff0000, STATIC, _("Erased names")); + addColor(ERASED, 0xff0000, GradientType::STATIC, _("Erased names")); // TRANSLATORS: palette color - addColor(PC, 0xffffff, STATIC, _("Other players names")); + addColor(PC, 0xffffff, GradientType::STATIC, _("Other players names")); // TRANSLATORS: palette color - addColor(SELF, 0xff8040, STATIC, _("Own name")); + addColor(SELF, 0xff8040, GradientType::STATIC, _("Own name")); // TRANSLATORS: palette color - addColor(GM, 0x00ff00, STATIC, _("GM names")); + addColor(GM, 0x00ff00, GradientType::STATIC, _("GM names")); // TRANSLATORS: palette color - addColor(NPC, 0xc8c8ff, STATIC, _("NPCs")); + addColor(NPC, 0xc8c8ff, GradientType::STATIC, _("NPCs")); // TRANSLATORS: palette color - addColor(MONSTER, 0xff4040, STATIC, _("Monsters")); + addColor(MONSTER, 0xff4040, GradientType::STATIC, _("Monsters")); // TRANSLATORS: palette color - addColor(MONSTER_HP, 0x00ff00, STATIC, _("Monster HP bar"), 50); - addColor(MONSTER_HP2, 0xff0000, STATIC, + addColor(MONSTER_HP, 0x00ff00, GradientType::STATIC, _("Monster HP bar"), 50); + addColor(MONSTER_HP2, 0xff0000, GradientType::STATIC, // TRANSLATORS: palette color _("Monster HP bar (second color)"), 50); // TRANSLATORS: palette color - addColor(PARTY, 0xff00d8, STATIC, _("Party members")); + addColor(PARTY, 0xff00d8, GradientType::STATIC, _("Party members")); // TRANSLATORS: palette color - addColor(GUILD, 0xff00d8, STATIC, _("Guild members")); + addColor(GUILD, 0xff00d8, GradientType::STATIC, _("Guild members")); // TRANSLATORS: palette color - addColor(PARTICLE, 0xffffff, STATIC, _("Particle effects")); + addColor(PARTICLE, 0xffffff, GradientType::STATIC, _("Particle effects")); // TRANSLATORS: palette color - addColor(PICKUP_INFO, 0x28dc28, STATIC, _("Pickup notification")); + addColor(PICKUP_INFO, 0x28dc28, GradientType::STATIC, _("Pickup notification")); // TRANSLATORS: palette color - addColor(EXP_INFO, 0xffff00, STATIC, _("Exp notification")); + addColor(EXP_INFO, 0xffff00, GradientType::STATIC, _("Exp notification")); // TRANSLATORS: palette color - addColor(PLAYER_HP, 0x00ff00, STATIC, _("Player HP bar"), 50); + addColor(PLAYER_HP, 0x00ff00, GradientType::STATIC, _("Player HP bar"), 50); // TRANSLATORS: palette color - addColor(PLAYER_HP2, 0xff0000, STATIC, + addColor(PLAYER_HP2, 0xff0000, GradientType::STATIC, // TRANSLATORS: palette color _("Player HP bar (second color)"), 50); // TRANSLATORS: palette color - addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, _("Player hits monster")); + addColor(HIT_PLAYER_MONSTER, 0x0064ff, GradientType::STATIC, _("Player hits monster")); // TRANSLATORS: palette color - addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, _("Monster hits player")); + addColor(HIT_MONSTER_PLAYER, 0xff3232, GradientType::STATIC, _("Monster hits player")); // TRANSLATORS: palette color - addColor(HIT_PLAYER_PLAYER, 0xff5050, STATIC, + addColor(HIT_PLAYER_PLAYER, 0xff5050, GradientType::STATIC, // TRANSLATORS: palette color _("Other player hits local player")); // TRANSLATORS: palette color - addColor(HIT_CRITICAL, 0xff0000, RAINBOW, _("Critical Hit")); + addColor(HIT_CRITICAL, 0xff0000, GradientType::RAINBOW, _("Critical Hit")); // TRANSLATORS: palette color - addColor(HIT_LOCAL_PLAYER_MONSTER, 0x00ff00, STATIC, + addColor(HIT_LOCAL_PLAYER_MONSTER, 0x00ff00, GradientType::STATIC, // TRANSLATORS: palette color _("Local player hits monster")); - addColor(HIT_LOCAL_PLAYER_CRITICAL, 0xff0000, RAINBOW, + addColor(HIT_LOCAL_PLAYER_CRITICAL, 0xff0000, GradientType::RAINBOW, // TRANSLATORS: palette color _("Local player critical hit")); - addColor(HIT_LOCAL_PLAYER_MISS, 0x00ffa6, STATIC, + addColor(HIT_LOCAL_PLAYER_MISS, 0x00ffa6, GradientType::STATIC, // TRANSLATORS: palette color _("Local player miss")); // TRANSLATORS: palette color - addColor(MISS, 0xffff00, STATIC, _("Misses")); + addColor(MISS, 0xffff00, GradientType::STATIC, _("Misses")); // TRANSLATORS: palette color - addColor(PORTAL_HIGHLIGHT, 0xC80000, STATIC, _("Portal highlight")); - addColor(COLLISION_HIGHLIGHT, 0x0000C8, STATIC, + addColor(PORTAL_HIGHLIGHT, 0xC80000, GradientType::STATIC, _("Portal highlight")); + addColor(COLLISION_HIGHLIGHT, 0x0000C8, GradientType::STATIC, // TRANSLATORS: palette color _("Default collision highlight"), 64); - addColor(AIR_COLLISION_HIGHLIGHT, 0xe0e0ff, STATIC, + addColor(AIR_COLLISION_HIGHLIGHT, 0xe0e0ff, GradientType::STATIC, // TRANSLATORS: palette color _("Air collision highlight"), 64); - addColor(WATER_COLLISION_HIGHLIGHT, 0x2050e0, STATIC, + addColor(WATER_COLLISION_HIGHLIGHT, 0x2050e0, GradientType::STATIC, // TRANSLATORS: palette color _("Water collision highlight"), 64); - addColor(GROUNDTOP_COLLISION_HIGHLIGHT, 0xffff00, STATIC, + addColor(GROUNDTOP_COLLISION_HIGHLIGHT, 0xffff00, GradientType::STATIC, // TRANSLATORS: palette color _("Special ground collision highlight"), 20); - addColor(WALKABLE_HIGHLIGHT, 0x00D000, STATIC, + addColor(WALKABLE_HIGHLIGHT, 0x00D000, GradientType::STATIC, // TRANSLATORS: palette color _("Walkable highlight"), 255); - addColor(ATTACK_RANGE, 0xffffff, STATIC, + addColor(ATTACK_RANGE, 0xffffff, GradientType::STATIC, // TRANSLATORS: palette color _("Local player attack range"), 5); - addColor(ATTACK_RANGE_BORDER, 0x0, STATIC, + addColor(ATTACK_RANGE_BORDER, 0x0, GradientType::STATIC, // TRANSLATORS: palette color _("Local player attack range border"), 76); - addColor(MONSTER_ATTACK_RANGE, 0xff0000, STATIC, + addColor(MONSTER_ATTACK_RANGE, 0xff0000, GradientType::STATIC, // TRANSLATORS: palette color _("Monster attack range"), 20); - addColor(FLOOR_ITEM_TEXT, 0xffffff, STATIC, + addColor(FLOOR_ITEM_TEXT, 0xffffff, GradientType::STATIC, // TRANSLATORS: palette color _("Floor item amount color"), 100); - addColor(HOME_PLACE, 0xffffff, STATIC, + addColor(HOME_PLACE, 0xffffff, GradientType::STATIC, // TRANSLATORS: palette color _("Home place"), 20); - addColor(HOME_PLACE_BORDER, 0xffff00, STATIC, + addColor(HOME_PLACE_BORDER, 0xffff00, GradientType::STATIC, // TRANSLATORS: palette color _("Home place border"), 200); - addColor(ROAD_POINT, 0x000000, STATIC, + addColor(ROAD_POINT, 0x000000, GradientType::STATIC, // TRANSLATORS: palette color _("Road point"), 100); - addColor(NET, 0x000000, STATIC, + addColor(NET, 0x000000, GradientType::STATIC, // TRANSLATORS: palette color _("Tiles border"), 64); // TRANSLATORS: palette color - addColor(PET, 0xffffff, STATIC, _("Pets")); + addColor(PET, 0xffffff, GradientType::STATIC, _("Pets")); // TRANSLATORS: palette color - addColor(MERCENARY, 0xffffff, STATIC, _("Mercenary")); + addColor(MERCENARY, 0xffffff, GradientType::STATIC, _("Mercenary")); // TRANSLATORS: palette color - addColor(HOMUNCULUS, 0xffffff, STATIC, _("Homunculus")); + addColor(HOMUNCULUS, 0xffffff, GradientType::STATIC, _("Homunculus")); commit(true); } @@ -235,7 +235,8 @@ UserPalette::~UserPalette() static_cast<int>(col->committedGrad)); config.setValue(configName + "Delay", col->delay); - if (col->grad == STATIC || col->grad == PULSE) + if (col->grad == GradientType::STATIC || + col->grad == GradientType::PULSE) { char buffer[20]; snprintf(buffer, sizeof(buffer), "0x%06x", col->getRGB()); @@ -256,11 +257,11 @@ void UserPalette::setColor(const int type, color.b = b; } -void UserPalette::setGradient(const int type, const GradientType grad) +void UserPalette::setGradient(const int type, const GradientTypeT grad) { ColorElem *const elem = &mColors[type]; - if (elem->grad != STATIC && grad == STATIC) + if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC) { const size_t sz = mGradVector.size(); for (size_t i = 0; i < sz; i++) @@ -272,7 +273,8 @@ void UserPalette::setGradient(const int type, const GradientType grad) } } } - else if (elem->grad == STATIC && grad != STATIC) + else if (elem->grad == GradientType::STATIC && + grad != GradientType::STATIC) { mGradVector.push_back(elem); } @@ -295,9 +297,9 @@ void UserPalette::commit(const bool commitNonStatic) { i->committedGrad = i->grad; i->committedDelay = i->delay; - if (commitNonStatic || i->grad == STATIC) + if (commitNonStatic || i->grad == GradientType::STATIC) i->committedColor = i->color; - else if (i->grad == PULSE) + else if (i->grad == GradientType::PULSE) i->committedColor = i->testColor; } } @@ -314,7 +316,7 @@ void UserPalette::rollback() setColor(i->type, committedColor.r, committedColor.g, committedColor.b); - if (i->grad == PULSE) + if (i->grad == GradientType::PULSE) { Color &testColor = i->testColor; testColor.r = committedColor.r; @@ -334,7 +336,7 @@ int UserPalette::getColorTypeAt(const int i) void UserPalette::addColor(const unsigned type, const unsigned rgb, - Palette::GradientType grad, + GradientTypeT grad, const std::string &text, int delay) { @@ -357,12 +359,13 @@ void UserPalette::addColor(const unsigned type, else rgbValue = atoi(rgbString.c_str()); const Color &trueCol = Color(rgbValue); - grad = static_cast<GradientType>(config.getValue(configName + "Gradient", - static_cast<int>(grad))); + grad = static_cast<GradientTypeT>(config.getValue( + configName + "Gradient", + static_cast<int>(grad))); delay = config.getValueInt(configName + "Delay", delay); mColors[type].set(type, trueCol, grad, delay); mColors[type].text = text; - if (grad != STATIC) + if (grad != GradientType::STATIC) mGradVector.push_back(&mColors[type]); } diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h index 249b48a0a..61f4a1799 100644 --- a/src/gui/userpalette.h +++ b/src/gui/userpalette.h @@ -143,7 +143,7 @@ class UserPalette final : public Palette, public ListModel * * @param grad gradient type to set */ - void setGradient(const int type, const Palette::GradientType grad); + void setGradient(const int type, const GradientTypeT grad); /** * Sets the gradient delay for the specified color. @@ -229,7 +229,7 @@ class UserPalette final : public Palette, public ListModel * @param text identifier of color */ void addColor(const unsigned type, const unsigned rgb, - GradientType grad, const std::string &text, + 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 28d52db0b..b511a1446 100644 --- a/src/gui/widgets/tabs/setup_colors.cpp +++ b/src/gui/widgets/tabs/setup_colors.cpp @@ -250,7 +250,7 @@ void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED) mSelected = mColorBox->getSelected(); const int type = userPalette->getColorTypeAt(mSelected); const Color *col = &userPalette->getColor(type); - const Palette::GradientType grad = userPalette->getGradientType(type); + const GradientTypeT grad = userPalette->getGradientType(type); const int delay = userPalette->getGradientDelay(type); mPreview->clearRows(); @@ -337,12 +337,12 @@ void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED) mGradDelaySlider->setScale(20, 100); break; } - if (grad != Palette::STATIC && grad != Palette::PULSE) + if (grad != GradientType::STATIC && grad != GradientType::PULSE) { // If nonstatic color, don't display the current, but the committed // color at the sliders col = &userPalette->getCommittedColor(type); } - else if (grad == Palette::PULSE) + else if (grad == GradientType::PULSE) { col = &userPalette->getTestColor(type); } @@ -395,17 +395,17 @@ void Setup_Colors::updateGradType() mSelected = mColorBox->getSelected(); const int type = userPalette->getColorTypeAt(mSelected); - const Palette::GradientType grad = userPalette->getGradientType(type); + const GradientTypeT grad = userPalette->getGradientType(type); mGradTypeText->setCaption( // TRANSLATORS: color type - (grad == Palette::STATIC) ? _("Static") : + (grad == GradientType::STATIC) ? _("Static") : // TRANSLATORS: color type - (grad == Palette::PULSE) ? _("Pulse") : + (grad == GradientType::PULSE) ? _("Pulse") : // TRANSLATORS: color type - (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); + (grad == GradientType::RAINBOW) ? _("Rainbow") : _("Spectrum")); - const bool enable = (grad == Palette::STATIC || grad == Palette::PULSE); + const bool enable = (grad == GradientType::STATIC || grad == GradientType::PULSE); const bool delayEnable = true; mGradDelayText->setEnabled(delayEnable); @@ -425,20 +425,20 @@ void Setup_Colors::updateColor() return; const int type = userPalette->getColorTypeAt(mSelected); - const Palette::GradientType grad = static_cast<Palette::GradientType>( - static_cast<int>(mGradTypeSlider->getValue())); + const GradientTypeT grad = static_cast<GradientTypeT>( + static_cast<int>(mGradTypeSlider->getValue())); const int delay = static_cast<int>(mGradDelaySlider->getValue()); userPalette->setGradient(type, grad); userPalette->setGradientDelay(type, delay); - if (grad == Palette::STATIC) + if (grad == GradientType::STATIC) { userPalette->setColor(type, static_cast<int>(mRedSlider->getValue()), static_cast<int>(mGreenSlider->getValue()), static_cast<int>(mBlueSlider->getValue())); } - else if (grad == Palette::PULSE) + else if (grad == GradientType::PULSE) { userPalette->setTestColor(type, Color( static_cast<int>(mRedSlider->getValue()), |