diff options
| author | Jules Blok <jules.blok@gmail.com> | 2015-06-10 00:00:12 +0200 |
|---|---|---|
| committer | Jules Blok <jules.blok@gmail.com> | 2015-06-10 00:00:12 +0200 |
| commit | 7dfced21a2e5aac7195e0e1ad76468e30306766b (patch) | |
| tree | bd671b639d3d911460b767caabad8fc8a759a6bf /Source/Core/InputCommon/ControllerInterface/Device.cpp | |
| parent | c25be031fc1031d795157d8344b87b7841145197 (diff) | |
| parent | 7b0a65e295c784f9d573f2ef52d4e2a7b9bb2889 (diff) | |
Merge branch 'master' into stable
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Device.cpp | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp new file mode 100644 index 0000000000..fae7e98e2f --- /dev/null +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -0,0 +1,185 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include <sstream> +#include <string> + +// 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" + +#include "InputCommon/ControllerInterface/Device.h" + +namespace ciface +{ +namespace Core +{ + +// +// Device :: ~Device +// +// Destructor, delete all inputs/outputs on device destruction +// +Device::~Device() +{ + // delete inputs + for (Device::Input* input : m_inputs) + delete input; + + // delete outputs + for (Device::Output* output: m_outputs) + delete output; +} + +void Device::AddInput(Device::Input* const i) +{ + m_inputs.push_back(i); +} + +void Device::AddOutput(Device::Output* const o) +{ + m_outputs.push_back(o); +} + +Device::Input* Device::FindInput(const std::string &name) const +{ + for (Input* input : m_inputs) + { + if (input->GetName() == name) + return input; + } + + return nullptr; +} + +Device::Output* Device::FindOutput(const std::string &name) const +{ + for (Output* output : m_outputs) + { + if (output->GetName() == name) + return output; + } + + return nullptr; +} + +bool Device::Control::InputGateOn() +{ + if (SConfig::GetInstance().m_BackgroundInput) + return true; + else if (Host_RendererHasFocus() || Host_UIHasFocus()) + return true; + else + return false; +} + +// +// DeviceQualifier :: ToString +// +// Get string from a device qualifier / serialize +// +std::string DeviceQualifier::ToString() const +{ + if (source.empty() && (cid < 0) && name.empty()) + return ""; + + std::ostringstream ss; + ss << source << '/'; + if (cid > -1) + ss << cid; + ss << '/' << name; + + return ss.str(); +} + +// +// DeviceQualifier :: FromString +// +// Set a device qualifier from a string / unserialize +// +void DeviceQualifier::FromString(const std::string& str) +{ + std::istringstream ss(str); + + std::getline(ss, source = "", '/'); + + // silly + std::getline(ss, name, '/'); + std::istringstream(name) >> (cid = -1); + + std::getline(ss, name = ""); +} + +// +// DeviceQualifier :: FromDevice +// +// Set a device qualifier from a device +// +void DeviceQualifier::FromDevice(const Device* const dev) +{ + name = dev->GetName(); + cid = dev->GetId(); + source= dev->GetSource(); +} + +bool DeviceQualifier::operator==(const Device* const dev) const +{ + if (dev->GetId() == cid) + if (dev->GetName() == name) + if (dev->GetSource() == source) + return true; + + return false; +} + +bool DeviceQualifier::operator==(const DeviceQualifier& devq) const +{ + if (cid == devq.cid) + if (name == devq.name) + if (source == devq.source) + return true; + + return false; +} + +Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const +{ + for (Device* d : m_devices) + { + if (devq == d) + return d; + } + + return nullptr; +} + +Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const +{ + if (def_dev) + { + Device::Input* const inp = def_dev->FindInput(name); + if (inp) + return inp; + } + + for (Device* d : m_devices) + { + Device::Input* const i = d->FindInput(name); + + if (i) + return i; + } + + return nullptr; +} + +Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const +{ + return def_dev->FindOutput(name); +} + +} +} |
