diff options
-rw-r--r-- | scene/gui/control.cpp | 19 | ||||
-rw-r--r-- | scene/gui/control.h | 3 |
2 files changed, 17 insertions, 5 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 1bb34c1a67..53d36e64ea 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1660,6 +1660,10 @@ void Control::_size_changed() { margin_pos[i]=area*data.margin[i]; } break; + case ANCHOR_CENTER: { + + margin_pos[i]=(area/2)-data.margin[i]; + } break; } } @@ -1724,6 +1728,9 @@ float Control::_s2a(float p_val, AnchorType p_anchor,float p_range) const { case ANCHOR_RATIO: { return p_val/p_range; } break; + case ANCHOR_CENTER: { + return (p_range/2)-p_val; + } break; } return 0; @@ -1743,6 +1750,9 @@ float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { case ANCHOR_RATIO: { return Math::floor(p_range*p_val); } break; + case ANCHOR_CENTER: { + return Math::floor((p_range/2)-p_val); + } break; } return 0; } @@ -2772,10 +2782,10 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::BOOL,"can_drop_data",PropertyInfo(Variant::VECTOR2,"pos"),PropertyInfo(Variant::NIL,"data"))); BIND_VMETHOD(MethodInfo("drop_data",PropertyInfo(Variant::VECTOR2,"pos"),PropertyInfo(Variant::NIL,"data"))); - ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor/left", PROPERTY_HINT_ENUM, "Begin,End,Ratio"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_LEFT ); - ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor/top", PROPERTY_HINT_ENUM, "Begin,End,Ratio"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_TOP ); - ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor/right", PROPERTY_HINT_ENUM, "Begin,End,Ratio"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_RIGHT ); - ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor/bottom", PROPERTY_HINT_ENUM, "Begin,End,Ratio"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_BOTTOM ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor/left", PROPERTY_HINT_ENUM, "Begin,End,Ratio,Center"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_LEFT ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor/top", PROPERTY_HINT_ENUM, "Begin,End,Ratio,Center"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_TOP ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor/right", PROPERTY_HINT_ENUM, "Begin,End,Ratio,Center"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_RIGHT ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor/bottom", PROPERTY_HINT_ENUM, "Begin,End,Ratio,Center"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_BOTTOM ); ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"margin/left", PROPERTY_HINT_RANGE, "-4096,4096"), _SCS("set_margin"),_SCS("get_margin"), MARGIN_LEFT ); ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"margin/top", PROPERTY_HINT_RANGE, "-4096,4096"), _SCS("set_margin"),_SCS("get_margin"), MARGIN_TOP ); @@ -2801,6 +2811,7 @@ void Control::_bind_methods() { BIND_CONSTANT( ANCHOR_BEGIN ); BIND_CONSTANT( ANCHOR_END ); BIND_CONSTANT( ANCHOR_RATIO ); + BIND_CONSTANT( ANCHOR_CENTER ); BIND_CONSTANT( FOCUS_NONE ); BIND_CONSTANT( FOCUS_CLICK ); BIND_CONSTANT( FOCUS_ALL ); diff --git a/scene/gui/control.h b/scene/gui/control.h index a5d302105f..dd8854f80e 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -54,7 +54,8 @@ public: enum AnchorType { ANCHOR_BEGIN, ANCHOR_END, - ANCHOR_RATIO + ANCHOR_RATIO, + ANCHOR_CENTER, }; enum FocusMode { |