From e423d48ebfb7c9716bf33b8ec509a7db72408d2a Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Fri, 15 Jan 2016 23:28:13 -0800 Subject: [PATCH] Color.opacity Sometimes you want the alpha channel as a double rather than an int. For convenience, provide an accessor on Color that returns this. --- sky/engine/core/painting/Color.dart | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sky/engine/core/painting/Color.dart b/sky/engine/core/painting/Color.dart index ea2f3439201..92dc29cea3b 100644 --- a/sky/engine/core/painting/Color.dart +++ b/sky/engine/core/painting/Color.dart @@ -10,7 +10,7 @@ Color _scaleAlpha(Color a, double factor) { /// An immutable 32 bit color value in ARGB class Color { - /// Construct a color from the lower 32 bits of an int + /// Construct a color from the lower 32 bits of an int. /// /// Bits 24-31 are the alpha value. /// Bits 16-23 are the red value. @@ -25,25 +25,28 @@ class Color { ((g & 0xff) << 8) | ((b & 0xff) << 0)) & 0xFFFFFFFF); - final int _value; - /// A 32 bit value representing this color + /// A 32 bit value representing this color. /// /// Bits 24-31 are the alpha value. /// Bits 16-23 are the red value. /// Bits 8-15 are the green value. /// Bits 0-7 are the blue value. int get value => _value; + final int _value; - /// The alpha channel of this color in an 8 bit value + /// The alpha channel of this color in an 8 bit value. int get alpha => (0xff000000 & _value) >> 24; - /// The red channel of this color in an 8 bit value + /// The alpha channel of this color as a double. + double get opacity => alpha / 0xFF; + + /// The red channel of this color in an 8 bit value. int get red => (0x00ff0000 & _value) >> 16; - /// The green channel of this color in an 8 bit value + /// The green channel of this color in an 8 bit value. int get green => (0x0000ff00 & _value) >> 8; - /// The blue channel of this color in an 8 bit value + /// The blue channel of this color in an 8 bit value. int get blue => (0x000000ff & _value) >> 0; /// Returns a new color that matches this color with the alpha channel replaced with a.