2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-12 17:15:16 +00:00
|
|
|
|
2010-06-03 18:05:08 +00:00
|
|
|
#include "ControllerEmu.h"
|
|
|
|
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ControllerEmu::~ControllerEmu()
|
|
|
|
{
|
|
|
|
// control groups
|
|
|
|
std::vector<ControlGroup*>::const_iterator
|
|
|
|
i = groups.begin(),
|
|
|
|
e = groups.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; i!=e; ++i)
|
2010-06-03 18:05:08 +00:00
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControllerEmu::ControlGroup::~ControlGroup()
|
|
|
|
{
|
|
|
|
// controls
|
|
|
|
std::vector<Control*>::const_iterator
|
|
|
|
ci = controls.begin(),
|
|
|
|
ce = controls.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ci!=ce; ++ci)
|
2010-06-03 18:05:08 +00:00
|
|
|
delete *ci;
|
|
|
|
|
|
|
|
// settings
|
|
|
|
std::vector<Setting*>::const_iterator
|
|
|
|
si = settings.begin(),
|
|
|
|
se = settings.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; si!=se; ++si)
|
2010-06-03 18:05:08 +00:00
|
|
|
delete *si;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControllerEmu::Extension::~Extension()
|
|
|
|
{
|
|
|
|
// attachments
|
|
|
|
std::vector<ControllerEmu*>::const_iterator
|
|
|
|
ai = attachments.begin(),
|
|
|
|
ae = attachments.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ai!=ae; ++ai)
|
2010-06-03 18:05:08 +00:00
|
|
|
delete *ai;
|
|
|
|
}
|
|
|
|
ControllerEmu::ControlGroup::Control::~Control()
|
|
|
|
{
|
|
|
|
delete control_ref;
|
|
|
|
}
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void ControllerEmu::UpdateReferences(ControllerInterface& devi)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
std::vector<ControlGroup*>::const_iterator
|
|
|
|
i = groups.begin(),
|
|
|
|
e = groups.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; i!=e; ++i)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
std::vector<ControlGroup::Control*>::const_iterator
|
|
|
|
ci = (*i)->controls.begin(),
|
|
|
|
ce = (*i)->controls.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ci!=ce; ++ci)
|
2010-06-21 03:12:16 +00:00
|
|
|
devi.UpdateReference((*ci)->control_ref, default_device);
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
// extension
|
2011-01-14 03:05:02 +00:00
|
|
|
if (GROUP_TYPE_EXTENSION == (*i)->type)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
std::vector<ControllerEmu*>::const_iterator
|
|
|
|
ai = ((Extension*)*i)->attachments.begin(),
|
|
|
|
ae = ((Extension*)*i)->attachments.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ai!=ae; ++ai)
|
2010-06-21 03:12:16 +00:00
|
|
|
(*ai)->UpdateReferences(devi);
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerEmu::UpdateDefaultDevice()
|
|
|
|
{
|
|
|
|
std::vector<ControlGroup*>::const_iterator
|
|
|
|
i = groups.begin(),
|
|
|
|
e = groups.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; i!=e; ++i)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
//std::vector<ControlGroup::Control*>::const_iterator
|
|
|
|
//ci = (*i)->controls.begin(),
|
|
|
|
//ce = (*i)->controls.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
//for (; ci!=ce; ++ci)
|
2010-06-21 03:12:16 +00:00
|
|
|
//(*ci)->control_ref->device_qualifier = default_device;
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
// extension
|
2011-01-14 03:05:02 +00:00
|
|
|
if (GROUP_TYPE_EXTENSION == (*i)->type)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
std::vector<ControllerEmu*>::const_iterator
|
|
|
|
ai = ((Extension*)*i)->attachments.begin(),
|
|
|
|
ae = ((Extension*)*i)->attachments.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ai!=ae; ++ai)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
(*ai)->default_device = default_device;
|
|
|
|
(*ai)->UpdateDefaultDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
std::string group(base + name); group += "/";
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
// settings
|
|
|
|
std::vector<ControlGroup::Setting*>::const_iterator
|
|
|
|
si = settings.begin(),
|
|
|
|
se = settings.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; si!=se; ++si)
|
2010-06-05 05:30:23 +00:00
|
|
|
{
|
|
|
|
sec->Get((group+(*si)->name).c_str(), &(*si)->value, (*si)->default_value*100);
|
|
|
|
(*si)->value /= 100;
|
|
|
|
}
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
// controls
|
|
|
|
std::vector<ControlGroup::Control*>::const_iterator
|
|
|
|
ci = controls.begin(),
|
|
|
|
ce = controls.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ci!=ce; ++ci)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
// control expression
|
|
|
|
sec->Get((group + (*ci)->name).c_str(), &(*ci)->control_ref->expression, "");
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
// range
|
2011-01-14 03:05:02 +00:00
|
|
|
sec->Get((group+(*ci)->name+"/Range").c_str(), &(*ci)->control_ref->range, 100.0f);
|
2010-06-05 05:30:23 +00:00
|
|
|
(*ci)->control_ref->range /= 100;
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// extensions
|
2011-01-14 03:05:02 +00:00
|
|
|
if (GROUP_TYPE_EXTENSION == type)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
Extension* const ex = ((Extension*)this);
|
|
|
|
|
|
|
|
ex->switch_extension = 0;
|
|
|
|
unsigned int n = 0;
|
2010-06-05 05:30:23 +00:00
|
|
|
std::string extname;
|
|
|
|
sec->Get((base + name).c_str(), &extname, "");
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
std::vector<ControllerEmu*>::const_iterator
|
|
|
|
ai = ((Extension*)this)->attachments.begin(),
|
|
|
|
ae = ((Extension*)this)->attachments.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ai!=ae; ++ai,++n)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
(*ai)->default_device.FromString(defdev);
|
|
|
|
(*ai)->LoadConfig(sec, base + (*ai)->GetName() + "/");
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
if ((*ai)->GetName() == extname)
|
2010-06-03 18:05:08 +00:00
|
|
|
ex->switch_extension = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
void ControllerEmu::LoadConfig(IniFile::Section *sec, const std::string& base)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
std::string defdev = default_device.ToString();
|
2010-06-04 20:03:03 +00:00
|
|
|
if (base.empty())
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2010-06-05 05:30:23 +00:00
|
|
|
sec->Get((base + "Device").c_str(), &defdev, "");
|
2010-06-04 20:03:03 +00:00
|
|
|
default_device.FromString(defdev);
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
|
|
|
e = groups.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; i!=e; ++i)
|
2010-06-04 20:03:03 +00:00
|
|
|
(*i)->LoadConfig(sec, defdev, base);
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
std::string group(base + name); group += "/";
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
// settings
|
|
|
|
std::vector<ControlGroup::Setting*>::const_iterator
|
|
|
|
si = settings.begin(),
|
|
|
|
se = settings.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; si!=se; ++si)
|
|
|
|
sec->Set((group+(*si)->name).c_str(), (*si)->value*100.0f, (*si)->default_value*100.0f);
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
// controls
|
|
|
|
std::vector<ControlGroup::Control*>::const_iterator
|
|
|
|
ci = controls.begin(),
|
|
|
|
ce = controls.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ci!=ce; ++ci)
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
// control expression
|
2011-01-14 03:05:02 +00:00
|
|
|
sec->Set((group+(*ci)->name).c_str(), (*ci)->control_ref->expression, "");
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
// range
|
2011-01-14 03:05:02 +00:00
|
|
|
sec->Set((group+(*ci)->name+"/Range").c_str(), (*ci)->control_ref->range*100.0f, 100.0f);
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// extensions
|
2011-01-14 03:05:02 +00:00
|
|
|
if (GROUP_TYPE_EXTENSION == type)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
Extension* const ext = ((Extension*)this);
|
2010-06-05 05:30:23 +00:00
|
|
|
sec->Set((base + name).c_str(), ext->attachments[ext->switch_extension]->GetName(), "None");
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
std::vector<ControllerEmu*>::const_iterator
|
|
|
|
ai = ((Extension*)this)->attachments.begin(),
|
|
|
|
ae = ((Extension*)this)->attachments.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; ai!=ae; ++ai)
|
|
|
|
(*ai)->SaveConfig(sec, base + (*ai)->GetName() + "/");
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
void ControllerEmu::SaveConfig(IniFile::Section *sec, const std::string& base)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
const std::string defdev = default_device.ToString();
|
2011-01-14 03:05:02 +00:00
|
|
|
if (base.empty())
|
|
|
|
sec->Set((/*std::string(" ") +*/ base + "Device").c_str(), defdev, "");
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
|
|
|
e = groups.end();
|
2011-01-14 03:05:02 +00:00
|
|
|
for (; i!=e; ++i)
|
|
|
|
(*i)->SaveConfig(sec, defdev, base);
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
ControllerEmu::AnalogStick::AnalogStick(const char* const _name) : ControlGroup(_name, GROUP_TYPE_STICK)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2013-10-29 05:09:01 +00:00
|
|
|
for (auto& named_direction : named_directions)
|
|
|
|
controls.push_back(new Input(named_direction));
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
controls.push_back(new Input(_trans("Modifier")));
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2011-11-10 08:27:33 +00:00
|
|
|
settings.push_back(new Setting(_trans("Radius"), 0.7f, 0, 100));
|
2011-01-14 03:05:02 +00:00
|
|
|
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
|
|
|
settings.push_back(new Setting(_trans("Square Stick"), 0));
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
ControllerEmu::Buttons::Buttons(const char* const _name) : ControlGroup(_name, GROUP_TYPE_BUTTONS)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
settings.push_back(new Setting(_trans("Threshold"), 0.5f));
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
ControllerEmu::MixedTriggers::MixedTriggers(const char* const _name) : ControlGroup(_name, GROUP_TYPE_MIXED_TRIGGERS)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
settings.push_back(new Setting(_trans("Threshold"), 0.9f));
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
ControllerEmu::Triggers::Triggers(const char* const _name) : ControlGroup(_name, GROUP_TYPE_TRIGGERS)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2010-10-05 21:43:51 +00:00
|
|
|
ControllerEmu::Slider::Slider(const char* const _name) : ControlGroup(_name, GROUP_TYPE_SLIDER)
|
|
|
|
{
|
|
|
|
controls.push_back(new Input("Left"));
|
|
|
|
controls.push_back(new Input("Right"));
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
2010-10-05 21:43:51 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
ControllerEmu::Force::Force(const char* const _name) : ControlGroup(_name, GROUP_TYPE_FORCE)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2010-07-26 05:30:50 +00:00
|
|
|
memset(m_swing, 0, sizeof(m_swing));
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
controls.push_back(new Input(_trans("Up")));
|
|
|
|
controls.push_back(new Input(_trans("Down")));
|
|
|
|
controls.push_back(new Input(_trans("Left")));
|
|
|
|
controls.push_back(new Input(_trans("Right")));
|
|
|
|
controls.push_back(new Input(_trans("Forward")));
|
|
|
|
controls.push_back(new Input(_trans("Backward")));
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
ControllerEmu::Tilt::Tilt(const char* const _name)
|
|
|
|
: ControlGroup(_name, GROUP_TYPE_TILT)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2010-06-12 02:08:01 +00:00
|
|
|
memset(m_tilt, 0, sizeof(m_tilt));
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
controls.push_back(new Input("Forward"));
|
|
|
|
controls.push_back(new Input("Backward"));
|
|
|
|
controls.push_back(new Input("Left"));
|
|
|
|
controls.push_back(new Input("Right"));
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
controls.push_back(new Input(_trans("Modifier")));
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
|
|
|
settings.push_back(new Setting(_trans("Circle Stick"), 0));
|
2013-01-20 01:16:01 +00:00
|
|
|
settings.push_back(new Setting(_trans("Angle"), 0.9f, 0, 180));
|
2010-06-03 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
ControllerEmu::Cursor::Cursor(const char* const _name)
|
|
|
|
: ControlGroup(_name, GROUP_TYPE_CURSOR)
|
2010-06-12 02:08:01 +00:00
|
|
|
, m_z(0)
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
2013-10-29 05:09:01 +00:00
|
|
|
for (auto& named_direction : named_directions)
|
|
|
|
controls.push_back(new Input(named_direction));
|
2011-01-14 03:05:02 +00:00
|
|
|
controls.push_back(new Input("Forward"));
|
|
|
|
controls.push_back(new Input("Backward"));
|
|
|
|
controls.push_back(new Input(_trans("Hide")));
|
|
|
|
|
|
|
|
settings.push_back(new Setting(_trans("Center"), 0.5f));
|
|
|
|
settings.push_back(new Setting(_trans("Width"), 0.5f));
|
|
|
|
settings.push_back(new Setting(_trans("Height"), 0.5f));
|
2010-06-03 18:05:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-10 06:48:24 +00:00
|
|
|
void ControllerEmu::LoadDefaults(const ControllerInterface &ciface)
|
|
|
|
{
|
|
|
|
// load an empty inifile section, clears everything
|
|
|
|
IniFile::Section sec;
|
|
|
|
LoadConfig(&sec);
|
|
|
|
|
|
|
|
if (ciface.Devices().size())
|
|
|
|
{
|
|
|
|
default_device.FromDevice(ciface.Devices()[0]);
|
|
|
|
UpdateDefaultDevice();
|
|
|
|
}
|
|
|
|
}
|