diff options
Diffstat (limited to 'editor/plugins')
| -rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 108 | ||||
| -rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 2 | ||||
| -rw-r--r-- | editor/plugins/shader_editor_plugin.cpp | 2 | ||||
| -rw-r--r-- | editor/plugins/shader_graph_editor_plugin.cpp | 2 | ||||
| -rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 10 | ||||
| -rw-r--r-- | editor/plugins/texture_region_editor_plugin.cpp | 2 |
6 files changed, 71 insertions, 55 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 9efbcbf199..b07112855c 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -602,30 +602,7 @@ bool CanvasItemEditor::_select(CanvasItem *item, Point2 p_click_pos, bool p_appe } if (p_drag) { - //prepare to move! - - List<Node *> &selection = editor_selection->get_selected_node_list(); - - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - - CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item || !canvas_item->is_visible_in_tree()) - continue; - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) - continue; - - CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); - if (!se) - continue; - - se->undo_state = canvas_item->edit_get_state(); - if (canvas_item->cast_to<Node2D>()) - se->undo_pivot = canvas_item->cast_to<Node2D>()->edit_get_pivot(); - } - - drag = DRAG_ALL; - drag_from = transform.affine_inverse().xform(p_click_pos); - drag_point_from = _find_topleftmost_point(); + _prepare_drag(p_click_pos); } viewport->update(); @@ -843,6 +820,37 @@ CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Transform2D & return DRAG_NONE; } +void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) { + + List<Node *> &selection = editor_selection->get_selected_node_list(); + + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + + CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); + if (!canvas_item || !canvas_item->is_visible_in_tree()) + continue; + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + continue; + + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); + if (!se) + continue; + + se->undo_state = canvas_item->edit_get_state(); + if (canvas_item->cast_to<Node2D>()) + se->undo_pivot = canvas_item->cast_to<Node2D>()->edit_get_pivot(); + } + + if (selection.size() == 1 && selection[0]->cast_to<Node2D>()) { + drag = DRAG_NODE_2D; + drag_point_from = selection[0]->cast_to<Node2D>()->get_global_position(); + } else { + drag = DRAG_ALL; + drag_point_from = _find_topleftmost_point(); + } + drag_from = transform.affine_inverse().xform(p_click_pos); +} + void CanvasItemEditor::incbeg(float &beg, float &end, float inc, float minsize, bool p_symmetric) { if (minsize < 0) { @@ -1380,29 +1388,7 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) { Point2 click = Point2(b.x, b.y); if ((b.mod.alt || tool == TOOL_MOVE) && get_item_count()) { - - List<Node *> &selection = editor_selection->get_selected_node_list(); - - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - - CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item || !canvas_item->is_visible_in_tree()) - continue; - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) - continue; - - CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); - if (!se) - continue; - - se->undo_state = canvas_item->edit_get_state(); - if (canvas_item->cast_to<Node2D>()) - se->undo_pivot = canvas_item->cast_to<Node2D>()->edit_get_pivot(); - } - - drag = DRAG_ALL; - drag_from = transform.affine_inverse().xform(click); - drag_point_from = _find_topleftmost_point(); + _prepare_drag(click); viewport->update(); return; } @@ -1471,8 +1457,16 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) { if (drag == DRAG_NONE) { if ((m.button_mask & BUTTON_MASK_LEFT && tool == TOOL_PAN) || m.button_mask & BUTTON_MASK_MIDDLE || (m.button_mask & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE))) { - h_scroll->set_value(h_scroll->get_value() - m.relative_x / zoom); - v_scroll->set_value(v_scroll->get_value() - m.relative_y / zoom); + + Point2i relative; + if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) { + relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect()); + } else { + relative = Point2i(m.relative_x, m.relative_y); + } + + h_scroll->set_value(h_scroll->get_value() - relative.x / zoom); + v_scroll->set_value(v_scroll->get_value() - relative.y / zoom); } return; @@ -1538,7 +1532,7 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) { bool uniform = m.mod.shift; bool symmetric = m.mod.alt; - dto = dto - (drag == DRAG_ALL ? drag_from - drag_point_from : Vector2(0, 0)); + dto = dto - (drag == DRAG_ALL || drag == DRAG_NODE_2D ? drag_from - drag_point_from : Vector2(0, 0)); if (uniform && (drag == DRAG_ALL || drag == DRAG_NODE_2D)) { if (ABS(dto.x - drag_point_from.x) > ABS(dto.y - drag_point_from.y)) { @@ -1637,6 +1631,12 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) { } continue; } break; + case DRAG_NODE_2D: { + + ERR_FAIL_COND(!canvas_item->cast_to<Node2D>()); + canvas_item->cast_to<Node2D>()->set_global_position(dto); + continue; + } break; default: {} } @@ -3583,6 +3583,8 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String & if (default_type == "Polygon2D" || default_type == "TouchScreenButton" || default_type == "TextureRect" || default_type == "Patch9Rect") { target_pos -= texture_size / 2; } + // there's nothing to be used as source position so snapping will work as absolute if enabled + target_pos = canvas->snap_point(target_pos, Vector2()); editor_data->get_undo_redo().add_do_method(child, "set_position", target_pos); } @@ -3627,7 +3629,11 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons } } Transform2D trans = canvas->get_canvas_transform(); - editor_data->get_undo_redo().add_do_method(instanced_scene, "set_pos", (p_point - trans.get_origin()) / trans.get_scale().x - pos); + Vector2 target_pos = (p_point - trans.get_origin()) / trans.get_scale().x - pos; + // in relative snapping it may be useful for the user to take the original node position into account + Vector2 start_pos = instanced_scene->cast_to<Node2D>() ? instanced_scene->cast_to<Node2D>()->get_position() : target_pos; + target_pos = canvas->snap_point(target_pos, start_pos); + editor_data->get_undo_redo().add_do_method(instanced_scene, "set_position", target_pos); return true; } diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 5f22437d39..ba3f240a49 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -144,6 +144,7 @@ class CanvasItemEditor : public VBoxContainer { DRAG_ALL, DRAG_ROTATE, DRAG_PIVOT, + DRAG_NODE_2D, }; @@ -323,6 +324,7 @@ class CanvasItemEditor : public VBoxContainer { void _list_select(const InputEventMouseButton &b); DragType _find_drag_type(const Transform2D &p_xform, const Rect2 &p_local_rect, const Point2 &p_click, Vector2 &r_point); + void _prepare_drag(const Point2 &p_click_pos); void _popup_callback(int p_op); bool updating_scroll; diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index c295a6679e..11dfb7b910 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -470,7 +470,7 @@ bool ShaderEditorPlugin::handles(Object *p_object) const { bool handles = true; Shader *shader = p_object->cast_to<Shader>(); /* - if (!shader || shader->cast_to<ShaderGraph>()) // Dont handle ShaderGraph's + if (!shader || shader->cast_to<ShaderGraph>()) // Don't handle ShaderGraph's handles = false; */ diff --git a/editor/plugins/shader_graph_editor_plugin.cpp b/editor/plugins/shader_graph_editor_plugin.cpp index d55c133dc9..bff7dece20 100644 --- a/editor/plugins/shader_graph_editor_plugin.cpp +++ b/editor/plugins/shader_graph_editor_plugin.cpp @@ -2425,7 +2425,7 @@ void ShaderGraphView::_create_node(int p_id) { colors.push_back("ShadowColor"); colors.push_back("Diffuse"); colors.push_back("Specular"); - colors.push_back("Emmision"); + colors.push_back("Emission"); Array reals; reals.push_back("Alpha"); reals.push_back("DiffuseAlpha"); diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index fcfb20bd7d..c00652bc35 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -29,6 +29,7 @@ #include "spatial_editor_plugin.h" #include "camera_matrix.h" +#include "core/os/input.h" #include "editor/animation_editor.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" @@ -1400,12 +1401,19 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (nav_scheme == NAVIGATION_MAYA && m.mod.shift) pan_speed *= pan_speed_modifier; + Point2i relative; + if (bool(EditorSettings::get_singleton()->get("editors/3d/warped_mouse_panning"))) { + relative = Input::get_singleton()->warp_mouse_motion(m, surface->get_global_rect()); + } else { + relative = Point2i(m.relative_x, m.relative_y); + } + Transform camera_transform; camera_transform.translate(cursor.pos); camera_transform.basis.rotate(Vector3(1, 0, 0), -cursor.x_rot); camera_transform.basis.rotate(Vector3(0, 1, 0), -cursor.y_rot); - Vector3 translation(-m.relative_x * pan_speed, m.relative_y * pan_speed, 0); + Vector3 translation(-relative.x * pan_speed, relative.y * pan_speed, 0); translation *= cursor.distance / DISTANCE_DEFAULT; camera_transform.translate(translation); cursor.pos = camera_transform.origin; diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 5e992d3ec1..c0b410ba99 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -710,7 +710,7 @@ void TextureRegionEditor::_edit_region() { autoslice_cache.erase(F->next()); } else { queue_erase = true; - //Cant delete the first rect in the list. + //Can't delete the first rect in the list. } merged = true; } |