| 1 |
/* |
| 2 |
* Copyright (C) 2024 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "AgentMouse.h" |
| 10 |
|
| 11 |
#include "games/controllers/Controller.h" |
| 12 |
#include "games/controllers/ControllerIDs.h" |
| 13 |
#include "games/controllers/input/ControllerActivity.h" |
| 14 |
#include "input/mouse/interfaces/IMouseInputProvider.h" |
| 15 |
#include "peripherals/devices/Peripheral.h" |
| 16 |
|
| 17 |
using namespace KODI; |
| 18 |
using namespace GAME; |
| 19 |
|
| 20 |
CAgentMouse::CAgentMouse(PERIPHERALS::PeripheralPtr peripheral) |
| 21 |
: m_peripheral(std::move(peripheral)), m_mouseActivity(std::make_unique<CControllerActivity>()) |
| 22 |
{ |
| 23 |
} |
| 24 |
|
| 25 |
CAgentMouse::~CAgentMouse() = default; |
| 26 |
|
| 27 |
void CAgentMouse::Initialize() |
| 28 |
{ |
| 29 |
// Record appearance to detect changes |
| 30 |
m_controllerAppearance = m_peripheral->ControllerProfile(); |
| 31 |
|
| 32 |
// Upcast peripheral to input provider interface |
| 33 |
MOUSE::IMouseInputProvider* inputProvider = m_peripheral.get(); |
| 34 |
|
| 35 |
// Register input handler to silently observe all input |
| 36 |
inputProvider->RegisterMouseHandler(this, true, true); |
| 37 |
} |
| 38 |
|
| 39 |
void CAgentMouse::Deinitialize() |
| 40 |
{ |
| 41 |
// Upcast peripheral to input interface |
| 42 |
MOUSE::IMouseInputProvider* inputProvider = m_peripheral.get(); |
| 43 |
|
| 44 |
// Unregister input handler |
| 45 |
inputProvider->UnregisterMouseHandler(this); |
| 46 |
|
| 47 |
// Reset appearance |
| 48 |
m_controllerAppearance.reset(); |
| 49 |
} |
| 50 |
|
| 51 |
void CAgentMouse::ClearButtonState() |
| 52 |
{ |
| 53 |
return m_mouseActivity->ClearButtonState(); |
| 54 |
} |
| 55 |
|
| 56 |
float CAgentMouse::GetActivation() const |
| 57 |
{ |
| 58 |
return m_mouseActivity->GetActivation(); |
| 59 |
} |
| 60 |
|
| 61 |
std::string CAgentMouse::ControllerID(void) const |
| 62 |
{ |
| 63 |
return DEFAULT_MOUSE_ID; |
| 64 |
} |
| 65 |
|
| 66 |
bool CAgentMouse::OnMotion(const MOUSE::PointerName& relpointer, int differenceX, int differenceY) |
| 67 |
{ |
| 68 |
m_mouseActivity->OnMouseMotion(relpointer, differenceX, differenceY); |
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
bool CAgentMouse::OnButtonPress(const MOUSE::ButtonName& button) |
| 73 |
{ |
| 74 |
m_mouseActivity->OnMouseButtonPress(button); |
| 75 |
return true; |
| 76 |
} |
| 77 |
|
| 78 |
void CAgentMouse::OnButtonRelease(const MOUSE::ButtonName& button) |
| 79 |
{ |
| 80 |
m_mouseActivity->OnMouseButtonRelease(button); |
| 81 |
} |
| 82 |
|
| 83 |
void CAgentMouse::OnInputFrame() |
| 84 |
{ |
| 85 |
m_mouseActivity->OnInputFrame(); |
| 86 |
} |