Ability to rotate controls using tool, closes #3800
This commit is contained in:
parent
47d6cc08bb
commit
e2d208f122
|
@ -49,14 +49,22 @@
|
||||||
|
|
||||||
Variant Control::edit_get_state() const {
|
Variant Control::edit_get_state() const {
|
||||||
|
|
||||||
return get_rect();
|
Dictionary s;
|
||||||
|
s["rect"]=get_rect();
|
||||||
|
s["rot"]=get_rotation();
|
||||||
|
s["scale"]=get_scale();
|
||||||
|
return s;
|
||||||
|
|
||||||
}
|
}
|
||||||
void Control::edit_set_state(const Variant& p_state) {
|
void Control::edit_set_state(const Variant& p_state) {
|
||||||
|
|
||||||
Rect2 state=p_state;
|
Dictionary s=p_state;
|
||||||
|
|
||||||
|
Rect2 state=s["rect"];
|
||||||
set_pos(state.pos);
|
set_pos(state.pos);
|
||||||
set_size(state.size);
|
set_size(state.size);
|
||||||
|
set_rotation(s["rot"]);
|
||||||
|
set_scale(s["scale"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::set_custom_minimum_size(const Size2& p_custom) {
|
void Control::set_custom_minimum_size(const Size2& p_custom) {
|
||||||
|
|
|
@ -1382,6 +1382,8 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
|
||||||
se->undo_state=canvas_item->edit_get_state();
|
se->undo_state=canvas_item->edit_get_state();
|
||||||
if (canvas_item->cast_to<Node2D>())
|
if (canvas_item->cast_to<Node2D>())
|
||||||
se->undo_pivot=canvas_item->cast_to<Node2D>()->edit_get_pivot();
|
se->undo_pivot=canvas_item->cast_to<Node2D>()->edit_get_pivot();
|
||||||
|
if (canvas_item->cast_to<Control>())
|
||||||
|
se->undo_pivot=Vector2();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1566,14 +1568,34 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
|
||||||
if (drag==DRAG_ROTATE) {
|
if (drag==DRAG_ROTATE) {
|
||||||
|
|
||||||
Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin();
|
Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin();
|
||||||
if (Node2D *node = canvas_item->cast_to<Node2D>()) {
|
{
|
||||||
Matrix32 rot;
|
Node2D *node = canvas_item->cast_to<Node2D>();
|
||||||
rot.elements[1] = (dfrom - center).normalized();
|
|
||||||
rot.elements[0] = rot.elements[1].tangent();
|
|
||||||
node->set_rot(snap_angle(rot.xform_inv(dto-center).angle() + node->get_rot(), node->get_rot()));
|
if (node) {
|
||||||
display_rotate_to = dto;
|
Matrix32 rot;
|
||||||
display_rotate_from = center;
|
rot.elements[1] = (dfrom - center).normalized();
|
||||||
viewport->update();
|
rot.elements[0] = rot.elements[1].tangent();
|
||||||
|
node->set_rot(snap_angle(rot.xform_inv(dto-center).angle() + node->get_rot(), node->get_rot()));
|
||||||
|
display_rotate_to = dto;
|
||||||
|
display_rotate_from = center;
|
||||||
|
viewport->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Control *node = canvas_item->cast_to<Control>();
|
||||||
|
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
Matrix32 rot;
|
||||||
|
rot.elements[1] = (dfrom - center).normalized();
|
||||||
|
rot.elements[0] = rot.elements[1].tangent();
|
||||||
|
node->set_rotation(snap_angle(rot.xform_inv(dto-center).angle() + node->get_rotation(), node->get_rotation()));
|
||||||
|
display_rotate_to = dto;
|
||||||
|
display_rotate_from = center;
|
||||||
|
viewport->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue