Calculate the mouse focus inverse transform only when needed
Revival of #49158 Co-authored-by: Marcel Admiraal <madmiraal@users.noreply.github.com>
This commit is contained in:
parent
f5f7d11ac4
commit
0d6d5e6421
2 changed files with 10 additions and 32 deletions
|
@ -1401,7 +1401,7 @@ Control *Viewport::gui_find_control(const Point2 &p_global) {
|
|||
xform = sw->get_canvas_transform();
|
||||
}
|
||||
|
||||
Control *ret = _gui_find_control_at_pos(sw, p_global, xform, gui.focus_inv_xform);
|
||||
Control *ret = _gui_find_control_at_pos(sw, p_global, xform);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -1410,7 +1410,7 @@ Control *Viewport::gui_find_control(const Point2 &p_global) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform) {
|
||||
Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform) {
|
||||
if (!p_node->is_visible()) {
|
||||
return nullptr; // Canvas item hidden, discard.
|
||||
}
|
||||
|
@ -1430,7 +1430,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
|
|||
continue;
|
||||
}
|
||||
|
||||
Control *ret = _gui_find_control_at_pos(ci, p_global, matrix, r_inv_xform);
|
||||
Control *ret = _gui_find_control_at_pos(ci, p_global, matrix);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -1448,7 +1448,6 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
|
|||
|
||||
Control *drag_preview = _gui_get_drag_preview();
|
||||
if (!drag_preview || (c != drag_preview && !drag_preview->is_ancestor_of(c))) {
|
||||
r_inv_xform = matrix;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -1495,12 +1494,11 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||
|
||||
Point2 mpos = mb->get_position();
|
||||
if (mb->is_pressed()) {
|
||||
Size2 pos = mpos;
|
||||
if (!gui.mouse_focus_mask.is_empty()) {
|
||||
// Do not steal mouse focus and stuff while a focus mask exists.
|
||||
gui.mouse_focus_mask.set_flag(mouse_button_to_mask(mb->get_button_index()));
|
||||
} else {
|
||||
gui.mouse_focus = gui_find_control(pos);
|
||||
gui.mouse_focus = gui_find_control(mpos);
|
||||
gui.last_mouse_focus = gui.mouse_focus;
|
||||
|
||||
if (!gui.mouse_focus) {
|
||||
|
@ -1519,10 +1517,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||
|
||||
mb = mb->xformed_by(Transform2D()); // Make a copy of the event.
|
||||
|
||||
mb->set_global_position(pos);
|
||||
|
||||
pos = gui.focus_inv_xform.xform(pos);
|
||||
|
||||
Point2 pos = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(mpos);
|
||||
mb->set_position(pos);
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
@ -1586,11 +1581,8 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||
return;
|
||||
}
|
||||
|
||||
Size2 pos = mpos;
|
||||
|
||||
mb = mb->xformed_by(Transform2D()); // Make a copy.
|
||||
mb->set_global_position(pos);
|
||||
pos = gui.focus_inv_xform.xform(pos);
|
||||
Point2 pos = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(mpos);
|
||||
mb->set_position(pos);
|
||||
|
||||
Control *mouse_focus = gui.mouse_focus;
|
||||
|
@ -1893,11 +1885,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||
bool stopped = false;
|
||||
if (over->can_process()) {
|
||||
touch_event = touch_event->xformed_by(Transform2D()); // Make a copy.
|
||||
if (over == gui.mouse_focus) {
|
||||
pos = gui.focus_inv_xform.xform(pos);
|
||||
} else {
|
||||
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
|
||||
}
|
||||
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
|
||||
touch_event->set_position(pos);
|
||||
stopped = _gui_call_input(over, touch_event);
|
||||
}
|
||||
|
@ -1912,11 +1900,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||
Control *over = control_id.is_valid() ? Object::cast_to<Control>(ObjectDB::get_instance(control_id)) : nullptr;
|
||||
if (over && over->can_process()) {
|
||||
touch_event = touch_event->xformed_by(Transform2D()); // Make a copy.
|
||||
if (over == gui.last_mouse_focus) {
|
||||
pos = gui.focus_inv_xform.xform(pos);
|
||||
} else {
|
||||
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
|
||||
}
|
||||
pos = gui.last_mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(pos);
|
||||
touch_event->set_position(pos);
|
||||
|
||||
stopped = _gui_call_input(over, touch_event);
|
||||
|
@ -1942,11 +1926,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||
bool stopped = false;
|
||||
if (over->can_process()) {
|
||||
gesture_event = gesture_event->xformed_by(Transform2D()); // Make a copy.
|
||||
if (over == gui.mouse_focus) {
|
||||
pos = gui.focus_inv_xform.xform(pos);
|
||||
} else {
|
||||
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
|
||||
}
|
||||
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
|
||||
gesture_event->set_position(pos);
|
||||
stopped = _gui_call_input(over, gesture_event);
|
||||
}
|
||||
|
@ -2393,7 +2373,6 @@ void Viewport::_post_gui_grab_click_focus() {
|
|||
}
|
||||
|
||||
gui.mouse_focus = focus_grabber;
|
||||
gui.focus_inv_xform = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse();
|
||||
click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
|
|
@ -374,7 +374,6 @@ private:
|
|||
ObjectID drag_preview_id;
|
||||
Ref<SceneTreeTimer> tooltip_timer;
|
||||
double tooltip_delay = 0.0;
|
||||
Transform2D focus_inv_xform;
|
||||
bool roots_order_dirty = false;
|
||||
List<Control *> roots;
|
||||
int canvas_sort_index = 0; //for sorting items with canvas as root
|
||||
|
@ -403,7 +402,7 @@ private:
|
|||
void _gui_call_notification(Control *p_control, int p_what);
|
||||
|
||||
void _gui_sort_roots();
|
||||
Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform);
|
||||
Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform);
|
||||
|
||||
void _gui_input_event(Ref<InputEvent> p_event);
|
||||
void _perform_drop(Control *p_control = nullptr, Point2 p_pos = Point2());
|
||||
|
|
Loading…
Reference in a new issue