+ use uint8_t in get/set methods
+ update to_string/to_hexstring
This commit is contained in:
parent
7d3dca725e
commit
6558c5c315
2 changed files with 26 additions and 27 deletions
|
@ -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),
|
||||
|
@ -76,14 +76,14 @@ public:
|
|||
|
||||
color& operator=(color const& rhs)
|
||||
{
|
||||
if (this==&rhs)
|
||||
if (this==&rhs)
|
||||
return *this;
|
||||
|
||||
|
||||
red_ = rhs.red_;
|
||||
green_ = rhs.green_;
|
||||
blue_ = rhs.blue_;
|
||||
alpha_ = rhs.alpha_;
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue