/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/src/sgx/input/controlbutton.cpp

*/

#include "sgx/core/core.hpp"
#include "sgx/input/input.hpp"

CSGXInputManager::CControlButton::CControlButton()
{
	reset();
}

void 
CSGXInputManager::CControlButton::reset()
{
	m_bPressed = FALSE;
	m_bReleased = FALSE;
	m_bIsUp = FALSE;
	m_bIsDown = FALSE;
}

void 
CSGXInputManager::CControlButton::update(const tREAL32 telaps)
{
SGX_UNUSED(telaps);
	m_bPressed = FALSE;
	m_bReleased = FALSE;
}


// NOTE: Implied data throughout
void 
CSGXInputManager::CControlButton::applyButtonDown()
{
	// Infer: Key is now down, but was up.
	m_bPressed = m_bIsUp;
	m_bReleased = FALSE;

	m_bIsUp = FALSE;
	m_bIsDown = TRUE;
}

void 
CSGXInputManager::CControlButton::applyButtonUp()
{
	// Infer: Key is now up, but was down.
	m_bReleased = m_bIsDown;
	m_bPressed = FALSE;

	m_bIsUp = TRUE;
	m_bIsDown = FALSE;
}

void 
CSGXInputManager::CControlButton::applyButtonPressed()
{
	m_bPressed = TRUE;
	m_bReleased = FALSE;

	m_bIsUp = FALSE;
	m_bIsDown = TRUE;
}

void 
CSGXInputManager::CControlButton::applyButtonReleased()
{
	m_bPressed = FALSE;
	m_bReleased = TRUE;

	m_bIsUp = TRUE;
	m_bIsDown = FALSE;
}

tBOOL	CSGXInputManager::CControlButton::wasPressed(const CCommandHandlerParameters &params) const{
	SGX_UNUSED(params);
	return m_bPressed;
}

tBOOL	CSGXInputManager::CControlButton::wasReleased(const CCommandHandlerParameters &params) const{
	SGX_UNUSED(params);
	return m_bReleased;
}

tBOOL	CSGXInputManager::CControlButton::getState(const CCommandHandlerParameters &params) const{
	SGX_UNUSED(params);
	return m_bIsDown;
}

tREAL32	CSGXInputManager::CControlButton::getPosition(const CCommandHandlerParameters &params) const{
	return params.prepareRange(m_bIsDown ? 1.0f : 0);
}

