2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-02-10 18:54:46 +00:00
|
|
|
// Refer to the license.txt file included.
|
2013-06-17 00:07:10 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-07-11 14:53:51 +00:00
|
|
|
// For InputGateOn()
|
|
|
|
// This is a really bad layering violation, but it's the cleanest
|
|
|
|
// place I could find to put it.
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Host.h"
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2013-06-17 00:07:10 +00:00
|
|
|
|
|
|
|
namespace ciface
|
|
|
|
{
|
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Device :: ~Device
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
|
|
|
// Destructor, delete all inputs/outputs on device destruction
|
|
|
|
//
|
|
|
|
Device::~Device()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// delete inputs
|
|
|
|
for (Device::Input* input : m_inputs)
|
|
|
|
delete input;
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// delete outputs
|
|
|
|
for (Device::Output* output : m_outputs)
|
|
|
|
delete output;
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Device::AddInput(Device::Input* const i)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_inputs.push_back(i);
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Device::AddOutput(Device::Output* const o)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_outputs.push_back(o);
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
Device::Input* Device::FindInput(const std::string& name) const
|
2013-06-17 00:07:10 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (Input* input : m_inputs)
|
|
|
|
{
|
|
|
|
if (input->GetName() == name)
|
|
|
|
return input;
|
|
|
|
}
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return nullptr;
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
Device::Output* Device::FindOutput(const std::string& name) const
|
2013-06-17 00:07:10 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (Output* output : m_outputs)
|
|
|
|
{
|
|
|
|
if (output->GetName() == name)
|
|
|
|
return output;
|
|
|
|
}
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return nullptr;
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 14:53:51 +00:00
|
|
|
bool Device::Control::InputGateOn()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (SConfig::GetInstance().m_BackgroundInput)
|
|
|
|
return true;
|
|
|
|
else if (Host_RendererHasFocus() || Host_UIHasFocus())
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2014-07-11 14:53:51 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// DeviceQualifier :: ToString
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Get string from a device qualifier / serialize
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
|
|
|
std::string DeviceQualifier::ToString() const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (source.empty() && (cid < 0) && name.empty())
|
|
|
|
return "";
|
2014-01-31 00:51:21 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
std::ostringstream ss;
|
|
|
|
ss << source << '/';
|
|
|
|
if (cid > -1)
|
|
|
|
ss << cid;
|
|
|
|
ss << '/' << name;
|
2014-01-31 00:51:21 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return ss.str();
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// DeviceQualifier :: FromString
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Set a device qualifier from a string / unserialize
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
|
|
|
void DeviceQualifier::FromString(const std::string& str)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::istringstream ss(str);
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
std::getline(ss, source = "", '/');
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// silly
|
|
|
|
std::getline(ss, name, '/');
|
|
|
|
std::istringstream(name) >> (cid = -1);
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
std::getline(ss, name = "");
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// DeviceQualifier :: FromDevice
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Set a device qualifier from a device
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
|
|
|
void DeviceQualifier::FromDevice(const Device* const dev)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
name = dev->GetName();
|
|
|
|
cid = dev->GetId();
|
|
|
|
source = dev->GetSource();
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DeviceQualifier::operator==(const Device* const dev) const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (dev->GetId() == cid)
|
|
|
|
if (dev->GetName() == name)
|
|
|
|
if (dev->GetSource() == source)
|
|
|
|
return true;
|
2014-01-31 00:51:21 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DeviceQualifier::operator==(const DeviceQualifier& devq) const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (cid == devq.cid)
|
|
|
|
if (name == devq.name)
|
|
|
|
if (source == devq.source)
|
|
|
|
return true;
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (Device* d : m_devices)
|
|
|
|
{
|
|
|
|
if (devq == d)
|
|
|
|
return d;
|
|
|
|
}
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return nullptr;
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (def_dev)
|
|
|
|
{
|
|
|
|
Device::Input* const inp = def_dev->FindInput(name);
|
|
|
|
if (inp)
|
|
|
|
return inp;
|
|
|
|
}
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
for (Device* d : m_devices)
|
|
|
|
{
|
|
|
|
Device::Input* const i = d->FindInput(name);
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (i)
|
|
|
|
return i;
|
|
|
|
}
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return nullptr;
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return def_dev->FindOutput(name);
|
2013-06-17 00:07:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|