2006-06-15 04:19:30 +00:00
|
|
|
#include "PH_DirectInput.h"
|
2008-08-24 21:28:42 +00:00
|
|
|
#include "ControllerSettingsWnd.h"
|
|
|
|
#include "InputConfig.h"
|
2008-12-24 01:39:03 +00:00
|
|
|
#include "placeholder_def.h"
|
2006-06-15 04:19:30 +00:00
|
|
|
|
2012-04-01 20:19:31 +00:00
|
|
|
CPH_DirectInput::CPH_DirectInput(HWND hWnd)
|
|
|
|
: m_hWnd(hWnd)
|
|
|
|
, m_manager(NULL)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
|
|
|
m_hWnd = hWnd;
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
CPH_DirectInput::~CPH_DirectInput()
|
|
|
|
{
|
2012-04-01 20:19:31 +00:00
|
|
|
delete m_manager;
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 01:37:47 +00:00
|
|
|
CPadHandler::FactoryFunction CPH_DirectInput::GetFactoryFunction(HWND hWnd)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2012-04-01 20:19:31 +00:00
|
|
|
return std::bind(&CPH_DirectInput::PadHandlerFactory, hWnd);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 01:37:47 +00:00
|
|
|
CPadHandler* CPH_DirectInput::PadHandlerFactory(HWND hWnd)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2008-01-24 01:37:47 +00:00
|
|
|
return new CPH_DirectInput(hWnd);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPH_DirectInput::Initialize()
|
|
|
|
{
|
2012-04-01 20:19:31 +00:00
|
|
|
m_manager = new Framework::DirectInput::CManager();
|
|
|
|
m_manager->CreateKeyboard(m_hWnd);
|
|
|
|
m_manager->CreateJoysticks(m_hWnd);
|
2008-08-24 21:28:42 +00:00
|
|
|
}
|
2006-06-15 04:19:30 +00:00
|
|
|
|
2012-04-01 20:19:31 +00:00
|
|
|
Framework::DirectInput::CManager* CPH_DirectInput::GetManager() const
|
2008-08-24 21:28:42 +00:00
|
|
|
{
|
2012-04-01 20:19:31 +00:00
|
|
|
return m_manager;
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
2008-01-25 23:47:09 +00:00
|
|
|
void CPH_DirectInput::Update(uint8* ram)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2012-04-01 20:19:31 +00:00
|
|
|
CInputConfig::InputEventHandler eventHandler(std::bind(&CPH_DirectInput::ProcessEvents, this,
|
|
|
|
std::placeholders::_1, std::placeholders::_2, ram));
|
|
|
|
m_manager->ProcessEvents(
|
|
|
|
std::bind(&CInputConfig::TranslateInputEvent, &CInputConfig::GetInstance(),
|
|
|
|
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::tr1::cref(eventHandler)));
|
2008-08-24 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 20:19:31 +00:00
|
|
|
void CPH_DirectInput::ProcessEvents(PS2::CControllerInfo::BUTTON button, uint32 value, uint8* ram)
|
2008-08-24 21:28:42 +00:00
|
|
|
{
|
2012-04-01 20:19:31 +00:00
|
|
|
for(auto listenerIterator(std::begin(m_listeners));
|
|
|
|
listenerIterator != std::end(m_listeners); listenerIterator++)
|
|
|
|
{
|
|
|
|
auto pListener(*listenerIterator);
|
|
|
|
if(PS2::CControllerInfo::IsAxis(button))
|
|
|
|
{
|
|
|
|
pListener->SetAxisState(0, button, static_cast<uint8>((value & 0xFFFF) >> 8), ram);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pListener->SetButtonState(0, button, value ? true : false, ram);
|
|
|
|
}
|
|
|
|
}
|
2008-08-24 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 20:19:31 +00:00
|
|
|
Framework::Win32::CModalWindow* CPH_DirectInput::CreateSettingsDialog(HWND parent)
|
2008-08-24 21:28:42 +00:00
|
|
|
{
|
2012-04-01 20:19:31 +00:00
|
|
|
return new CControllerSettingsWnd(parent, m_manager);
|
2008-08-24 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPH_DirectInput::OnSettingsDialogDestroyed()
|
|
|
|
{
|
|
|
|
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|