Merge pull request #6167 from ligfx/encapsulatedefaultdevice
EmulatedController: encapsulate default device behind getters/setters
This commit is contained in:
commit
1e24a5f309
|
@ -114,7 +114,7 @@ void IOWindow::Update()
|
||||||
m_range_spinbox->setValue(m_reference->range * SLIDER_TICK_COUNT);
|
m_range_spinbox->setValue(m_reference->range * SLIDER_TICK_COUNT);
|
||||||
m_range_slider->setValue(m_reference->range * SLIDER_TICK_COUNT);
|
m_range_slider->setValue(m_reference->range * SLIDER_TICK_COUNT);
|
||||||
|
|
||||||
m_devq.FromString(m_controller->default_device.ToString());
|
m_devq.FromString(m_controller->GetDefaultDevice().ToString());
|
||||||
|
|
||||||
UpdateDeviceList();
|
UpdateDeviceList();
|
||||||
UpdateOptionList();
|
UpdateOptionList();
|
||||||
|
@ -147,7 +147,7 @@ void IOWindow::AppendSelectedOption(const std::string& prefix)
|
||||||
m_expression_text->insertPlainText(
|
m_expression_text->insertPlainText(
|
||||||
QString::fromStdString(prefix) +
|
QString::fromStdString(prefix) +
|
||||||
MappingCommon::GetExpressionForControl(m_option_list->currentItem()->text(), m_devq,
|
MappingCommon::GetExpressionForControl(m_option_list->currentItem()->text(), m_devq,
|
||||||
m_controller->default_device));
|
m_controller->GetDefaultDevice()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void IOWindow::OnDeviceChanged(const QString& device)
|
void IOWindow::OnDeviceChanged(const QString& device)
|
||||||
|
@ -237,10 +237,9 @@ void IOWindow::UpdateDeviceList()
|
||||||
Core::RunAsCPUThread([&] {
|
Core::RunAsCPUThread([&] {
|
||||||
g_controller_interface.RefreshDevices();
|
g_controller_interface.RefreshDevices();
|
||||||
m_controller->UpdateReferences(g_controller_interface);
|
m_controller->UpdateReferences(g_controller_interface);
|
||||||
m_controller->UpdateDefaultDevice();
|
|
||||||
|
|
||||||
// Adding default device regardless if it's currently connected or not
|
// Adding default device regardless if it's currently connected or not
|
||||||
const auto default_device = m_controller->default_device.ToString();
|
const auto default_device = m_controller->GetDefaultDevice().ToString();
|
||||||
|
|
||||||
m_devices_combo->addItem(QString::fromStdString(default_device));
|
m_devices_combo->addItem(QString::fromStdString(default_device));
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,9 @@ void MappingButton::OnButtonPressed()
|
||||||
// Avoid that the button press itself is registered as an event
|
// Avoid that the button press itself is registered as an event
|
||||||
Common::SleepCurrentThread(100);
|
Common::SleepCurrentThread(100);
|
||||||
|
|
||||||
const auto expr = MappingCommon::DetectExpression(m_reference, dev.get(),
|
const auto expr = MappingCommon::DetectExpression(
|
||||||
m_parent->GetParent()->GetDeviceQualifier(),
|
m_reference, dev.get(), m_parent->GetParent()->GetDeviceQualifier(),
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->GetDefaultDevice());
|
||||||
|
|
||||||
releaseMouse();
|
releaseMouse();
|
||||||
releaseKeyboard();
|
releaseKeyboard();
|
||||||
|
|
|
@ -211,7 +211,7 @@ void MappingWindow::OnDeviceChanged(int index)
|
||||||
{
|
{
|
||||||
const auto device = m_devices_combo->currentText().toStdString();
|
const auto device = m_devices_combo->currentText().toStdString();
|
||||||
m_devq.FromString(device);
|
m_devq.FromString(device);
|
||||||
m_controller->default_device.FromString(device);
|
m_controller->SetDefaultDevice(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingWindow::RefreshDevices()
|
void MappingWindow::RefreshDevices()
|
||||||
|
@ -221,9 +221,8 @@ void MappingWindow::RefreshDevices()
|
||||||
Core::RunAsCPUThread([&] {
|
Core::RunAsCPUThread([&] {
|
||||||
g_controller_interface.RefreshDevices();
|
g_controller_interface.RefreshDevices();
|
||||||
m_controller->UpdateReferences(g_controller_interface);
|
m_controller->UpdateReferences(g_controller_interface);
|
||||||
m_controller->UpdateDefaultDevice();
|
|
||||||
|
|
||||||
const auto default_device = m_controller->default_device.ToString();
|
const auto default_device = m_controller->GetDefaultDevice().ToString();
|
||||||
|
|
||||||
m_devices_combo->addItem(QString::fromStdString(default_device));
|
m_devices_combo->addItem(QString::fromStdString(default_device));
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ ControlDialog::ControlDialog(InputConfigDialog* const parent, InputConfig& confi
|
||||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
||||||
control_reference(ref), m_config(config), m_parent(parent)
|
control_reference(ref), m_config(config), m_parent(parent)
|
||||||
{
|
{
|
||||||
m_devq = m_parent->GetController()->default_device;
|
m_devq = m_parent->GetController()->GetDefaultDevice();
|
||||||
const int space5 = FromDIP(5);
|
const int space5 = FromDIP(5);
|
||||||
|
|
||||||
// GetStrings() sounds slow :/
|
// GetStrings() sounds slow :/
|
||||||
|
@ -360,7 +360,7 @@ void ControlDialog::UpdateGUI()
|
||||||
void InputConfigDialog::UpdateGUI()
|
void InputConfigDialog::UpdateGUI()
|
||||||
{
|
{
|
||||||
if (device_cbox != nullptr)
|
if (device_cbox != nullptr)
|
||||||
device_cbox->SetValue(StrToWxStr(controller->default_device.ToString()));
|
device_cbox->SetValue(StrToWxStr(controller->GetDefaultDevice().ToString()));
|
||||||
|
|
||||||
for (ControlGroupBox* cgBox : control_groups)
|
for (ControlGroupBox* cgBox : control_groups)
|
||||||
{
|
{
|
||||||
|
@ -405,7 +405,7 @@ bool ControlDialog::Validate()
|
||||||
|
|
||||||
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
||||||
control_reference->UpdateReference(g_controller_interface,
|
control_reference->UpdateReference(g_controller_interface,
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->GetDefaultDevice());
|
||||||
|
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
|
|
||||||
|
@ -415,13 +415,10 @@ bool ControlDialog::Validate()
|
||||||
|
|
||||||
void InputConfigDialog::SetDevice(wxCommandEvent&)
|
void InputConfigDialog::SetDevice(wxCommandEvent&)
|
||||||
{
|
{
|
||||||
controller->default_device.FromString(WxStrToStr(device_cbox->GetValue()));
|
controller->SetDefaultDevice(WxStrToStr(device_cbox->GetValue()));
|
||||||
|
|
||||||
// show user what it was validated as
|
// show user what it was validated as
|
||||||
device_cbox->SetValue(StrToWxStr(controller->default_device.ToString()));
|
device_cbox->SetValue(StrToWxStr(controller->GetDefaultDevice().ToString()));
|
||||||
|
|
||||||
// this will set all the controls to this default device
|
|
||||||
controller->UpdateDefaultDevice();
|
|
||||||
|
|
||||||
// update references
|
// update references
|
||||||
controller->UpdateReferences(g_controller_interface);
|
controller->UpdateReferences(g_controller_interface);
|
||||||
|
@ -444,7 +441,7 @@ void ControlDialog::ClearControl(wxCommandEvent&)
|
||||||
|
|
||||||
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
||||||
control_reference->UpdateReference(g_controller_interface,
|
control_reference->UpdateReference(g_controller_interface,
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->GetDefaultDevice());
|
||||||
|
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
}
|
}
|
||||||
|
@ -459,8 +456,8 @@ inline bool IsAlphabetic(wxString& str)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void GetExpressionForControl(wxString& expr, wxString& control_name,
|
inline void GetExpressionForControl(wxString& expr, wxString& control_name,
|
||||||
ciface::Core::DeviceQualifier* control_device = nullptr,
|
const ciface::Core::DeviceQualifier* control_device = nullptr,
|
||||||
ciface::Core::DeviceQualifier* default_device = nullptr)
|
const ciface::Core::DeviceQualifier* default_device = nullptr)
|
||||||
{
|
{
|
||||||
expr = "";
|
expr = "";
|
||||||
|
|
||||||
|
@ -486,7 +483,8 @@ bool ControlDialog::GetExpressionForSelectedControl(wxString& expr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wxString control_name = control_lbox->GetString(num);
|
wxString control_name = control_lbox->GetString(num);
|
||||||
GetExpressionForControl(expr, control_name, &m_devq, &m_parent->GetController()->default_device);
|
GetExpressionForControl(expr, control_name, &m_devq,
|
||||||
|
&m_parent->GetController()->GetDefaultDevice());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -503,7 +501,7 @@ void ControlDialog::SetSelectedControl(wxCommandEvent&)
|
||||||
|
|
||||||
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
||||||
control_reference->UpdateReference(g_controller_interface,
|
control_reference->UpdateReference(g_controller_interface,
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->GetDefaultDevice());
|
||||||
|
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
}
|
}
|
||||||
|
@ -539,7 +537,7 @@ void ControlDialog::AppendControl(wxCommandEvent& event)
|
||||||
|
|
||||||
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
||||||
control_reference->UpdateReference(g_controller_interface,
|
control_reference->UpdateReference(g_controller_interface,
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->GetDefaultDevice());
|
||||||
|
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
}
|
}
|
||||||
|
@ -700,7 +698,7 @@ bool InputConfigDialog::DetectButton(ControlButton* button)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
// find device :/
|
// find device :/
|
||||||
const auto dev = g_controller_interface.FindDevice(controller->default_device);
|
const auto dev = g_controller_interface.FindDevice(controller->GetDefaultDevice());
|
||||||
if (dev != nullptr)
|
if (dev != nullptr)
|
||||||
{
|
{
|
||||||
m_event_filter.BlockEvents(true);
|
m_event_filter.BlockEvents(true);
|
||||||
|
@ -721,7 +719,7 @@ bool InputConfigDialog::DetectButton(ControlButton* button)
|
||||||
button->control_reference->SetExpression(WxStrToStr(expr));
|
button->control_reference->SetExpression(WxStrToStr(expr));
|
||||||
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
||||||
button->control_reference->UpdateReference(g_controller_interface,
|
button->control_reference->UpdateReference(g_controller_interface,
|
||||||
controller->default_device);
|
controller->GetDefaultDevice());
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -912,7 +910,7 @@ void InputConfigDialog::UpdateDeviceComboBox()
|
||||||
for (const std::string& device_string : g_controller_interface.GetAllDeviceStrings())
|
for (const std::string& device_string : g_controller_interface.GetAllDeviceStrings())
|
||||||
device_cbox->Append(StrToWxStr(device_string));
|
device_cbox->Append(StrToWxStr(device_string));
|
||||||
|
|
||||||
device_cbox->SetValue(StrToWxStr(controller->default_device.ToString()));
|
device_cbox->SetValue(StrToWxStr(controller->GetDefaultDevice().ToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputConfigDialog::RefreshDevices(wxCommandEvent&)
|
void InputConfigDialog::RefreshDevices(wxCommandEvent&)
|
||||||
|
|
|
@ -78,7 +78,7 @@ void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
|
||||||
|
|
||||||
for (auto& ai : ext->attachments)
|
for (auto& ai : ext->attachments)
|
||||||
{
|
{
|
||||||
ai->default_device.FromString(defdev);
|
ai->SetDefaultDevice(defdev);
|
||||||
ai->LoadConfig(sec, base + ai->GetName() + "/");
|
ai->LoadConfig(sec, base + ai->GetName() + "/");
|
||||||
|
|
||||||
if (ai->GetName() == extname)
|
if (ai->GetName() == extname)
|
||||||
|
|
|
@ -37,7 +37,7 @@ void EmulatedController::UpdateReferences(const ControllerInterface& devi)
|
||||||
for (auto& ctrlGroup : groups)
|
for (auto& ctrlGroup : groups)
|
||||||
{
|
{
|
||||||
for (auto& control : ctrlGroup->controls)
|
for (auto& control : ctrlGroup->controls)
|
||||||
control->control_ref.get()->UpdateReference(devi, default_device);
|
control->control_ref.get()->UpdateReference(devi, GetDefaultDevice());
|
||||||
|
|
||||||
// extension
|
// extension
|
||||||
if (ctrlGroup->type == GroupType::Extension)
|
if (ctrlGroup->type == GroupType::Extension)
|
||||||
|
@ -48,8 +48,22 @@ void EmulatedController::UpdateReferences(const ControllerInterface& devi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmulatedController::UpdateDefaultDevice()
|
const ciface::Core::DeviceQualifier& EmulatedController::GetDefaultDevice() const
|
||||||
{
|
{
|
||||||
|
return m_default_device;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmulatedController::SetDefaultDevice(const std::string& device)
|
||||||
|
{
|
||||||
|
ciface::Core::DeviceQualifier devq;
|
||||||
|
devq.FromString(device);
|
||||||
|
SetDefaultDevice(std::move(devq));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmulatedController::SetDefaultDevice(ciface::Core::DeviceQualifier devq)
|
||||||
|
{
|
||||||
|
m_default_device = std::move(devq);
|
||||||
|
|
||||||
for (auto& ctrlGroup : groups)
|
for (auto& ctrlGroup : groups)
|
||||||
{
|
{
|
||||||
// extension
|
// extension
|
||||||
|
@ -57,8 +71,7 @@ void EmulatedController::UpdateDefaultDevice()
|
||||||
{
|
{
|
||||||
for (auto& ai : ((Extension*)ctrlGroup.get())->attachments)
|
for (auto& ai : ((Extension*)ctrlGroup.get())->attachments)
|
||||||
{
|
{
|
||||||
ai->default_device = default_device;
|
ai->SetDefaultDevice(m_default_device);
|
||||||
ai->UpdateDefaultDevice();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,11 +79,11 @@ void EmulatedController::UpdateDefaultDevice()
|
||||||
|
|
||||||
void EmulatedController::LoadConfig(IniFile::Section* sec, const std::string& base)
|
void EmulatedController::LoadConfig(IniFile::Section* sec, const std::string& base)
|
||||||
{
|
{
|
||||||
std::string defdev = default_device.ToString();
|
std::string defdev = GetDefaultDevice().ToString();
|
||||||
if (base.empty())
|
if (base.empty())
|
||||||
{
|
{
|
||||||
sec->Get(base + "Device", &defdev, "");
|
sec->Get(base + "Device", &defdev, "");
|
||||||
default_device.FromString(defdev);
|
SetDefaultDevice(defdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& cg : groups)
|
for (auto& cg : groups)
|
||||||
|
@ -79,7 +92,7 @@ void EmulatedController::LoadConfig(IniFile::Section* sec, const std::string& ba
|
||||||
|
|
||||||
void EmulatedController::SaveConfig(IniFile::Section* sec, const std::string& base)
|
void EmulatedController::SaveConfig(IniFile::Section* sec, const std::string& base)
|
||||||
{
|
{
|
||||||
const std::string defdev = default_device.ToString();
|
const std::string defdev = GetDefaultDevice().ToString();
|
||||||
if (base.empty())
|
if (base.empty())
|
||||||
sec->Set(/*std::string(" ") +*/ base + "Device", defdev, "");
|
sec->Set(/*std::string(" ") +*/ base + "Device", defdev, "");
|
||||||
|
|
||||||
|
@ -96,8 +109,7 @@ void EmulatedController::LoadDefaults(const ControllerInterface& ciface)
|
||||||
const std::string& default_device_string = ciface.GetDefaultDeviceString();
|
const std::string& default_device_string = ciface.GetDefaultDeviceString();
|
||||||
if (!default_device_string.empty())
|
if (!default_device_string.empty())
|
||||||
{
|
{
|
||||||
default_device.FromString(default_device_string);
|
SetDefaultDevice(default_device_string);
|
||||||
UpdateDefaultDevice();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
|
@ -32,7 +32,10 @@ public:
|
||||||
|
|
||||||
virtual void LoadConfig(IniFile::Section* sec, const std::string& base = "");
|
virtual void LoadConfig(IniFile::Section* sec, const std::string& base = "");
|
||||||
virtual void SaveConfig(IniFile::Section* sec, const std::string& base = "");
|
virtual void SaveConfig(IniFile::Section* sec, const std::string& base = "");
|
||||||
void UpdateDefaultDevice();
|
|
||||||
|
const ciface::Core::DeviceQualifier& GetDefaultDevice() const;
|
||||||
|
void SetDefaultDevice(const std::string& device);
|
||||||
|
void SetDefaultDevice(ciface::Core::DeviceQualifier devq);
|
||||||
|
|
||||||
void UpdateReferences(const ControllerInterface& devi);
|
void UpdateReferences(const ControllerInterface& devi);
|
||||||
|
|
||||||
|
@ -44,6 +47,7 @@ public:
|
||||||
|
|
||||||
std::vector<std::unique_ptr<ControlGroup>> groups;
|
std::vector<std::unique_ptr<ControlGroup>> groups;
|
||||||
|
|
||||||
ciface::Core::DeviceQualifier default_device;
|
private:
|
||||||
|
ciface::Core::DeviceQualifier m_default_device;
|
||||||
};
|
};
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
|
@ -133,7 +133,7 @@ bool InputConfig::IsControllerControlledByGamepadDevice(int index) const
|
||||||
if (static_cast<size_t>(index) >= m_controllers.size())
|
if (static_cast<size_t>(index) >= m_controllers.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto& controller = m_controllers.at(index).get()->default_device;
|
const auto& controller = m_controllers.at(index).get()->GetDefaultDevice();
|
||||||
|
|
||||||
// Filter out anything which obviously not a gamepad
|
// Filter out anything which obviously not a gamepad
|
||||||
return !((controller.source == "Quartz") // OSX Quartz Keyboard/Mouse
|
return !((controller.source == "Quartz") // OSX Quartz Keyboard/Mouse
|
||||||
|
|
Loading…
Reference in New Issue