@@ -58,6 +58,7 @@ Dictionary Control::_edit_get_state() const {
5858 s[" rotation" ] = get_rotation ();
5959 s[" scale" ] = get_scale ();
6060 s[" pivot" ] = get_pivot_offset ();
61+ s[" pivot_ratio" ] = get_pivot_offset_ratio ();
6162
6263 Array anchors = { get_anchor (SIDE_LEFT), get_anchor (SIDE_TOP), get_anchor (SIDE_RIGHT), get_anchor (SIDE_BOTTOM) };
6364 s[" anchors" ] = anchors;
@@ -74,13 +75,14 @@ Dictionary Control::_edit_get_state() const {
7475void Control::_edit_set_state (const Dictionary &p_state) {
7576 ERR_FAIL_COND (p_state.is_empty () ||
7677 !p_state.has (" rotation" ) || !p_state.has (" scale" ) ||
77- !p_state.has (" pivot" ) || !p_state.has (" anchors" ) || !p_state.has (" offsets" ) ||
78+ !p_state.has (" pivot" ) || !p_state.has (" pivot_ratio " ) || !p_state. has ( " anchors" ) || !p_state.has (" offsets" ) ||
7879 !p_state.has (" layout_mode" ) || !p_state.has (" anchors_layout_preset" ));
7980 Dictionary state = p_state;
8081
8182 set_rotation (state[" rotation" ]);
8283 set_scale (state[" scale" ]);
8384 set_pivot_offset (state[" pivot" ]);
85+ set_pivot_offset_ratio (state[" pivot_ratio" ]);
8486
8587 Array anchors = state[" anchors" ];
8688
@@ -152,10 +154,11 @@ void Control::_edit_set_pivot(const Point2 &p_pivot) {
152154 Vector2 move = Vector2 ((std::cos (data.rotation ) - 1.0 ) * delta_pivot.x - std::sin (data.rotation ) * delta_pivot.y , std::sin (data.rotation ) * delta_pivot.x + (std::cos (data.rotation ) - 1.0 ) * delta_pivot.y );
153155 set_position (get_position () + move);
154156 set_pivot_offset (p_pivot);
157+ set_pivot_offset_ratio (Vector2 ());
155158}
156159
157160Point2 Control::_edit_get_pivot () const {
158- return get_pivot_offset ();
161+ return get_combined_pivot_offset ();
159162}
160163
161164bool Control::_edit_use_pivot () const {
@@ -536,7 +539,7 @@ void Control::_validate_property(PropertyInfo &p_property) const {
536539 // If the parent is a container, display only container-related properties.
537540 if (p_property.name .begins_with (" anchor_" ) || p_property.name .begins_with (" offset_" ) || p_property.name .begins_with (" grow_" ) || p_property.name == " anchors_preset" ) {
538541 p_property.usage ^= PROPERTY_USAGE_DEFAULT;
539- } else if (p_property.name == " position" || p_property.name == " rotation" || p_property.name == " scale" || p_property.name == " size" || p_property.name == " pivot_offset" ) {
542+ } else if (p_property.name == " position" || p_property.name == " rotation" || p_property.name == " scale" || p_property.name == " size" || p_property.name == " pivot_offset" || p_property. name == " pivot_offset_ratio " ) {
540543 p_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY;
541544 } else if (Engine::get_singleton ()->is_editor_hint () && p_property.name == " layout_mode" ) {
542545 // Set the layout mode to be disabled with the proper value.
@@ -709,8 +712,8 @@ Size2 Control::get_parent_area_size() const {
709712
710713Transform2D Control::_get_internal_transform () const {
711714 // T(pivot_offset) * R(rotation) * S(scale) * T(-pivot_offset)
712- Transform2D xform (data.rotation , data.scale , 0 .0f , data. pivot_offset );
713- xform.translate_local (-data. pivot_offset );
715+ Transform2D xform (data.rotation , data.scale , 0 .0f , get_combined_pivot_offset () );
716+ xform.translate_local (-get_combined_pivot_offset () );
714717 return xform;
715718}
716719
@@ -1606,6 +1609,23 @@ real_t Control::get_rotation_degrees() const {
16061609 return Math::rad_to_deg (get_rotation ());
16071610}
16081611
1612+ void Control::set_pivot_offset_ratio (const Vector2 &p_ratio) {
1613+ ERR_MAIN_THREAD_GUARD;
1614+ if (data.pivot_offset_ratio == p_ratio) {
1615+ return ;
1616+ }
1617+
1618+ data.pivot_offset_ratio = p_ratio;
1619+ queue_redraw ();
1620+ _notify_transform ();
1621+ queue_accessibility_update ();
1622+ }
1623+
1624+ Vector2 Control::get_pivot_offset_ratio () const {
1625+ ERR_READ_THREAD_GUARD_V (Vector2 ());
1626+ return data.pivot_offset_ratio ;
1627+ }
1628+
16091629void Control::set_pivot_offset (const Vector2 &p_pivot) {
16101630 ERR_MAIN_THREAD_GUARD;
16111631 if (data.pivot_offset == p_pivot) {
@@ -1623,6 +1643,11 @@ Vector2 Control::get_pivot_offset() const {
16231643 return data.pivot_offset ;
16241644}
16251645
1646+ Vector2 Control::get_combined_pivot_offset () const {
1647+ ERR_READ_THREAD_GUARD_V (Vector2 ());
1648+ return data.pivot_offset + data.pivot_offset_ratio * get_size ();
1649+ }
1650+
16261651// / Sizes.
16271652
16281653void Control::_update_minimum_size () {
@@ -3984,6 +4009,7 @@ void Control::_bind_methods() {
39844009 ClassDB::bind_method (D_METHOD (" set_rotation_degrees" , " degrees" ), &Control::set_rotation_degrees);
39854010 ClassDB::bind_method (D_METHOD (" set_scale" , " scale" ), &Control::set_scale);
39864011 ClassDB::bind_method (D_METHOD (" set_pivot_offset" , " pivot_offset" ), &Control::set_pivot_offset);
4012+ ClassDB::bind_method (D_METHOD (" set_pivot_offset_ratio" , " ratio" ), &Control::set_pivot_offset_ratio);
39874013 ClassDB::bind_method (D_METHOD (" get_begin" ), &Control::get_begin);
39884014 ClassDB::bind_method (D_METHOD (" get_end" ), &Control::get_end);
39894015 ClassDB::bind_method (D_METHOD (" get_position" ), &Control::get_position);
@@ -3992,6 +4018,8 @@ void Control::_bind_methods() {
39924018 ClassDB::bind_method (D_METHOD (" get_rotation_degrees" ), &Control::get_rotation_degrees);
39934019 ClassDB::bind_method (D_METHOD (" get_scale" ), &Control::get_scale);
39944020 ClassDB::bind_method (D_METHOD (" get_pivot_offset" ), &Control::get_pivot_offset);
4021+ ClassDB::bind_method (D_METHOD (" get_pivot_offset_ratio" ), &Control::get_pivot_offset_ratio);
4022+ ClassDB::bind_method (D_METHOD (" get_combined_pivot_offset" ), &Control::get_combined_pivot_offset);
39954023 ClassDB::bind_method (D_METHOD (" get_custom_minimum_size" ), &Control::get_custom_minimum_size);
39964024 ClassDB::bind_method (D_METHOD (" get_parent_area_size" ), &Control::get_parent_area_size);
39974025 ClassDB::bind_method (D_METHOD (" get_global_position" ), &Control::get_global_position);
@@ -4218,7 +4246,8 @@ void Control::_bind_methods() {
42184246 ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " rotation" , PROPERTY_HINT_RANGE, " -360,360,0.1,or_less,or_greater,radians_as_degrees" ), " set_rotation" , " get_rotation" );
42194247 ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " rotation_degrees" , PROPERTY_HINT_NONE, " " , PROPERTY_USAGE_NONE), " set_rotation_degrees" , " get_rotation_degrees" );
42204248 ADD_PROPERTY (PropertyInfo (Variant::VECTOR2, " scale" ), " set_scale" , " get_scale" );
4221- ADD_PROPERTY (PropertyInfo (Variant::VECTOR2, " pivot_offset" , PROPERTY_HINT_NONE, " suffix:px" ), " set_pivot_offset" , " get_pivot_offset" );
4249+ ADD_PROPERTY (PropertyInfo (Variant::VECTOR2, " pivot_offset" , PROPERTY_HINT_NONE, " suffix:px" , PROPERTY_USAGE_EDITOR), " set_pivot_offset" , " get_pivot_offset" );
4250+ ADD_PROPERTY (PropertyInfo (Variant::VECTOR2, " pivot_offset_ratio" ), " set_pivot_offset_ratio" , " get_pivot_offset_ratio" );
42224251
42234252 ADD_SUBGROUP (" Container Sizing" , " size_flags_" );
42244253 ADD_PROPERTY (PropertyInfo (Variant::INT, " size_flags_horizontal" , PROPERTY_HINT_FLAGS, " Fill:1,Expand:2,Shrink Center:4,Shrink End:8" ), " set_h_size_flags" , " get_h_size_flags" );
0 commit comments