Esempio n. 1
0
        public void OnDeserialization(object sender)
        {
            childRegions = new SortedDictionary <int, AbstractRegion>();

            regionTiles = new RegionTile[size.Width, size.Height];
            for (int x = 0; x < size.Width; ++x)
            {
                for (int y = 0; y < size.Height; ++y)
                {
                    regionTiles[x, y] = new RegionTile();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Change the size of the region.
        /// </summary>
        /// <param name="dimensions">The new size.</param>
        private void ResizeRegion(Size dimensions)
        {
            foreach (KeyValuePair <Int32, AbstractRegion> kvp in this.childRegions)
            {
                AbstractRegion child = kvp.Value;

                Int32 childleft   = child.Location.X;
                Int32 childtop    = child.Location.Y;
                Int32 childwidth  = child.Size.Width;
                Int32 childheight = child.Size.Height;

                if ((child.RegionAnchor | Anchor.Top) == Anchor.Top)
                {
                    if ((child.RegionAnchor | Anchor.Bottom) == Anchor.Bottom)
                    {
                        childheight += dimensions.Height - size.Height;
                    }
                }
                else
                {
                    if ((child.RegionAnchor | Anchor.Bottom) == Anchor.Bottom)
                    {
                        childtop += dimensions.Height - size.Height;
                    }
                }

                if ((child.RegionAnchor | Anchor.Left) == Anchor.Left)
                {
                    if ((child.RegionAnchor | Anchor.Right) == Anchor.Right)
                    {
                        childleft += dimensions.Width - size.Width;
                    }
                }
                else
                {
                    if ((child.RegionAnchor | Anchor.Right) == Anchor.Right)
                    {
                        childwidth += dimensions.Width - size.Width;
                    }
                }

                child.Location = new Point(childleft, childtop);
                child.Size     = new Size(childwidth, childheight);
            }

            if (Parent != null)
            {
                Parent.InvalidateTiles(new Rectangle(this.location,
                                                     new Size(Math.Max(this.Size.Width, dimensions.Width),
                                                              Math.Max(this.Size.Height, dimensions.Height))));
            }

            RegionTile[,] newRegion = new RegionTile[dimensions.Width, dimensions.Height];

            for (Int32 y = 0; y < dimensions.Height; y++)
            {
                for (Int32 x = 0; x < dimensions.Width; x++)
                {
                    if (x < regionTiles.GetLength(0) && y < regionTiles.GetLength(1))
                    {
                        newRegion[x, y] = regionTiles[x, y];
                    }
                    else
                    {
                        newRegion[x, y] = new RegionTile();
                    }
                }
            }

            regionTiles = newRegion;
        }