core: Implement DefineButtonCxform SWF tag
(Although nothing uses this... it was only used in SWF version 2 and below!)
This commit is contained in:
parent
bc872cbf9c
commit
f2d31b222b
|
@ -89,6 +89,24 @@ impl<'gc> Button<'gc> {
|
|||
static_data.down_to_over_sound = sounds.down_to_over_sound;
|
||||
static_data.over_to_up_sound = sounds.over_to_up_sound;
|
||||
}
|
||||
|
||||
/// Handles the ancient DefineButtonCxform SWF tag.
|
||||
/// Set the color transform for all children of each state.
|
||||
pub fn set_colors(
|
||||
self,
|
||||
gc_context: MutationContext<'gc, '_>,
|
||||
color_transforms: &[swf::ColorTransform],
|
||||
) {
|
||||
let button = self.0.write(gc_context);
|
||||
let mut static_data = button.static_data.write(gc_context);
|
||||
|
||||
// This tag isn't documented well in SWF19. It is only used in very old SWF<=2 content.
|
||||
// It applies color transforms to every character in a button, in sequence(?).
|
||||
for (record, color_transform) in static_data.records.iter_mut().zip(color_transforms.iter())
|
||||
{
|
||||
record.color_transform = color_transform.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'gc> TDisplayObject<'gc> for Button<'gc> {
|
||||
|
|
|
@ -873,6 +873,7 @@ impl<'gc, 'a> MovieClipData<'gc> {
|
|||
TagCode::DefineBitsLossless2 => self.define_bits_lossless(context, reader, 2),
|
||||
TagCode::DefineButton => self.define_button_1(context, reader),
|
||||
TagCode::DefineButton2 => self.define_button_2(context, reader),
|
||||
TagCode::DefineButtonCxform => self.define_button_cxform(context, reader, tag_len),
|
||||
TagCode::DefineButtonSound => self.define_button_sound(context, reader),
|
||||
TagCode::DefineEditText => self.define_edit_text(context, reader),
|
||||
TagCode::DefineFont => self.define_font_1(context, reader),
|
||||
|
@ -1240,6 +1241,32 @@ impl<'gc, 'a> MovieClipData<'gc> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn define_button_cxform(
|
||||
&mut self,
|
||||
context: &mut UpdateContext<'_, 'gc, '_>,
|
||||
reader: &mut SwfStream<&'a [u8]>,
|
||||
tag_len: usize,
|
||||
) -> DecodeResult {
|
||||
let button_colors = reader.read_define_button_cxform(tag_len)?;
|
||||
if let Some(button) = context.library.get_character_by_id(button_colors.id) {
|
||||
if let Character::Button(button) = button {
|
||||
button.set_colors(context.gc_context, &button_colors.color_transforms[..]);
|
||||
} else {
|
||||
log::warn!(
|
||||
"DefineButtonCxform: Tried to apply on non-button ID {}",
|
||||
button_colors.id
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log::warn!(
|
||||
"DefineButtonCxform: Character ID {} doesn't exist",
|
||||
button_colors.id
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn define_button_sound(
|
||||
&mut self,
|
||||
|
|
Loading…
Reference in New Issue