Merge pull request #239 from sanikoyes/hotfix-add-new-anchor-options

Add anchor options "Center"
This commit is contained in:
reduz 2014-04-05 09:27:43 -03:00
commit 368a14b500
2 changed files with 17 additions and 5 deletions

View file

@ -1660,6 +1660,10 @@ void Control::_size_changed() {
margin_pos[i]=area*data.margin[i]; margin_pos[i]=area*data.margin[i];
} break; } 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: { case ANCHOR_RATIO: {
return p_val/p_range; return p_val/p_range;
} break; } break;
case ANCHOR_CENTER: {
return (p_range/2)-p_val;
} break;
} }
return 0; return 0;
@ -1743,6 +1750,9 @@ float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const {
case ANCHOR_RATIO: { case ANCHOR_RATIO: {
return Math::floor(p_range*p_val); return Math::floor(p_range*p_val);
} break; } break;
case ANCHOR_CENTER: {
return Math::floor((p_range/2)-p_val);
} break;
} }
return 0; 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(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"))); 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/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"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_TOP ); 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"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_RIGHT ); 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"), _SCS("set_anchor"),_SCS("get_anchor"), MARGIN_BOTTOM ); 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/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 ); 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_BEGIN );
BIND_CONSTANT( ANCHOR_END ); BIND_CONSTANT( ANCHOR_END );
BIND_CONSTANT( ANCHOR_RATIO ); BIND_CONSTANT( ANCHOR_RATIO );
BIND_CONSTANT( ANCHOR_CENTER );
BIND_CONSTANT( FOCUS_NONE ); BIND_CONSTANT( FOCUS_NONE );
BIND_CONSTANT( FOCUS_CLICK ); BIND_CONSTANT( FOCUS_CLICK );
BIND_CONSTANT( FOCUS_ALL ); BIND_CONSTANT( FOCUS_ALL );

View file

@ -54,7 +54,8 @@ public:
enum AnchorType { enum AnchorType {
ANCHOR_BEGIN, ANCHOR_BEGIN,
ANCHOR_END, ANCHOR_END,
ANCHOR_RATIO ANCHOR_RATIO,
ANCHOR_CENTER,
}; };
enum FocusMode { enum FocusMode {