summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorSean Bohan <pixelpicosean@gmail.com>2017-06-06 07:33:38 +0800
committerSean Bohan <pixelpicosean@gmail.com>2017-06-08 18:05:41 +0800
commit45b71ac2d02eebb85948761af8d4b2e3fe6f0815 (patch)
treede27061b9beeb5e8aabb0ff2ebfc945e16ddfda7 /editor/plugins
parentb21e68c8bc0168120ded326259d021d394a9d7bf (diff)
Add settings to pan canvas editor with scrolling
This feature is mainly designed for developers who uses touchpad instead of mouse, and want to scroll instead of zoom. Every macOS developers will like it since it feels intuitive. 2 new settings are added to “editors/2d”: scroll_to_pan: turn on to use mouse/touchpad scroll to pan canvas item editor view instead of zoom pan_speed: use this value to change scroll speed
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp68
1 files changed, 48 insertions, 20 deletions
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())) {