From b0143ff918bbc7f4af0060f5f53e0fa73ec32c8c Mon Sep 17 00:00:00 2001 From: Mike Welsh Date: Tue, 15 Jun 2021 11:27:55 -0700 Subject: [PATCH] core: Add Player::mouse_pressed_object --- core/src/avm1/object/script_object.rs | 1 + core/src/avm1/test_utils.rs | 1 + core/src/context.rs | 4 ++++ core/src/player.rs | 14 ++++++++++++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/src/avm1/object/script_object.rs b/core/src/avm1/object/script_object.rs index 02b02073f..791051864 100644 --- a/core/src/avm1/object/script_object.rs +++ b/core/src/avm1/object/script_object.rs @@ -788,6 +788,7 @@ mod tests { log: &mut NullLogBackend::new(), video: &mut NullVideoBackend::new(), mouse_hovered_object: None, + mouse_pressed_object: None, mouse_position: &(Twips::ZERO, Twips::ZERO), drag_object: &mut None, player: None, diff --git a/core/src/avm1/test_utils.rs b/core/src/avm1/test_utils.rs index 767bad85c..328e43cd3 100644 --- a/core/src/avm1/test_utils.rs +++ b/core/src/avm1/test_utils.rs @@ -60,6 +60,7 @@ where log: &mut NullLogBackend::new(), video: &mut NullVideoBackend::new(), mouse_hovered_object: None, + mouse_pressed_object: None, mouse_position: &(Twips::ZERO, Twips::ZERO), drag_object: &mut None, player: None, diff --git a/core/src/context.rs b/core/src/context.rs index 5bfc594e4..7c2dc723d 100644 --- a/core/src/context.rs +++ b/core/src/context.rs @@ -95,6 +95,9 @@ pub struct UpdateContext<'a, 'gc, 'gc_context> { /// The display object that the mouse is currently hovering over. pub mouse_hovered_object: Option>, + /// If the mouse is down, the display object that the mouse is currently pressing. + pub mouse_pressed_object: Option>, + /// The location of the mouse when it was last over the player. pub mouse_position: &'a (Twips, Twips), @@ -266,6 +269,7 @@ impl<'a, 'gc, 'gc_context> UpdateContext<'a, 'gc, 'gc_context> { rng: self.rng, stage: self.stage, mouse_hovered_object: self.mouse_hovered_object, + mouse_pressed_object: self.mouse_pressed_object, mouse_position: self.mouse_position, drag_object: self.drag_object, player: self.player.clone(), diff --git a/core/src/player.rs b/core/src/player.rs index 16acd34cd..5708ff66b 100644 --- a/core/src/player.rs +++ b/core/src/player.rs @@ -59,7 +59,11 @@ struct GcRootData<'gc> { /// accessed in AVM2. stage: Stage<'gc>, - mouse_hovered_object: Option>, // TODO: Remove GcCell wrapped inside GcCell. + /// The display object that the mouse is currently hovering over. + mouse_hovered_object: Option>, + + /// If the mouse is down, the display object that the mouse is currently pressing. + mouse_pressed_object: Option>, /// The object being dragged via a `startDrag` action. drag_object: Option>, @@ -265,6 +269,7 @@ impl Player { library: Library::empty(gc_context), stage: Stage::empty(gc_context, movie_width, movie_height), mouse_hovered_object: None, + mouse_pressed_object: None, drag_object: None, avm1: Avm1::new(gc_context, NEWEST_PLAYER_VERSION), avm2: Avm2::new(gc_context), @@ -1354,6 +1359,7 @@ impl Player { self.gc_arena.mutate(|gc_context, gc_root| { let mut root_data = gc_root.0.write(gc_context); let mouse_hovered_object = root_data.mouse_hovered_object; + let mouse_pressed_object = root_data.mouse_pressed_object; let focus_tracker = root_data.focus_tracker; let ( stage, @@ -1384,6 +1390,7 @@ impl Player { gc_context, stage, mouse_hovered_object, + mouse_pressed_object, mouse_position, drag_object, player, @@ -1430,7 +1437,10 @@ impl Player { .map(|clip| clip.current_frame()); // Hovered object may have been updated; copy it back to the GC root. - root_data.mouse_hovered_object = update_context.mouse_hovered_object; + let mouse_hovered_object = update_context.mouse_hovered_object; + let mouse_pressed_object = update_context.mouse_pressed_object; + root_data.mouse_hovered_object = mouse_hovered_object; + root_data.mouse_pressed_object = mouse_pressed_object; ret })