Merge pull request #8483 from lioncash/input

InputCommon: Make use of fmt where applicable
This commit is contained in:
Léo Lam 2019-11-22 20:53:11 +01:00 committed by GitHub
commit 28f7c5fb2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 14 deletions

View File

@ -58,8 +58,12 @@ add_library(inputcommon
ControlReference/FunctionExpression.h ControlReference/FunctionExpression.h
) )
target_link_libraries(inputcommon PUBLIC target_link_libraries(inputcommon
PUBLIC
common common
PRIVATE
fmt::fmt
) )
if(WIN32) if(WIN32)

View File

@ -7,6 +7,8 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <fmt/format.h>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "Common/Matrix.h" #include "Common/Matrix.h"
@ -270,11 +272,11 @@ void ReshapableInput::SaveConfig(IniFile::Section* section, const std::string& d
std::vector<std::string> save_data(m_calibration.size()); std::vector<std::string> save_data(m_calibration.size());
std::transform( std::transform(
m_calibration.begin(), m_calibration.end(), save_data.begin(), m_calibration.begin(), m_calibration.end(), save_data.begin(),
[](ControlState val) { return StringFromFormat("%.2f", val * CALIBRATION_CONFIG_SCALE); }); [](ControlState val) { return fmt::format("{:.2f}", val * CALIBRATION_CONFIG_SCALE); });
section->Set(group + CALIBRATION_CONFIG_NAME, JoinStrings(save_data, " "), ""); section->Set(group + CALIBRATION_CONFIG_NAME, JoinStrings(save_data, " "), "");
const auto center_data = StringFromFormat("%.2f %.2f", m_center.x * CENTER_CONFIG_SCALE, const auto center_data = fmt::format("{:.2f} {:.2f}", m_center.x * CENTER_CONFIG_SCALE,
m_center.y * CENTER_CONFIG_SCALE); m_center.y * CENTER_CONFIG_SCALE);
section->Set(group + CENTER_CONFIG_NAME, center_data, ""); section->Set(group + CENTER_CONFIG_NAME, center_data, "");
} }

View File

@ -11,7 +11,8 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
#include "Common/StringUtil.h" #include <fmt/format.h>
#include "Common/Thread.h" #include "Common/Thread.h"
namespace ciface::Core namespace ciface::Core
@ -47,7 +48,7 @@ void Device::AddOutput(Device::Output* const o)
std::string Device::GetQualifiedName() const std::string Device::GetQualifiedName() const
{ {
return StringFromFormat("%s/%i/%s", this->GetSource().c_str(), GetId(), this->GetName().c_str()); return fmt::format("{}/{}/{}", GetSource(), GetId(), GetName());
} }
Device::Input* Device::FindInput(std::string_view name) const Device::Input* Device::FindInput(std::string_view name) const

View File

@ -10,6 +10,8 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <fmt/format.h>
#include "InputCommon/ControllerInterface/Xlib/XInput2.h" #include "InputCommon/ControllerInterface/Xlib/XInput2.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -338,7 +340,7 @@ ControlState KeyboardMouse::Key::GetState() const
KeyboardMouse::Button::Button(unsigned int index, unsigned int* buttons) KeyboardMouse::Button::Button(unsigned int index, unsigned int* buttons)
: m_buttons(buttons), m_index(index) : m_buttons(buttons), m_index(index)
{ {
name = StringFromFormat("Click %d", m_index + 1); name = fmt::format("Click {}", m_index + 1);
} }
ControlState KeyboardMouse::Button::GetState() const ControlState KeyboardMouse::Button::GetState() const
@ -349,7 +351,7 @@ ControlState KeyboardMouse::Button::GetState() const
KeyboardMouse::Cursor::Cursor(u8 index, bool positive, const float* cursor) KeyboardMouse::Cursor::Cursor(u8 index, bool positive, const float* cursor)
: m_cursor(cursor), m_index(index), m_positive(positive) : m_cursor(cursor), m_index(index), m_positive(positive)
{ {
name = std::string("Cursor ") + (char)('X' + m_index) + (m_positive ? '+' : '-'); name = fmt::format("Cursor {}{}", static_cast<char>('X' + m_index), (m_positive ? '+' : '-'));
} }
ControlState KeyboardMouse::Cursor::GetState() const ControlState KeyboardMouse::Cursor::GetState() const
@ -360,7 +362,7 @@ ControlState KeyboardMouse::Cursor::GetState() const
KeyboardMouse::Axis::Axis(u8 index, bool positive, const float* axis) KeyboardMouse::Axis::Axis(u8 index, bool positive, const float* axis)
: m_axis(axis), m_index(index), m_positive(positive) : m_axis(axis), m_index(index), m_positive(positive)
{ {
name = std::string("Axis ") + (char)('X' + m_index) + (m_positive ? '+' : '-'); name = fmt::format("Axis {}{}", static_cast<char>('X' + m_index), (m_positive ? '+' : '-'));
} }
ControlState KeyboardMouse::Axis::GetState() const ControlState KeyboardMouse::Axis::GetState() const

View File

@ -2,6 +2,13 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "InputCommon/InputProfile.h"
#include <algorithm>
#include <iterator>
#include <fmt/format.h>
#include "Common/FileSearch.h" #include "Common/FileSearch.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -13,10 +20,6 @@
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"
#include "InputCommon/InputProfile.h"
#include <algorithm>
#include <iterator>
namespace InputProfile namespace InputProfile
{ {
@ -180,7 +183,7 @@ std::string ProfileCycler::GetWiimoteInputProfilesForGame(int controller_index)
const IniFile::Section* const control_section = game_ini.GetOrCreateSection("Controls"); const IniFile::Section* const control_section = game_ini.GetOrCreateSection("Controls");
std::string result; std::string result;
control_section->Get(StringFromFormat("WiimoteProfile%d", controller_index + 1), &result); control_section->Get(fmt::format("WiimoteProfile{}", controller_index + 1), &result);
return result; return result;
} }