[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / games / ports / input / PortInput.cpp
blobaf1652b0489dbaf159710374684a6e0a81e3c8d8
1 /*
2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "PortInput.h"
11 #include "games/addons/GameClient.h"
12 #include "games/controllers/input/InputSink.h"
13 #include "guilib/WindowIDs.h"
14 #include "input/joysticks/keymaps/KeymapHandling.h"
15 #include "peripherals/devices/Peripheral.h"
17 using namespace KODI;
18 using namespace GAME;
20 CPortInput::CPortInput(JOYSTICK::IInputHandler* gameInput)
21 : m_gameInput(gameInput), m_inputSink(new CInputSink(gameInput))
25 CPortInput::~CPortInput() = default;
27 void CPortInput::RegisterInput(JOYSTICK::IInputProvider* provider)
29 // Give input sink the lowest priority by registering it before the other
30 // input handlers
31 provider->RegisterInputHandler(m_inputSink.get(), false);
33 // Register input handler
34 provider->RegisterInputHandler(this, false);
36 // Register GUI input
37 m_appInput.reset(new JOYSTICK::CKeymapHandling(provider, false, this));
40 void CPortInput::UnregisterInput(JOYSTICK::IInputProvider* provider)
42 // Unregister in reverse order
43 if (provider == nullptr && m_appInput)
44 m_appInput->UnregisterInputProvider();
45 m_appInput.reset();
47 if (provider != nullptr)
49 provider->UnregisterInputHandler(this);
50 provider->UnregisterInputHandler(m_inputSink.get());
54 std::string CPortInput::ControllerID() const
56 return m_gameInput->ControllerID();
59 bool CPortInput::AcceptsInput(const std::string& feature) const
61 return m_gameInput->AcceptsInput(feature);
64 bool CPortInput::OnButtonPress(const std::string& feature, bool bPressed)
66 if (bPressed && !m_gameInput->AcceptsInput(feature))
67 return false;
69 return m_gameInput->OnButtonPress(feature, bPressed);
72 void CPortInput::OnButtonHold(const std::string& feature, unsigned int holdTimeMs)
74 m_gameInput->OnButtonHold(feature, holdTimeMs);
77 bool CPortInput::OnButtonMotion(const std::string& feature,
78 float magnitude,
79 unsigned int motionTimeMs)
81 if (magnitude > 0.0f && !m_gameInput->AcceptsInput(feature))
82 return false;
84 return m_gameInput->OnButtonMotion(feature, magnitude, motionTimeMs);
87 bool CPortInput::OnAnalogStickMotion(const std::string& feature,
88 float x,
89 float y,
90 unsigned int motionTimeMs)
92 if ((x != 0.0f || y != 0.0f) && !m_gameInput->AcceptsInput(feature))
93 return false;
95 return m_gameInput->OnAnalogStickMotion(feature, x, y, motionTimeMs);
98 bool CPortInput::OnAccelerometerMotion(const std::string& feature, float x, float y, float z)
100 if (!m_gameInput->AcceptsInput(feature))
101 return false;
103 return m_gameInput->OnAccelerometerMotion(feature, x, y, z);
106 bool CPortInput::OnWheelMotion(const std::string& feature,
107 float position,
108 unsigned int motionTimeMs)
110 if ((position != 0.0f) && !m_gameInput->AcceptsInput(feature))
111 return false;
113 return m_gameInput->OnWheelMotion(feature, position, motionTimeMs);
116 bool CPortInput::OnThrottleMotion(const std::string& feature,
117 float position,
118 unsigned int motionTimeMs)
120 if ((position != 0.0f) && !m_gameInput->AcceptsInput(feature))
121 return false;
123 return m_gameInput->OnThrottleMotion(feature, position, motionTimeMs);
126 int CPortInput::GetWindowID() const
128 return WINDOW_FULLSCREEN_GAME;