From 3ace97660fde7fe1f0cc07a3925d1114af9a9c2f Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Tue, 16 Jul 2024 10:22:03 +0300 Subject: Implement gradient color interpolation option (#548) * Added the better color averaging code (tested & functional) * rustfmt * Make Color f32 0..1, clarify premul/unpremul * Fix imports and test name * Premultiply gradient colors matching CSS * Fix indentation * fixup * Add gradient image --------- Co-authored-by: K's Thinkpad --- src/layout/focus_ring.rs | 15 +++++++++------ src/layout/tile.rs | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/layout') diff --git a/src/layout/focus_ring.rs b/src/layout/focus_ring.rs index 97a1b75a..7cd73760 100644 --- a/src/layout/focus_ring.rs +++ b/src/layout/focus_ring.rs @@ -1,7 +1,7 @@ use std::iter::zip; use arrayvec::ArrayVec; -use niri_config::{CornerRadius, Gradient, GradientRelativeTo}; +use niri_config::{CornerRadius, Gradient, GradientInterpolation, GradientRelativeTo}; use smithay::backend::renderer::element::Kind; use smithay::utils::{Logical, Point, Rectangle, Size}; @@ -72,7 +72,7 @@ impl FocusRing { }; for buf in &mut self.buffers { - buf.set_color(color.into()); + buf.set_color(color.to_array_premul()); } let radius = radius.fit_to(self.full_size.w as f32, self.full_size.h as f32); @@ -91,6 +91,7 @@ impl FocusRing { to: color, angle: 0, relative_to: GradientRelativeTo::Window, + in_: GradientInterpolation::default(), }); let full_rect = Rectangle::from_loc_and_size((-width, -width), self.full_size); @@ -178,8 +179,9 @@ impl FocusRing { border.update( size, Rectangle::from_loc_and_size(gradient_area.loc - loc, gradient_area.size), - gradient.from.into(), - gradient.to.into(), + gradient.in_, + gradient.from, + gradient.to, ((gradient.angle as f32) - 90.).to_radians(), Rectangle::from_loc_and_size(full_rect.loc - loc, full_rect.size), rounded_corner_border_width, @@ -198,8 +200,9 @@ impl FocusRing { gradient_area.loc - self.locations[0], gradient_area.size, ), - gradient.from.into(), - gradient.to.into(), + gradient.in_, + gradient.from, + gradient.to, ((gradient.angle as f32) - 90.).to_radians(), Rectangle::from_loc_and_size(full_rect.loc - self.locations[0], full_rect.size), rounded_corner_border_width, diff --git a/src/layout/tile.rs b/src/layout/tile.rs index 710add83..167ff2c6 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -1,7 +1,7 @@ use std::rc::Rc; use std::time::Duration; -use niri_config::CornerRadius; +use niri_config::{Color, CornerRadius, GradientInterpolation}; use smithay::backend::allocator::Fourcc; use smithay::backend::renderer::element::{Element, Kind}; use smithay::backend::renderer::gles::GlesRenderer; @@ -757,8 +757,9 @@ impl Tile { return BorderRenderElement::new( geo.size, Rectangle::from_loc_and_size((0., 0.), geo.size), - elem.color(), - elem.color(), + GradientInterpolation::default(), + Color::from_array_premul(elem.color()), + Color::from_array_premul(elem.color()), 0., Rectangle::from_loc_and_size((0., 0.), geo.size), 0., -- cgit