Esempio n. 1
0
 /// <summary>
 /// ons the tile added.
 /// </summary>
 /// <param name="arg1">The arg1.</param>
 /// <param name="arg2">The arg2.</param>
 private void onTileAdded(TileMaskCollection arg1, TileMask arg2)
 {
     requireUpdateLeft   = true;
     requireUpdateTop    = true;
     requireUpdateBottom = true;
     requireUpdateRight  = true;
 }
        /// <summary>
        /// Increases the selection z index.
        /// </summary>
        public bool IncreaseSelectionZIndex()
        {
            selection.Sort();

            uint     selMinZ  = selection.tiles.First().Z;
            uint     selMaxZ  = selection.tiles.Last().Z;
            TileMask MaxZTile = tiles.FirstOrDefault(t =>
            {
                return(t.Z > selMinZ && !selection.tiles.Contains(t));
            });

            if (MaxZTile != default(TileMask))
            {
                var upperTiles = tiles.Where(t =>
                {
                    return(t.Z > MaxZTile.Z && !selection.tiles.Contains(t));
                });

                uint i = MaxZTile.Z + 1;

                foreach (TileMask t in selection.tiles)
                {
                    t.Z = i;
                    i++;
                }

                foreach (TileMask t in upperTiles)
                {
                    t.Z = i;
                    i++;
                }

                sorted = false;
                Sort();
                OnSelectionZIndexChanged?.Invoke(this, selection);
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Adds the.
        /// </summary>
        /// <param name="tile">The tile.</param>
        public void Add(TileMask tile)
        {
            if (tile == null)
            {
                return;
            }
            if (Count > 0)
            {
                tile.Z = tiles.Last().Z + 1;
            }
            else
            {
                tile.Z = 0;
            }

            tiles.Add(tile);

            if (tile.X < Left || Left < 0)
            {
                Left = tile.X;
            }
            if (tile.X + tile.Width > Right)
            {
                Right = tile.X + tile.Width;
            }
            if (tile.Y < Top || Top < 0)
            {
                Top = tile.Y;
            }
            if (tile.Y + tile.Height > Bottom)
            {
                Bottom = tile.Y + tile.Height;
            }

            RequireRefresh = true;
            OnTileAdded?.Invoke(this, tile);
        }
        /// <summary>
        /// Finds the by position.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        public TileMaskCollection FindByPosition(int x, int y)
        {
            ClearSelection();

            TileMask tm = tiles.FirstOrDefault((t) =>
            {
                if (t.X <= x && t.X + t.Width >= x &&
                    t.Y <= y && t.Y + t.Height >= y)
                {
                    return(true);
                }

                return(false);
            });

            if (tm == default)
            {
                return(selection);
            }

            selection.Add(tm);
            OnSelectionChanged?.Invoke(this, selection);
            return(selection);
        }