Exemplo n.º 1
0
        /// <summary>
        /// Gets a unique set of identifiers that were selected on the screen.
        /// </summary>
        /// <param name="screenRectangle">The screen rectangle to select from.</param>
        /// <returns></returns>
        public IEnumerable <uint> GetIDsSelected(Rectangle screenRectangle)
        {
            int width  = Buffer.Width;
            int height = Buffer.Height;

            int            startX   = MathFunctions.Clamp(screenRectangle.X / Scale, 0, width - 1);
            int            startY   = MathFunctions.Clamp(screenRectangle.Y / Scale, 0, height - 1);
            int            endX     = MathFunctions.Clamp(screenRectangle.Right / Scale, 0, width - 1);
            int            endY     = MathFunctions.Clamp(screenRectangle.Bottom / Scale, 0, height - 1);
            HashSet <uint> selected = new HashSet <uint>();

            for (int x = startX; x <= endX; x++)
            {
                for (int y = startY; y <= endY; y++)
                {
                    uint id = GameComponent.GlobalIDFromColor(colorBuffer[x + y * width]);
                    if (id == 0)
                    {
                        continue;
                    }
                    if (selected.Contains(id))
                    {
                        continue;
                    }
                    selected.Add(id);
                    yield return(id);
                }
            }
        }