summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-31 14:23:11 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-31 14:23:11 +0300
commitd7c67fa2b6faa3e81269244224da4b72f045d659 (patch)
tree596010d034e44ff46eabccca3c77d995626fca88 /src/gui
parentb072723595e729eed79199f246439ffed62cdbb5 (diff)
downloadmanaverse-d7c67fa2b6faa3e81269244224da4b72f045d659.tar.gz
manaverse-d7c67fa2b6faa3e81269244224da4b72f045d659.tar.bz2
manaverse-d7c67fa2b6faa3e81269244224da4b72f045d659.tar.xz
manaverse-d7c67fa2b6faa3e81269244224da4b72f045d659.zip
Convert ProgressColorId enum into strong typed enum.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/theme.cpp21
-rw-r--r--src/gui/theme.h4
-rw-r--r--src/gui/widgets/avatarlistbox.cpp8
-rw-r--r--src/gui/widgets/progressbar.cpp17
-rw-r--r--src/gui/widgets/progressbar.h8
-rw-r--r--src/gui/windows/ministatuswindow.cpp5
-rw-r--r--src/gui/windows/ministatuswindow.h6
7 files changed, 44 insertions, 25 deletions
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index d9740de3b..7a6a49d45 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -73,7 +73,8 @@ Theme::Theme() :
Palette(ThemeColorId::THEME_COLORS_END * THEME_PALETTES),
mSkins(),
mMinimumOpacity(-1.0F),
- mProgressColors(ProgressColors(ProgressColorId::THEME_PROG_END))
+ mProgressColors(ProgressColors(static_cast<size_t>(
+ ProgressColorId::THEME_PROG_END)))
{
initDefaultThemePath();
@@ -139,18 +140,25 @@ Theme::~Theme()
delete_all(mProgressColors);
}
-Color Theme::getProgressColor(const int type, const float progress)
+Color Theme::getProgressColor(const ProgressColorIdT type,
+ const float progress)
{
int color[3] = {0, 0, 0};
if (theme)
{
- const DyePalette *const dye = theme->mProgressColors[type];
+ const DyePalette *const dye
+ = theme->mProgressColors[static_cast<size_t>(type)];
if (dye)
+ {
dye->getColor(progress, color);
+ }
else
- logger->log("color not found: " + toString(type));
+ {
+ logger->log("color not found: "
+ + toString(static_cast<int>(type)));
+ }
}
return Color(color[0], color[1], color[2]);
@@ -937,7 +945,8 @@ static GradientTypeT readColorGradient(const std::string &grad)
static int readProgressType(const std::string &type)
{
- static const std::string colors[ProgressColorId::THEME_PROG_END] =
+ static const std::string colors[static_cast<size_t>(
+ ProgressColorId::THEME_PROG_END)] =
{
"HP",
"HP_POISON",
@@ -956,7 +965,7 @@ static int readProgressType(const std::string &type)
if (type.empty())
return -1;
- for (int i = 0; i < ProgressColorId::THEME_PROG_END; i++)
+ for (int i = 0; i < static_cast<int>(ProgressColorId::THEME_PROG_END); i++)
{
if (compareStrI(type, colors[i]) == 0)
return i;
diff --git a/src/gui/theme.h b/src/gui/theme.h
index 3d0c21998..edbe31a08 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -25,6 +25,8 @@
#ifndef GUI_THEME_H
#define GUI_THEME_H
+#include "enums/gui/progresscolorid.h"
+
#include "listeners/configlistener.h"
#include "render/graphics.h"
@@ -91,7 +93,7 @@ class Theme final : public Palette,
const int w,
const int h)A_WARN_UNUSED;
- static Color getProgressColor(const int type,
+ static Color getProgressColor(const ProgressColorIdT type,
const float progress) A_WARN_UNUSED;
/**
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 5c2f0a65d..d5b6cbaf8 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -179,7 +179,7 @@ void AvatarListBox::draw(Graphics *graphics)
const bool isPoison = a->getPoison();
if (a->getMaxHp())
{
- const int themeColor = (isPoison
+ const ProgressColorIdT themeColor = (isPoison
? ProgressColorId::PROG_HP_POISON : ProgressColorId::PROG_HP);
Color color = Theme::getProgressColor(
themeColor, static_cast<float>(a->getHp())
@@ -204,7 +204,7 @@ void AvatarListBox::draw(Graphics *graphics)
a->getDamageHp());
}
- const int themeColor = (a->getPoison()
+ const ProgressColorIdT themeColor = (a->getPoison()
? ProgressColorId::PROG_HP_POISON : ProgressColorId::PROG_HP);
Color color = Theme::getProgressColor(themeColor, 1);
color.a = 80;
@@ -416,7 +416,7 @@ void AvatarListBox::safeDraw(Graphics *graphics)
const bool isPoison = a->getPoison();
if (a->getMaxHp())
{
- const int themeColor = (isPoison
+ const ProgressColorIdT themeColor = (isPoison
? ProgressColorId::PROG_HP_POISON : ProgressColorId::PROG_HP);
Color color = Theme::getProgressColor(
themeColor, static_cast<float>(a->getHp())
@@ -441,7 +441,7 @@ void AvatarListBox::safeDraw(Graphics *graphics)
a->getDamageHp());
}
- const int themeColor = (a->getPoison()
+ const ProgressColorIdT themeColor = (a->getPoison()
? ProgressColorId::PROG_HP_POISON : ProgressColorId::PROG_HP);
Color color = Theme::getProgressColor(themeColor, 1);
color.a = 80;
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index dfba99892..2965fc410 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -43,7 +43,7 @@ ProgressBar::ProgressBar(const Widget2 *const widget,
float progress,
const int width,
const int height,
- const int backColor,
+ const ProgressColorIdT backColor,
const std::string &skin,
const std::string &skinFill) :
Widget(widget),
@@ -62,8 +62,10 @@ ProgressBar::ProgressBar(const Widget2 *const widget,
mSmoothProgress(true),
mSmoothColorChange(true)
{
- mBackgroundColor = Theme::getProgressColor(backColor >= 0
- ? backColor : 0, mProgress);
+ mBackgroundColor = Theme::getProgressColor(
+ backColor >= ProgressColorId::PROG_HP
+ ? backColor : ProgressColorId::PROG_HP,
+ mProgress);
mBackgroundColorToGo = mBackgroundColor;
mForegroundColor2 = getThemeColor(ThemeColorId::PROGRESS_BAR_OUTLINE);
@@ -297,20 +299,21 @@ void ProgressBar::setProgress(const float progress)
if (!mSmoothProgress)
mProgress = p;
- if (mProgressPalette >= 0)
+ if (mProgressPalette >= ProgressColorId::PROG_HP)
{
mBackgroundColorToGo = Theme::getProgressColor(
mProgressPalette, progress);
}
}
-void ProgressBar::setProgressPalette(const int progressPalette)
+void ProgressBar::setProgressPalette(const ProgressColorIdT progressPalette)
{
- const int oldPalette = mProgressPalette;
+ const ProgressColorIdT oldPalette = mProgressPalette;
mProgressPalette = progressPalette;
mRedraw = true;
- if (mProgressPalette != oldPalette && mProgressPalette >= 0)
+ if (mProgressPalette != oldPalette &&
+ mProgressPalette >= ProgressColorId::PROG_HP)
{
mBackgroundColorToGo = Theme::getProgressColor(
mProgressPalette, mProgressToGo);
diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h
index 053710ae8..571568e6c 100644
--- a/src/gui/widgets/progressbar.h
+++ b/src/gui/widgets/progressbar.h
@@ -23,6 +23,8 @@
#ifndef GUI_WIDGETS_PROGRESSBAR_H
#define GUI_WIDGETS_PROGRESSBAR_H
+#include "enums/gui/progresscolorid.h"
+
#include "gui/widgets/widget.h"
#include "listeners/widgetlistener.h"
@@ -50,7 +52,7 @@ class ProgressBar final : public Widget,
float progress,
const int width,
const int height,
- const int backColor,
+ const ProgressColorIdT backColor,
const std::string &skin,
const std::string &skinFill);
@@ -90,7 +92,7 @@ class ProgressBar final : public Widget,
* Change the ProgressPalette for this ProgressBar to follow or -1 to
* disable this and manage color manually.
*/
- void setProgressPalette(const int progressPalette);
+ void setProgressPalette(const ProgressColorIdT progressPalette);
/**
* Change the color of the progress bar.
@@ -146,7 +148,7 @@ class ProgressBar final : public Widget,
std::string mText;
ImageCollection *mVertexes;
- int mProgressPalette; /** < Entry in ProgressPalette or -1 for none. */
+ ProgressColorIdT mProgressPalette;
unsigned int mPadding;
unsigned int mFillPadding;
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
index 96901249e..7d0e030b3 100644
--- a/src/gui/windows/ministatuswindow.cpp
+++ b/src/gui/windows/ministatuswindow.cpp
@@ -173,9 +173,10 @@ MiniStatusWindow::~MiniStatusWindow()
}
ProgressBar *MiniStatusWindow::createBar(const float progress,
- const int width, const int height,
+ const int width,
+ const int height,
const int textColor,
- const int backColor,
+ const ProgressColorIdT backColor,
const std::string &restrict skin,
const std::string &restrict skinFill,
const std::string &restrict name,
diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h
index bd1e6a393..2edb8e66e 100644
--- a/src/gui/windows/ministatuswindow.h
+++ b/src/gui/windows/ministatuswindow.h
@@ -110,8 +110,10 @@ class MiniStatusWindow final : public Window,
bool isInBar(ProgressBar *bar, int x, int y) const;
ProgressBar *createBar(const float progress,
- const int width, const int height,
- const int textColor, const int backColor,
+ const int width,
+ const int height,
+ const int textColor,
+ const ProgressColorIdT backColor,
const std::string &restrict skin,
const std::string &restrict skinFill,
const std::string &restrict name,