avm2: Implement `Graphics.lineTo`

This commit is contained in:
David Wendt 2021-02-11 17:41:23 -05:00 committed by Mike Welsh
parent 9464a8800a
commit 15d3a1e99d
1 changed files with 34 additions and 0 deletions

View File

@ -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<Object<'gc>>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, 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
}