Пример #1
0
        /// <summary>
        /// normalize instance value from negative to positive rectangle
        /// </summary>
        /// <returns></returns>
        public LayoutRect Normalize()
        {
            var l = Math.Min(L.Lx, R.Lx);
            var t = Math.Min(T.Ly, B.Ly);
            var r = Math.Max(L.Lx, R.Lx);
            var b = Math.Max(T.Ly, B.Ly);

            LT = new LayoutPos
            {
                X = new LayoutX {
                    Lx = l
                },
                Y = new LayoutY {
                    Ly = t
                },
            };
            RB = new LayoutPos
            {
                X = new LayoutX {
                    Lx = r
                },
                Y = new LayoutY {
                    Ly = b
                },
            };
            return(this);
        }
Пример #2
0
        /// <summary>
        /// make a new instance from Left-Top and size
        /// </summary>
        /// <param name="lt"></param>
        /// <param name="size"></param>
        /// <returns></returns>

        public static LayoutRect From(LayoutPos lt, LayoutSize size)
        {
            return(new LayoutRect
            {
                LT = new LayoutPos
                {
                    X = new LayoutX {
                        Lx = lt.X.Lx
                    },
                    Y = new LayoutY {
                        Ly = lt.Y.Ly
                    },
                },
                RB = new LayoutPos
                {
                    X = new LayoutX {
                        Lx = lt.X.Lx + size.Width.Lx
                    },
                    Y = new LayoutY {
                        Ly = lt.Y.Ly + size.Height.Ly
                    },
                },
            });
        }
Пример #3
0
        /// <summary>
        /// make a new instance from left, center y, width and height
        /// </summary>
        /// <param name="leftcenter"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>

        public static LayoutRect FromLWH(LayoutPos leftcenter, double width, double height)
        {
            return(new LayoutRect
            {
                LT = new LayoutPos
                {
                    X = new LayoutX {
                        Lx = leftcenter.X.Lx
                    },
                    Y = new LayoutY {
                        Ly = leftcenter.Y.Ly - height / 2
                    },
                },
                RB = new LayoutPos
                {
                    X = new LayoutX {
                        Lx = leftcenter.X.Lx + width
                    },
                    Y = new LayoutY {
                        Ly = leftcenter.Y.Ly + height / 2
                    },
                },
            });
        }
Пример #4
0
 /// <summary>
 /// make a new instance from center x, bottom y, width and height
 /// </summary>
 /// <param name="centerbottom"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <returns></returns>
 public static LayoutRect FromCbWH(LayoutPos centerbottom, double width, double height)
 {
     return(new LayoutRect
     {
         LT = new LayoutPos
         {
             X = new LayoutX {
                 Lx = centerbottom.X.Lx - width / 2
             },
             Y = new LayoutY {
                 Ly = centerbottom.Y.Ly - height
             },
         },
         RB = new LayoutPos
         {
             X = new LayoutX {
                 Lx = centerbottom.X.Lx + width / 2
             },
             Y = new LayoutY {
                 Ly = centerbottom.Y.Ly
             },
         },
     });
 }
Пример #5
0
        /// <summary>
        /// make a new instance from Left-Top, width and height
        /// </summary>
        /// <param name="lt"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>

        public static LayoutRect FromLTWH(LayoutPos lt, double width, double height)
        {
            return(new LayoutRect
            {
                LT = new LayoutPos
                {
                    X = new LayoutX {
                        Lx = lt.X.Lx
                    },
                    Y = new LayoutY {
                        Ly = lt.Y.Ly
                    },
                },
                RB = new LayoutPos
                {
                    X = new LayoutX {
                        Lx = lt.X.Lx + width
                    },
                    Y = new LayoutY {
                        Ly = lt.Y.Ly + height
                    },
                },
            });
        }
Пример #6
0
        /// <summary>
        /// make a new instance from LT and RB
        /// </summary>
        /// <param name="lt">Left-Top</param>
        /// <param name="rb">Right-Bottom</param>
        /// <returns></returns>

        public static LayoutRect FromLTRB(LayoutPos lt, LayoutPos rb)
        {
            return(new LayoutRect
            {
                LT = new LayoutPos
                {
                    X = new LayoutX {
                        Lx = lt.X.Lx
                    },
                    Y = new LayoutY {
                        Ly = lt.Y.Ly
                    },
                },
                RB = new LayoutPos
                {
                    X = new LayoutX {
                        Lx = rb.X.Lx
                    },
                    Y = new LayoutY {
                        Ly = rb.Y.Ly
                    },
                },
            });
        }
Пример #7
0
        /// <summary>
        /// make a new instance from center and size
        /// </summary>
        /// <param name="center"></param>
        /// <param name="size"></param>
        /// <returns></returns>

        public static LayoutRect FromCS(LayoutPos center, LayoutSize size)
        {
            return(FromCWH(center, size.Width.Lx, size.Height.Ly));
        }
Пример #8
0
 /// <summary>
 /// check position is in this space
 /// </summary>
 /// <param name="pos"></param>
 /// <returns></returns>
 public bool IsIn(LayoutPos pos)
 {
     return(LT.X <= pos.X && RB.X >= pos.X && LT.Y <= pos.Y && RB.Y >= pos.Y);
 }
Пример #9
0
        /// <summary>
        /// offset vertical position
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <returns></returns>

        public static LayoutRect operator -(LayoutRect v1, LayoutY v2)
        {
            return(new LayoutRect {
                LT = LayoutPos.From(v1.LT.X, v1.LT.Y - v2), RB = LayoutPos.From(v1.R, v1.RB.Y - v2),
            });
        }
Пример #10
0
        /// <summary>
        /// offset horizontal position
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <returns></returns>

        public static LayoutRect operator +(LayoutRect v1, LayoutX v2)
        {
            return(new LayoutRect {
                LT = LayoutPos.From(v1.LT.X + v2, v1.LT.Y), RB = LayoutPos.From(v1.R + v2, v1.RB.Y),
            });
        }
Пример #11
0
 /// <summary>
 /// deflate instance
 /// </summary>
 /// <param name="all"></param>
 /// <returns></returns>
 public void Deflate(LayoutSize size)
 {
     LT += size / 2;
     RB -= size / 2;
 }
Пример #12
0
 /// <summary>
 /// infrate instance
 /// </summary>
 /// <param name="all"></param>
 /// <returns></returns>
 public void Inflate(LayoutSize size)
 {
     LT -= size / 2.0;
     RB += size / 2.0;
 }