Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions core/src/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pub struct DisplayObjectBase<'gc> {
parent: Lock<Option<DisplayObject<'gc>>>,
place_frame: Cell<u16>,
depth: Cell<Depth>,
ratio: Cell<u16>,
name: Lock<Option<AvmString<'gc>>>,
clip_depth: Cell<Depth>,

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 3 additions & 14 deletions core/src/display_object/morph_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -35,7 +35,6 @@ pub struct MorphShapeData<'gc> {
shared: Lock<Gc<'gc, MorphShapeShared>>,
/// The AVM2 representation of this MorphShape.
object: Lock<Option<Avm2StageObject<'gc>>>,
ratio: Cell<u16>,
}

impl<'gc> MorphShape<'gc> {
Expand All @@ -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> {
Expand Down Expand Up @@ -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
Expand All @@ -126,7 +115,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
}

fn self_bounds(self) -> Rectangle<Twips> {
let ratio = self.0.ratio.get();
let ratio = self.ratio();
let shared = self.0.shared.get();
let frame = shared.get_frame(ratio);
frame.bounds
Expand Down
4 changes: 4 additions & 0 deletions core/src/display_object/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading