Merge pull request #18380 from groud/fix_spacebar_panning

Fixes 2d editor panning not working
This commit is contained in:
Rémi Verschelde 2018-05-01 08:56:13 +02:00 committed by GitHub
commit e1ef2f538f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 40 deletions

View file

@ -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,15 +939,45 @@ 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) ||
(m->get_button_mask() & BUTTON_MASK_MIDDLE) ||
((m->get_button_mask() & BUTTON_MASK_LEFT) && Input::get_singleton()->is_key_pressed(KEY_SPACE)) ||
(EditorSettings::get_singleton()->get("editors/2d/simple_spacebar_panning") && Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
// Pan the viewport // Pan the viewport
Point2i relative; Point2i relative;
if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) { if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) {
@ -962,7 +992,6 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) {
return true; return true;
} }
} }
}
Ref<InputEventMagnifyGesture> magnify_gesture = p_event; Ref<InputEventMagnifyGesture> magnify_gesture = p_event;
if (magnify_gesture.is_valid()) { if (magnify_gesture.is_valid()) {
@ -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,9 +1948,6 @@ 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)) {
c = CURSOR_DRAG;
} else {
switch (tool) { switch (tool) {
case TOOL_MOVE: case TOOL_MOVE:
c = CURSOR_MOVE; c = CURSOR_MOVE;
@ -1935,7 +1961,6 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
default: default:
break; break;
} }
}
break; break;
case DRAG_LEFT: case DRAG_LEFT:
case DRAG_RIGHT: case DRAG_RIGHT:
@ -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;
} }

View file

@ -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;