Merge pull request #32934 from ajweeks/fix-scale-origin
Fix 2D scale gizmo placement
This commit is contained in:
commit
9e1be8f8aa
|
@ -1812,7 +1812,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
|
||||||
if (_is_node_movable(canvas_item)) {
|
if (_is_node_movable(canvas_item)) {
|
||||||
|
|
||||||
Transform2D xform = transform * canvas_item->get_global_transform_with_canvas();
|
Transform2D xform = transform * canvas_item->get_global_transform_with_canvas();
|
||||||
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized();
|
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized();
|
||||||
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
||||||
|
|
||||||
drag_type = DRAG_SCALE_BOTH;
|
drag_type = DRAG_SCALE_BOTH;
|
||||||
|
@ -1846,7 +1846,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
|
||||||
drag_to = transform.affine_inverse().xform(m->get_position());
|
drag_to = transform.affine_inverse().xform(m->get_position());
|
||||||
|
|
||||||
Transform2D parent_xform = canvas_item->get_global_transform_with_canvas() * canvas_item->get_transform().affine_inverse();
|
Transform2D parent_xform = canvas_item->get_global_transform_with_canvas() * canvas_item->get_transform().affine_inverse();
|
||||||
Transform2D unscaled_transform = (transform * parent_xform * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized();
|
Transform2D unscaled_transform = (transform * parent_xform * canvas_item->_edit_get_transform()).orthonormalized();
|
||||||
Transform2D simple_xform = (viewport->get_transform() * unscaled_transform).affine_inverse() * transform;
|
Transform2D simple_xform = (viewport->get_transform() * unscaled_transform).affine_inverse() * transform;
|
||||||
|
|
||||||
bool uniform = m->get_shift();
|
bool uniform = m->get_shift();
|
||||||
|
@ -3126,7 +3126,7 @@ void CanvasItemEditor::_draw_selection() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized();
|
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized();
|
||||||
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
||||||
viewport->draw_set_transform_matrix(simple_xform);
|
viewport->draw_set_transform_matrix(simple_xform);
|
||||||
viewport->draw_texture(position_icon, -(position_icon->get_size() / 2));
|
viewport->draw_texture(position_icon, -(position_icon->get_size() / 2));
|
||||||
|
@ -3138,7 +3138,7 @@ void CanvasItemEditor::_draw_selection() {
|
||||||
if (canvas_item->_edit_use_pivot()) {
|
if (canvas_item->_edit_use_pivot()) {
|
||||||
|
|
||||||
// Draw the node's pivot
|
// Draw the node's pivot
|
||||||
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position() + canvas_item->_edit_get_pivot())).orthonormalized();
|
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized();
|
||||||
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
||||||
|
|
||||||
viewport->draw_set_transform_matrix(simple_xform);
|
viewport->draw_set_transform_matrix(simple_xform);
|
||||||
|
@ -3183,7 +3183,7 @@ void CanvasItemEditor::_draw_selection() {
|
||||||
bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT);
|
bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT);
|
||||||
if ((is_alt && is_ctrl) || tool == TOOL_SCALE || drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) {
|
if ((is_alt && is_ctrl) || tool == TOOL_SCALE || drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) {
|
||||||
if (_is_node_movable(canvas_item)) {
|
if (_is_node_movable(canvas_item)) {
|
||||||
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized();
|
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized();
|
||||||
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
||||||
|
|
||||||
Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE);
|
Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE);
|
||||||
|
@ -3402,7 +3402,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans
|
||||||
|
|
||||||
// Draw the node's position
|
// Draw the node's position
|
||||||
Ref<Texture> position_icon = get_icon("EditorPositionUnselected", "EditorIcons");
|
Ref<Texture> position_icon = get_icon("EditorPositionUnselected", "EditorIcons");
|
||||||
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized();
|
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized();
|
||||||
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
|
||||||
viewport->draw_set_transform_matrix(simple_xform);
|
viewport->draw_set_transform_matrix(simple_xform);
|
||||||
viewport->draw_texture(position_icon, -position_icon->get_size() / 2, Color(1.0, 1.0, 1.0, 0.5));
|
viewport->draw_texture(position_icon, -position_icon->get_size() / 2, Color(1.0, 1.0, 1.0, 0.5));
|
||||||
|
|
|
@ -360,6 +360,10 @@ bool CanvasItem::_edit_is_selected_on_click(const Point2 &p_point, double p_tole
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transform2D CanvasItem::_edit_get_transform() const {
|
||||||
|
return Transform2D(_edit_get_rotation(), _edit_get_position() + _edit_get_pivot());
|
||||||
|
}
|
||||||
|
|
||||||
bool CanvasItem::is_visible_in_tree() const {
|
bool CanvasItem::is_visible_in_tree() const {
|
||||||
|
|
||||||
if (!is_inside_tree())
|
if (!is_inside_tree())
|
||||||
|
@ -1133,6 +1137,7 @@ void CanvasItem::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("_edit_set_pivot", "pivot"), &CanvasItem::_edit_set_pivot);
|
ClassDB::bind_method(D_METHOD("_edit_set_pivot", "pivot"), &CanvasItem::_edit_set_pivot);
|
||||||
ClassDB::bind_method(D_METHOD("_edit_get_pivot"), &CanvasItem::_edit_get_pivot);
|
ClassDB::bind_method(D_METHOD("_edit_get_pivot"), &CanvasItem::_edit_get_pivot);
|
||||||
ClassDB::bind_method(D_METHOD("_edit_use_pivot"), &CanvasItem::_edit_use_pivot);
|
ClassDB::bind_method(D_METHOD("_edit_use_pivot"), &CanvasItem::_edit_use_pivot);
|
||||||
|
ClassDB::bind_method(D_METHOD("_edit_get_transform"), &CanvasItem::_edit_get_transform);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item);
|
ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item);
|
||||||
|
|
||||||
|
|
|
@ -281,6 +281,8 @@ public:
|
||||||
virtual void _edit_set_pivot(const Point2 &p_pivot){};
|
virtual void _edit_set_pivot(const Point2 &p_pivot){};
|
||||||
virtual Point2 _edit_get_pivot() const { return Point2(); };
|
virtual Point2 _edit_get_pivot() const { return Point2(); };
|
||||||
|
|
||||||
|
virtual Transform2D _edit_get_transform() const;
|
||||||
|
|
||||||
/* VISIBILITY */
|
/* VISIBILITY */
|
||||||
|
|
||||||
void set_visible(bool p_visible);
|
void set_visible(bool p_visible);
|
||||||
|
|
Loading…
Reference in New Issue