diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-06-09 10:48:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-09 10:48:59 +0200 |
commit | 63fd693c1ebd2d3d2c23f3969ca8f6f3e18ff3e4 (patch) | |
tree | cff7933cd170491f3e7658a80b2fd39589b3950c /editor | |
parent | 612ab8fcdb94bf0cd9d7b4a3006b4e4f76c9a13b (diff) | |
parent | 45b71ac2d02eebb85948761af8d4b2e3fe6f0815 (diff) |
Merge pull request #9060 from pixelpicosean/scroll-to-pan-canvas-item-editor-3.0
Add settings to pan canvas editor with scrolling
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_settings.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 68 |
2 files changed, 50 insertions, 20 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 3dab1707a1..ec7e7597d5 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -614,6 +614,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.9)); set("editors/2d/keep_margins_when_changing_anchors", false); set("editors/2d/warped_mouse_panning", true); + set("editors/2d/scroll_to_pan", false); + set("editors/2d/pan_speed", 20); set("editors/poly_editor/point_grab_radius", 8); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index e6c08a9009..803e59469c 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1010,8 +1010,7 @@ void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) { selection_menu->add_item(item->get_name()); selection_menu->set_item_icon(i, icon); selection_menu->set_item_metadata(i, node_path); - selection_menu->set_item_tooltip(i, String(item->get_name()) + - "\nType: " + item->get_class() + "\nPath: " + node_path); + selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path); } additive_selection = b->get_shift(); @@ -1047,17 +1046,25 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b->get_button_index() == BUTTON_WHEEL_DOWN) { - if (zoom < MIN_ZOOM) - return; + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + v_scroll->set_value(v_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + + } else { + + if (zoom < MIN_ZOOM) + return; - float prev_zoom = zoom; - zoom = zoom * (1 - (0.05 * b->get_factor())); - { - Point2 ofs = b->get_position(); - ofs = ofs / prev_zoom - ofs / zoom; - h_scroll->set_value(h_scroll->get_value() + ofs.x); - v_scroll->set_value(v_scroll->get_value() + ofs.y); + float prev_zoom = zoom; + zoom = zoom * (1 - (0.05 * b->get_factor())); + { + Point2 ofs = b->get_position(); + ofs = ofs / prev_zoom - ofs / zoom; + h_scroll->set_value(h_scroll->get_value() + ofs.x); + v_scroll->set_value(v_scroll->get_value() + ofs.y); + } } + _update_scroll(0); viewport->update(); return; @@ -1065,16 +1072,21 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b->get_button_index() == BUTTON_WHEEL_UP) { - if (zoom > MAX_ZOOM) - return; + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + v_scroll->set_value(v_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); - float prev_zoom = zoom; - zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95); - { - Point2 ofs = b->get_position(); - ofs = ofs / prev_zoom - ofs / zoom; - h_scroll->set_value(h_scroll->get_value() + ofs.x); - v_scroll->set_value(v_scroll->get_value() + ofs.y); + } else { + if (zoom > MAX_ZOOM) return; + + float prev_zoom = zoom; + zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95); + { + Point2 ofs = b->get_position(); + ofs = ofs / prev_zoom - ofs / zoom; + h_scroll->set_value(h_scroll->get_value() + ofs.x); + v_scroll->set_value(v_scroll->get_value() + ofs.y); + } } _update_scroll(0); @@ -1082,6 +1094,22 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { return; } + if (b->get_button_index() == BUTTON_WHEEL_LEFT) { + + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + h_scroll->set_value(h_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + } + } + + if (b->get_button_index() == BUTTON_WHEEL_RIGHT) { + + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + h_scroll->set_value(h_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + } + } + if (b->get_button_index() == BUTTON_RIGHT) { if (b->is_pressed() && (tool == TOOL_SELECT && b->get_alt())) { |