2016-10-11 18:48:38 -06:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-02-26 18:46:21 -07:00
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
|
2016-10-11 18:48:38 -06: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()
|
|
|
|
{
|
2017-07-12 01:11:29 -06:00
|
|
|
return SConfig::GetInstance().m_BackgroundInput || Host_RendererHasFocus() ||
|
|
|
|
Host_UINeedsControllerState();
|
2016-10-11 18:48:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// UpdateReference
|
|
|
|
//
|
|
|
|
// Updates a controlreference's binded devices/controls
|
2017-06-07 20:02:16 -06:00
|
|
|
// need to call this to re-bind a control reference after changing its expression
|
2016-10-11 18:48:38 -06:00
|
|
|
//
|
2017-02-10 22:29:22 -07:00
|
|
|
void ControlReference::UpdateReference(const ciface::Core::DeviceContainer& devices,
|
2016-10-11 18:48:38 -06:00
|
|
|
const ciface::Core::DeviceQualifier& default_device)
|
|
|
|
{
|
2016-12-09 14:13:11 -07:00
|
|
|
ControlFinder finder(devices, default_device, IsInput());
|
2017-06-07 19:48:17 -06:00
|
|
|
if (m_parsed_expression)
|
|
|
|
m_parsed_expression->UpdateReferences(finder);
|
2016-12-09 14:07:49 -07:00
|
|
|
}
|
2016-12-09 14:19:23 -07:00
|
|
|
|
2016-12-09 14:07:49 -07:00
|
|
|
int ControlReference::BoundCount() const
|
|
|
|
{
|
2016-12-09 14:57:01 -07:00
|
|
|
if (m_parsed_expression)
|
2017-06-07 18:30:07 -06:00
|
|
|
return m_parsed_expression->CountNumControls();
|
2016-12-09 14:07:49 -07:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-28 02:58:03 -07:00
|
|
|
ParseStatus ControlReference::GetParseStatus() const
|
2016-12-09 14:19:23 -07:00
|
|
|
{
|
|
|
|
return m_parse_status;
|
|
|
|
}
|
|
|
|
|
2017-06-07 20:02:16 -06: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 14:57:01 -07:00
|
|
|
ControlReference::ControlReference() : range(1), m_parsed_expression(nullptr)
|
2016-12-09 14:07:49 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-10 11:58:42 -07:00
|
|
|
ControlReference::~ControlReference() = default;
|
|
|
|
|
2016-12-09 14:13:11 -07:00
|
|
|
InputReference::InputReference() : ControlReference()
|
2016-12-09 14:07:49 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:13:11 -07:00
|
|
|
OutputReference::OutputReference() : ControlReference()
|
2016-12-09 14:07:49 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:13:11 -07:00
|
|
|
bool InputReference::IsInput() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OutputReference::IsInput() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-11 18:48:38 -06:00
|
|
|
//
|
|
|
|
// InputReference :: State
|
|
|
|
//
|
|
|
|
// Gets the state of an input reference
|
|
|
|
// override function for ControlReference::State ...
|
|
|
|
//
|
|
|
|
ControlState InputReference::State(const ControlState ignore)
|
|
|
|
{
|
2016-12-09 14:57:01 -07:00
|
|
|
if (m_parsed_expression && InputGateOn())
|
|
|
|
return m_parsed_expression->GetValue() * range;
|
2016-10-11 18:48:38 -06: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 15:47:11 -06:00
|
|
|
if (m_parsed_expression)
|
|
|
|
m_parsed_expression->SetValue(state * range);
|
2016-10-11 18:48:38 -06:00
|
|
|
return 0.0;
|
|
|
|
}
|