Gonzo.Elements.UIElement.PixelCheck C# (CSharp) Method

PixelCheck() protected method

protected PixelCheck ( InputHelper Input, int Width ) : bool
Input InputHelper
Width int
return bool
        protected bool PixelCheck(InputHelper Input, int Width)
        {
            if (Image == null || !Image.Loaded)
                return false;

            // Get Mouse position relative to top left of Texture
            Vector2 pixelPosition = Input.MousePosition - m_Position;

            // I know. I just checked this condition at OnMouseOver or we wouldn't be here
            // but just to be sure the spot we're checking is within the bounds of the texture...
            if (pixelPosition.X >= 0 && pixelPosition.X < Width &&
                pixelPosition.Y >= 0 && pixelPosition.Y < Image.Texture.Height)
            {
                // Get the Texture Data within the Rectangle coords, in this case a 1 X 1 rectangle
                // Store the data in pixelData Array
                Image.Texture.GetData<uint>(0, new Rectangle((int)pixelPosition.X, (int)pixelPosition.Y,
                    (1), (1)), PixelData, 0, 1);

                // Check if pixel in Array is non Alpha, give or take 20
                if (((PixelData[0] & 0xFF000000) >> 24) > 20)
                    return true;
            }

            return false;
        }