public void Add(RelationType relationType, bool usePercent)
        {
            if (relationType == RelationType.Size)
            {
                Add(RelationType.Width, usePercent);
                Add(RelationType.Height, usePercent);
                return;
            }

            foreach (RelationDef def in _defs)
            {
                if (def.type == relationType)
                {
                    return;
                }
            }

            RelationDef info = new RelationDef();

            info.affectBySelfSizeChanged = relationType >= RelationType.Center_Center && relationType <= RelationType.Right_Right ||
                                           relationType >= RelationType.Middle_Middle && relationType <= RelationType.Bottom_Bottom;
            info.percent = usePercent;
            info.type    = relationType;
            _defs.Add(info);
        }
Beispiel #2
0
        public void ApplyOnSelfSizeChanged(float dWidth, float dHeight)
        {
            int cnt = _defs.Count;

            if (cnt == 0)
            {
                return;
            }

            float ox = _owner.x;
            float oy = _owner.y;

            for (int i = 0; i < cnt; i++)
            {
                RelationDef info = _defs[i];
                switch (info.type)
                {
                case RelationType.Center_Center:
                case RelationType.Right_Center:
                    _owner.x -= dWidth / 2;
                    break;

                case RelationType.Right_Left:
                case RelationType.Right_Right:
                    _owner.x -= dWidth;
                    break;

                case RelationType.Middle_Middle:
                case RelationType.Bottom_Middle:
                    _owner.y -= dHeight / 2;
                    break;

                case RelationType.Bottom_Top:
                case RelationType.Bottom_Bottom:
                    _owner.y -= dHeight;
                    break;
                }
            }

            if (!Mathf.Approximately(ox, _owner.x) || !Mathf.Approximately(oy, _owner.y))
            {
                ox = _owner.x - ox;
                oy = _owner.y - oy;

                if (_owner.gearXY.controller != null)
                {
                    _owner.gearXY.UpdateFromRelations(ox, oy);
                }

                if (_owner.parent != null)
                {
                    int transCount = _owner.parent._transitions.Count;
                    for (int i = 0; i < transCount; i++)
                    {
                        _owner.parent._transitions[i].UpdateFromRelations(_owner.id, ox, oy);
                    }
                }
            }
        }
Beispiel #3
0
        void ApplyOnXYChanged(RelationDef info, float dx, float dy)
        {
            float tmp;

            switch (info.type)
            {
            case RelationType.Left_Left:
            case RelationType.Left_Center:
            case RelationType.Left_Right:
            case RelationType.Center_Center:
            case RelationType.Right_Left:
            case RelationType.Right_Center:
            case RelationType.Right_Right:
                _owner.x += dx;
                break;

            case RelationType.Top_Top:
            case RelationType.Top_Middle:
            case RelationType.Top_Bottom:
            case RelationType.Middle_Middle:
            case RelationType.Bottom_Top:
            case RelationType.Bottom_Middle:
            case RelationType.Bottom_Bottom:
                _owner.y += dy;
                break;

            case RelationType.Width:
            case RelationType.Height:
                break;

            case RelationType.LeftExt_Left:
            case RelationType.LeftExt_Right:
                tmp          = _owner.xMin;
                _owner.width = _owner._rawWidth - dx;
                _owner.xMin  = tmp + dx;
                break;

            case RelationType.RightExt_Left:
            case RelationType.RightExt_Right:
                tmp          = _owner.xMin;
                _owner.width = _owner._rawWidth + dx;
                _owner.xMin  = tmp;
                break;

            case RelationType.TopExt_Top:
            case RelationType.TopExt_Bottom:
                tmp           = _owner.yMin;
                _owner.height = _owner._rawHeight - dy;
                _owner.yMin   = tmp + dy;
                break;

            case RelationType.BottomExt_Top:
            case RelationType.BottomExt_Bottom:
                tmp           = _owner.yMin;
                _owner.height = _owner._rawHeight + dy;
                _owner.yMin   = tmp;
                break;
            }
        }
        public void ApplyOnSelfSizeChanged(float dWidth, float dHeight, bool applyPivot)
        {
            int cnt = _defs.Count;

            if (cnt == 0)
            {
                return;
            }

            float ox = _owner.x;
            float oy = _owner.y;

            for (int i = 0; i < cnt; i++)
            {
                RelationDef info = _defs[i];
                switch (info.type)
                {
                case RelationType.Center_Center:
                    _owner.x -= (0.5f - (applyPivot ? _owner.pivotX : 0)) * dWidth;
                    break;

                case RelationType.Right_Center:
                case RelationType.Right_Left:
                case RelationType.Right_Right:
                    _owner.x -= (1 - (applyPivot ? _owner.pivotX : 0)) * dWidth;
                    break;

                case RelationType.Middle_Middle:
                    _owner.y -= (0.5f - (applyPivot ? _owner.pivotY : 0)) * dHeight;
                    break;

                case RelationType.Bottom_Middle:
                case RelationType.Bottom_Top:
                case RelationType.Bottom_Bottom:
                    _owner.y -= (1 - (applyPivot ? _owner.pivotY : 0)) * dHeight;
                    break;
                }
            }

            if (!MathHelpers.Approximately(ox, _owner.x) || !MathHelpers.Approximately(oy, _owner.y))
            {
                ox = _owner.x - ox;
                oy = _owner.y - oy;

                _owner.UpdateGearFromRelations(1, ox, oy);

                if (_owner.parent != null)
                {
                    int transCount = _owner.parent._transitions.Count;
                    for (int i = 0; i < transCount; i++)
                    {
                        _owner.parent._transitions[i].UpdateFromRelations(_owner.id, ox, oy);
                    }
                }
            }
        }
Beispiel #5
0
        public void CopyFrom(RelationItem source)
        {
            this.target = source.target;

            _defs.Clear();
            foreach (RelationDef info in source._defs)
            {
                RelationDef info2 = new RelationDef();
                info2.copyFrom(info);
                _defs.Add(info2);
            }
        }
Beispiel #6
0
        public void InternalAdd(RelationType relationType, bool usePercent)
        {
            if (relationType == RelationType.Size)
            {
                InternalAdd(RelationType.Width, usePercent);
                InternalAdd(RelationType.Height, usePercent);
                return;
            }

            RelationDef info = new RelationDef();

            info.percent = usePercent;
            info.type    = relationType;
            info.axis    = (relationType <= RelationType.Right_Right || relationType == RelationType.Width || relationType >= RelationType.LeftExt_Left && relationType <= RelationType.RightExt_Right) ? 0 : 1;
            _defs.Add(info);
        }
        internal void QuickAdd(RelationType relationType, bool usePercent)
        {
            if (relationType == RelationType.Size)
            {
                QuickAdd(RelationType.Width, usePercent);
                QuickAdd(RelationType.Height, usePercent);
                return;
            }
            RelationDef info = new RelationDef();

            info.affectBySelfSizeChanged = relationType >= RelationType.Center_Center && relationType <= RelationType.Right_Right ||
                                           relationType >= RelationType.Middle_Middle && relationType <= RelationType.Bottom_Bottom;
            info.percent = usePercent;
            info.type    = relationType;
            _defs.Add(info);
        }
Beispiel #8
0
        public void InternalAdd(RelationType relationType, bool usePercent)
        {
            if (relationType == RelationType.Size)
            {
                InternalAdd(RelationType.Width, usePercent);
                InternalAdd(RelationType.Height, usePercent);
                return;
            }

            RelationDef info = new RelationDef();
            info.percent = usePercent;
            info.type = relationType;
            info.axis = (relationType <= RelationType.Right_Right || relationType == RelationType.Width || relationType >= RelationType.LeftExt_Left && relationType <= RelationType.RightExt_Right) ? 0 : 1;
            _defs.Add(info);

            //当使用中线关联时,因为需要除以2,很容易因为奇数宽度/高度造成小数点坐标;当使用百分比时,也会造成小数坐标;
            //所以设置了这类关联的对象,自动启用pixelSnapping
            if (usePercent || relationType == RelationType.Left_Center || relationType == RelationType.Center_Center || relationType == RelationType.Right_Center
                    || relationType == RelationType.Top_Middle || relationType == RelationType.Middle_Middle || relationType == RelationType.Bottom_Middle)
                _owner.pixelSnapping = true;
        }
Beispiel #9
0
        public void InternalAdd(RelationType relationType, bool usePercent)
        {
            if (relationType == RelationType.Size)
            {
                InternalAdd(RelationType.Width, usePercent);
                InternalAdd(RelationType.Height, usePercent);
                return;
            }

            RelationDef info = new RelationDef();

            info.percent = usePercent;
            info.type    = relationType;
            _defs.Add(info);

            //当使用中线关联时,因为需要除以2,很容易因为奇数宽度/高度造成小数点坐标,所以设置了这类关联的对象,自动启用pixelSnapping
            if (relationType == RelationType.Left_Center || relationType == RelationType.Center_Center || relationType == RelationType.Right_Center ||
                relationType == RelationType.Top_Middle || relationType == RelationType.Middle_Middle || relationType == RelationType.Bottom_Middle)
            {
                _owner.pixelSnapping = true;
            }
        }
Beispiel #10
0
        void ApplyOnSizeChanged(RelationDef info)
        {
            float targetX, targetY;
            if (_target != _owner.parent)
            {
                targetX = _target.x;
                targetY = _target.y;
            }
            else
            {
                targetX = 0;
                targetY = 0;
            }
            float v, tmp;

            switch (info.type)
            {
                case RelationType.Left_Left:
                    break;
                case RelationType.Left_Center:
                    v = _owner.x - (targetX + _targetData.z / 2);
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    _owner.x = targetX + _target._rawWidth / 2 + v;
                    break;
                case RelationType.Left_Right:
                    v = _owner.x - (targetX + _targetData.z);
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    _owner.x = targetX + _target._rawWidth + v;
                    break;
                case RelationType.Center_Center:
                    v = _owner.x + _owner._rawWidth / 2 - (targetX + _targetData.z / 2);
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    _owner.x = targetX + _target._rawWidth / 2 + v - _owner._rawWidth / 2;
                    break;
                case RelationType.Right_Left:
                    v = _owner.x + _owner._rawWidth - targetX;
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    _owner.x = targetX + v - _owner._rawWidth;
                    break;
                case RelationType.Right_Center:
                    v = _owner.x + _owner._rawWidth - (targetX + _targetData.z / 2);
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    _owner.x = targetX + _target._rawWidth / 2 + v - _owner._rawWidth;
                    break;
                case RelationType.Right_Right:
                    v = _owner.x + _owner._rawWidth - (targetX + _targetData.z);
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    _owner.x = targetX + _target._rawWidth + v - _owner._rawWidth;
                    break;

                case RelationType.Top_Top:
                    break;
                case RelationType.Top_Middle:
                    v = _owner.y - (targetY + _targetData.w / 2);
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    _owner.y = targetY + _target._rawHeight / 2 + v;
                    break;
                case RelationType.Top_Bottom:
                    v = _owner.y - (targetY + _targetData.w);
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    _owner.y = targetY + _target._rawHeight + v;
                    break;
                case RelationType.Middle_Middle:
                    v = _owner.y + _owner._rawHeight / 2 - (targetY + _targetData.w / 2);
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    _owner.y = targetY + _target._rawHeight / 2 + v - _owner._rawHeight / 2;
                    break;
                case RelationType.Bottom_Top:
                    v = _owner.y + _owner._rawHeight - targetY;
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    _owner.y = targetY + v - _owner._rawHeight;
                    break;
                case RelationType.Bottom_Middle:
                    v = _owner.y + _owner._rawHeight - (targetY + _targetData.w / 2);
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    _owner.y = targetY + _target._rawHeight / 2 + v - _owner._rawHeight;
                    break;
                case RelationType.Bottom_Bottom:
                    v = _owner.y + _owner._rawHeight - (targetY + _targetData.w);
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    _owner.y = targetY + _target._rawHeight + v - _owner._rawHeight;
                    break;

                case RelationType.Width:
                    if (_owner.underConstruct && _owner == _target.parent)
                        v = _owner.sourceWidth - _target.initWidth;
                    else
                        v = _owner._rawWidth - _targetData.z;
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    if (_target == _owner.parent)
                        _owner.SetSize(_target._rawWidth + v, _owner._rawHeight, true);
                    else
                        _owner.width = _target._rawWidth + v;
                    break;
                case RelationType.Height:
                    if (_owner.underConstruct && _owner == _target.parent)
                        v = _owner.sourceHeight - _target.initHeight;
                    else
                        v = _owner._rawHeight - _targetData.w;
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    if (_target == _owner.parent)
                        _owner.SetSize(_owner._rawWidth, _target._rawHeight + v, true);
                    else
                        _owner.height = _target._rawHeight + v;
                    break;

                case RelationType.LeftExt_Left:
                    break;
                case RelationType.LeftExt_Right:
                    v = _owner.x - (targetX + _targetData.z);
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    tmp = _owner.x;
                    _owner.x = targetX + _target._rawWidth + v;
                    _owner.width = _owner._rawWidth - (_owner.x - tmp);
                    break;
                case RelationType.RightExt_Left:
                    break;
                case RelationType.RightExt_Right:
                    if (_owner.underConstruct && _owner == _target.parent)
                        v = _owner.sourceWidth - (targetX + _target.initWidth);
                    else
                        v = _owner._rawWidth - (targetX + _targetData.z);
                    if (_owner != _target.parent)
                        v += _owner.x;
                    if (info.percent)
                        v = v / _targetData.z * _target._rawWidth;
                    if (_owner != _target.parent)
                        _owner.width = targetX + _target._rawWidth + v - _owner.x;
                    else
                        _owner.width = targetX + _target._rawWidth + v;
                    break;
                case RelationType.TopExt_Top:
                    break;
                case RelationType.TopExt_Bottom:
                    v = _owner.y - (targetY + _targetData.w);
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    tmp = _owner.y;
                    _owner.y = targetY + _target._rawHeight + v;
                    _owner.height = _owner._rawHeight - (_owner.y - tmp);
                    break;
                case RelationType.BottomExt_Top:
                    break;
                case RelationType.BottomExt_Bottom:
                    if (_owner.underConstruct && _owner == _target.parent)
                        v = _owner.sourceHeight - (targetY + _target.initHeight);
                    else
                        v = _owner._rawHeight - (targetY + _targetData.w);
                    if (_owner != _target.parent)
                        v += _owner.y;
                    if (info.percent)
                        v = v / _targetData.w * _target._rawHeight;
                    if (_owner != _target.parent)
                        _owner.height = targetY + _target._rawHeight + v - _owner.y;
                    else
                        _owner.height = targetY + _target._rawHeight + v;
                    break;
            }
        }
 public void copyFrom(RelationDef source)
 {
     this.affectBySelfSizeChanged = source.affectBySelfSizeChanged;
     this.percent = source.percent;
     this.type = source.type;
 }
Beispiel #12
0
        void ApplyOnSizeChanged(RelationDef info)
        {
            float targetX, targetY;

            if (_target != _owner.parent)
            {
                targetX = _target.x;
                targetY = _target.y;
            }
            else
            {
                targetX = 0;
                targetY = 0;
            }
            float v, tmp;

            switch (info.type)
            {
            case RelationType.Left_Left:
                break;

            case RelationType.Left_Center:
                v = _owner.x - (targetX + _targetData.z / 2);
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                _owner.x = targetX + _target._rawWidth / 2 + v;
                break;

            case RelationType.Left_Right:
                v = _owner.x - (targetX + _targetData.z);
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                _owner.x = targetX + _target._rawWidth + v;
                break;

            case RelationType.Center_Center:
                v = _owner.x + _owner._rawWidth / 2 - (targetX + _targetData.z / 2);
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                _owner.x = targetX + _target._rawWidth / 2 + v - _owner._rawWidth / 2;
                break;

            case RelationType.Right_Left:
                v = _owner.x + _owner._rawWidth - targetX;
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                _owner.x = targetX + v - _owner._rawWidth;
                break;

            case RelationType.Right_Center:
                v = _owner.x + _owner._rawWidth - (targetX + _targetData.z / 2);
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                _owner.x = targetX + _target._rawWidth / 2 + v - _owner._rawWidth;
                break;

            case RelationType.Right_Right:
                v = _owner.x + _owner._rawWidth - (targetX + _targetData.z);
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                _owner.x = targetX + _target._rawWidth + v - _owner._rawWidth;
                break;

            case RelationType.Top_Top:
                break;

            case RelationType.Top_Middle:
                v = _owner.y - (targetY + _targetData.w / 2);
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                _owner.y = targetY + _target._rawHeight / 2 + v;
                break;

            case RelationType.Top_Bottom:
                v = _owner.y - (targetY + _targetData.w);
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                _owner.y = targetY + _target._rawHeight + v;
                break;

            case RelationType.Middle_Middle:
                v = _owner.y + _owner._rawHeight / 2 - (targetY + _targetData.w / 2);
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                _owner.y = targetY + _target._rawHeight / 2 + v - _owner._rawHeight / 2;
                break;

            case RelationType.Bottom_Top:
                v = _owner.y + _owner._rawHeight - targetY;
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                _owner.y = targetY + v - _owner._rawHeight;
                break;

            case RelationType.Bottom_Middle:
                v = _owner.y + _owner._rawHeight - (targetY + _targetData.w / 2);
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                _owner.y = targetY + _target._rawHeight / 2 + v - _owner._rawHeight;
                break;

            case RelationType.Bottom_Bottom:
                v = _owner.y + _owner._rawHeight - (targetY + _targetData.w);
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                _owner.y = targetY + _target._rawHeight + v - _owner._rawHeight;
                break;

            case RelationType.Width:
                if (_owner.underConstruct && _owner == _target.parent)
                {
                    v = _owner.sourceWidth - _target.initWidth;
                }
                else
                {
                    v = _owner._rawWidth - _targetData.z;
                }
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                if (_target == _owner.parent)
                {
                    _owner.SetSize(_target._rawWidth + v, _owner._rawHeight, true);
                }
                else
                {
                    _owner.width = _target._rawWidth + v;
                }
                break;

            case RelationType.Height:
                if (_owner.underConstruct && _owner == _target.parent)
                {
                    v = _owner.sourceHeight - _target.initHeight;
                }
                else
                {
                    v = _owner._rawHeight - _targetData.w;
                }
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                if (_target == _owner.parent)
                {
                    _owner.SetSize(_owner._rawWidth, _target._rawHeight + v, true);
                }
                else
                {
                    _owner.height = _target._rawHeight + v;
                }
                break;

            case RelationType.LeftExt_Left:
                break;

            case RelationType.LeftExt_Right:
                v = _owner.x - (targetX + _targetData.z);
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                tmp          = _owner.x;
                _owner.x     = targetX + _target._rawWidth + v;
                _owner.width = _owner._rawWidth - (_owner.x - tmp);
                break;

            case RelationType.RightExt_Left:
                break;

            case RelationType.RightExt_Right:
                if (_owner.underConstruct && _owner == _target.parent)
                {
                    v = _owner.sourceWidth - (targetX + _target.initWidth);
                }
                else
                {
                    v = _owner._rawWidth - (targetX + _targetData.z);
                }
                if (_owner != _target.parent)
                {
                    v += _owner.x;
                }
                if (info.percent)
                {
                    v = (int)(v / _targetData.z * _target._rawWidth);
                }
                if (_owner != _target.parent)
                {
                    _owner.width = targetX + _target._rawWidth + v - _owner.x;
                }
                else
                {
                    _owner.width = targetX + _target._rawWidth + v;
                }
                break;

            case RelationType.TopExt_Top:
                break;

            case RelationType.TopExt_Bottom:
                v = _owner.y - (targetY + _targetData.w);
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                tmp           = _owner.y;
                _owner.y      = targetY + _target._rawHeight + v;
                _owner.height = _owner._rawHeight - (_owner.y - tmp);
                break;

            case RelationType.BottomExt_Top:
                break;

            case RelationType.BottomExt_Bottom:
                if (_owner.underConstruct && _owner == _target.parent)
                {
                    v = _owner.sourceHeight - (targetY + _target.initHeight);
                }
                else
                {
                    v = _owner._rawHeight - (targetY + _targetData.w);
                }
                if (_owner != _target.parent)
                {
                    v += _owner.y;
                }
                if (info.percent)
                {
                    v = (int)(v / _targetData.w * _target._rawHeight);
                }
                if (_owner != _target.parent)
                {
                    _owner.height = targetY + _target._rawHeight + v - _owner.y;
                }
                else
                {
                    _owner.height = targetY + _target._rawHeight + v;
                }
                break;
            }
        }
        public void Add(RelationType relationType, bool usePercent)
        {
            if (relationType == RelationType.Size)
            {
                Add(RelationType.Width, usePercent);
                Add(RelationType.Height, usePercent);
                return;
            }
            foreach (RelationDef def in _defs)
            {
                if (def.type == relationType)
                    return;
            }

            RelationDef info = new RelationDef();
            info.affectBySelfSizeChanged = relationType >= RelationType.Center_Center && relationType <= RelationType.Right_Right
                || relationType >= RelationType.Middle_Middle && relationType <= RelationType.Bottom_Bottom;
            info.percent = usePercent;
            info.type = relationType;
            _defs.Add(info);
        }
Beispiel #14
0
 public void copyFrom(RelationDef source)
 {
     this.percent = source.percent;
     this.type    = source.type;
 }
 public void copyFrom(RelationDef source)
 {
     this.affectBySelfSizeChanged = source.affectBySelfSizeChanged;
     this.percent = source.percent;
     this.type    = source.type;
 }
Beispiel #16
0
        public void CopyFrom(RelationItem source)
        {
            this.target = source.target;

            _defs.Clear();
            foreach (RelationDef info in source._defs)
            {
                RelationDef info2 = new RelationDef();
                info2.copyFrom(info);
                _defs.Add(info2);
            }
        }
Beispiel #17
0
        public void InternalAdd(RelationType relationType, bool usePercent)
        {
            if (relationType == RelationType.Size)
            {
                InternalAdd(RelationType.Width, usePercent);
                InternalAdd(RelationType.Height, usePercent);
                return;
            }

            RelationDef info = new RelationDef();
            info.percent = usePercent;
            info.type = relationType;
            _defs.Add(info);

            //当使用中线关联时,因为需要除以2,很容易因为奇数宽度/高度造成小数点坐标;当使用百分比时,也会造成小数坐标;
            //所以设置了这类关联的对象,自动启用pixelSnapping
            if (usePercent || relationType == RelationType.Left_Center || relationType == RelationType.Center_Center || relationType == RelationType.Right_Center
                    || relationType == RelationType.Top_Middle || relationType == RelationType.Middle_Middle || relationType == RelationType.Bottom_Middle)
                _owner.pixelSnapping = true;
        }
Beispiel #18
0
        void ApplyOnSizeChanged(RelationDef info)
        {
            float pos = 0, pivot = 0, delta = 0;
            if (info.axis == 0)
            {
                if (_target != _owner.parent)
                {
                    pos = _target.x;
                    if (_target.pivotAsAnchor)
                        pivot = _target.pivotX;
                }

                if (info.percent)
                {
                    if (_targetData.z != 0)
                        delta = _target._width / _targetData.z;
                }
                else
                    delta = _target._width - _targetData.z;
            }
            else
            {
                if (_target != _owner.parent)
                {
                    pos = _target.y;
                    if (_target.pivotAsAnchor)
                        pivot = _target.pivotY;
                }

                if (info.percent)
                {
                    if (_targetData.w != 0)
                        delta = _target._height / _targetData.w;
                }
                else
                    delta = _target._height - _targetData.w;
            }

            float v, tmp;

            switch (info.type)
            {
                case RelationType.Left_Left:
                    if (info.percent)
                        _owner.xMin = pos + (_owner.xMin - pos) * delta;
                    else if (pivot != 0)
                        _owner.x += delta * (-pivot);
                    break;
                case RelationType.Left_Center:
                    if (info.percent)
                        _owner.xMin = pos + (_owner.xMin - pos) * delta;
                    else
                        _owner.x += delta * (0.5f - pivot);
                    break;
                case RelationType.Left_Right:
                    if (info.percent)
                        _owner.xMin = pos + (_owner.xMin - pos) * delta;
                    else
                        _owner.x += delta * (1 - pivot);
                    break;
                case RelationType.Center_Center:
                    if (info.percent)
                        _owner.xMin = pos + (_owner.xMin + _owner._rawWidth * 0.5f - pos) * delta - _owner._rawWidth * 0.5f;
                    else
                        _owner.x += delta * (0.5f - pivot);
                    break;
                case RelationType.Right_Left:
                    if (info.percent)
                        _owner.xMin = pos + (_owner.xMin + _owner._rawWidth - pos) * delta - _owner._rawWidth;
                    else if (pivot != 0)
                        _owner.x += delta * (-pivot);
                    break;
                case RelationType.Right_Center:
                    if (info.percent)
                        _owner.xMin = pos + (_owner.xMin + _owner._rawWidth - pos) * delta - _owner._rawWidth;
                    else
                        _owner.x += delta * (0.5f - pivot);
                    break;
                case RelationType.Right_Right:
                    if (info.percent)
                        _owner.xMin = pos + (_owner.xMin + _owner._rawWidth - pos) * delta - _owner._rawWidth;
                    else
                        _owner.x += delta * (1 - pivot);
                    break;

                case RelationType.Top_Top:
                    if (info.percent)
                        _owner.yMin = pos + (_owner.yMin - pos) * delta;
                    else if (pivot != 0)
                        _owner.y += delta * (-pivot);
                    break;
                case RelationType.Top_Middle:
                    if (info.percent)
                        _owner.yMin = pos + (_owner.yMin - pos) * delta;
                    else
                        _owner.y += delta * (0.5f - pivot);
                    break;
                case RelationType.Top_Bottom:
                    if (info.percent)
                        _owner.yMin = pos + (_owner.yMin - pos) * delta;
                    else
                        _owner.y += delta * (1 - pivot);
                    break;
                case RelationType.Middle_Middle:
                    if (info.percent)
                        _owner.yMin = pos + (_owner.yMin + _owner._rawHeight * 0.5f - pos) * delta - _owner._rawHeight * 0.5f;
                    else
                        _owner.y += delta * (0.5f - pivot);
                    break;
                case RelationType.Bottom_Top:
                    if (info.percent)
                        _owner.yMin = pos + (_owner.yMin + _owner._rawHeight - pos) * delta - _owner._rawHeight;
                    else if (pivot != 0)
                        _owner.y += delta * (-pivot);
                    break;
                case RelationType.Bottom_Middle:
                    if (info.percent)
                        _owner.yMin = pos + (_owner.yMin + _owner._rawHeight - pos) * delta - _owner._rawHeight;
                    else
                        _owner.y += delta * (0.5f - pivot);
                    break;
                case RelationType.Bottom_Bottom:
                    if (info.percent)
                        _owner.yMin = pos + (_owner.yMin + _owner._rawHeight - pos) * delta - _owner._rawHeight;
                    else
                        _owner.y += delta * (1 - pivot);
                    break;

                case RelationType.Width:
                    if (_owner.underConstruct && _owner == _target.parent)
                        v = _owner.sourceWidth - _target.initWidth;
                    else
                        v = _owner._rawWidth - _targetData.z;
                    if (info.percent)
                        v = v * delta;
                    if (_target == _owner.parent)
                    {
                        if (_owner.pivotAsAnchor)
                        {
                            tmp = _owner.xMin;
                            _owner.SetSize(_target._width + v, _owner._rawHeight, true);
                            _owner.xMin = tmp;
                        }
                        else
                            _owner.SetSize(_target._width + v, _owner._rawHeight, true);
                    }
                    else
                        _owner.width = _target._width + v;
                    break;
                case RelationType.Height:
                    if (_owner.underConstruct && _owner == _target.parent)
                        v = _owner.sourceHeight - _target.initHeight;
                    else
                        v = _owner._rawHeight - _targetData.w;
                    if (info.percent)
                        v = v * delta;
                    if (_target == _owner.parent)
                    {
                        if (_owner.pivotAsAnchor)
                        {
                            tmp = _owner.yMin;
                            _owner.SetSize(_owner._rawWidth, _target._height + v, true);
                            _owner.yMin = tmp;
                        }
                        else
                            _owner.SetSize(_owner._rawWidth, _target._height + v, true);
                    }
                    else
                        _owner.height = _target._height + v;
                    break;

                case RelationType.LeftExt_Left:
                    tmp = _owner.xMin;
                    if (info.percent)
                        v = pos + (tmp - pos) * delta - tmp;
                    else
                        v = delta * (-pivot);
                    _owner.width = _owner._rawWidth - v;
                    _owner.xMin = tmp + v;
                    break;
                case RelationType.LeftExt_Right:
                    tmp = _owner.xMin;
                    if (info.percent)
                        v = pos + (tmp - pos) * delta - tmp;
                    else
                        v = delta * (1 - pivot);
                    _owner.width = _owner._rawWidth - v;
                    _owner.xMin = tmp + v;
                    break;
                case RelationType.RightExt_Left:
                    tmp = _owner.xMin;
                    if (info.percent)
                        v = pos + (tmp + _owner._rawWidth - pos) * delta - (tmp + _owner._rawWidth);
                    else
                        v = delta * (-pivot);
                    _owner.width = _owner._rawWidth + v;
                    _owner.xMin = tmp;
                    break;
                case RelationType.RightExt_Right:
                    tmp = _owner.xMin;
                    if (info.percent)
                    {
                        if (_owner == _target.parent)
                        {
                            if (_owner.underConstruct)
                                _owner.width = pos + _target._width - _target._width * pivot +
                                    (_owner.sourceWidth - pos - _target.initWidth + _target.initWidth * pivot) * delta;
                            else
                                _owner.width = pos + (_owner._rawWidth - pos) * delta;
                        }
                        else
                        {
                            v = pos + (tmp + _owner._rawWidth - pos) * delta - (tmp + _owner._rawWidth);
                            _owner.width = _owner._rawWidth + v;
                            _owner.xMin = tmp;
                        }
                    }
                    else
                    {
                        if (_owner == _target.parent)
                        {
                            if (_owner.underConstruct)
                                _owner.width = _owner.sourceWidth + (_target._width - _target.initWidth) * (1 - pivot);
                            else
                                _owner.width = _owner._rawWidth + delta * (1 - pivot);
                        }
                        else
                        {
                            v = delta * (1 - pivot);
                            _owner.width = _owner._rawWidth + v;
                            _owner.xMin = tmp;
                        }
                    }
                    break;
                case RelationType.TopExt_Top:
                    tmp = _owner.yMin;
                    if (info.percent)
                        v = pos + (tmp - pos) * delta - tmp;
                    else
                        v = delta * (-pivot);
                    _owner.height = _owner._rawHeight - v;
                    _owner.yMin = tmp + v;
                    break;
                case RelationType.TopExt_Bottom:
                    tmp = _owner.yMin;
                    if (info.percent)
                        v = pos + (tmp - pos) * delta - tmp;
                    else
                        v = delta * (1 - pivot);
                    _owner.height = _owner._rawHeight - v;
                    _owner.yMin = tmp + v;
                    break;
                case RelationType.BottomExt_Top:
                    tmp = _owner.yMin;
                    if (info.percent)
                        v = pos + (tmp + _owner._rawHeight - pos) * delta - (tmp + _owner._rawHeight);
                    else
                        v = delta * (-pivot);
                    _owner.height = _owner._rawHeight + v;
                    _owner.yMin = tmp;
                    break;
                case RelationType.BottomExt_Bottom:
                    tmp = _owner.yMin;
                    if (info.percent)
                    {
                        if (_owner == _target.parent)
                        {
                            if (_owner.underConstruct)
                                _owner.height = pos + _target._height - _target._height * pivot +
                                    (_owner.sourceHeight - pos - _target.initHeight + _target.initHeight * pivot) * delta;
                            else
                                _owner.height = pos + (_owner._rawHeight - pos) * delta;
                        }
                        else
                        {
                            v = pos + (tmp + _owner._rawHeight - pos) * delta - (tmp + _owner._rawHeight);
                            _owner.height = _owner._rawHeight + v;
                            _owner.yMin = tmp;
                        }
                    }
                    else
                    {
                        if (_owner == _target.parent)
                        {
                            if (_owner.underConstruct)
                                _owner.height = _owner.sourceHeight + (_target._height - _target.initHeight) * (1 - pivot);
                            else
                                _owner.height = _owner._rawHeight + delta * (1 - pivot);
                        }
                        else
                        {
                            v = delta * (1 - pivot);
                            _owner.height = _owner._rawHeight + v;
                            _owner.yMin = tmp;
                        }
                    }
                    break;
            }
        }
Beispiel #19
0
        void ApplyOnXYChanged(RelationDef info, float dx, float dy)
        {
            float tmp;
            switch (info.type)
            {
                case RelationType.Left_Left:
                case RelationType.Left_Center:
                case RelationType.Left_Right:
                case RelationType.Center_Center:
                case RelationType.Right_Left:
                case RelationType.Right_Center:
                case RelationType.Right_Right:
                    _owner.x += dx;
                    break;

                case RelationType.Top_Top:
                case RelationType.Top_Middle:
                case RelationType.Top_Bottom:
                case RelationType.Middle_Middle:
                case RelationType.Bottom_Top:
                case RelationType.Bottom_Middle:
                case RelationType.Bottom_Bottom:
                    _owner.y += dy;
                    break;

                case RelationType.Width:
                case RelationType.Height:
                    break;

                case RelationType.LeftExt_Left:
                case RelationType.LeftExt_Right:
                    tmp = _owner.x;
                    _owner.x += dx;
                    _owner.width = _owner._rawWidth - (_owner.x - tmp);
                    break;

                case RelationType.RightExt_Left:
                case RelationType.RightExt_Right:
                    _owner.width = _owner._rawWidth + dx;
                    break;

                case RelationType.TopExt_Top:
                case RelationType.TopExt_Bottom:
                    tmp = _owner.y;
                    _owner.y += dy;
                    _owner.height = _owner._rawHeight - (_owner.y - tmp);
                    break;

                case RelationType.BottomExt_Top:
                case RelationType.BottomExt_Bottom:
                    _owner.height = _owner._rawHeight + dy;
                    break;
            }
        }
 internal void QuickAdd(RelationType relationType, bool usePercent)
 {
     if (relationType == RelationType.Size)
     {
         QuickAdd(RelationType.Width, usePercent);
         QuickAdd(RelationType.Height, usePercent);
         return;
     }
     RelationDef info = new RelationDef();
     info.affectBySelfSizeChanged = relationType >= RelationType.Center_Center && relationType <= RelationType.Right_Right
         || relationType >= RelationType.Middle_Middle && relationType <= RelationType.Bottom_Bottom;
     info.percent = usePercent;
     info.type = relationType;
     _defs.Add(info);
 }
Beispiel #21
0
 public void copyFrom(RelationDef source)
 {
     this.percent = source.percent;
     this.type = source.type;
 }