Esempio 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)
        {
            if (colorBuffer == null)
            {
                yield break;
            }

            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 = GameComponentExtensions.GlobalIDFromColor(colorBuffer[x + y * width]);
                    if (id == 0)
                    {
                        continue;
                    }
                    if (selected.Contains(id))
                    {
                        continue;
                    }
                    selected.Add(id);
                    yield return(id);
                }
            }
        }
Esempio n. 2
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)
        {
            ValidateBuffer(GameStates.GameState.Game.GraphicsDevice);
            HashSet <uint> selected = new HashSet <uint>();

            lock (ColorBufferMutex)
            {
                if (colorBuffer == null)
                {
                    return(selected);
                }

                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);

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

            return(selected);
        }