/** 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/input_keys.cpp

*/

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

//
// Application of data from the platform-specific loop
//
void 
CSGXInputManager::applyKeyboardKeyUp(const tKey &key)
{
	m_pDeviceKeyboard->m_Key[key].applyButtonUp();
}

void 
CSGXInputManager::applyKeyboardKeyDown(const tKey &key)
{
	m_pDeviceKeyboard->m_Key[key].applyButtonDown();
}

void 
CSGXInputManager::applyKeyboardPressed(const tKey &key)
{
	m_pDeviceKeyboard->m_Key[key].applyButtonPressed();
}

void 
CSGXInputManager::applyKeyboardReleased(const tKey &key)
{
	m_pDeviceKeyboard->m_Key[key].applyButtonReleased();
}

//
// Cross-platform query functions
//
tBOOL
CSGXInputManager::isKeyboardKeyUp(const tKey &key)
{
    return m_Keyboard.m_Key[key].m_bIsUp;
}

tBOOL
CSGXInputManager::isKeyboardKeyDown(const tKey &key)
{
    return m_Keyboard.m_Key[key].m_bIsDown;
}

tBOOL
CSGXInputManager::isKeyboardKeyPressed(const tKey &key)
{
    return m_Keyboard.m_Key[key].m_bPressed;
}

tBOOL
CSGXInputManager::isKeyboardKeyReleased(const tKey &key)
{
    return m_Keyboard.m_Key[key].m_bReleased;
}


tUINT32		
CSGXInputManager::getKeyboardState(tBYTE *bitStates) {
	sgxMemset(bitStates, '\0', 8);
	for(tUINT32 i=0;i<256;++i) {
		bitStates[i/32] |= m_Keyboard.m_Key[i].m_bIsDown ? (1<<(i&31)):0;
	}
	return 8;
}
