summaryrefslogtreecommitdiffstats
path: root/graphics/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-10-24 05:34:03 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-02 02:24:45 +0100
commitf4d66486016076bb339a338bc589645119962d1e (patch)
treebbb9c4d996216893296cf4323857323542d6e757 /graphics/src
parenta6e91d13d5d43796d0e6bb570fb4f010cf27921a (diff)
downloadiced-f4d66486016076bb339a338bc589645119962d1e.tar.gz
iced-f4d66486016076bb339a338bc589645119962d1e.tar.bz2
iced-f4d66486016076bb339a338bc589645119962d1e.zip
Introduce `with_transformation` to `Renderer` trait
Diffstat (limited to '')
-rw-r--r--core/src/transformation.rs (renamed from graphics/src/transformation.rs)15
-rw-r--r--graphics/src/lib.rs2
-rw-r--r--graphics/src/primitive.rs4
-rw-r--r--graphics/src/renderer.rs18
-rw-r--r--graphics/src/viewport.rs4
5 files changed, 17 insertions, 26 deletions
diff --git a/graphics/src/transformation.rs b/core/src/transformation.rs
index e2642980..b2c488b0 100644
--- a/graphics/src/transformation.rs
+++ b/core/src/transformation.rs
@@ -1,4 +1,4 @@
-use crate::core::{Point, Rectangle, Size, Vector};
+use crate::{Point, Rectangle, Size, Vector};
use glam::{Mat4, Vec3, Vec4};
use std::ops::Mul;
@@ -31,19 +31,14 @@ impl Transformation {
Transformation(Mat4::from_scale(Vec3::new(scaling, scaling, 1.0)))
}
- /// The scale factor of the [`Transformation`].
+ /// Returns the scale factor of the [`Transformation`].
pub fn scale_factor(&self) -> f32 {
self.0.x_axis.x
}
- /// The translation on the X axis.
- pub fn translation_x(&self) -> f32 {
- self.0.w_axis.x
- }
-
- /// The translation on the Y axis.
- pub fn translation_y(&self) -> f32 {
- self.0.w_axis.y
+ /// Returns the translation of the [`Transformation`].
+ pub fn translation(&self) -> Vector {
+ Vector::new(self.0.w_axis.x, self.0.w_axis.y)
}
}
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index 76de56bf..aa9d00e8 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -19,7 +19,6 @@
mod antialiasing;
mod error;
mod primitive;
-mod transformation;
mod viewport;
pub mod backend;
@@ -46,7 +45,6 @@ pub use gradient::Gradient;
pub use mesh::Mesh;
pub use primitive::Primitive;
pub use renderer::Renderer;
-pub use transformation::Transformation;
pub use viewport::Viewport;
pub use iced_core as core;
diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs
index 32008698..6929b0a1 100644
--- a/graphics/src/primitive.rs
+++ b/graphics/src/primitive.rs
@@ -4,11 +4,11 @@ use crate::core::image;
use crate::core::svg;
use crate::core::text;
use crate::core::{
- Background, Border, Color, Font, Pixels, Point, Rectangle, Shadow, Vector,
+ Background, Border, Color, Font, Pixels, Point, Rectangle, Shadow,
+ Transformation, Vector,
};
use crate::text::editor;
use crate::text::paragraph;
-use crate::Transformation;
use std::sync::Arc;
diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs
index cb07c23b..143f348b 100644
--- a/graphics/src/renderer.rs
+++ b/graphics/src/renderer.rs
@@ -6,7 +6,7 @@ use crate::core::renderer;
use crate::core::svg;
use crate::core::text::Text;
use crate::core::{
- Background, Color, Font, Pixels, Point, Rectangle, Size, Vector,
+ Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
};
use crate::text;
use crate::Primitive;
@@ -73,20 +73,20 @@ impl<B: Backend> Renderer<B> {
}
/// Starts recording a translation.
- pub fn start_translation(&mut self) -> Vec<Primitive<B::Primitive>> {
+ pub fn start_transformation(&mut self) -> Vec<Primitive<B::Primitive>> {
std::mem::take(&mut self.primitives)
}
/// Ends the recording of a translation.
- pub fn end_translation(
+ pub fn end_transformation(
&mut self,
primitives: Vec<Primitive<B::Primitive>>,
- translation: Vector,
+ transformation: Transformation,
) {
let layer = std::mem::replace(&mut self.primitives, primitives);
self.primitives
- .push(Primitive::group(layer).translate(translation));
+ .push(Primitive::group(layer).transform(transformation));
}
}
@@ -99,16 +99,16 @@ impl<B: Backend> iced_core::Renderer for Renderer<B> {
self.end_layer(current, bounds);
}
- fn with_translation(
+ fn with_transformation(
&mut self,
- translation: Vector,
+ transformation: Transformation,
f: impl FnOnce(&mut Self),
) {
- let current = self.start_translation();
+ let current = self.start_transformation();
f(self);
- self.end_translation(current, translation);
+ self.end_transformation(current, transformation);
}
fn fill_quad(
diff --git a/graphics/src/viewport.rs b/graphics/src/viewport.rs
index 5792555d..dc8e21d3 100644
--- a/graphics/src/viewport.rs
+++ b/graphics/src/viewport.rs
@@ -1,6 +1,4 @@
-use crate::Transformation;
-
-use iced_core::Size;
+use crate::core::{Size, Transformation};
/// A viewing region for displaying computer graphics.
#[derive(Debug, Clone)]