From 03679977c3c6210b6283b56b8d1cca25aada9537 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Tue, 19 Nov 2019 09:48:04 -0800 Subject: [PATCH] Adding opacity -> alpha method to Color class (flutter/engine#13902) --- engine/src/flutter/lib/ui/painting.dart | 8 ++++++++ engine/src/flutter/lib/web_ui/lib/src/ui/painting.dart | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 0eacb1bca4..b3861970b5 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -307,6 +307,14 @@ class Color { } } + /// Returns an alpha value representative of the provided [opacity] value. + /// + /// The [opacity] value may not be null. + static int getAlphaFromOpacity(double opacity) { + assert(opacity != null); + return (opacity.clamp(0.0, 1.0) * 255).round(); + } + @override bool operator ==(dynamic other) { if (identical(this, other)) diff --git a/engine/src/flutter/lib/web_ui/lib/src/ui/painting.dart b/engine/src/flutter/lib/web_ui/lib/src/ui/painting.dart index ff280ad0bd..09a268c97a 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/ui/painting.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/ui/painting.dart @@ -226,6 +226,14 @@ class Color { } } + /// Returns an alpha value representative of the provided [opacity] value. + /// + /// The [opacity] value may not be null. + static int getAlphaFromOpacity(double opacity) { + assert(opacity != null); + return (opacity.clamp(0.0, 1.0) * 255).round(); + } + @override bool operator ==(dynamic other) { if (identical(this, other)) {