diff --git a/core/src/avm1/globals/movie_clip.rs b/core/src/avm1/globals/movie_clip.rs index 51accf99c..d91afd016 100644 --- a/core/src/avm1/globals/movie_clip.rs +++ b/core/src/avm1/globals/movie_clip.rs @@ -124,7 +124,7 @@ pub fn constructor<'gc>( fn new_rectangle<'gc>( activation: &mut Activation<'_, 'gc, '_>, - rectangle: Rectangle, + rectangle: Rectangle, ) -> Result, Error<'gc>> { let x = rectangle.x_min.to_pixels(); let y = rectangle.y_min.to_pixels(); @@ -138,7 +138,7 @@ fn new_rectangle<'gc>( fn object_to_rectangle<'gc>( activation: &mut Activation<'_, 'gc, '_>, object: Object<'gc>, -) -> Result, Error<'gc>> { +) -> Result>, Error<'gc>> { const NAMES: &[&str] = &["x", "y", "width", "height"]; let mut values = [0; 4]; for (&name, value) in NAMES.iter().zip(&mut values) { diff --git a/core/src/avm2/globals/flash/display/displayobject.rs b/core/src/avm2/globals/flash/display/displayobject.rs index 3d58d3553..6f4c54721 100644 --- a/core/src/avm2/globals/flash/display/displayobject.rs +++ b/core/src/avm2/globals/flash/display/displayobject.rs @@ -771,7 +771,7 @@ pub fn set_blend_mode<'gc>( fn new_rectangle<'gc>( activation: &mut Activation<'_, 'gc, '_>, - rectangle: Rectangle, + rectangle: Rectangle, ) -> Result, Error<'gc>> { let x = rectangle.x_min.to_pixels(); let y = rectangle.y_min.to_pixels(); @@ -803,7 +803,7 @@ fn scroll_rect<'gc>( fn object_to_rectangle<'gc>( activation: &mut Activation<'_, 'gc, '_>, object: Object<'gc>, -) -> Result> { +) -> Result, Error<'gc>> { const NAMES: &[&str] = &["x", "y", "width", "height"]; let mut values = [0.0; 4]; for (&name, value) in NAMES.iter().zip(&mut values) { diff --git a/core/src/display_object.rs b/core/src/display_object.rs index e14f8961d..c70e77628 100644 --- a/core/src/display_object.rs +++ b/core/src/display_object.rs @@ -107,13 +107,13 @@ pub struct DisplayObjectBase<'gc> { /// The 'internal' scroll rect used for rendering and methods like 'localToGlobal'. /// This is updated from 'pre_render' #[collect(require_static)] - scroll_rect: Option, + scroll_rect: Option>, /// The 'next' scroll rect, which we will copy to 'scroll_rect' from 'pre_render'. /// This is used by the ActionScript 'DisplayObject.scrollRect' getter, which sees /// changes immediately (without needing wait for a render) #[collect(require_static)] - next_scroll_rect: Rectangle, + next_scroll_rect: Rectangle, } impl<'gc> Default for DisplayObjectBase<'gc> { @@ -1031,15 +1031,19 @@ pub trait TDisplayObject<'gc>: self.base_mut(gc_context).set_maskee(node); } - fn scroll_rect(&self) -> Option { + fn scroll_rect(&self) -> Option> { self.base().scroll_rect.clone() } - fn next_scroll_rect(&self) -> Rectangle { + fn next_scroll_rect(&self) -> Rectangle { self.base().next_scroll_rect.clone() } - fn set_next_scroll_rect(&self, gc_context: MutationContext<'gc, '_>, rectangle: Rectangle) { + fn set_next_scroll_rect( + &self, + gc_context: MutationContext<'gc, '_>, + rectangle: Rectangle, + ) { self.base_mut(gc_context).next_scroll_rect = rectangle; } diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index 93bd0fdeb..d354cc0f9 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -1780,7 +1780,7 @@ bitflags::bitflags! { struct EditTextStatic { swf: Arc, id: CharacterId, - bounds: swf::Rectangle, + bounds: swf::Rectangle, layout: Option, initial_text: Option, } diff --git a/core/src/html/dimensions.rs b/core/src/html/dimensions.rs index 46f36df6c..2c0020be4 100644 --- a/core/src/html/dimensions.rs +++ b/core/src/html/dimensions.rs @@ -156,11 +156,11 @@ where } } -impl From> for Rectangle +impl From> for Rectangle where T: Into + Add, { - fn from(bounds: BoxBounds) -> Rectangle { + fn from(bounds: BoxBounds) -> Rectangle { Rectangle { x_min: bounds.offset_x.into(), x_max: bounds.extent_x.into(), @@ -170,11 +170,11 @@ where } } -impl From for BoxBounds +impl From> for BoxBounds where T: From, { - fn from(bounds: Rectangle) -> Self { + fn from(bounds: Rectangle) -> Self { Self { offset_x: T::from(bounds.x_min), extent_x: T::from(bounds.x_max), diff --git a/core/src/html/test.rs b/core/src/html/test.rs index c76312e3f..aa596225f 100644 --- a/core/src/html/test.rs +++ b/core/src/html/test.rs @@ -28,7 +28,7 @@ fn into_swf_rectangle() { let pos = Position::from((Twips::new(3), Twips::new(5))); let size = Size::from((Twips::new(20), Twips::new(80))); let bounds = BoxBounds::from_position_and_size(pos, size); - let rect: Rectangle = bounds.into(); + let rect: Rectangle = bounds.into(); assert_eq!( rect, diff --git a/core/src/tag_utils.rs b/core/src/tag_utils.rs index 35246ad49..a627991e8 100644 --- a/core/src/tag_utils.rs +++ b/core/src/tag_utils.rs @@ -173,7 +173,7 @@ impl SwfMovie { self.header.is_action_script_3() } - pub fn stage_size(&self) -> &Rectangle { + pub fn stage_size(&self) -> &Rectangle { self.header.stage_size() } diff --git a/render/src/bounding_box.rs b/render/src/bounding_box.rs index 6a064f958..f07835d93 100644 --- a/render/src/bounding_box.rs +++ b/render/src/bounding_box.rs @@ -154,8 +154,8 @@ impl BoundingBox { } } -impl From for BoundingBox { - fn from(rect: swf::Rectangle) -> Self { +impl From> for BoundingBox { + fn from(rect: swf::Rectangle) -> Self { Self { x_min: rect.x_min, y_min: rect.y_min, @@ -166,8 +166,8 @@ impl From for BoundingBox { } } -impl From<&swf::Rectangle> for BoundingBox { - fn from(rect: &swf::Rectangle) -> Self { +impl From<&swf::Rectangle> for BoundingBox { + fn from(rect: &swf::Rectangle) -> Self { Self { x_min: rect.x_min, y_min: rect.y_min, diff --git a/render/src/shape_utils.rs b/render/src/shape_utils.rs index 3182ab355..cf937d5d8 100644 --- a/render/src/shape_utils.rs +++ b/render/src/shape_utils.rs @@ -3,7 +3,7 @@ use crate::matrix::Matrix; use smallvec::SmallVec; use swf::{CharacterId, FillStyle, LineStyle, Shape, ShapeRecord, Twips}; -pub fn calculate_shape_bounds(shape_records: &[swf::ShapeRecord]) -> swf::Rectangle { +pub fn calculate_shape_bounds(shape_records: &[swf::ShapeRecord]) -> swf::Rectangle { let mut bounds = swf::Rectangle { x_min: Twips::new(i32::MAX), y_min: Twips::new(i32::MAX), diff --git a/swf/src/read.rs b/swf/src/read.rs index acef87c69..da2ef71c7 100644 --- a/swf/src/read.rs +++ b/swf/src/read.rs @@ -602,7 +602,7 @@ impl<'a> Reader<'a> { Ok(tag) } - pub fn read_rectangle(&mut self) -> Result { + pub fn read_rectangle(&mut self) -> Result> { let mut bits = self.bits(); let num_bits = bits.read_ubits(5)?; Ok(Rectangle { diff --git a/swf/src/types.rs b/swf/src/types.rs index c8976c454..8ffa7f009 100644 --- a/swf/src/types.rs +++ b/swf/src/types.rs @@ -12,11 +12,13 @@ use std::str::FromStr; mod color; mod fixed; mod matrix; +mod rectangle; mod twips; pub use color::Color; pub use fixed::{Fixed16, Fixed8}; pub use matrix::Matrix; +pub use rectangle::Rectangle; pub use twips::Twips; /// A complete header and tags in the SWF file. @@ -46,7 +48,7 @@ pub struct SwfBuf { pub struct Header { pub compression: Compression, pub version: u8, - pub stage_size: Rectangle, + pub stage_size: Rectangle, pub frame_rate: Fixed8, pub num_frames: u16, } @@ -138,7 +140,7 @@ impl HeaderExt { /// The stage dimensions of this SWF. #[inline] - pub fn stage_size(&self) -> &Rectangle { + pub fn stage_size(&self) -> &Rectangle { &self.header.stage_size } @@ -189,24 +191,6 @@ pub enum Compression { Lzma, } -/// A rectangular region defined by minimum -/// and maximum x- and y-coordinate positions -/// measured in [`Twips`]. -#[derive(Clone, Debug, Default, Eq, PartialEq)] -pub struct Rectangle { - /// The minimum x-position of the rectangle. - pub x_min: Twips, - - /// The maximum x-position of the rectangle. - pub x_max: Twips, - - /// The minimum y-position of the rectangle. - pub y_min: Twips, - - /// The maximum y-position of the rectangle. - pub y_max: Twips, -} - #[derive(Clone, Debug, Eq, PartialEq)] pub struct ColorTransform { pub r_multiply: Fixed8, @@ -635,7 +619,7 @@ pub enum Tag<'a> { DefineMorphShape(Box), DefineScalingGrid { id: CharacterId, - splitter_rect: Rectangle, + splitter_rect: Rectangle, }, DefineShape(Shape), DefineSound(Box>), @@ -724,8 +708,8 @@ pub struct ShapeContext { pub struct Shape { pub version: u8, pub id: CharacterId, - pub shape_bounds: Rectangle, - pub edge_bounds: Rectangle, + pub shape_bounds: Rectangle, + pub edge_bounds: Rectangle, pub flags: ShapeFlag, pub styles: ShapeStyles, pub shape: Vec, @@ -1215,8 +1199,8 @@ bitflags! { #[derive(Clone, Debug, Eq, PartialEq)] pub struct MorphShape { - pub shape_bounds: Rectangle, - pub edge_bounds: Rectangle, + pub shape_bounds: Rectangle, + pub edge_bounds: Rectangle, pub fill_styles: Vec, pub line_styles: Vec, pub shape: Vec, @@ -1266,7 +1250,7 @@ pub struct Glyph { pub shape_records: Vec, pub code: u16, pub advance: i16, - pub bounds: Option, + pub bounds: Option>, } #[derive(Clone, Debug, Eq, PartialEq)] @@ -1314,7 +1298,7 @@ pub struct DefineBinaryData<'a> { #[derive(Clone, Debug, Eq, PartialEq)] pub struct Text { pub id: CharacterId, - pub bounds: Rectangle, + pub bounds: Rectangle, pub matrix: Matrix, pub records: Vec, } @@ -1338,7 +1322,7 @@ pub struct GlyphEntry { #[derive(Clone, Debug, Eq, PartialEq)] pub struct EditText<'a> { pub(crate) id: CharacterId, - pub(crate) bounds: Rectangle, + pub(crate) bounds: Rectangle, pub(crate) font_id: CharacterId, pub(crate) font_class: &'a SwfStr, pub(crate) height: Twips, @@ -1357,12 +1341,12 @@ impl<'a> EditText<'a> { } #[inline] - pub fn bounds(&self) -> &Rectangle { + pub fn bounds(&self) -> &Rectangle { &self.bounds } #[inline] - pub fn with_bounds(mut self, bounds: Rectangle) -> Self { + pub fn with_bounds(mut self, bounds: Rectangle) -> Self { self.bounds = bounds; self } diff --git a/swf/src/types/rectangle.rs b/swf/src/types/rectangle.rs new file mode 100644 index 000000000..e23953079 --- /dev/null +++ b/swf/src/types/rectangle.rs @@ -0,0 +1,15 @@ +/// A rectangular region defined by minimum and maximum x- and y-coordinate positions. +#[derive(Clone, Debug, Default, Eq, PartialEq)] +pub struct Rectangle { + /// The minimum x-position of the rectangle. + pub x_min: T, + + /// The maximum x-position of the rectangle. + pub x_max: T, + + /// The minimum y-position of the rectangle. + pub y_min: T, + + /// The maximum y-position of the rectangle. + pub y_max: T, +} diff --git a/swf/src/write.rs b/swf/src/write.rs index 906e025cd..3a3d2694b 100644 --- a/swf/src/write.rs +++ b/swf/src/write.rs @@ -288,7 +288,7 @@ impl Writer { Ok(()) } - fn write_rectangle(&mut self, rectangle: &Rectangle) -> Result<()> { + fn write_rectangle(&mut self, rectangle: &Rectangle) -> Result<()> { let num_bits = [ rectangle.x_min, rectangle.x_max, @@ -2614,7 +2614,7 @@ mod tests { #[test] fn write_rectangle_zero() { - let rect: Rectangle = Default::default(); + let rect: Rectangle = Default::default(); let mut buf = Vec::new(); { let mut writer = Writer::new(&mut buf, 1);