core: Fix drag constraint with `lockCenter` set to `false`

Previously `last_mouse_position` was updated irrespectively of
whether the dragged object was inside or outside the constraint
box. Change it follow mouse deltas, after clamping is performed.

Fixes #11254.
This commit is contained in:
relrelb 2023-06-11 00:19:28 +03:00
parent dced6445ee
commit 226a2be2bd
1 changed files with 10 additions and 6 deletions

View File

@ -1205,20 +1205,24 @@ impl Player {
let global_to_local_matrix = local_to_global_matrix.inverse().unwrap_or_default(); let global_to_local_matrix = local_to_global_matrix.inverse().unwrap_or_default();
let new_position = if drag_object.lock_center { let new_position = if drag_object.lock_center {
global_to_local_matrix * mouse_position let new_position = global_to_local_matrix * mouse_position;
drag_object.constraint.clamp(new_position)
} else { } else {
let mouse_delta = mouse_position - drag_object.last_mouse_position;
// TODO: Introduce `DisplayObject::position()`? // TODO: Introduce `DisplayObject::position()`?
let position = Point::new(display_object.x(), display_object.y()); let position = Point::new(display_object.x(), display_object.y());
position + global_to_local_matrix * mouse_delta let mouse_delta = mouse_position - drag_object.last_mouse_position;
}; let new_position = position + global_to_local_matrix * mouse_delta;
let new_position = drag_object.constraint.clamp(new_position); let new_position = drag_object.constraint.clamp(new_position);
let mouse_delta = local_to_global_matrix * (new_position - position);
drag_object.last_mouse_position += mouse_delta;
new_position
};
// TODO: Introduce `DisplayObject::set_position()`? // TODO: Introduce `DisplayObject::set_position()`?
display_object.set_x(context.gc_context, new_position.x); display_object.set_x(context.gc_context, new_position.x);
display_object.set_y(context.gc_context, new_position.y); display_object.set_y(context.gc_context, new_position.y);
drag_object.last_mouse_position = mouse_position;
// Update `_droptarget` property of dragged object. // Update `_droptarget` property of dragged object.
if let Some(movie_clip) = display_object.as_movie_clip() { if let Some(movie_clip) = display_object.as_movie_clip() {