mirror of
https://github.com/godotengine/godot.git
synced 2025-02-13 06:10:58 +00:00
Merge pull request #18380 from groud/fix_spacebar_panning
Fixes 2d editor panning not working
This commit is contained in:
commit
e1ef2f538f
@ -896,7 +896,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||||||
bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) {
|
bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) {
|
||||||
Ref<InputEventMouseButton> b = p_event;
|
Ref<InputEventMouseButton> b = p_event;
|
||||||
if (b.is_valid()) {
|
if (b.is_valid()) {
|
||||||
if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
|
if (b->is_pressed() && b->get_button_index() == BUTTON_WHEEL_DOWN) {
|
||||||
// Scroll or pan down
|
// Scroll or pan down
|
||||||
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
||||||
view_offset.y += int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
view_offset.y += int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
||||||
@ -908,7 +908,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->get_button_index() == BUTTON_WHEEL_UP) {
|
if (b->is_pressed() && b->get_button_index() == BUTTON_WHEEL_UP) {
|
||||||
// Scroll or pan up
|
// Scroll or pan up
|
||||||
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
||||||
view_offset.y -= int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
view_offset.y -= int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
||||||
@ -920,7 +920,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->get_button_index() == BUTTON_WHEEL_LEFT) {
|
if (b->is_pressed() && b->get_button_index() == BUTTON_WHEEL_LEFT) {
|
||||||
// Pan left
|
// Pan left
|
||||||
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
||||||
view_offset.x -= int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
view_offset.x -= int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
||||||
@ -930,7 +930,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->get_button_index() == BUTTON_WHEEL_RIGHT) {
|
if (b->is_pressed() && b->get_button_index() == BUTTON_WHEEL_RIGHT) {
|
||||||
// Pan right
|
// Pan right
|
||||||
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
|
||||||
view_offset.x += int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
view_offset.x += int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor();
|
||||||
@ -939,28 +939,57 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (drag_type == DRAG_NONE) {
|
||||||
|
if (b->is_pressed() &&
|
||||||
|
(b->get_button_index() == BUTTON_MIDDLE ||
|
||||||
|
(b->get_button_index() == BUTTON_LEFT && tool == TOOL_PAN) ||
|
||||||
|
(b->get_button_index() == BUTTON_LEFT && !EditorSettings::get_singleton()->get("editors/2d/simple_spacebar_panning") && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
|
||||||
|
// Pan the viewport
|
||||||
|
drag_type = DRAG_PAN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drag_type == DRAG_PAN) {
|
||||||
|
if (!b->is_pressed()) {
|
||||||
|
// Stop panning the viewport (for any mouse button press)
|
||||||
|
drag_type = DRAG_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<InputEventKey> k = p_event;
|
||||||
|
if (k.is_valid()) {
|
||||||
|
if (k->get_scancode() == KEY_SPACE && EditorSettings::get_singleton()->get("editors/2d/simple_spacebar_panning")) {
|
||||||
|
if (drag_type == DRAG_NONE) {
|
||||||
|
if (k->is_pressed() && !k->is_echo()) {
|
||||||
|
//Pan the viewport
|
||||||
|
drag_type = DRAG_PAN;
|
||||||
|
}
|
||||||
|
} else if (drag_type == DRAG_PAN) {
|
||||||
|
if (!k->is_pressed()) {
|
||||||
|
// Stop panning the viewport (for any mouse button press)
|
||||||
|
drag_type = DRAG_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<InputEventMouseMotion> m = p_event;
|
Ref<InputEventMouseMotion> m = p_event;
|
||||||
if (m.is_valid()) {
|
if (m.is_valid()) {
|
||||||
if (drag_type == DRAG_NONE) {
|
if (drag_type == DRAG_PAN) {
|
||||||
if (((m->get_button_mask() & BUTTON_MASK_LEFT) && tool == TOOL_PAN) ||
|
// Pan the viewport
|
||||||
(m->get_button_mask() & BUTTON_MASK_MIDDLE) ||
|
Point2i relative;
|
||||||
((m->get_button_mask() & BUTTON_MASK_LEFT) && Input::get_singleton()->is_key_pressed(KEY_SPACE)) ||
|
if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) {
|
||||||
(EditorSettings::get_singleton()->get("editors/2d/simple_spacebar_panning") && Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
|
relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect());
|
||||||
// Pan the viewport
|
} else {
|
||||||
Point2i relative;
|
relative = m->get_relative();
|
||||||
if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) {
|
|
||||||
relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect());
|
|
||||||
} else {
|
|
||||||
relative = m->get_relative();
|
|
||||||
}
|
|
||||||
view_offset.x -= relative.x / zoom;
|
|
||||||
view_offset.y -= relative.y / zoom;
|
|
||||||
_update_scrollbars();
|
|
||||||
viewport->update();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
view_offset.x -= relative.x / zoom;
|
||||||
|
view_offset.y -= relative.y / zoom;
|
||||||
|
_update_scrollbars();
|
||||||
|
viewport->update();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1903,10 +1932,10 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
|
|||||||
//printf("Rotate\n");
|
//printf("Rotate\n");
|
||||||
} else if ((accepted = _gui_input_move(p_event))) {
|
} else if ((accepted = _gui_input_move(p_event))) {
|
||||||
//printf("Move\n");
|
//printf("Move\n");
|
||||||
} else if ((accepted = _gui_input_select(p_event))) {
|
|
||||||
//printf("Selection\n");
|
|
||||||
} else if ((accepted = _gui_input_zoom_or_pan(p_event))) {
|
} else if ((accepted = _gui_input_zoom_or_pan(p_event))) {
|
||||||
//printf("Zoom or pan\n");
|
//printf("Zoom or pan\n");
|
||||||
|
} else if ((accepted = _gui_input_select(p_event))) {
|
||||||
|
//printf("Selection\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accepted)
|
if (accepted)
|
||||||
@ -1919,22 +1948,18 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
|
|||||||
CursorShape c = CURSOR_ARROW;
|
CursorShape c = CURSOR_ARROW;
|
||||||
switch (drag_type) {
|
switch (drag_type) {
|
||||||
case DRAG_NONE:
|
case DRAG_NONE:
|
||||||
if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
|
switch (tool) {
|
||||||
c = CURSOR_DRAG;
|
case TOOL_MOVE:
|
||||||
} else {
|
c = CURSOR_MOVE;
|
||||||
switch (tool) {
|
break;
|
||||||
case TOOL_MOVE:
|
case TOOL_EDIT_PIVOT:
|
||||||
c = CURSOR_MOVE;
|
c = CURSOR_CROSS;
|
||||||
break;
|
break;
|
||||||
case TOOL_EDIT_PIVOT:
|
case TOOL_PAN:
|
||||||
c = CURSOR_CROSS;
|
c = CURSOR_DRAG;
|
||||||
break;
|
break;
|
||||||
case TOOL_PAN:
|
default:
|
||||||
c = CURSOR_DRAG;
|
break;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DRAG_LEFT:
|
case DRAG_LEFT:
|
||||||
@ -1956,6 +1981,8 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
|
|||||||
case DRAG_ALL:
|
case DRAG_ALL:
|
||||||
c = CURSOR_MOVE;
|
c = CURSOR_MOVE;
|
||||||
break;
|
break;
|
||||||
|
case DRAG_PAN:
|
||||||
|
c = CURSOR_DRAG;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,8 @@ class CanvasItemEditor : public VBoxContainer {
|
|||||||
DRAG_V_GUIDE,
|
DRAG_V_GUIDE,
|
||||||
DRAG_H_GUIDE,
|
DRAG_H_GUIDE,
|
||||||
DRAG_DOUBLE_GUIDE,
|
DRAG_DOUBLE_GUIDE,
|
||||||
DRAG_KEY_MOVE
|
DRAG_KEY_MOVE,
|
||||||
|
DRAG_PAN
|
||||||
};
|
};
|
||||||
|
|
||||||
EditorSelection *editor_selection;
|
EditorSelection *editor_selection;
|
||||||
|
Loading…
Reference in New Issue
Block a user