+ use uint8_t in get/set methods

+ update to_string/to_hexstring
This commit is contained in:
artemp 2013-01-03 13:51:16 +00:00
parent 7d3dca725e
commit 6558c5c315
2 changed files with 26 additions and 27 deletions

View file

@ -53,7 +53,7 @@ public:
alpha_(0xff)
{}
color(unsigned red, unsigned green, unsigned blue, unsigned alpha = 0xff)
color(boost::uint8_t red, boost::uint8_t green, boost::uint8_t blue, boost::uint8_t alpha = 0xff)
: red_(red),
green_(green),
blue_(blue),
@ -95,38 +95,38 @@ public:
(alpha_ == rhs.alpha());
}
inline unsigned red() const
inline boost::uint8_t red() const
{
return red_;
}
inline unsigned green() const
inline boost::uint8_t green() const
{
return green_;
}
inline unsigned blue() const
inline boost::uint8_t blue() const
{
return blue_;
}
inline unsigned alpha() const
inline boost::uint8_t alpha() const
{
return alpha_;
}
inline void set_red(unsigned red)
inline void set_red(boost::uint8_t red)
{
red_ = red;
}
inline void set_green(unsigned green)
inline void set_green(boost::uint8_t green)
{
green_ = green;
}
inline void set_blue(unsigned blue)
inline void set_blue(boost::uint8_t blue)
{
blue_ = blue;
}
inline void set_alpha(unsigned alpha)
inline void set_alpha(boost::uint8_t alpha)
{
alpha_ = alpha;
}

View file

@ -47,17 +47,17 @@ std::string color::to_string() const
if (alpha_ == 255)
{
ss << "rgb("
<< red() << ","
<< green() << ","
<< blue() << ")";
<< static_cast<unsigned>(red()) << ","
<< static_cast<unsigned>(green()) << ","
<< static_cast<unsigned>(blue()) << ")";
}
else
{
ss << "rgba("
<< red() << ","
<< green() << ","
<< blue() << ","
<< alpha()/255.0 << ")";
<< static_cast<unsigned>(red()) << ","
<< static_cast<unsigned>(green()) << ","
<< static_cast<unsigned>(blue()) << ","
<< alpha() / 255.0 << ")";
}
return ss.str();
}
@ -67,17 +67,17 @@ std::string color::to_hex_string() const
if (alpha_ == 255 )
{
return (boost::format("#%1$02x%2$02x%3$02x")
% red()
% green()
% blue() ).str();
% static_cast<unsigned>(red())
% static_cast<unsigned>(green())
% static_cast<unsigned>(blue())).str();
}
else
{
return (boost::format("#%1$02x%2$02x%3$02x%4$02x")
% red()
% green()
% blue()
% alpha()).str();
% static_cast<unsigned>(red())
% static_cast<unsigned>(green())
% static_cast<unsigned>(blue())
% static_cast<unsigned>(alpha())).str();
}
}
@ -101,4 +101,3 @@ void color::demultiply()
}
}