support bitwise & and | operators for Color (not sure if we should, but one of the example uses & u32)
use crate::prelude::*;
use crate::skia::u8cpu;
-use std::ops::{Index,Mul,IndexMut};
+use std::ops::{Index, Mul, IndexMut, BitOr, BitAnd};
use skia_bindings::{
SkColor,
SkRGBToHSV,
@@ -32,6 +32,42 @@ impl From<RGB> for Color {
}
}
+//
+// Bitwise operators.
+//
+
+impl BitOr for Color {
+ type Output = Self;
+
+ fn bitor(self, rhs: Self) -> Self::Output {
+ Color::from_native(self.native() | rhs.native())
+ }
+}
+
+impl BitAnd for Color {
+ type Output = Self;
+
+ fn bitand(self, rhs: Self) -> Self::Output {
+ Color::from_native(self.native() & rhs.native())
+ }
+}
+
+impl BitOr<u32> for Color {
+ type Output = Self;
+
+ fn bitor(self, rhs: u32) -> Self::Output {
+ self | (Color::from_native(rhs))
+ }
+}
+
+impl BitAnd<u32> for Color {
+ type Output = Self;
+
+ fn bitand(self, rhs: u32) -> Self::Output {
+ self & (Color::from_native(rhs))
+ }
+}
+
impl Color {
// note: we don't use the u8cpu type here, because we trust the rust
