/// <summary> /// Was button actually clicked? /// </summary> /// <param name="button">Button object to test</param> /// <returns>True if button was clicked, else false</returns> public bool IsButtonClicked(Button button) { // Test mouse input that we had a button click event first if (m_currentMouseState.LeftButton == ButtonState.Released && m_lastMouseState.LeftButton == ButtonState.Pressed) { // Check if mouse pointer is inside button if ((button.Rect.X) >= m_currentMouseState.X && (button.Rect.Y) >= m_currentMouseState.Y && (button.Rect.X + button.Rect.Width) <= m_currentMouseState.X && (button.Rect.Y + button.Rect.Height) <= m_currentMouseState.Y) { return true; } } return false; }
/// <summary> /// Is button pressed down by touch points? /// </summary> /// <param name="button">Button object to test</param> /// <returns>True if mouse pointer is presseing down on this button, else false</returns> public bool IsButtonDown(Button button) { // Test mouse input if (m_currentMouseState.LeftButton == ButtonState.Pressed) { // Check if mouse pointer is inside button if ((button.Rect.X) >= m_currentMouseState.X && (button.Rect.Y) >= m_currentMouseState.Y && (button.Rect.X + button.Rect.Width) <= m_currentMouseState.X && (button.Rect.Y + button.Rect.Height) <= m_currentMouseState.Y) { return true; } } return false; }
/// <summary> /// Draw a button /// </summary> /// <param name="button">Button object</param> /// <param name="down">Is button pressed down?</param> public void DrawButton(Button button, bool down) { // Bind sprite batcher m_spriteBatch.Begin(); // Draw button m_spriteBatch.Draw(down ? button.Down : button.Up, button.Rect, Color.White); // Unbind the sprite batcher m_spriteBatch.End(); }