From cec9850a33a1e198c4f3f4a9c0fa9413bbf3b433 Mon Sep 17 00:00:00 2001 From: relrelb Date: Sun, 29 May 2022 21:03:22 +0300 Subject: [PATCH] core: Use `swf::Matrix::translate` in more places Replace direct instatiations of `swf::Matrix` where only `tx` and `ty` are specified, and other fields are default. This results in a slightly more shorter, readable code. --- core/src/display_object/edit_text.rs | 16 +++++----------- core/src/transform.rs | 9 +-------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index 0220f581c..1163423e9 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -1621,11 +1621,7 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> { let edit_text = self.0.read(); context.transform_stack.push(&Transform { - matrix: Matrix { - tx: edit_text.bounds.x_min, - ty: edit_text.bounds.y_min, - ..Default::default() - }, + matrix: Matrix::translate(edit_text.bounds.x_min, edit_text.bounds.y_min), ..Default::default() }); @@ -1659,12 +1655,10 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> { // TODO: Where does this come from? How is this different than INTERNAL_PADDING? Does this apply to y as well? // If this is actually right, offset the border in `redraw_border` instead of doing an extra push. context.transform_stack.push(&Transform { - matrix: Matrix { - tx: Twips::from_pixels(Self::INTERNAL_PADDING) - - Twips::from_pixels(edit_text.hscroll), - ty: Twips::from_pixels(Self::INTERNAL_PADDING) - scroll_offset, - ..Default::default() - }, + matrix: Matrix::translate( + Twips::from_pixels(Self::INTERNAL_PADDING) - Twips::from_pixels(edit_text.hscroll), + Twips::from_pixels(Self::INTERNAL_PADDING) - scroll_offset, + ), ..Default::default() }); diff --git a/core/src/transform.rs b/core/src/transform.rs index ff9a8c23b..048d5d508 100644 --- a/core/src/transform.rs +++ b/core/src/transform.rs @@ -15,14 +15,7 @@ pub struct Transform { impl From> for Transform { fn from(pos: Position) -> Self { Self { - matrix: Matrix { - a: 1.0, - b: 0.0, - c: 0.0, - d: 1.0, - tx: pos.x(), - ty: pos.y(), - }, + matrix: Matrix::translate(pos.x(), pos.y()), color_transform: Default::default(), } }