From 1e389112a15f6d75e43a132d93f598222d604b22 Mon Sep 17 00:00:00 2001 From: Mike Welsh Date: Thu, 18 Aug 2022 12:33:51 -0700 Subject: [PATCH] avm1: Wire up MovieClip.blendMode --- core/src/avm1/globals/movie_clip.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/core/src/avm1/globals/movie_clip.rs b/core/src/avm1/globals/movie_clip.rs index bc9781aba..af44b4fef 100644 --- a/core/src/avm1/globals/movie_clip.rs +++ b/core/src/avm1/globals/movie_clip.rs @@ -14,11 +14,13 @@ use crate::display_object::{ }; use crate::ecma_conversions::f64_to_wrapping_i32; use crate::prelude::*; +use crate::string::AvmString; use crate::vminterface::Instantiator; use gc_arena::MutationContext; use ruffle_render::shape_utils::DrawCommand; +use std::str::FromStr; use swf::{ - FillStyle, Fixed8, Gradient, GradientInterpolation, GradientRecord, GradientSpread, + BlendMode, FillStyle, Fixed8, Gradient, GradientInterpolation, GradientRecord, GradientSpread, LineCapStyle, LineJoinStyle, LineStyle, Twips, }; @@ -107,6 +109,7 @@ const PROTO_DECLS: &[Declaration] = declare_properties! { "focusEnabled" => property(mc_getter!(focus_enabled), mc_setter!(set_focus_enabled); DONT_DELETE | DONT_ENUM); "_lockroot" => property(mc_getter!(lock_root), mc_setter!(set_lock_root); DONT_DELETE | DONT_ENUM); "useHandCursor" => property(mc_getter!(use_hand_cursor), mc_setter!(set_use_hand_cursor); DONT_DELETE | DONT_ENUM); + "blendMode" => property(mc_getter!(blend_mode), mc_setter!(set_blend_mode); DONT_DELETE | DONT_ENUM); }; /// Implements `MovieClip` @@ -1461,3 +1464,27 @@ fn set_use_hand_cursor<'gc>( this.set_use_hand_cursor(&mut activation.context, use_hand_cursor); Ok(()) } + +fn blend_mode<'gc>( + this: MovieClip<'gc>, + activation: &mut Activation<'_, 'gc, '_>, +) -> Result, Error<'gc>> { + let mode = AvmString::new_utf8(activation.context.gc_context, this.blend_mode().to_string()); + Ok(mode.into()) +} + +fn set_blend_mode<'gc>( + this: MovieClip<'gc>, + activation: &mut Activation<'_, 'gc, '_>, + value: Value<'gc>, +) -> Result<(), Error<'gc>> { + // No-op if value is not a string. + if let Value::String(mode) = value { + if let Ok(mode) = BlendMode::from_str(&mode.to_string()) { + this.set_blend_mode(activation.context.gc_context, mode); + } else { + log::error!("Unknown blend mode {}", mode); + }; + } + Ok(()) +}