render: Add Matrix::create_box_with_rotation
This patch splits the current method of create_box into 1. create_box -- without rotation, and 2. create_box_with_rotation -- with rotation. The reason for that refactor is that create_box was often used without rotation, and always passing 0.0 as rotation and having a dedicated condition for 0.0 was superfluous.
This commit is contained in:
parent
78b2d84fa7
commit
23f01e0dd9
|
@ -340,7 +340,7 @@ fn create_box<'gc>(
|
|||
0.0
|
||||
};
|
||||
|
||||
let matrix = Matrix::create_box(
|
||||
let matrix = Matrix::create_box_with_rotation(
|
||||
scale_x as f32,
|
||||
scale_y as f32,
|
||||
rotation as f32,
|
||||
|
|
|
@ -673,7 +673,7 @@ impl<'a, 'gc> RenderContext<'a, 'gc> {
|
|||
// Top
|
||||
self.commands.draw_rect(
|
||||
color,
|
||||
Matrix::create_box(width, thickness_pixels, 0.0, bounds.x_min, bounds.y_min),
|
||||
Matrix::create_box(width, thickness_pixels, bounds.x_min, bounds.y_min),
|
||||
);
|
||||
// Bottom
|
||||
self.commands.draw_rect(
|
||||
|
@ -681,7 +681,6 @@ impl<'a, 'gc> RenderContext<'a, 'gc> {
|
|||
Matrix::create_box(
|
||||
width,
|
||||
thickness_pixels,
|
||||
0.0,
|
||||
bounds.x_min,
|
||||
bounds.y_max - thickness,
|
||||
),
|
||||
|
@ -689,7 +688,7 @@ impl<'a, 'gc> RenderContext<'a, 'gc> {
|
|||
// Left
|
||||
self.commands.draw_rect(
|
||||
color,
|
||||
Matrix::create_box(thickness_pixels, height, 0.0, bounds.x_min, bounds.y_min),
|
||||
Matrix::create_box(thickness_pixels, height, bounds.x_min, bounds.y_min),
|
||||
);
|
||||
// Right
|
||||
self.commands.draw_rect(
|
||||
|
@ -697,7 +696,6 @@ impl<'a, 'gc> RenderContext<'a, 'gc> {
|
|||
Matrix::create_box(
|
||||
thickness_pixels,
|
||||
height,
|
||||
0.0,
|
||||
bounds.x_max - thickness,
|
||||
bounds.y_min,
|
||||
),
|
||||
|
|
|
@ -971,7 +971,6 @@ pub fn render_base<'gc>(this: DisplayObject<'gc>, context: &mut RenderContext<'_
|
|||
Matrix::create_box(
|
||||
bounds.width().to_pixels() as f32,
|
||||
bounds.height().to_pixels() as f32,
|
||||
0.0,
|
||||
bounds.x_min,
|
||||
bounds.y_min,
|
||||
),
|
||||
|
|
|
@ -1046,7 +1046,6 @@ impl<'gc> EditText<'gc> {
|
|||
* Matrix::create_box(
|
||||
width.to_pixels() as f32,
|
||||
height.to_pixels() as f32,
|
||||
0.0,
|
||||
x,
|
||||
Twips::ZERO,
|
||||
);
|
||||
|
@ -1065,7 +1064,6 @@ impl<'gc> EditText<'gc> {
|
|||
* Matrix::create_box(
|
||||
cursor_width.to_pixels() as f32,
|
||||
height.to_pixels() as f32,
|
||||
0.0,
|
||||
x - cursor_width,
|
||||
Twips::ZERO,
|
||||
);
|
||||
|
@ -2173,7 +2171,6 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
|
|||
let mask = Matrix::create_box(
|
||||
edit_text.bounds.width().to_pixels() as f32,
|
||||
edit_text.bounds.height().to_pixels() as f32,
|
||||
0.0,
|
||||
Twips::ZERO,
|
||||
Twips::ZERO,
|
||||
);
|
||||
|
|
|
@ -615,7 +615,6 @@ impl<'gc> Stage<'gc> {
|
|||
Matrix::create_box(
|
||||
viewport_width,
|
||||
margin_top,
|
||||
0.0,
|
||||
Twips::default(),
|
||||
Twips::default(),
|
||||
),
|
||||
|
@ -627,7 +626,6 @@ impl<'gc> Stage<'gc> {
|
|||
Matrix::create_box(
|
||||
viewport_width,
|
||||
margin_bottom,
|
||||
0.0,
|
||||
Twips::default(),
|
||||
Twips::from_pixels((viewport_height - margin_bottom) as f64),
|
||||
),
|
||||
|
@ -641,7 +639,6 @@ impl<'gc> Stage<'gc> {
|
|||
Matrix::create_box(
|
||||
margin_left,
|
||||
viewport_height,
|
||||
0.0,
|
||||
Twips::default(),
|
||||
Twips::default(),
|
||||
),
|
||||
|
@ -653,7 +650,6 @@ impl<'gc> Stage<'gc> {
|
|||
Matrix::create_box(
|
||||
margin_right,
|
||||
viewport_height,
|
||||
0.0,
|
||||
Twips::from_pixels((viewport_width - margin_right) as f64),
|
||||
Twips::default(),
|
||||
),
|
||||
|
|
|
@ -94,31 +94,31 @@ impl Matrix {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_box(
|
||||
pub fn create_box(scale_x: f32, scale_y: f32, translate_x: Twips, translate_y: Twips) -> Self {
|
||||
Self {
|
||||
a: scale_x,
|
||||
c: 0.0,
|
||||
tx: translate_x,
|
||||
b: 0.0,
|
||||
d: scale_y,
|
||||
ty: translate_y,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_box_with_rotation(
|
||||
scale_x: f32,
|
||||
scale_y: f32,
|
||||
rotation: f32,
|
||||
translate_x: Twips,
|
||||
translate_y: Twips,
|
||||
) -> Self {
|
||||
if rotation != 0.0 {
|
||||
Self {
|
||||
a: rotation.cos() * scale_x,
|
||||
c: -rotation.sin() * scale_x,
|
||||
tx: translate_x,
|
||||
b: rotation.sin() * scale_y,
|
||||
d: rotation.cos() * scale_y,
|
||||
ty: translate_y,
|
||||
}
|
||||
} else {
|
||||
Self {
|
||||
a: scale_x,
|
||||
c: 0.0,
|
||||
tx: translate_x,
|
||||
b: 0.0,
|
||||
d: scale_y,
|
||||
ty: translate_y,
|
||||
}
|
||||
Self {
|
||||
a: rotation.cos() * scale_x,
|
||||
c: -rotation.sin() * scale_x,
|
||||
tx: translate_x,
|
||||
b: rotation.sin() * scale_y,
|
||||
d: rotation.cos() * scale_y,
|
||||
ty: translate_y,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ impl Matrix {
|
|||
translate_x: Twips,
|
||||
translate_y: Twips,
|
||||
) -> Self {
|
||||
Self::create_box(
|
||||
Self::create_box_with_rotation(
|
||||
width / 1638.4,
|
||||
height / 1638.4,
|
||||
rotation,
|
||||
|
|
Loading…
Reference in New Issue