avm2: Implement `Graphics.curveTo`
This commit is contained in:
parent
71b6bca100
commit
3dfeeacfcc
|
@ -9,8 +9,9 @@ use crate::avm2::traits::Trait;
|
||||||
use crate::avm2::value::Value;
|
use crate::avm2::value::Value;
|
||||||
use crate::avm2::Error;
|
use crate::avm2::Error;
|
||||||
use crate::display_object::TDisplayObject;
|
use crate::display_object::TDisplayObject;
|
||||||
|
use crate::shape_utils::DrawCommand;
|
||||||
use gc_arena::{GcCell, MutationContext};
|
use gc_arena::{GcCell, MutationContext};
|
||||||
use swf::{Color, FillStyle};
|
use swf::{Color, FillStyle, Twips};
|
||||||
|
|
||||||
/// Implements `flash.display.Graphics`'s instance constructor.
|
/// Implements `flash.display.Graphics`'s instance constructor.
|
||||||
pub fn instance_init<'gc>(
|
pub fn instance_init<'gc>(
|
||||||
|
@ -81,6 +82,51 @@ pub fn clear<'gc>(
|
||||||
Ok(Value::Undefined)
|
Ok(Value::Undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements `Graphics.curveTo`.
|
||||||
|
pub fn curve_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 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.
|
/// Construct `Graphics`'s class.
|
||||||
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
|
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
|
||||||
let class = Class::new(
|
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"),
|
QName::new(Namespace::public(), "clear"),
|
||||||
Method::from_builtin(clear),
|
Method::from_builtin(clear),
|
||||||
));
|
));
|
||||||
|
write.define_instance_trait(Trait::from_method(
|
||||||
|
QName::new(Namespace::public(), "curveTo"),
|
||||||
|
Method::from_builtin(curve_to),
|
||||||
|
));
|
||||||
|
|
||||||
class
|
class
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue