avm2: Implement BitmapData.rect and stub BitmapData.applyFilter

These are the last BitmapData methods needed for Solarmax
(the victory screen after beating the last level now renders).
This commit is contained in:
Aaron Hill 2022-09-09 12:46:29 -05:00
parent bb138d9082
commit ca030169f7
4 changed files with 44 additions and 1 deletions

View File

@ -452,6 +452,37 @@ pub fn dispose<'gc>(
Ok(Value::Undefined)
}
/// Implement `BitmapData.rect`
pub fn rect<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(bitmap_data) = this.and_then(|this| this.as_bitmap_data()) {
let bd = bitmap_data.read();
return Ok(activation
.avm2()
.classes()
.rectangle
.construct(
activation,
&[0.into(), 0.into(), bd.width().into(), bd.height().into()],
)?
.into());
}
Ok(Value::Undefined)
}
/// Implement `BitmapData.applyFilter`
pub fn apply_filter<'gc>(
_activation: &mut Activation<'_, 'gc, '_>,
_this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
log::warn!("BitmapData.applyFilter: Not yet implemented");
Ok(Value::Undefined)
}
/// Construct `BitmapData`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new(
@ -476,6 +507,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
)] = &[
("width", Some(width), None),
("height", Some(height), None),
("rect", Some(rect), None),
("transparent", Some(transparent), None),
];
write.define_public_builtin_instance_properties(mc, PUBLIC_INSTANCE_PROPERTIES);
@ -490,6 +522,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
("draw", draw),
("fillRect", fill_rect),
("dispose", dispose),
("applyFilter", apply_filter),
];
write.define_public_builtin_instance_methods(mc, PUBLIC_INSTANCE_METHODS);

View File

@ -1,4 +1,4 @@
package {
package {
public class Test {
}
}
@ -14,6 +14,9 @@ trace(bd.width);
trace("///bd.height;");
trace(bd.height);
trace("///bd.rect;");
trace(bd.rect);
trace("///bd.transparent;");
trace(bd.transparent);
@ -29,6 +32,9 @@ trace(bd.width);
trace("///bd.height;");
trace(bd.height);
trace("///bd.rect;");
trace(bd.rect);
trace("///bd.transparent;");
trace(bd.transparent);

View File

@ -3,6 +3,8 @@
128
///bd.height;
128
///bd.rect;
(x=0, y=0, w=128, h=128)
///bd.transparent;
true
///bd.getPixel(0,0);
@ -12,6 +14,8 @@ true
128
///bd.height;
128
///bd.rect;
(x=0, y=0, w=128, h=128)
///bd.transparent;
false
///bd.getPixel(0,0);