Changed anchor constants to enum, removed ANCHOR_CENTER, fixes #9889

This commit is contained in:
Juan Linietsky 2017-08-15 19:48:38 -03:00
parent f0b19137f9
commit 1ecb48b8c2
3 changed files with 14 additions and 8 deletions

View File

@ -779,7 +779,7 @@ float CanvasItemEditor::_anchor_snap(float p_anchor, bool *p_snapped, float p_op
bool snapped = false;
float dist, dist_min = 0.0;
float radius = 0.05 / zoom;
float basic_anchors[3] = { ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_END };
float basic_anchors[3] = { 0.0, 0.5, 1.0 };
for (int i = 0; i < 3; i++) {
if ((dist = fabs(p_anchor - basic_anchors[i])) < radius) {
if (!snapped || dist <= dist_min) {

View File

@ -1363,7 +1363,7 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) {
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
set_anchor(MARGIN_LEFT, ANCHOR_CENTER, p_keep_margin);
set_anchor(MARGIN_LEFT, 0.5, p_keep_margin);
break;
case PRESET_TOP_RIGHT:
@ -1391,7 +1391,7 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) {
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
set_anchor(MARGIN_TOP, ANCHOR_CENTER, p_keep_margin);
set_anchor(MARGIN_TOP, 0.5, p_keep_margin);
break;
case PRESET_BOTTOM_LEFT:
@ -1415,7 +1415,7 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) {
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
set_anchor(MARGIN_RIGHT, ANCHOR_CENTER, p_keep_margin);
set_anchor(MARGIN_RIGHT, 0.5, p_keep_margin);
break;
case PRESET_TOP_RIGHT:
@ -1443,7 +1443,7 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) {
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
set_anchor(MARGIN_BOTTOM, ANCHOR_CENTER, p_keep_margin);
set_anchor(MARGIN_BOTTOM, 0.5, p_keep_margin);
break;
case PRESET_BOTTOM_LEFT:
@ -2694,6 +2694,9 @@ void Control::_bind_methods() {
BIND_CONSTANT(GROW_DIRECTION_BEGIN);
BIND_CONSTANT(GROW_DIRECTION_END);
BIND_CONSTANT(ANCHOR_BEGIN);
BIND_CONSTANT(ANCHOR_END);
ADD_SIGNAL(MethodInfo("resized"));
ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("mouse_entered"));

View File

@ -51,9 +51,11 @@ class Control : public CanvasItem {
OBJ_CATEGORY("GUI Nodes");
public:
static const float ANCHOR_BEGIN = 0.0f;
static const float ANCHOR_CENTER = 0.5f;
static const float ANCHOR_END = 1.0f;
enum Anchor {
ANCHOR_BEGIN = 0,
ANCHOR_END = 1
};
enum GrowDirection {
GROW_DIRECTION_BEGIN,
@ -449,5 +451,6 @@ VARIANT_ENUM_CAST(Control::CursorShape);
VARIANT_ENUM_CAST(Control::LayoutPreset);
VARIANT_ENUM_CAST(Control::MouseFilter);
VARIANT_ENUM_CAST(Control::GrowDirection);
VARIANT_ENUM_CAST(Control::Anchor);
#endif