Added changes as Adrian recommended

This commit is contained in:
michiel2005 2023-06-21 11:05:35 +02:00 committed by kmeisthax
parent 412f2880ad
commit 8834b3b42b
2 changed files with 18 additions and 18 deletions

View File

@ -1687,8 +1687,7 @@ pub trait TDisplayObject<'gc>:
fn state(&self) -> Option<ButtonState> { fn state(&self) -> Option<ButtonState> {
None None
} }
fn set_state(self, _context: &mut crate::context::UpdateContext<'_, 'gc>, _state: ButtonState) { fn set_state(self, _context: &mut UpdateContext<'_, 'gc>, _state: ButtonState) {}
}
/// Run any start-of-frame actions for this display object. /// Run any start-of-frame actions for this display object.
/// ///
/// When fired on `Stage`, this also emits the AVM2 `enterFrame` broadcast. /// When fired on `Stage`, this also emits the AVM2 `enterFrame` broadcast.

View File

@ -1259,14 +1259,13 @@ impl Player {
if !context.is_action_script_3() && hovered.as_displayobject().avm1_removed() { if !context.is_action_script_3() && hovered.as_displayobject().avm1_removed() {
context.mouse_over_object = None; context.mouse_over_object = None;
if let Some(new_object) = new_over_object { if let Some(new_object) = new_over_object {
if new_object.as_displayobject().id() == hovered.as_displayobject().id() if Self::check_display_object_equality(
&& new_object.as_displayobject().depth() new_object.as_displayobject(),
== hovered.as_displayobject().depth() hovered.as_displayobject(),
&& Arc::ptr_eq( ) && Arc::ptr_eq(
&new_object.as_displayobject().movie(), &new_object.as_displayobject().movie(),
&hovered.as_displayobject().movie(), &hovered.as_displayobject().movie(),
) ) {
{
if let Some(state) = hovered.as_displayobject().state() { if let Some(state) = hovered.as_displayobject().state() {
new_object.as_displayobject().set_state(context, state); new_object.as_displayobject().set_state(context, state);
} }
@ -1288,19 +1287,18 @@ impl Player {
); );
} }
if let Some(new_object) = display_object { if let Some(new_down_object) = display_object {
if new_object.id() == down_object.as_displayobject().id() if new_down_object.depth() == new_down_object.depth()
&& new_object.depth() == new_object.depth()
&& Arc::ptr_eq( && Arc::ptr_eq(
&new_object.movie(), &new_down_object.movie(),
&down_object.as_displayobject().movie(), &down_object.as_displayobject().movie(),
) )
{ {
if let Some(state) = down_object.as_displayobject().state() { if let Some(state) = down_object.as_displayobject().state() {
new_object.set_state(context, state); new_down_object.set_state(context, state);
} }
context.mouse_down_object = if display_object.is_some() { context.mouse_down_object = if display_object.is_some() {
new_object.as_interactive() new_down_object.as_interactive()
} else { } else {
None None
}; };
@ -1495,6 +1493,10 @@ impl Player {
needs_render needs_render
} }
//Checks if two displayObjects have the same depth and id
fn check_display_object_equality(object1: DisplayObject, object2: DisplayObject) -> bool {
object1.depth() == object2.depth() && object1.id() == object2.id()
}
///This searches for a display object by it's id. ///This searches for a display object by it's id.
///When a button is being held down but the mouse stops hovering over the object ///When a button is being held down but the mouse stops hovering over the object
///we need to know if th button is still there after goto. ///we need to know if th button is still there after goto.
@ -1505,8 +1507,7 @@ impl Player {
) -> Option<DisplayObject<'gc>> { ) -> Option<DisplayObject<'gc>> {
if let Some(parent) = obj.as_container() { if let Some(parent) = obj.as_container() {
for child in parent.iter_render_list() { for child in parent.iter_render_list() {
if child.id() == previous_object.id() if Self::check_display_object_equality(child, previous_object)
&& child.depth() == previous_object.depth()
&& Arc::ptr_eq(&child.movie(), &previous_object.movie()) && Arc::ptr_eq(&child.movie(), &previous_object.movie())
{ {
return Some(child); return Some(child);