mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-04 13:30:48 +00:00
Node graph improvements (#855)
* Selecting multiple nodes * Improve logs * Log bad types in dyn any * Add (broken) node links * New topological sort * Fix reorder ids function * Input and output node * Add nodes that operate on images * Fixups * Show node parameters together with layer properties * New nodes don't crash editor * Fix tests * Node positions backend * Generate node graph on value change * Add expose input message * Fix tests Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
bbe98d3fe3
commit
2994afa6b8
23 changed files with 734 additions and 331 deletions
|
@ -5,16 +5,16 @@ use self::color::Color;
|
|||
pub mod color;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct GrayscaleNode;
|
||||
pub struct GrayscaleColorNode;
|
||||
|
||||
impl Node<Color> for GrayscaleNode {
|
||||
impl Node<Color> for GrayscaleColorNode {
|
||||
type Output = Color;
|
||||
fn eval(self, color: Color) -> Color {
|
||||
let avg = (color.r() + color.g() + color.b()) / 3.0;
|
||||
Color::from_rgbaf32_unchecked(avg, avg, avg, color.a())
|
||||
}
|
||||
}
|
||||
impl<'n> Node<Color> for &'n GrayscaleNode {
|
||||
impl<'n> Node<Color> for &'n GrayscaleColorNode {
|
||||
type Output = Color;
|
||||
fn eval(self, color: Color) -> Color {
|
||||
let avg = (color.r() + color.g() + color.b()) / 3.0;
|
||||
|
@ -49,9 +49,9 @@ impl<N: Node<(), Output = f32> + Copy> BrightenColorNode<N> {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct HueShiftNode<N: Node<(), Output = f32>>(N);
|
||||
pub struct HueShiftColorNode<N: Node<(), Output = f32>>(N);
|
||||
|
||||
impl<N: Node<(), Output = f32>> Node<Color> for HueShiftNode<N> {
|
||||
impl<N: Node<(), Output = f32>> Node<Color> for HueShiftColorNode<N> {
|
||||
type Output = Color;
|
||||
fn eval(self, color: Color) -> Color {
|
||||
let hue_shift = self.0.eval(());
|
||||
|
@ -59,7 +59,7 @@ impl<N: Node<(), Output = f32>> Node<Color> for HueShiftNode<N> {
|
|||
Color::from_hsla(hue + hue_shift / 360., saturation, luminance, alpha)
|
||||
}
|
||||
}
|
||||
impl<N: Node<(), Output = f32> + Copy> Node<Color> for &HueShiftNode<N> {
|
||||
impl<N: Node<(), Output = f32> + Copy> Node<Color> for &HueShiftColorNode<N> {
|
||||
type Output = Color;
|
||||
fn eval(self, color: Color) -> Color {
|
||||
let hue_shift = self.0.eval(());
|
||||
|
@ -68,7 +68,7 @@ impl<N: Node<(), Output = f32> + Copy> Node<Color> for &HueShiftNode<N> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: Node<(), Output = f32> + Copy> HueShiftNode<N> {
|
||||
impl<N: Node<(), Output = f32> + Copy> HueShiftColorNode<N> {
|
||||
pub fn new(node: N) -> Self {
|
||||
Self(node)
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ mod test {
|
|||
#[test]
|
||||
fn map_node() {
|
||||
// let array = &mut [Color::from_rgbaf32(1.0, 0.0, 0.0, 1.0).unwrap()];
|
||||
(&GrayscaleNode).eval(Color::from_rgbf32_unchecked(1., 0., 0.));
|
||||
(&GrayscaleColorNode).eval(Color::from_rgbf32_unchecked(1., 0., 0.));
|
||||
/*let map = ForEachNode(MutWrapper(GrayscaleNode));
|
||||
(&map).eval(array.iter_mut());
|
||||
assert_eq!(array[0], Color::from_rgbaf32(0.33333334, 0.33333334, 0.33333334, 1.0).unwrap());*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue