Rename Color::toFormalString -> toHumanReadableString and replace bool param with an enum.

This commit is contained in:
David Capello 2012-02-12 23:32:34 -03:00
parent 041140f528
commit 385f4b66a2
4 changed files with 13 additions and 8 deletions

View File

@ -186,12 +186,11 @@ std::string Color::toString() const
return result.str();
}
std::string Color::toFormalString(PixelFormat pixelFormat, bool long_format) const
std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableString humanReadable) const
{
std::stringstream result;
// Long format
if (long_format) {
if (humanReadable == LongHumanReadableString) {
switch (getType()) {
case Color::MaskType:
@ -256,8 +255,7 @@ std::string Color::toFormalString(PixelFormat pixelFormat, bool long_format) con
break;
}
}
// Short format
else {
else if (humanReadable == ShortHumanReadableString) {
switch (getType()) {
case Color::MaskType:

View File

@ -36,6 +36,11 @@ public:
IndexType,
};
enum HumanReadableString {
ShortHumanReadableString,
LongHumanReadableString
};
// Default ctor is mask color
Color() : m_type(MaskType) { }
@ -50,7 +55,7 @@ public:
static Color fromString(const std::string& str);
std::string toString() const;
std::string toFormalString(PixelFormat format, bool long_format) const;
std::string toHumanReadableString(PixelFormat format, HumanReadableString type) const;
bool operator==(const Color& other) const;
bool operator!=(const Color& other) const {

View File

@ -213,7 +213,8 @@ void ColorButton::onPaint(PaintEvent& ev) // TODO use "ev.getGraphics()"
this->hasMouseOver(), false);
// Draw text
std::string str = m_color.toFormalString(m_pixelFormat, false);
std::string str = m_color.toHumanReadableString(m_pixelFormat,
Color::ShortHumanReadableString);
setTextQuiet(str.c_str());
jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0);

View File

@ -522,7 +522,8 @@ bool StatusBar::onProcessMessage(Message* msg)
x += (32+4)*jguiscale();
// Draw color description
std::string str = m_color.toFormalString(app_get_current_pixel_format(), true);
std::string str = m_color.toHumanReadableString(app_get_current_pixel_format(),
Color::LongHumanReadableString);
if (m_alpha < 255) {
char buf[512];
usprintf(buf, ", Alpha %d", m_alpha);