//-----------------------------------------------------------------------------------------------------------------------------------
void Button::HandleInput(DX::StepTimer const& timer, const Vector2& mousePosition)
{
	UIObject::HandleInput(timer, mousePosition);

	if (AcceptsInput())
	{
		if (IsMouseOver() && m_buttonState != ButtonState::kPressed)
		{
			m_buttonState = ButtonState::kHighlighted;
			SetColour(m_highlightedColour);
		}

		if (IsSelected())
		{
			if (m_buttonState != ButtonState::kPressed)
			{
				assert(m_clickFunction);

				m_clickFunction();
				m_buttonState = ButtonState::kPressed;
			}
		}
	}
}
Exemple #2
0
bool Button::processEvent(const cpp3ds::Event &event)
{
	if (event.type == cpp3ds::Event::TouchBegan)
	{
		if (m_rect.contains(event.touch.x, event.touch.y))
		{
			m_active = true;
			m_needsUpdate = true;
			return false;
		}
	}

	if (event.type == cpp3ds::Event::TouchEnded)
	{
		if (m_active) {
			m_active = false;
			m_needsUpdate = true;
			if (m_clickFunction)
				m_clickFunction();
			return false;
		}
	}

	if (event.type == cpp3ds::Event::TouchMoved)
	{
		if (m_active) {
			if (!m_rect.contains(event.touch.x, event.touch.y)) {
				m_active = false;
				m_needsUpdate = true;
			}
			return false;
		}
	}

	return true;
}