summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2020-05-30 12:29:53 +0200
committerHugo Locurcio <hugo.locurcio@hugo.pro>2020-06-03 22:16:36 +0200
commitd10a5b2928175b313baf709b480620d755983f36 (patch)
treef5489acd1958dac4a0376a7aed29e6b6841659de /editor
parentdc67d0737b86c7a6cab66752b96631c59c703997 (diff)
Allow mouse zooming without hovering the texture in the TileSet editor
This partially addresses https://github.com/godotengine/godot-proposals/issues/968.
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp33
-rw-r--r--editor/plugins/tile_set_editor_plugin.h1
2 files changed, 25 insertions, 9 deletions
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index 644facd5bd..b3d4b391d3 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -569,6 +569,7 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) {
scroll = memnew(ScrollContainer);
main_vb->add_child(scroll);
scroll->set_v_size_flags(SIZE_EXPAND_FILL);
+ scroll->connect("gui_input", callable_mp(this, &TileSetEditor::_on_scroll_container_input));
scroll->set_clip_contents(true);
empty_message = memnew(Label);
@@ -1198,6 +1199,27 @@ bool TileSetEditor::is_within_grabbing_distance_of_first_point(const Vector2 &p_
return distance < p_grab_threshold;
}
+void TileSetEditor::_on_scroll_container_input(const Ref<InputEvent> &p_event) {
+ const Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid()) {
+ // Zoom in/out using Ctrl + mouse wheel. This is done on the ScrollContainer
+ // to allow performing this action anywhere, even if the cursor isn't
+ // hovering the texture in the workspace.
+ if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed() && mb->get_control()) {
+ print_line("zooming in");
+ _zoom_in();
+ // Don't scroll up after zooming in.
+ accept_event();
+ } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed() && mb->get_control()) {
+ print_line("zooming out");
+ _zoom_out();
+ // Don't scroll down after zooming out.
+ accept_event();
+ }
+ }
+}
+
void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
if (tileset.is_null() || !get_current_texture().is_valid()) {
return;
@@ -1214,8 +1236,8 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
current_tile_region.position += WORKSPACE_MARGIN;
- Ref<InputEventMouseButton> mb = p_ie;
- Ref<InputEventMouseMotion> mm = p_ie;
+ const Ref<InputEventMouseButton> mb = p_ie;
+ const Ref<InputEventMouseMotion> mm = p_ie;
if (mb.is_valid()) {
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && !creating_shape) {
@@ -1239,13 +1261,6 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
delete tiles;
}
}
-
- // Mouse Wheel Event
- if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed() && mb->get_control()) {
- _zoom_in();
- } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed() && mb->get_control()) {
- _zoom_out();
- }
}
// Drag Middle Mouse
if (mm.is_valid()) {
diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h
index 827325cfd7..2955dda244 100644
--- a/editor/plugins/tile_set_editor_plugin.h
+++ b/editor/plugins/tile_set_editor_plugin.h
@@ -200,6 +200,7 @@ private:
void _on_workspace_overlay_draw();
void _on_workspace_draw();
void _on_workspace_process();
+ void _on_scroll_container_input(const Ref<InputEvent> &p_event);
void _on_workspace_input(const Ref<InputEvent> &p_ie);
void _on_tool_clicked(int p_tool);
void _on_priority_changed(float val);