core: Issue `mouseOver`, `mouseOut`, etc when dragging.

This commit is contained in:
David Wendt 2021-12-09 19:34:31 -05:00 committed by Mike Welsh
parent 42b606d058
commit 84d1d5aa76
6 changed files with 45 additions and 16 deletions

View File

@ -446,12 +446,12 @@ impl<'gc> TInteractiveObject<'gc> for Avm1Button<'gc> {
let static_data = write.static_data;
let static_data = static_data.read();
let (new_state, condition, sound) = match event {
ClipEvent::DragOut => (
ClipEvent::DragOut { .. } => (
ButtonState::Over,
ButtonActionCondition::OVER_DOWN_TO_OUT_DOWN,
None,
),
ClipEvent::DragOver => (
ClipEvent::DragOver { .. } => (
ButtonState::Down,
ButtonActionCondition::OUT_DOWN_TO_OVER_DOWN,
None,

View File

@ -749,8 +749,8 @@ impl<'gc> TInteractiveObject<'gc> for Avm2Button<'gc> {
let static_data = write.static_data;
let static_data = static_data.read();
let (new_state, sound) = match event {
ClipEvent::DragOut => (ButtonState::Over, None),
ClipEvent::DragOver => (ButtonState::Down, None),
ClipEvent::DragOut { .. } => (ButtonState::Over, None),
ClipEvent::DragOver { .. } => (ButtonState::Down, None),
ClipEvent::Press => (ButtonState::Down, static_data.over_to_down_sound.as_ref()),
ClipEvent::Release => (ButtonState::Over, static_data.down_to_over_sound.as_ref()),
ClipEvent::ReleaseOutside => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),

View File

@ -264,7 +264,7 @@ pub trait TInteractiveObject<'gc>:
ClipEventResult::Handled
}
ClipEvent::RollOut { to } => {
ClipEvent::RollOut { to } | ClipEvent::DragOut { to } => {
let mut avm2_event = Avm2Event::new(
"mouseOut",
Avm2EventData::mouse_event(context, self.as_displayobject(), to, 0),
@ -302,7 +302,7 @@ pub trait TInteractiveObject<'gc>:
ClipEventResult::Handled
}
ClipEvent::RollOver { from } => {
ClipEvent::RollOver { from } | ClipEvent::DragOver { from } => {
let lca = lowest_common_ancestor(
self.as_displayobject(),
from.map(|t| t.as_displayobject())

View File

@ -2064,10 +2064,10 @@ impl<'gc> TInteractiveObject<'gc> for MovieClip<'gc> {
) -> ClipEventResult {
let frame_name = match event {
ClipEvent::RollOut { .. } | ClipEvent::ReleaseOutside => Some(WStr::from_units(b"_up")),
ClipEvent::RollOver { .. } | ClipEvent::Release | ClipEvent::DragOut => {
ClipEvent::RollOver { .. } | ClipEvent::Release | ClipEvent::DragOut { .. } => {
Some(WStr::from_units(b"_over"))
}
ClipEvent::Press | ClipEvent::DragOver => Some(WStr::from_units(b"_down")),
ClipEvent::Press | ClipEvent::DragOver { .. } => Some(WStr::from_units(b"_down")),
_ => None,
};

View File

@ -77,8 +77,27 @@ pub enum ClipEventResult {
pub enum ClipEvent<'gc> {
Construct,
Data,
DragOut,
DragOver,
/// Mouse moved out of a display object while the primary button is held
/// down.
///
/// This is a targeted equivalent to `MouseMove` and is available in both
/// AVM1 and AVM2. In AVM2, it is dispatched identically to `RollOut`, with
/// the only difference being that the `buttonDown` flag is set to true.
DragOut {
to: Option<InteractiveObject<'gc>>,
},
/// Mouse moved into of a display object while the primary button is held
/// down.
///
/// This is a targeted equivalent to `MouseMove` and is available in both
/// AVM1 and AVM2. In AVM2, it is dispatched identically to `RollOver`,
/// with the only difference being that the `buttonDown` flag is set to
/// true.
DragOver {
from: Option<InteractiveObject<'gc>>,
},
EnterFrame,
Initialize,
KeyUp,
@ -182,8 +201,8 @@ impl<'gc> ClipEvent<'gc> {
match self {
ClipEvent::Construct => ClipEventFlag::CONSTRUCT,
ClipEvent::Data => ClipEventFlag::DATA,
ClipEvent::DragOut => ClipEventFlag::DRAG_OUT,
ClipEvent::DragOver => ClipEventFlag::DRAG_OVER,
ClipEvent::DragOut { .. } => ClipEventFlag::DRAG_OUT,
ClipEvent::DragOver { .. } => ClipEventFlag::DRAG_OVER,
ClipEvent::EnterFrame => ClipEventFlag::ENTER_FRAME,
ClipEvent::Initialize => ClipEventFlag::INITIALIZE,
ClipEvent::KeyDown => ClipEventFlag::KEY_DOWN,
@ -230,8 +249,8 @@ impl<'gc> ClipEvent<'gc> {
match self {
ClipEvent::Construct => None,
ClipEvent::Data => Some("onData"),
ClipEvent::DragOut => Some("onDragOut"),
ClipEvent::DragOver => Some("onDragOver"),
ClipEvent::DragOut { .. } => Some("onDragOut"),
ClipEvent::DragOver { .. } => Some("onDragOver"),
ClipEvent::EnterFrame => Some("onEnterFrame"),
ClipEvent::Initialize => None,
ClipEvent::KeyDown => Some("onKeyDown"),

View File

@ -1145,13 +1145,23 @@ impl Player {
cur_over_object,
) {
// Dragged from outside the clicked object to the inside.
events.push((down_object, ClipEvent::DragOut));
events.push((
down_object,
ClipEvent::DragOut {
to: new_over_object,
},
));
} else if InteractiveObject::option_ptr_eq(
context.mouse_down_object,
new_over_object,
) {
// Dragged from inside the clicked object to the outside.
events.push((down_object, ClipEvent::DragOver));
events.push((
down_object,
ClipEvent::DragOver {
from: cur_over_object,
},
));
}
}
} else {