mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 05:44:52 +00:00
Provide red/green/blue/alpha getters for Rust and C++ Color
And fix up the C++ class docs.
This commit is contained in:
parent
09142beac4
commit
52b19606d1
2 changed files with 42 additions and 0 deletions
|
@ -16,10 +16,15 @@ LICENSE END */
|
|||
|
||||
namespace sixtyfps {
|
||||
|
||||
/// Color represents a color in the SixtyFPS run-time, represented using 8-bit channels for
|
||||
/// red, green, blue and the alpha (opacity).
|
||||
class Color
|
||||
{
|
||||
public:
|
||||
/// Default constructs a new color that is entirely transparent.
|
||||
Color() { inner.red = inner.green = inner.blue = inner.alpha = 0; }
|
||||
|
||||
/// Construct a color from an integer encoded as `0xAARRGGBB`
|
||||
static Color from_argb_encoded(uint32_t argb_encoded)
|
||||
{
|
||||
Color col;
|
||||
|
@ -30,18 +35,35 @@ public:
|
|||
return col;
|
||||
}
|
||||
|
||||
/// Returns `(alpha, red, green, blue)` encoded as uint32_t.
|
||||
uint32_t as_argb_encoded() const
|
||||
{
|
||||
return (uint32_t(inner.red) << 16) | (uint32_t(inner.green) << 8) | uint32_t(inner.blue)
|
||||
| (uint32_t(inner.alpha) << 24);
|
||||
}
|
||||
|
||||
/// Returns the red channel of the color as u8 in the range 0..255.
|
||||
uint8_t red() const { return inner.red; }
|
||||
|
||||
/// Returns the green channel of the color as u8 in the range 0..255.
|
||||
uint8_t green() const { return inner.green; }
|
||||
|
||||
/// Returns the blue channel of the color as u8 in the range 0..255.
|
||||
uint8_t blue() const { return inner.blue; }
|
||||
|
||||
/// Returns the alpha channel of the color as u8 in the range 0..255.
|
||||
uint8_t alpha() const { return inner.alpha; }
|
||||
|
||||
/// Returns true if \a lhs has the same values for the individual color channels as \rhs; false
|
||||
/// otherwise.
|
||||
friend bool operator==(const Color &lhs, const Color &rhs)
|
||||
{
|
||||
return lhs.inner.red == rhs.inner.red && lhs.inner.green == rhs.inner.green
|
||||
&& lhs.inner.blue == rhs.inner.blue && lhs.inner.alpha == rhs.inner.alpha;
|
||||
}
|
||||
|
||||
/// Returns true if \a lhs has any different values for the individual color channels as \rhs;
|
||||
/// false otherwise.
|
||||
friend bool operator!=(const Color &lhs, const Color &rhs) { return !(lhs == rhs); }
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue