From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- xbmc/peripherals/addons/AddonButtonMapping.cpp | 139 +++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 xbmc/peripherals/addons/AddonButtonMapping.cpp (limited to 'xbmc/peripherals/addons/AddonButtonMapping.cpp') diff --git a/xbmc/peripherals/addons/AddonButtonMapping.cpp b/xbmc/peripherals/addons/AddonButtonMapping.cpp new file mode 100644 index 0000000..abf981f --- /dev/null +++ b/xbmc/peripherals/addons/AddonButtonMapping.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2014-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "AddonButtonMapping.h" + +#include "input/joysticks/generic/ButtonMapping.h" +#include "input/joysticks/interfaces/IButtonMapper.h" +#include "peripherals/Peripherals.h" +#include "peripherals/addons/AddonButtonMap.h" +#include "utils/log.h" + +using namespace KODI; +using namespace JOYSTICK; +using namespace PERIPHERALS; + +CAddonButtonMapping::CAddonButtonMapping(CPeripherals& manager, + CPeripheral* peripheral, + IButtonMapper* mapper) +{ + PeripheralAddonPtr addon = manager.GetAddonWithButtonMap(peripheral); + + if (!addon) + { + CLog::Log(LOGDEBUG, "Failed to locate add-on for \"{}\"", peripheral->DeviceName()); + } + else + { + const std::string controllerId = mapper->ControllerID(); + m_buttonMap = std::make_unique(peripheral, addon, controllerId, manager); + if (m_buttonMap->Load()) + { + IKeymap* keymap = peripheral->GetKeymap(controllerId); + m_buttonMapping.reset(new CButtonMapping(mapper, m_buttonMap.get(), keymap)); + + // Allow the mapper to save our button map + mapper->SetButtonMapCallback(peripheral->Location(), this); + } + else + m_buttonMap.reset(); + } +} + +CAddonButtonMapping::~CAddonButtonMapping(void) +{ + m_buttonMapping.reset(); + m_buttonMap.reset(); +} + +bool CAddonButtonMapping::OnButtonMotion(unsigned int buttonIndex, bool bPressed) +{ + if (m_buttonMapping) + return m_buttonMapping->OnButtonMotion(buttonIndex, bPressed); + + return false; +} + +bool CAddonButtonMapping::OnHatMotion(unsigned int hatIndex, HAT_STATE state) +{ + if (m_buttonMapping) + return m_buttonMapping->OnHatMotion(hatIndex, state); + + return false; +} + +bool CAddonButtonMapping::OnAxisMotion(unsigned int axisIndex, + float position, + int center, + unsigned int range) +{ + if (m_buttonMapping) + return m_buttonMapping->OnAxisMotion(axisIndex, position, center, range); + + return false; +} + +void CAddonButtonMapping::OnInputFrame(void) +{ + if (m_buttonMapping) + m_buttonMapping->OnInputFrame(); +} + +bool CAddonButtonMapping::OnKeyPress(const CKey& key) +{ + if (m_buttonMapping) + return m_buttonMapping->OnKeyPress(key); + + return false; +} + +void CAddonButtonMapping::OnKeyRelease(const CKey& key) +{ + if (m_buttonMapping) + m_buttonMapping->OnKeyRelease(key); +} + +bool CAddonButtonMapping::OnPosition(int x, int y) +{ + if (m_buttonMapping) + return m_buttonMapping->OnPosition(x, y); + + return false; +} + +bool CAddonButtonMapping::OnButtonPress(MOUSE::BUTTON_ID button) +{ + if (m_buttonMapping) + return m_buttonMapping->OnButtonPress(button); + + return false; +} + +void CAddonButtonMapping::OnButtonRelease(MOUSE::BUTTON_ID button) +{ + if (m_buttonMapping) + m_buttonMapping->OnButtonRelease(button); +} + +void CAddonButtonMapping::SaveButtonMap() +{ + if (m_buttonMapping) + m_buttonMapping->SaveButtonMap(); +} + +void CAddonButtonMapping::ResetIgnoredPrimitives() +{ + if (m_buttonMapping) + m_buttonMapping->ResetIgnoredPrimitives(); +} + +void CAddonButtonMapping::RevertButtonMap() +{ + if (m_buttonMapping) + m_buttonMapping->RevertButtonMap(); +} -- cgit v1.2.3