Added some helper types to identify an integer as color

expr_color clr(static_cast<color_rgb>(0xrrggbb));
This commit is contained in:
cnjinhao 2014-12-21 23:04:20 +08:00
parent f62ad0aa9f
commit 34c8392f35
2 changed files with 28 additions and 20 deletions

View File

@ -147,16 +147,10 @@ namespace nana
highlight = 0x1CC4F7
};
#pragma pack(1)
struct rgb_color
{
unsigned char blue;
unsigned char green;
unsigned char red;
rgb_color(unsigned clr);
};
#pragma pack()
//Some helper types to identify an integer as color.
enum class color_rgb : unsigned{};
enum class color_argb: unsigned{};
enum class color_rgba : unsigned{};
class expr_color
{
@ -164,7 +158,9 @@ namespace nana
expr_color() = default;
expr_color(colors);
expr_color(colors, double alpha);
expr_color(const rgb_color&);
expr_color(color_rgb);
expr_color(color_argb);
expr_color(color_rgba);
expr_color(unsigned red, unsigned green, unsigned blue);
expr_color(unsigned red, unsigned green, unsigned blue, double alpha);
@ -193,7 +189,7 @@ namespace nana
double r_;
double g_;
double b_;
double a_{ 0.0 };
double a_{ 0.0 }; //invisible
};

View File

@ -13,10 +13,6 @@
namespace nana
{
rgb_color::rgb_color(unsigned clr)
: blue((0xFF00 & clr) >> 8), green(0xFF & clr), red((0xFF0000 & clr) >> 16)
{}
//class color
expr_color::expr_color(colors clr)
: expr_color((static_cast<unsigned>(clr)& 0xFF0000) >> 16, (static_cast<unsigned>(clr)& 0xFF00) >> 8, static_cast<unsigned>(clr)& 0xFF)
@ -26,10 +22,26 @@ namespace nana
: expr_color((static_cast<unsigned>(clr)& 0xFF0000) >> 16, (static_cast<unsigned>(clr)& 0xFF00) >> 8, static_cast<unsigned>(clr)& 0xFF, alpha)
{}
expr_color::expr_color(const rgb_color& rgb)
: a_(1.0), r_(rgb.red), g_(rgb.green), b_(rgb.blue)
{
}
expr_color::expr_color(color_rgb rgb)
: r_((static_cast<int>(rgb) >> 16) & 0xFF),
g_((static_cast<int>(rgb) >> 8) & 0xFF),
b_(static_cast<int>(rgb) & 0xFF),
a_(1.0)
{}
expr_color::expr_color(color_argb argb)
: r_((static_cast<int>(argb) >> 16) & 0xFF),
g_((static_cast<int>(argb) >> 8) & 0xFF),
b_(static_cast<int>(argb) & 0xFF),
a_(((static_cast<int>(argb) >> 24) & 0xFF) / 255.0)
{}
expr_color::expr_color(color_rgba rgba)
: r_((static_cast<int>(rgba) >> 24) & 0xFF),
g_((static_cast<int>(rgba) >> 16) & 0xFF),
b_((static_cast<int>(rgba) >> 8) & 0xFF),
a_((static_cast<int>(rgba) & 0xFF) / 255.0)
{}
expr_color::expr_color(unsigned red, unsigned green, unsigned blue)
: a_(1.0), r_(red), g_(green), b_(blue)