2016-10-12 00:48:38 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-02-27 01:46:21 +00:00
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
|
2016-10-12 00:48:38 +00:00
|
|
|
// For InputGateOn()
|
|
|
|
// This is a bad layering violation, but it's the cleanest
|
|
|
|
// place I could find to put it.
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Host.h"
|
|
|
|
|
|
|
|
using namespace ciface::ExpressionParser;
|
|
|
|
|
|
|
|
bool ControlReference::InputGateOn()
|
|
|
|
{
|
2019-03-18 16:30:33 +00:00
|
|
|
return (SConfig::GetInstance().m_BackgroundInput || Host_RendererHasFocus() ||
|
|
|
|
Host_UINeedsControllerState()) &&
|
|
|
|
!Host_UIBlocksControllerState();
|
2016-10-12 00:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// UpdateReference
|
|
|
|
//
|
|
|
|
// Updates a controlreference's binded devices/controls
|
2017-06-08 02:02:16 +00:00
|
|
|
// need to call this to re-bind a control reference after changing its expression
|
2016-10-12 00:48:38 +00:00
|
|
|
//
|
2017-02-11 05:29:22 +00:00
|
|
|
void ControlReference::UpdateReference(const ciface::Core::DeviceContainer& devices,
|
2016-10-12 00:48:38 +00:00
|
|
|
const ciface::Core::DeviceQualifier& default_device)
|
|
|
|
{
|
2016-12-09 21:13:11 +00:00
|
|
|
ControlFinder finder(devices, default_device, IsInput());
|
2017-06-08 01:48:17 +00:00
|
|
|
if (m_parsed_expression)
|
|
|
|
m_parsed_expression->UpdateReferences(finder);
|
2016-12-09 21:07:49 +00:00
|
|
|
}
|
2016-12-09 21:19:23 +00:00
|
|
|
|
2016-12-09 21:07:49 +00:00
|
|
|
int ControlReference::BoundCount() const
|
|
|
|
{
|
2016-12-09 21:57:01 +00:00
|
|
|
if (m_parsed_expression)
|
2017-06-08 00:30:07 +00:00
|
|
|
return m_parsed_expression->CountNumControls();
|
2016-12-09 21:07:49 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-28 09:58:03 +00:00
|
|
|
ParseStatus ControlReference::GetParseStatus() const
|
2016-12-09 21:19:23 +00:00
|
|
|
{
|
|
|
|
return m_parse_status;
|
|
|
|
}
|
|
|
|
|
2017-06-08 02:02:16 +00:00
|
|
|
std::string ControlReference::GetExpression() const
|
|
|
|
{
|
|
|
|
return m_expression;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlReference::SetExpression(std::string expr)
|
|
|
|
{
|
|
|
|
m_expression = std::move(expr);
|
|
|
|
std::tie(m_parse_status, m_parsed_expression) = ParseExpression(m_expression);
|
|
|
|
}
|
|
|
|
|
2016-12-09 21:57:01 +00:00
|
|
|
ControlReference::ControlReference() : range(1), m_parsed_expression(nullptr)
|
2016-12-09 21:07:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-10 18:58:42 +00:00
|
|
|
ControlReference::~ControlReference() = default;
|
|
|
|
|
2016-12-09 21:13:11 +00:00
|
|
|
InputReference::InputReference() : ControlReference()
|
2016-12-09 21:07:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-09 21:13:11 +00:00
|
|
|
OutputReference::OutputReference() : ControlReference()
|
2016-12-09 21:07:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-09 21:13:11 +00:00
|
|
|
bool InputReference::IsInput() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OutputReference::IsInput() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-12 00:48:38 +00:00
|
|
|
//
|
|
|
|
// InputReference :: State
|
|
|
|
//
|
|
|
|
// Gets the state of an input reference
|
|
|
|
// override function for ControlReference::State ...
|
|
|
|
//
|
|
|
|
ControlState InputReference::State(const ControlState ignore)
|
|
|
|
{
|
2016-12-09 21:57:01 +00:00
|
|
|
if (m_parsed_expression && InputGateOn())
|
|
|
|
return m_parsed_expression->GetValue() * range;
|
2016-10-12 00:48:38 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// OutputReference :: State
|
|
|
|
//
|
|
|
|
// Set the state of all binded outputs
|
|
|
|
// overrides ControlReference::State .. combined them so I could make the GUI simple / inputs ==
|
|
|
|
// same as outputs one list
|
|
|
|
// I was lazy and it works so watever
|
|
|
|
//
|
|
|
|
ControlState OutputReference::State(const ControlState state)
|
|
|
|
{
|
2018-04-19 21:47:11 +00:00
|
|
|
if (m_parsed_expression)
|
|
|
|
m_parsed_expression->SetValue(state * range);
|
2016-10-12 00:48:38 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|