You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 19:41:11 +00:00
Merge pull request #53185 from KoBeWi/viewing_pan
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
if (panner->gui_input(p_event)) {
|
||||
accept_event();
|
||||
}
|
||||
}
|
||||
|
||||
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::_scroll_callback(Vector2 p_scroll_vec) {
|
||||
_pan_callback(-p_scroll_vec * 32);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
Reference in New Issue
Block a user