From 15d3a1e99d1a9f60338af092367a4d7ed9266906 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Thu, 11 Feb 2021 17:41:23 -0500 Subject: [PATCH] avm2: Implement `Graphics.lineTo` --- .../avm2/globals/flash/display/graphics.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/src/avm2/globals/flash/display/graphics.rs b/core/src/avm2/globals/flash/display/graphics.rs index 97d841dea..93ae904c7 100644 --- a/core/src/avm2/globals/flash/display/graphics.rs +++ b/core/src/avm2/globals/flash/display/graphics.rs @@ -268,6 +268,36 @@ pub fn line_style<'gc>( Ok(Value::Undefined) } +/// Implements `Graphics.lineTo`. +pub fn line_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 x = Twips::from_pixels( + args.get(0) + .cloned() + .unwrap_or(Value::Undefined) + .coerce_to_number(activation)?, + ); + let y = Twips::from_pixels( + args.get(1) + .cloned() + .unwrap_or(Value::Undefined) + .coerce_to_number(activation)?, + ); + + mc.draw_command(&mut activation.context, DrawCommand::LineTo { x, y }); + } + } + } + + Ok(Value::Undefined) +} + /// Construct `Graphics`'s class. pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { let class = Class::new( @@ -300,6 +330,10 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> QName::new(Namespace::public(), "lineStyle"), Method::from_builtin(line_style), )); + write.define_instance_trait(Trait::from_method( + QName::new(Namespace::public(), "lineTo"), + Method::from_builtin(line_to), + )); class }