summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_node.cpp3
-rw-r--r--editor/plugins/tiles/tile_atlas_view.cpp68
-rw-r--r--editor/plugins/tiles/tile_atlas_view.h7
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp4
4 files changed, 39 insertions, 43 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index afd5407f37..26ce78c0c6 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -6038,6 +6038,9 @@ EditorNode::EditorNode() {
EDITOR_DEF("interface/inspector/default_color_picker_shape", (int32_t)ColorPicker::SHAPE_VHS_CIRCLE);
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "interface/inspector/default_color_picker_shape", PROPERTY_HINT_ENUM, "HSV Rectangle,HSV Rectangle Wheel,VHS Circle", PROPERTY_USAGE_DEFAULT));
EDITOR_DEF("run/auto_save/save_before_running", true);
+ EDITOR_DEF("interface/editors/sub_editor_panning_scheme", 0);
+ // Should be in sync with ControlScheme in ViewPanner.
+ EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "interface/editors/sub_editor_panning_scheme", PROPERTY_HINT_ENUM, "Scroll Zooms,Scroll Pans", PROPERTY_USAGE_DEFAULT));
const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
for (const String &E : textfile_ext) {
diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp
index c85956991a..24ede3b85e 100644
--- a/editor/plugins/tiles/tile_atlas_view.cpp
+++ b/editor/plugins/tiles/tile_atlas_view.cpp
@@ -37,57 +37,31 @@
#include "scene/gui/label.h"
#include "scene/gui/panel.h"
#include "scene/gui/texture_rect.h"
+#include "scene/gui/view_panner.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
void TileAtlasView::gui_input(const Ref<InputEvent> &p_event) {
- Ref<InputEventMouseButton> mb = p_event;
- if (mb.is_valid()) {
- drag_type = DRAG_TYPE_NONE;
-
- Vector2i scroll_vec = Vector2((mb->get_button_index() == MouseButton::WHEEL_LEFT) - (mb->get_button_index() == MouseButton::WHEEL_RIGHT), (mb->get_button_index() == MouseButton::WHEEL_UP) - (mb->get_button_index() == MouseButton::WHEEL_DOWN));
- if (scroll_vec != Vector2()) {
- if (mb->is_ctrl_pressed()) {
- if (mb->is_shift_pressed()) {
- panning.x += 32 * mb->get_factor() * scroll_vec.y;
- panning.y += 32 * mb->get_factor() * scroll_vec.x;
- } else {
- panning.y += 32 * mb->get_factor() * scroll_vec.y;
- panning.x += 32 * mb->get_factor() * scroll_vec.x;
- }
-
- emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning);
- _update_zoom_and_panning(true);
- accept_event();
+ if (panner->gui_input(p_event)) {
+ accept_event();
+ }
+}
- } else if (!mb->is_shift_pressed()) {
- zoom_widget->set_zoom_by_increments(scroll_vec.y * 2);
- emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning);
- _update_zoom_and_panning(true);
- accept_event();
- }
- }
+void TileAtlasView::_scroll_callback(Vector2 p_scroll_vec) {
+ _pan_callback(-p_scroll_vec * 32);
+}
- if (mb->get_button_index() == MouseButton::MIDDLE || mb->get_button_index() == MouseButton::RIGHT) {
- if (mb->is_pressed()) {
- drag_type = DRAG_TYPE_PAN;
- } else {
- drag_type = DRAG_TYPE_NONE;
- }
- accept_event();
- }
- }
+void TileAtlasView::_pan_callback(Vector2 p_scroll_vec) {
+ panning += p_scroll_vec;
+ emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning);
+ _update_zoom_and_panning(true);
+}
- Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid()) {
- if (drag_type == DRAG_TYPE_PAN) {
- panning += mm->get_relative();
- _update_zoom_and_panning();
- emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning);
- accept_event();
- }
- }
+void TileAtlasView::_zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin) {
+ zoom_widget->set_zoom_by_increments(-p_scroll_vec.y * 2);
+ emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning);
+ _update_zoom_and_panning(true);
}
Size2i TileAtlasView::_compute_base_tiles_control_size() {
@@ -548,6 +522,11 @@ void TileAtlasView::update() {
void TileAtlasView::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED:
+ panner->set_control_scheme((ViewPanner::ControlScheme)EDITOR_GET("interface/editors/sub_editor_panning_scheme").operator int());
+ break;
+
case NOTIFICATION_READY:
button_center_view->set_icon(get_theme_icon(SNAME("CenterView"), SNAME("EditorIcons")));
break;
@@ -561,6 +540,9 @@ void TileAtlasView::_bind_methods() {
TileAtlasView::TileAtlasView() {
set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST);
+ panner.instantiate();
+ panner->set_callbacks(callable_mp(this, &TileAtlasView::_scroll_callback), callable_mp(this, &TileAtlasView::_pan_callback), callable_mp(this, &TileAtlasView::_zoom_callback));
+
Panel *panel = memnew(Panel);
panel->set_clip_contents(true);
panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
diff --git a/editor/plugins/tiles/tile_atlas_view.h b/editor/plugins/tiles/tile_atlas_view.h
index ca7f083132..6a0e0ae820 100644
--- a/editor/plugins/tiles/tile_atlas_view.h
+++ b/editor/plugins/tiles/tile_atlas_view.h
@@ -41,6 +41,8 @@
#include "scene/gui/texture_rect.h"
#include "scene/resources/tile_set.h"
+class ViewPanner;
+
class TileAtlasView : public Control {
GDCLASS(TileAtlasView, Control);
@@ -64,6 +66,11 @@ private:
void _center_view();
virtual void gui_input(const Ref<InputEvent> &p_event) override;
+ Ref<ViewPanner> panner;
+ void _scroll_callback(Vector2 p_scroll_vec);
+ void _pan_callback(Vector2 p_scroll_vec);
+ void _zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin);
+
Map<Vector2, Map<int, Rect2i>> alternative_tiles_rect_cache;
void _update_alternative_tiles_rect_cache();
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 587e690780..43997d489a 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -3209,6 +3209,10 @@ void VisualShaderEditor::_notification(int p_what) {
}
}
+ if (p_what == NOTIFICATION_ENTER_TREE || p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
+ graph->set_panning_scheme((GraphEdit::PanningScheme)EDITOR_GET("interface/editors/sub_editor_panning_scheme").operator int());
+ }
+
if (p_what == NOTIFICATION_DRAG_BEGIN) {
Dictionary dd = get_viewport()->gui_get_drag_data();
if (members->is_visible_in_tree() && dd.has("id")) {