diff --git a/core/src/avm2/globals/flash/display/graphics.rs b/core/src/avm2/globals/flash/display/graphics.rs index 45553877e..2a6799729 100644 --- a/core/src/avm2/globals/flash/display/graphics.rs +++ b/core/src/avm2/globals/flash/display/graphics.rs @@ -9,8 +9,9 @@ use crate::avm2::traits::Trait; use crate::avm2::value::Value; use crate::avm2::Error; use crate::display_object::TDisplayObject; +use crate::shape_utils::DrawCommand; use gc_arena::{GcCell, MutationContext}; -use swf::{Color, FillStyle}; +use swf::{Color, FillStyle, Twips}; /// Implements `flash.display.Graphics`'s instance constructor. pub fn instance_init<'gc>( @@ -81,6 +82,51 @@ pub fn clear<'gc>( Ok(Value::Undefined) } +/// Implements `Graphics.curveTo`. +pub fn curve_to<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + args: &[Value<'gc>], +) -> Result, Error> { + if let Some(this) = this { + if let Some(dobj) = this.as_display_object() { + if let Some(mc) = dobj.as_movie_clip() { + let x1 = Twips::from_pixels( + args.get(0) + .cloned() + .unwrap_or(Value::Undefined) + .coerce_to_number(activation)?, + ); + let y1 = Twips::from_pixels( + args.get(1) + .cloned() + .unwrap_or(Value::Undefined) + .coerce_to_number(activation)?, + ); + let x2 = Twips::from_pixels( + args.get(2) + .cloned() + .unwrap_or(Value::Undefined) + .coerce_to_number(activation)?, + ); + let y2 = Twips::from_pixels( + args.get(3) + .cloned() + .unwrap_or(Value::Undefined) + .coerce_to_number(activation)?, + ); + + mc.draw_command( + &mut activation.context, + DrawCommand::CurveTo { x1, y1, x2, y2 }, + ); + } + } + } + + Ok(Value::Undefined) +} + /// Construct `Graphics`'s class. pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { let class = Class::new( @@ -101,6 +147,10 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> QName::new(Namespace::public(), "clear"), Method::from_builtin(clear), )); + write.define_instance_trait(Trait::from_method( + QName::new(Namespace::public(), "curveTo"), + Method::from_builtin(curve_to), + )); class }