diff --git a/core/src/avm2/globals.rs b/core/src/avm2/globals.rs index 7dd13500e..4e05f2104 100644 --- a/core/src/avm2/globals.rs +++ b/core/src/avm2/globals.rs @@ -846,6 +846,7 @@ pub fn load_player_globals<'gc>( flash::ui::contextmenu::create_class(mc), script ); + class(activation, flash::ui::mouse::create_class(mc), script)?; // package `flash.net` avm2_system_class!( diff --git a/core/src/avm2/globals/flash/ui.rs b/core/src/avm2/globals/flash/ui.rs index 7a8eb060e..708f1f9d4 100644 --- a/core/src/avm2/globals/flash/ui.rs +++ b/core/src/avm2/globals/flash/ui.rs @@ -1,3 +1,4 @@ //! `flash.ui` namespace pub mod contextmenu; +pub mod mouse; diff --git a/core/src/avm2/globals/flash/ui/mouse.rs b/core/src/avm2/globals/flash/ui/mouse.rs new file mode 100644 index 000000000..9186a6fff --- /dev/null +++ b/core/src/avm2/globals/flash/ui/mouse.rs @@ -0,0 +1,63 @@ +//! `flash.ui.Mouse` builtin + +use crate::avm2::activation::Activation; +use crate::avm2::class::{Class, ClassAttributes}; +use crate::avm2::method::{Method, NativeMethodImpl}; +use crate::avm2::names::{Namespace, QName}; +use crate::avm2::object::Object; +use crate::avm2::value::Value; +use crate::avm2::Error; +use gc_arena::{GcCell, MutationContext}; + +fn instance_init<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + Err("The Mouse class cannot be constructed.".into()) +} + +fn class_init<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + Ok(Value::Undefined) +} + +fn hide<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + activation.context.ui.set_mouse_visible(false); + Ok(Value::Undefined) +} + +fn show<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + activation.context.ui.set_mouse_visible(true); + Ok(Value::Undefined) +} + +pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { + let class = Class::new( + QName::new(Namespace::package("flash.ui"), "Mouse"), + Some(QName::new(Namespace::package(""), "Object").into()), + Method::from_builtin(instance_init, "", mc), + Method::from_builtin(class_init, "", mc), + mc, + ); + + let mut write = class.write(mc); + + write.set_attributes(ClassAttributes::SEALED | ClassAttributes::FINAL); + + const PUBLIC_CLASS_METHODS: &[(&str, NativeMethodImpl)] = &[("show", show), ("hide", hide)]; + write.define_public_builtin_class_methods(mc, PUBLIC_CLASS_METHODS); + + class +}