From 5467c19c80c992f03890264ed58156305a26b19a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 23 Oct 2023 03:13:28 +0200 Subject: Replace `Primitive::Translate` with `Transform` --- wgpu/src/layer.rs | 72 ++++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 41 deletions(-) (limited to 'wgpu/src/layer.rs') diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index e213c95f..fd5f2345 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -15,7 +15,7 @@ use crate::core::alignment; use crate::core::{Color, Font, Pixels, Point, Rectangle, Size, Vector}; use crate::graphics; use crate::graphics::color; -use crate::graphics::Viewport; +use crate::graphics::{Transformation, Viewport}; use crate::primitive::{self, Primitive}; use crate::quad::{self, Quad}; @@ -104,7 +104,7 @@ impl<'a> Layer<'a> { for primitive in primitives { Self::process_primitive( &mut layers, - Vector::new(0.0, 0.0), + Transformation::IDENTITY, primitive, 0, ); @@ -115,7 +115,7 @@ impl<'a> Layer<'a> { fn process_primitive( layers: &mut Vec, - translation: Vector, + transformation: Transformation, primitive: &'a Primitive, current_layer: usize, ) { @@ -130,9 +130,10 @@ impl<'a> Layer<'a> { layer.text.push(Text::Paragraph { paragraph: paragraph.clone(), - position: *position + translation, + position: *position * transformation, color: *color, - clip_bounds: *clip_bounds + translation, + clip_bounds: *clip_bounds * transformation, + scale: transformation.scale_y(), }); } Primitive::Editor { @@ -145,9 +146,10 @@ impl<'a> Layer<'a> { layer.text.push(Text::Editor { editor: editor.clone(), - position: *position + translation, + position: *position * transformation, color: *color, - clip_bounds: *clip_bounds + translation, + clip_bounds: *clip_bounds * transformation, + scale: transformation.scale_y(), }); } Primitive::Text { @@ -166,7 +168,7 @@ impl<'a> Layer<'a> { layer.text.push(Text::Cached(text::Cached { content, - bounds: *bounds + translation, + bounds: *bounds * transformation, size: *size, line_height: *line_height, color: *color, @@ -174,7 +176,7 @@ impl<'a> Layer<'a> { horizontal_alignment: *horizontal_alignment, vertical_alignment: *vertical_alignment, shaping: *shaping, - clip_bounds: *clip_bounds + translation, + clip_bounds: *clip_bounds * transformation, })); } graphics::Primitive::RawText(graphics::text::Raw { @@ -187,9 +189,9 @@ impl<'a> Layer<'a> { layer.text.push(Text::Raw(graphics::text::Raw { buffer: buffer.clone(), - position: *position + translation, + position: *position * transformation, color: *color, - clip_bounds: *clip_bounds + translation, + clip_bounds: *clip_bounds * transformation, })); } Primitive::Quad { @@ -199,12 +201,10 @@ impl<'a> Layer<'a> { shadow, } => { let layer = &mut layers[current_layer]; + let bounds = *bounds * transformation; let quad = Quad { - position: [ - bounds.x + translation.x, - bounds.y + translation.y, - ], + position: [bounds.x, bounds.y], size: [bounds.width, bounds.height], border_color: color::pack(border.color), border_radius: border.radius.into(), @@ -226,7 +226,7 @@ impl<'a> Layer<'a> { layer.images.push(Image::Raster { handle: handle.clone(), filter_method: *filter_method, - bounds: *bounds + translation, + bounds: *bounds * transformation, }); } Primitive::Svg { @@ -239,7 +239,7 @@ impl<'a> Layer<'a> { layer.images.push(Image::Vector { handle: handle.clone(), color: *color, - bounds: *bounds + translation, + bounds: *bounds * transformation, }); } Primitive::Group { primitives } => { @@ -247,7 +247,7 @@ impl<'a> Layer<'a> { for primitive in primitives { Self::process_primitive( layers, - translation, + transformation, primitive, current_layer, ); @@ -255,7 +255,7 @@ impl<'a> Layer<'a> { } Primitive::Clip { bounds, content } => { let layer = &mut layers[current_layer]; - let translated_bounds = *bounds + translation; + let translated_bounds = *bounds * transformation; // Only draw visible content if let Some(clip_bounds) = @@ -266,19 +266,19 @@ impl<'a> Layer<'a> { Self::process_primitive( layers, - translation, + transformation, content, layers.len() - 1, ); } } - Primitive::Translate { - translation: new_translation, + Primitive::Transform { + transformation: new_transformation, content, } => { Self::process_primitive( layers, - translation + *new_translation, + transformation * *new_transformation, content, current_layer, ); @@ -286,7 +286,7 @@ impl<'a> Layer<'a> { Primitive::Cache { content } => { Self::process_primitive( layers, - translation, + transformation, content, current_layer, ); @@ -296,20 +296,15 @@ impl<'a> Layer<'a> { graphics::Mesh::Solid { buffers, size } => { let layer = &mut layers[current_layer]; - let bounds = Rectangle::new( - Point::new(translation.x, translation.y), - *size, - ); + let bounds = + Rectangle::with_size(*size) * transformation; // Only draw visible content if let Some(clip_bounds) = layer.bounds.intersection(&bounds) { layer.meshes.push(Mesh::Solid { - origin: Point::new( - translation.x, - translation.y, - ), + transformation, buffers, clip_bounds, }); @@ -318,20 +313,15 @@ impl<'a> Layer<'a> { graphics::Mesh::Gradient { buffers, size } => { let layer = &mut layers[current_layer]; - let bounds = Rectangle::new( - Point::new(translation.x, translation.y), - *size, - ); + let bounds = + Rectangle::with_size(*size) * transformation; // Only draw visible content if let Some(clip_bounds) = layer.bounds.intersection(&bounds) { layer.meshes.push(Mesh::Gradient { - origin: Point::new( - translation.x, - translation.y, - ), + transformation, buffers, clip_bounds, }); @@ -340,7 +330,7 @@ impl<'a> Layer<'a> { }, primitive::Custom::Pipeline(pipeline) => { let layer = &mut layers[current_layer]; - let bounds = pipeline.bounds + translation; + let bounds = pipeline.bounds * transformation; if let Some(clip_bounds) = layer.bounds.intersection(&bounds) -- cgit From aa41d7656e734b5dae3c19dff87afbc74617a67f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 24 Oct 2023 02:51:02 +0200 Subject: Apply `Transform` scaling to text primitives --- wgpu/src/layer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/layer.rs') diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index fd5f2345..82e8ba02 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -169,7 +169,7 @@ impl<'a> Layer<'a> { layer.text.push(Text::Cached(text::Cached { content, bounds: *bounds * transformation, - size: *size, + size: *size * transformation.scale_y(), line_height: *line_height, color: *color, font: *font, -- cgit From a6e91d13d5d43796d0e6bb570fb4f010cf27921a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 24 Oct 2023 03:18:03 +0200 Subject: Allow only uniform scaling in `Transformation` --- wgpu/src/layer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'wgpu/src/layer.rs') diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index 82e8ba02..4a2e72df 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -133,7 +133,7 @@ impl<'a> Layer<'a> { position: *position * transformation, color: *color, clip_bounds: *clip_bounds * transformation, - scale: transformation.scale_y(), + scale: transformation.scale_factor(), }); } Primitive::Editor { @@ -149,7 +149,7 @@ impl<'a> Layer<'a> { position: *position * transformation, color: *color, clip_bounds: *clip_bounds * transformation, - scale: transformation.scale_y(), + scale: transformation.scale_factor(), }); } Primitive::Text { @@ -169,7 +169,7 @@ impl<'a> Layer<'a> { layer.text.push(Text::Cached(text::Cached { content, bounds: *bounds * transformation, - size: *size * transformation.scale_y(), + size: *size * transformation.scale_factor(), line_height: *line_height, color: *color, font: *font, -- cgit From f4d66486016076bb339a338bc589645119962d1e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 24 Oct 2023 05:34:03 +0200 Subject: Introduce `with_transformation` to `Renderer` trait --- wgpu/src/layer.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'wgpu/src/layer.rs') diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index 4a2e72df..12588849 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -12,10 +12,12 @@ pub use text::Text; use crate::core; use crate::core::alignment; -use crate::core::{Color, Font, Pixels, Point, Rectangle, Size, Vector}; +use crate::core::{ + Color, Font, Pixels, Point, Rectangle, Size, Transformation, Vector, +}; use crate::graphics; use crate::graphics::color; -use crate::graphics::{Transformation, Viewport}; +use crate::graphics::Viewport; use crate::primitive::{self, Primitive}; use crate::quad::{self, Quad}; @@ -130,10 +132,10 @@ impl<'a> Layer<'a> { layer.text.push(Text::Paragraph { paragraph: paragraph.clone(), - position: *position * transformation, + position: *position, color: *color, - clip_bounds: *clip_bounds * transformation, - scale: transformation.scale_factor(), + clip_bounds: *clip_bounds, + transformation, }); } Primitive::Editor { @@ -146,10 +148,10 @@ impl<'a> Layer<'a> { layer.text.push(Text::Editor { editor: editor.clone(), - position: *position * transformation, + position: *position, color: *color, - clip_bounds: *clip_bounds * transformation, - scale: transformation.scale_factor(), + clip_bounds: *clip_bounds, + transformation, }); } Primitive::Text { @@ -168,7 +170,7 @@ impl<'a> Layer<'a> { layer.text.push(Text::Cached(text::Cached { content, - bounds: *bounds * transformation, + bounds: *bounds + transformation.translation(), size: *size * transformation.scale_factor(), line_height: *line_height, color: *color, -- cgit From b3adf3184594c9bf60e0548a0362d30c512f3966 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 2 Feb 2024 14:43:04 +0100 Subject: Apply `Transformation` to `RawText` primitives --- wgpu/src/layer.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'wgpu/src/layer.rs') diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index 12588849..cc767c25 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -181,20 +181,13 @@ impl<'a> Layer<'a> { clip_bounds: *clip_bounds * transformation, })); } - graphics::Primitive::RawText(graphics::text::Raw { - buffer, - position, - color, - clip_bounds, - }) => { + graphics::Primitive::RawText(raw) => { let layer = &mut layers[current_layer]; - layer.text.push(Text::Raw(graphics::text::Raw { - buffer: buffer.clone(), - position: *position * transformation, - color: *color, - clip_bounds: *clip_bounds * transformation, - })); + layer.text.push(Text::Raw { + raw: raw.clone(), + transformation, + }); } Primitive::Quad { bounds, -- cgit