diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-12 01:03:02 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-08-12 01:03:02 +0800 |
commit | 04367ead7027e9f0359d24681f5cc0dd916b934d (patch) | |
tree | f2a277ac9d53863c9f4efc8099450138974bdb4d /include/cru/platform/graphic_base.hpp | |
parent | 86e776eaebf7c45a269001ca7da0dfafba069d0a (diff) | |
download | cru-04367ead7027e9f0359d24681f5cc0dd916b934d.tar.gz cru-04367ead7027e9f0359d24681f5cc0dd916b934d.tar.bz2 cru-04367ead7027e9f0359d24681f5cc0dd916b934d.zip |
...
Diffstat (limited to 'include/cru/platform/graphic_base.hpp')
-rw-r--r-- | include/cru/platform/graphic_base.hpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/include/cru/platform/graphic_base.hpp b/include/cru/platform/graphic_base.hpp index 2aa4e2cb..fd479e56 100644 --- a/include/cru/platform/graphic_base.hpp +++ b/include/cru/platform/graphic_base.hpp @@ -239,8 +239,14 @@ struct Color { : red(red), green(green), blue(blue), alpha(alpha) {} constexpr static Color FromHex(std::uint32_t hex) { - return Color(hex & (0b11111111 << 16), hex & (0b11111111 << 8), - hex & (0b11111111), hex & (0b11111111 << 24)); + const std::uint32_t mask = 0b11111111; + return Color((hex >> 16) & mask, (hex >> 8) & mask, hex & mask, 255); + } + + constexpr static Color FromHexAlpha(std::uint32_t hex) { + const std::uint32_t mask = 0b11111111; + return Color((hex >> 16) & mask, (hex >> 8) & mask, hex & mask, + (hex >> 24) & mask); } std::uint8_t red; @@ -254,4 +260,4 @@ constexpr Color black{0, 0, 0}; constexpr Color white{255, 255, 255}; constexpr Color skyblue = Color::FromHex(0x87ceeb); } // namespace colors -} // namespace cru::ui +} // namespace cru::platform |