App: improve ColorLegend

This commit is contained in:
wmayer
2022-02-03 22:01:52 +01:00
parent 90a5c200d4
commit e54b6e167a
2 changed files with 33 additions and 33 deletions

View File

@@ -338,7 +338,7 @@ bool ColorLegend::operator == (const ColorLegend &rclCL) const
outsideGrayed == rclCL.outsideGrayed;
}
float ColorLegend::getValue (unsigned long ulPos) const
float ColorLegend::getValue (std::size_t ulPos) const
{
if (ulPos < values.size())
return values[ulPos];
@@ -346,7 +346,7 @@ float ColorLegend::getValue (unsigned long ulPos) const
return 0.0f;
}
bool ColorLegend::setValue (unsigned long ulPos, float fVal)
bool ColorLegend::setValue (std::size_t ulPos, float fVal)
{
if (ulPos < values.size())
{
@@ -357,7 +357,7 @@ bool ColorLegend::setValue (unsigned long ulPos, float fVal)
return false;
}
Color ColorLegend::getColor (unsigned long ulPos) const
Color ColorLegend::getColor (std::size_t ulPos) const
{
if (ulPos < colorFields.size())
return colorFields[ulPos];
@@ -366,13 +366,13 @@ Color ColorLegend::getColor (unsigned long ulPos) const
}
// color as: 0x00rrggbb
uint32_t ColorLegend::getPackedColor (unsigned long ulPos) const
uint32_t ColorLegend::getPackedColor (std::size_t ulPos) const
{
Color clRGB = getColor(ulPos);
return clRGB.getPackedValue();
}
std::string ColorLegend::getText (unsigned long ulPos) const
std::string ColorLegend::getText (std::size_t ulPos) const
{
if (ulPos < names.size())
return names[ulPos];
@@ -380,10 +380,10 @@ std::string ColorLegend::getText (unsigned long ulPos) const
return "";
}
bool ColorLegend::addMin (const std::string &rclName)
std::size_t ColorLegend::addMin (const std::string &rclName)
{
names.push_front(rclName);
values.push_front(*values.begin() - 1.0f);
values.push_front(values.front() - 1.0f);
Color clNewRGB;
clNewRGB.r = ((float)rand() / (float)RAND_MAX);
@@ -392,13 +392,13 @@ bool ColorLegend::addMin (const std::string &rclName)
colorFields.push_front(clNewRGB);
return true;
return colorFields.size() - 1;
}
bool ColorLegend::addMax (const std::string &rclName)
std::size_t ColorLegend::addMax (const std::string &rclName)
{
names.push_back(rclName);
values.push_back(*(values.end()-1) + 1.0f);
values.push_back(values.back() + 1.0f);
Color clNewRGB;
clNewRGB.r = ((float)rand() / (float)RAND_MAX);
@@ -407,10 +407,10 @@ bool ColorLegend::addMax (const std::string &rclName)
colorFields.push_back(clNewRGB);
return true;
return colorFields.size() - 1;
}
bool ColorLegend::remove (unsigned long ulPos)
bool ColorLegend::remove (std::size_t ulPos)
{
if (ulPos < colorFields.size())
{
@@ -444,7 +444,7 @@ void ColorLegend::removeLast ()
}
}
void ColorLegend::resize (unsigned long ulCt)
void ColorLegend::resize (std::size_t ulCt)
{
if ((ulCt < 2) || (ulCt == colorFields.size()))
return;
@@ -463,7 +463,7 @@ void ColorLegend::resize (unsigned long ulCt)
}
}
bool ColorLegend::setColor (unsigned long ulPos, float ucRed, float ucGreen, float ucBlue)
bool ColorLegend::setColor (std::size_t ulPos, float ucRed, float ucGreen, float ucBlue)
{
if (ulPos < names.size())
{
@@ -475,7 +475,7 @@ bool ColorLegend::setColor (unsigned long ulPos, float ucRed, float ucGreen, flo
}
// color as 0x00rrggbb
bool ColorLegend::setColor (unsigned long ulPos, unsigned long ulColor)
bool ColorLegend::setColor (std::size_t ulPos, unsigned long ulColor)
{
unsigned char ucRed = (unsigned char)((ulColor & 0x00ff0000) >> 16);
unsigned char ucGreen = (unsigned char)((ulColor & 0x0000ff00) >> 8);
@@ -483,13 +483,13 @@ bool ColorLegend::setColor (unsigned long ulPos, unsigned long ulColor)
return setColor(ulPos, ucRed, ucGreen, ucBlue);
}
bool ColorLegend::setText (unsigned long ulPos, const std::string &rclName)
bool ColorLegend::setText (std::size_t ulPos, const std::string &rclName)
{
if (ulPos < names.size())
{
names[ulPos] = rclName;
return true;
}
else
return false;
return false;
}

View File

@@ -375,22 +375,22 @@ public:
bool operator == (const ColorLegend &rclCL) const;
bool operator != (const ColorLegend &rclCL) const { return !(*this == rclCL); }
void resize (unsigned long ulN);
bool addMin (const std::string &rclName);
bool addMax (const std::string &rclName);
bool remove (unsigned long ulPos);
void resize (std::size_t ulN);
std::size_t addMin (const std::string &rclName);
std::size_t addMax (const std::string &rclName);
bool remove (std::size_t ulPos);
void removeFirst ();
void removeLast ();
Color getColor (unsigned long ulPos) const;
uint32_t getPackedColor (unsigned long ulPos) const;
bool setColor (unsigned long ulPos, float ucRed, float ucGreen, float ucBlue);
bool setColor (unsigned long ulPos, unsigned long ulColor);
float getValue (unsigned long ulPos) const;
bool setValue (unsigned long ulPos, float fVal);
std::string getText (unsigned long ulPos) const;
bool setText (unsigned long ulPos, const std::string &rclName);
unsigned long hasNumberOfFields () const { return (unsigned long)colorFields.size(); }
Color getColor (std::size_t ulPos) const;
uint32_t getPackedColor (std::size_t ulPos) const;
bool setColor (std::size_t ulPos, float ucRed, float ucGreen, float ucBlue);
bool setColor (std::size_t ulPos, unsigned long ulColor);
float getValue (std::size_t ulPos) const;
bool setValue (std::size_t ulPos, float fVal);
std::string getText (std::size_t ulPos) const;
bool setText (std::size_t ulPos, const std::string &rclName);
std::size_t hasNumberOfFields () const { return colorFields.size(); }
void setOutsideGrayed (bool bOS) { outsideGrayed = bOS; }
bool isOutsideGrayed () const { return outsideGrayed; }
inline float getMinValue () const;
@@ -450,12 +450,12 @@ inline std::size_t ColorLegend::getColorIndex (float fVal) const
inline float ColorLegend::getMinValue () const
{
return *values.begin();
return values.front();
}
inline float ColorLegend::getMaxValue () const
{
return *(values.end()-1);
return values.back();
}
inline Color ColorGradient::getColor (float fVal) const