Skip to content

Commit

Permalink
core: Add click index to ClipEvent::Release
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarosh authored and Dinnerbone committed Jul 15, 2024
1 parent 6fa2f41 commit 0b64bc6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/src/display_object/avm1_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ impl<'gc> TInteractiveObject<'gc> for Avm1Button<'gc> {
Some(ButtonActionCondition::OVER_UP_TO_OVER_DOWN),
static_data.over_to_down_sound.as_ref(),
),
ClipEvent::Release => (
ClipEvent::Release { .. } => (
ButtonState::Over,
Some(ButtonActionCondition::OVER_DOWN_TO_OVER_UP),
static_data.down_to_over_sound.as_ref(),
Expand Down
4 changes: 3 additions & 1 deletion core/src/display_object/avm2_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,9 @@ impl<'gc> TInteractiveObject<'gc> for Avm2Button<'gc> {
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::Release { .. } => {
(ButtonState::Over, static_data.down_to_over_sound.as_ref())
}
ClipEvent::ReleaseOutside => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),
ClipEvent::MouseUpInside => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),
ClipEvent::RollOut { .. } => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),
Expand Down
2 changes: 1 addition & 1 deletion core/src/display_object/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ pub trait TInteractiveObject<'gc>:

Avm2::dispatch_event(&mut activation.context, avm2_event, target).into()
}
ClipEvent::Release => {
ClipEvent::Release { .. } => {
let read = self.raw_interactive();
let last_click = read.last_click;
let this_click = Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion core/src/display_object/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,7 @@ 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 { .. } => {
Expand Down
9 changes: 6 additions & 3 deletions core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ pub enum ClipEvent<'gc> {
/// This is a targeted equivalent to `MouseUp` and is available in both
/// AVM1 and AVM2. The target of this event is the last target of the
/// `Press` event.
Release,
Release {
/// The index of this click, same as the index of the last [`ClipEvent::Press`] event.
index: usize,
},

/// Right mouse button was released inside a previously-pressed display object.
///
Expand Down Expand Up @@ -350,7 +353,7 @@ impl<'gc> ClipEvent<'gc> {
ClipEvent::Press { .. } => Some(ClipEventFlag::PRESS),
ClipEvent::RollOut { .. } => Some(ClipEventFlag::ROLL_OUT),
ClipEvent::RollOver { .. } => Some(ClipEventFlag::ROLL_OVER),
ClipEvent::Release => Some(ClipEventFlag::RELEASE),
ClipEvent::Release { .. } => Some(ClipEventFlag::RELEASE),
ClipEvent::ReleaseOutside => Some(ClipEventFlag::RELEASE_OUTSIDE),
ClipEvent::Unload => Some(ClipEventFlag::UNLOAD),
_ => None,
Expand Down Expand Up @@ -407,7 +410,7 @@ impl<'gc> ClipEvent<'gc> {
ClipEvent::Press { .. } => Some("onPress"),
ClipEvent::RollOut { .. } => Some("onRollOut"),
ClipEvent::RollOver { .. } => Some("onRollOver"),
ClipEvent::Release => Some("onRelease"),
ClipEvent::Release { .. } => Some("onRelease"),
ClipEvent::ReleaseOutside => Some("onReleaseOutside"),
ClipEvent::Unload => Some("onUnload"),
_ => None,
Expand Down
6 changes: 4 additions & 2 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ impl Player {
// The button/clip is pressed and then immediately released.
// We do not have to wait for KeyUp.
focus.handle_clip_event(context, ClipEvent::Press { index: 0 });
focus.handle_clip_event(context, ClipEvent::Release);
focus.handle_clip_event(context, ClipEvent::Release { index: 0 });
}

if let PlayerEvent::KeyDown { key_code, .. } = event {
Expand Down Expand Up @@ -1621,7 +1621,9 @@ impl Player {
}
if released_inside {
let event = match button {
MouseButton::Left => ClipEvent::Release,
MouseButton::Left => ClipEvent::Release {
index: context.input.last_click_index(),
},
MouseButton::Right => ClipEvent::RightRelease,
MouseButton::Middle => ClipEvent::MiddleRelease,
_ => unreachable!(),
Expand Down

0 comments on commit 0b64bc6

Please sign in to comment.