avm2: Add PressAndTapGestureEvent

This commit is contained in:
Marc Bornand 2023-07-26 22:56:19 +02:00 committed by Adrian Wielgosik
parent f61c1f8713
commit c8e4ec98f0
6 changed files with 111 additions and 22 deletions

View File

@ -5,5 +5,6 @@ pub mod event_dispatcher;
pub mod gesture_event;
pub mod keyboard_event;
pub mod mouse_event;
pub mod press_and_tap_gesture_event;
pub mod timer_event;
pub mod touch_event;

View File

@ -0,0 +1,50 @@
package flash.events
{
public class PressAndTapGestureEvent extends GestureEvent
{
public static const GESTURE_PRESS_AND_TAP : String = "gesturePressAndTap";
private var _tapLocalX: Number;
private var _tapLocalY: Number;
public function PressAndTapGestureEvent(type:String, bubbles:Boolean = true, cancelable:Boolean = false, phase:String = null,
localX:Number = 0, localY:Number = 0, tapLocalX:Number = 0, tapLocalY:Number = 0,
ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false,
controlKey:Boolean = false) {
super(type, bubbles, cancelable, phase, localX, localY, ctrlKey, altKey, shiftKey, controlKey);
this._tapLocalX = tapLocalX;
this._tapLocalY = tapLocalY;
}
override public function clone():Event {
return new PressAndTapGestureEvent(this.type, this.bubbles, this.cancelable, this.phase, this.localX, this.localY,
this.tapLocalX, this.tapLocalY, this.ctrlKey, this.altKey, this.shiftKey, this.controlKey);
}
override public function toString():String
{
// should fail on FP too, see discussion https://github.com/ruffle-rs/ruffle/pull/12330
return this.formatToString("GestureEvent","type","bubbles","cancelable","args");
}
public function get tapLocalX(): Number {
return this._tapLocalX;
}
public function set tapLocalX(value: Number): void {
this._tapLocalX = value;
}
public function get tapLocalY(): Number {
return this._tapLocalY;
}
public function set tapLocalY(value: Number): void {
this._tapLocalY = value;
}
public native function get tapStageX():Number;
public native function get tapStageY():Number;
}
}

View File

@ -4,20 +4,18 @@ use crate::avm2::object::Object;
use crate::avm2::value::Value;
use crate::avm2::Error;
// Borrow mouse_event's `stageX` getter
pub fn get_stage_x<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
args: &[Value<'gc>],
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
mouse_event::get_stage_x(activation, this, args)
mouse_event::local_to_stage_x(activation, this, "localX", "localY")
}
// Borrow mouse_event's `stageY` getter
pub fn get_stage_y<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
args: &[Value<'gc>],
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
mouse_event::get_stage_y(activation, this, args)
mouse_event::local_to_stage_y(activation, this, "localX", "localY")
}

View File

@ -10,13 +10,40 @@ pub fn get_stage_x<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
local_to_stage_x(activation, this, "localX", "localY")
}
/// Implements `stageY`'s getter.
pub fn get_stage_y<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
local_to_stage_y(activation, this, "localX", "localY")
}
pub fn update_after_event<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
*activation.context.needs_render = true;
Ok(Value::Undefined)
}
pub(super) fn local_to_stage_x<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
label_x: &'static str,
label_y: &'static str,
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(evt) = this.as_event() {
let local_x = this
.get_public_property("localX", activation)?
.get_public_property(label_x, activation)?
.coerce_to_number(activation)?;
let local_y = this
.get_public_property("localY", activation)?
.get_public_property(label_y, activation)?
.coerce_to_number(activation)?;
if local_x.is_nan() || local_y.is_nan() {
@ -35,18 +62,18 @@ pub fn get_stage_x<'gc>(
Ok(Value::Undefined)
}
/// Implements `stageY`'s getter.
pub fn get_stage_y<'gc>(
pub(super) fn local_to_stage_y<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
_args: &[Value<'gc>],
label_x: &'static str,
label_y: &'static str,
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(evt) = this.as_event() {
let local_x = this
.get_public_property("localX", activation)?
.get_public_property(label_x, activation)?
.coerce_to_number(activation)?;
let local_y = this
.get_public_property("localY", activation)?
.get_public_property(label_y, activation)?
.coerce_to_number(activation)?;
if local_x.is_nan() || local_y.is_nan() {
@ -64,12 +91,3 @@ pub fn get_stage_y<'gc>(
Ok(Value::Undefined)
}
pub fn update_after_event<'gc>(
activation: &mut Activation<'_, 'gc>,
_this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
*activation.context.needs_render = true;
Ok(Value::Undefined)
}

View File

@ -0,0 +1,21 @@
use crate::avm2::activation::Activation;
use crate::avm2::globals::flash::events::mouse_event;
use crate::avm2::object::Object;
use crate::avm2::value::Value;
use crate::avm2::Error;
pub fn get_tap_stage_x<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
mouse_event::local_to_stage_x(activation, this, "localTapX", "localTapY")
}
pub fn get_tap_stage_y<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
mouse_event::local_to_stage_y(activation, this, "localTapX", "localTapY")
}

View File

@ -160,6 +160,7 @@ include "flash/events/IOErrorEvent.as"
include "flash/events/KeyboardEvent.as"
include "flash/events/NetDataEvent.as"
include "flash/events/NetStatusEvent.as"
include "flash/events/PressAndTapGestureEvent.as"
include "flash/events/ProgressEvent.as"
include "flash/events/SampleDataEvent.as"
include "flash/events/SecurityErrorEvent.as"