diff --git a/core/src/display_object.rs b/core/src/display_object.rs index d5f22f820563..d6a7bbadd9dc 100644 --- a/core/src/display_object.rs +++ b/core/src/display_object.rs @@ -238,6 +238,7 @@ pub struct DisplayObjectBase<'gc> { parent: Lock>>, place_frame: Cell, depth: Cell, + ratio: Cell, name: Lock>>, clip_depth: Cell, @@ -316,6 +317,7 @@ impl Default for DisplayObjectBase<'_> { parent: Default::default(), place_frame: Default::default(), depth: Default::default(), + ratio: Default::default(), name: Lock::new(None), clip_depth: Default::default(), matrix: Default::default(), @@ -1686,6 +1688,20 @@ pub trait TDisplayObject<'gc>: self.set_scale_y(Percent::from_unit(new_scale_y)); } + #[no_dynamic] + fn ratio(self) -> u16 { + self.base().ratio.get() + } + + #[no_dynamic] + fn set_ratio(self, context: &mut UpdateContext<'gc>, ratio: u16) { + self.base().ratio.set(ratio); + self.invalidate_cached_bitmap(); + self.on_ratio_changed(context, ratio); + } + + fn on_ratio_changed(self, _context: &mut UpdateContext<'gc>, _new_ratio: u16) {} + /// The opacity of this display object. /// 1 is fully opaque. /// Returned by the `_alpha`/`alpha` ActionScript properties. @@ -2427,11 +2443,7 @@ pub trait TDisplayObject<'gc>: } } if let Some(ratio) = place_object.ratio { - if let Some(morph_shape) = self.as_morph_shape() { - morph_shape.set_ratio(ratio); - } else if let Some(video) = self.as_video() { - video.seek(context, ratio.into()); - } + self.set_ratio(context, ratio); } if let Some(is_bitmap_cached) = place_object.is_bitmap_cached { self.set_bitmap_cached_preference(is_bitmap_cached); diff --git a/core/src/display_object/morph_shape.rs b/core/src/display_object/morph_shape.rs index c97304f9a8c1..3ff748d68fed 100644 --- a/core/src/display_object/morph_shape.rs +++ b/core/src/display_object/morph_shape.rs @@ -11,7 +11,7 @@ use gc_arena::lock::Lock; use gc_arena::{Collect, Gc, Mutation}; use ruffle_render::backend::ShapeHandle; use ruffle_render::commands::CommandHandler; -use std::cell::{Cell, RefCell, RefMut}; +use std::cell::{RefCell, RefMut}; use std::sync::Arc; use swf::{Fixed16, Fixed8}; @@ -35,7 +35,6 @@ pub struct MorphShapeData<'gc> { shared: Lock>, /// The AVM2 representation of this MorphShape. object: Lock>>, - ratio: Cell, } impl<'gc> MorphShape<'gc> { @@ -50,20 +49,10 @@ impl<'gc> MorphShape<'gc> { MorphShapeData { base: Default::default(), shared: Lock::new(Gc::new(gc_context, shared)), - ratio: Cell::new(0), object: Lock::new(None), }, )) } - - pub fn ratio(self) -> u16 { - self.0.ratio.get() - } - - pub fn set_ratio(self, ratio: u16) { - self.0.ratio.set(ratio); - self.invalidate_cached_bitmap(); - } } impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> { @@ -117,7 +106,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> { } fn render_self(self, context: &mut RenderContext) { - let ratio = self.0.ratio.get(); + let ratio = self.ratio(); let shared = self.0.shared.get(); let shape_handle = shared.get_shape(context, context.library, ratio); context @@ -126,7 +115,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> { } fn self_bounds(self) -> Rectangle { - let ratio = self.0.ratio.get(); + let ratio = self.ratio(); let shared = self.0.shared.get(); let frame = shared.get_frame(ratio); frame.bounds diff --git a/core/src/display_object/video.rs b/core/src/display_object/video.rs index eb33e8587c1c..0d22d4fa8e8b 100644 --- a/core/src/display_object/video.rs +++ b/core/src/display_object/video.rs @@ -454,6 +454,10 @@ impl<'gc> TDisplayObject<'gc> for Video<'gc> { } } + fn on_ratio_changed(self, context: &mut UpdateContext<'gc>, new_ratio: u16) { + self.seek(context, new_ratio.into()); + } + fn id(self) -> CharacterId { match self.0.source.get() { VideoSource::Swf(swf_source) => swf_source.streamdef.id,