diff --git a/include/nana/basic_types.hpp b/include/nana/basic_types.hpp index e1607fd7..b07f5da0 100644 --- a/include/nana/basic_types.hpp +++ b/include/nana/basic_types.hpp @@ -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 }; diff --git a/source/basic_types.cpp b/source/basic_types.cpp index 531c3824..91f113e7 100644 --- a/source/basic_types.cpp +++ b/source/basic_types.cpp @@ -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(clr)& 0xFF0000) >> 16, (static_cast(clr)& 0xFF00) >> 8, static_cast(clr)& 0xFF) @@ -26,10 +22,26 @@ namespace nana : expr_color((static_cast(clr)& 0xFF0000) >> 16, (static_cast(clr)& 0xFF00) >> 8, static_cast(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(rgb) >> 16) & 0xFF), + g_((static_cast(rgb) >> 8) & 0xFF), + b_(static_cast(rgb) & 0xFF), + a_(1.0) + {} + + expr_color::expr_color(color_argb argb) + : r_((static_cast(argb) >> 16) & 0xFF), + g_((static_cast(argb) >> 8) & 0xFF), + b_(static_cast(argb) & 0xFF), + a_(((static_cast(argb) >> 24) & 0xFF) / 255.0) + {} + + expr_color::expr_color(color_rgba rgba) + : r_((static_cast(rgba) >> 24) & 0xFF), + g_((static_cast(rgba) >> 16) & 0xFF), + b_((static_cast(rgba) >> 8) & 0xFF), + a_((static_cast(rgba) & 0xFF) / 255.0) + {} expr_color::expr_color(unsigned red, unsigned green, unsigned blue) : a_(1.0), r_(red), g_(green), b_(blue)