core: Add `DisplayObject::scaling_grid`

This commit is contained in:
Mike Welsh 2023-04-05 14:41:50 -07:00 committed by Nathan Adams
parent 10ebc60a7d
commit cc6320a2dc
2 changed files with 36 additions and 0 deletions

View File

@ -252,6 +252,10 @@ pub struct DisplayObjectBase<'gc> {
#[collect(require_static)] #[collect(require_static)]
next_scroll_rect: Rectangle<Twips>, next_scroll_rect: Rectangle<Twips>,
/// Rectangle used for 9-slice scaling (`DislayObject.scale9grid`).
#[collect(require_static)]
scaling_grid: Rectangle<Twips>,
/// If this Display Object should cacheAsBitmap - and if so, the cache itself. /// If this Display Object should cacheAsBitmap - and if so, the cache itself.
/// None means not cached, Some means cached. /// None means not cached, Some means cached.
#[collect(require_static)] #[collect(require_static)]
@ -282,6 +286,7 @@ impl<'gc> Default for DisplayObjectBase<'gc> {
flags: DisplayObjectFlags::VISIBLE, flags: DisplayObjectFlags::VISIBLE,
scroll_rect: None, scroll_rect: None,
next_scroll_rect: Default::default(), next_scroll_rect: Default::default(),
scaling_grid: Default::default(),
cache: None, cache: None,
} }
} }
@ -1616,6 +1621,14 @@ pub trait TDisplayObject<'gc>:
} }
} }
fn scaling_grid(&self) -> Rectangle<Twips> {
self.base().scaling_grid.clone()
}
fn set_scaling_grid(&self, gc_context: &Mutation<'gc>, rect: Rectangle<Twips>) {
self.base_mut(gc_context).scaling_grid = rect;
}
/// Whether this object has been removed. Only applies to AVM1. /// Whether this object has been removed. Only applies to AVM1.
fn avm1_removed(&self) -> bool { fn avm1_removed(&self) -> bool {
self.base().avm1_removed() self.base().avm1_removed()

View File

@ -598,6 +598,10 @@ impl<'gc> MovieClip<'gc> {
.0 .0
.write(context.gc_context) .write(context.gc_context)
.define_morph_shape(context, reader, 2), .define_morph_shape(context, reader, 2),
TagCode::DefineScalingGrid => self
.0
.write(context.gc_context)
.define_scaling_grid(context, reader),
TagCode::DefineShape => self TagCode::DefineShape => self
.0 .0
.write(context.gc_context) .write(context.gc_context)
@ -3473,6 +3477,25 @@ impl<'gc, 'a> MovieClipData<'gc> {
Ok(()) Ok(())
} }
#[inline]
fn define_scaling_grid(
&mut self,
context: &mut UpdateContext<'_, 'gc>,
reader: &mut SwfStream<'a>,
) -> Result<(), Error> {
let id = reader.read_u16()?;
let rect = reader.read_rectangle()?;
let library = context.library.library_for_movie_mut(self.movie());
if let Some(character) = library.character_by_id(id) {
if let Character::MovieClip(clip) = character {
clip.set_scaling_grid(context.gc_context, rect);
} else {
tracing::warn!("DefineScalingGrid for invalid ID {}", id);
}
}
Ok(())
}
#[inline] #[inline]
fn define_morph_shape( fn define_morph_shape(
&mut self, &mut self,