Skip to content

Commit

Permalink
Merge pull request godotengine#69376 from zaevi/adjust_dropping_texture
Browse files Browse the repository at this point in the history
Adjust position and size for dropping texture in canvas editor.
  • Loading branch information
akien-mga committed Nov 30, 2022
2 parents c868e0b + a1419f3 commit cd491c6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5596,7 +5596,7 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
// make visible for certain node type
if (Object::cast_to<Control>(child)) {
Size2 texture_size = texture->get_size();
undo_redo->add_do_property(child, "rect_size", texture_size);
undo_redo->add_do_property(child, "size", texture_size);
} else if (Object::cast_to<Polygon2D>(child)) {
Size2 texture_size = texture->get_size();
Vector<Vector2> list = {
Expand All @@ -5612,6 +5612,11 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
Transform2D xform = canvas_item_editor->get_canvas_transform();
Point2 target_position = xform.affine_inverse().xform(p_point);

// Adjust position for Control and TouchScreenButton
if (Object::cast_to<Control>(child) || Object::cast_to<TouchScreenButton>(child)) {
target_position -= texture->get_size() / 2;
}

// there's nothing to be used as source position so snapping will work as absolute if enabled
target_position = canvas_item_editor->snap_point(target_position);
undo_redo->add_do_method(child, "set_global_position", target_position);
Expand Down

0 comments on commit cd491c6

Please sign in to comment.