avm2: Implement Graphics.copyFrom

This commit is contained in:
Aaron Hill 2023-06-30 15:32:42 -04:00
parent 3401971729
commit f7cbe3b7cd
5 changed files with 47 additions and 3 deletions

View File

@ -819,10 +819,25 @@ pub fn cubic_curve_to<'gc>(
/// Implements `Graphics.copyFrom`
pub fn copy_from<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
this: Option<Object<'gc>>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
avm2_stub_method!(activation, "flash.display.Graphics", "copyFrom");
if let Some(this) = this.and_then(|t| t.as_display_object()) {
let source = args
.get_object(activation, 0, "sourceGraphics")?
.as_display_object()
.expect("Bad sourceGraphics");
let source = source
.as_drawing(activation.context.gc_context)
.expect("Missing drawing for sourceGraphics");
let mut target_drawing = this
.as_drawing(activation.context.gc_context)
.expect("Missing drawing for target");
target_drawing.copy_from(&source);
}
Ok(Value::Undefined)
}

View File

@ -104,6 +104,23 @@ impl Drawing {
this
}
pub fn copy_from(&mut self, other: &Drawing) {
*self = Drawing {
render_handle: RefCell::new(None),
dirty: Cell::new(true),
shape_bounds: other.shape_bounds.clone(),
edge_bounds: other.edge_bounds.clone(),
paths: other.paths.clone(),
bitmaps: other.bitmaps.clone(),
current_fill: other.current_fill.clone(),
current_line: other.current_line.clone(),
pending_lines: other.pending_lines.clone(),
cursor: other.cursor,
fill_start: other.fill_start,
winding_rule: other.winding_rule,
}
}
pub fn set_winding_rule(&mut self, rule: FillRule) {
self.winding_rule = rule;
}

View File

@ -48,8 +48,20 @@
shape.graphics.moveTo(90, 20);
shape.graphics.lineTo(110, 20);
shape.graphics.moveTo(120, 20);
shape.graphics.beginFill(0xFF0000FF);
var partial = new Shape();
// These two commands should get overwritten by copyFrom
partial.graphics.drawCircle(0, 0, 30);
partial.graphics.beginFill(0xFFFF0000);
partial.graphics.copyFrom(shape.graphics);
partial.graphics.drawCircle(0, 0, 10);
partial.y = 100;
shape.graphics.lineTo(130, 20);
this.addChild(shape);
this.addChild(partial);
}
function cubicCircle() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB