Allow only uniform scaling in Transformation
This commit is contained in:
parent
aa41d7656e
commit
a6e91d13d5
4 changed files with 16 additions and 21 deletions
|
|
@ -26,21 +26,16 @@ impl Transformation {
|
|||
Transformation(Mat4::from_translation(Vec3::new(x, y, 0.0)))
|
||||
}
|
||||
|
||||
/// Creates a scale transformation.
|
||||
pub fn scale(x: f32, y: f32) -> Transformation {
|
||||
Transformation(Mat4::from_scale(Vec3::new(x, y, 1.0)))
|
||||
/// Creates a uniform scaling transformation.
|
||||
pub fn scale(scaling: f32) -> Transformation {
|
||||
Transformation(Mat4::from_scale(Vec3::new(scaling, scaling, 1.0)))
|
||||
}
|
||||
|
||||
/// The scale factor on the X axis.
|
||||
pub fn scale_x(&self) -> f32 {
|
||||
/// The scale factor of the [`Transformation`].
|
||||
pub fn scale_factor(&self) -> f32 {
|
||||
self.0.x_axis.x
|
||||
}
|
||||
|
||||
/// The scale factor on the Y axis.
|
||||
pub fn scale_y(&self) -> f32 {
|
||||
self.0.y_axis.y
|
||||
}
|
||||
|
||||
/// The translation on the X axis.
|
||||
pub fn translation_x(&self) -> f32 {
|
||||
self.0.w_axis.x
|
||||
|
|
|
|||
|
|
@ -461,7 +461,7 @@ impl Backend {
|
|||
paragraph,
|
||||
*position * transformation,
|
||||
*color,
|
||||
scale_factor,
|
||||
scale_factor * transformation.scale_factor(),
|
||||
pixels,
|
||||
clip_mask,
|
||||
);
|
||||
|
|
@ -523,7 +523,7 @@ impl Backend {
|
|||
*horizontal_alignment,
|
||||
*vertical_alignment,
|
||||
*shaping,
|
||||
scale_factor,
|
||||
scale_factor * transformation.scale_factor(),
|
||||
pixels,
|
||||
clip_mask,
|
||||
);
|
||||
|
|
@ -770,10 +770,10 @@ fn into_color(color: Color) -> tiny_skia::Color {
|
|||
|
||||
fn into_transform(transformation: Transformation) -> tiny_skia::Transform {
|
||||
tiny_skia::Transform {
|
||||
sx: transformation.scale_x(),
|
||||
sx: transformation.scale_factor(),
|
||||
kx: 0.0,
|
||||
ky: 0.0,
|
||||
sy: transformation.scale_y(),
|
||||
sy: transformation.scale_factor(),
|
||||
tx: transformation.translation_x(),
|
||||
ty: transformation.translation_y(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,8 +147,8 @@ impl Backend {
|
|||
}
|
||||
|
||||
if !layer.meshes.is_empty() {
|
||||
let scaled = transformation
|
||||
* Transformation::scale(scale_factor, scale_factor);
|
||||
let scaled =
|
||||
transformation * Transformation::scale(scale_factor);
|
||||
|
||||
self.triangle_pipeline.prepare(
|
||||
device,
|
||||
|
|
@ -161,8 +161,8 @@ impl Backend {
|
|||
#[cfg(any(feature = "image", feature = "svg"))]
|
||||
{
|
||||
if !layer.images.is_empty() {
|
||||
let scaled = transformation
|
||||
* Transformation::scale(scale_factor, scale_factor);
|
||||
let scaled =
|
||||
transformation * Transformation::scale(scale_factor);
|
||||
|
||||
self.image_pipeline.prepare(
|
||||
device,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue