示例#1
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="other"></param>
 public AnchorArea(AnchorArea other)
 {
     Right  = other.Right;
     Left   = other.Left;
     Bottom = other.Bottom;
     Top    = other.Top;
     Center = other.Center;
     Middle = other.Middle;
 }
示例#2
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="other"></param>
 public AnchorArea(AnchorArea other)
 {
     Right = other.Right;
     Left = other.Left;
     Bottom = other.Bottom;
     Top = other.Top;
     Center = other.Center;
     Middle = other.Middle;
 }
示例#3
0
        /// <summary>
        /// Calculate the destination area of
        /// </summary>
        /// <param name="area"></param>
        /// <param name="content"></param>
        /// <param name="anchor"></param>
        /// <returns></returns>
        public static RectangleF CalculateArea(RectangleF area, SizeF content, AnchorArea anchor)
        {
            if (anchor.IsEmpty)
            {
                return(area);
            }
            else
            {
                RectangleF destination = new RectangleF();

                //Left and width
                if (anchor.Center)
                {
                    //TODO Try in the future to use also Left and Right property when align the content.
                    destination.X     = (area.X + area.Width / 2.0F) - content.Width / 2.0F;
                    destination.Width = content.Width;
                }
                else if (anchor.HasLeft && anchor.HasRight)
                {
                    destination.X     = area.Left + anchor.Left;
                    destination.Width = area.Width - (anchor.Left + anchor.Right);
                }
                else if (anchor.HasLeft)
                {
                    destination.X     = area.Left + anchor.Left;
                    destination.Width = content.Width;
                }
                else if (anchor.HasRight)
                {
                    destination.X     = (area.Right - content.Width) - anchor.Right;
                    destination.Width = content.Width;
                }
                else
                {
                    destination.X     = area.Left;
                    destination.Width = content.Width;
                }

                //Top and height
                if (anchor.Middle)
                {
                    //TODO Try in the future to use also Left and Right property when align the content.
                    destination.Y      = (area.Y + area.Height / 2.0F) - content.Height / 2.0F;
                    destination.Height = content.Height;
                }
                else if (anchor.HasTop && anchor.HasBottom)
                {
                    destination.Y      = area.Top + anchor.Top;
                    destination.Height = area.Height - (anchor.Top + anchor.Bottom);
                }
                else if (anchor.HasTop)
                {
                    destination.Y      = area.Top + anchor.Top;
                    destination.Height = content.Height;
                }
                else if (anchor.HasBottom)
                {
                    destination.Y      = (area.Bottom - content.Height) - anchor.Bottom;
                    destination.Height = content.Height;
                }
                else
                {
                    destination.Y      = area.Top;
                    destination.Height = content.Height;
                }

                destination.Intersect(area);
                return(destination);
            }
        }
示例#4
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            if (!(obj is AnchorArea))
            {
                throw new ArgumentException("Invalid object, AnchorArea expected");
            }

            AnchorArea other = (AnchorArea)obj;

            int topCompare    = Top.CompareTo(other.Top);
            int bottomCompare = Bottom.CompareTo(other.Bottom);
            int leftCompare   = Left.CompareTo(other.Left);
            int rightCompare  = Right.CompareTo(other.Right);
            int centerCompare = Center.CompareTo(other.Center);
            int middleCompare = Middle.CompareTo(other.Middle);

            if (topCompare > 1)
            {
                return(1);
            }
            else if (topCompare < 1)
            {
                return(-1);
            }
            else
            {
                if (bottomCompare > 1)
                {
                    return(1);
                }
                else if (bottomCompare < 1)
                {
                    return(-1);
                }
                else
                {
                    if (rightCompare > 1)
                    {
                        return(1);
                    }
                    else if (rightCompare < 1)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (leftCompare > 1)
                        {
                            return(1);
                        }
                        else if (leftCompare < 1)
                        {
                            return(-1);
                        }
                        else
                        {
                            if (centerCompare > 1)
                            {
                                return(1);
                            }
                            else if (centerCompare < 1)
                            {
                                return(-1);
                            }
                            else
                            {
                                if (middleCompare > 1)
                                {
                                    return(1);
                                }
                                else if (middleCompare < 1)
                                {
                                    return(-1);
                                }
                                else
                                {
                                    return(0);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Calculate the destination area of 
        /// </summary>
        /// <param name="area"></param>
        /// <param name="content"></param>
        /// <param name="anchor"></param>
        /// <returns></returns>
        public static RectangleF CalculateArea(RectangleF area, SizeF content, AnchorArea anchor)
        {
            if (anchor.IsEmpty)
                return area;
            else
            {
                RectangleF destination = new RectangleF();

                //Left and width
                if (anchor.Center)
                {
                    //TODO Try in the future to use also Left and Right property when align the content.
                    destination.X = (area.X + area.Width / 2.0F) - content.Width / 2.0F;
                    destination.Width = content.Width;
                }
                else if (anchor.HasLeft && anchor.HasRight)
                {
                    destination.X = area.Left + anchor.Left;
                    destination.Width = area.Width - (anchor.Left + anchor.Right);
                }
                else if (anchor.HasLeft)
                {
                    destination.X = area.Left + anchor.Left;
                    destination.Width = content.Width;
                }
                else if (anchor.HasRight)
                {
                    destination.X = (area.Right - content.Width) - anchor.Right;
                    destination.Width = content.Width;
                }
                else
                {
                    destination.X = area.Left;
                    destination.Width = content.Width;
                }

                //Top and height
                if (anchor.Middle)
                {
                    //TODO Try in the future to use also Left and Right property when align the content.
                    destination.Y = (area.Y + area.Height / 2.0F) - content.Height / 2.0F;
                    destination.Height = content.Height;
                }
                else if (anchor.HasTop && anchor.HasBottom)
                {
                    destination.Y = area.Top + anchor.Top;
                    destination.Height = area.Height - (anchor.Top + anchor.Bottom);
                }
                else if (anchor.HasTop)
                {
                    destination.Y = area.Top + anchor.Top;
                    destination.Height = content.Height;
                }
                else if (anchor.HasBottom)
                {
                    destination.Y = (area.Bottom - content.Height) - anchor.Bottom;
                    destination.Height = content.Height;
                }
                else
                {
                    destination.Y = area.Top;
                    destination.Height = content.Height;
                }

                destination.Intersect(area);
                return destination;
            }
        }