File indexing completed on 2024-05-12 05:35:40
0001 /* 0002 SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0003 SPDX-FileCopyrightText: 2023 Jeremy Whiting <jpwhiting@kde.org> 0004 SPDX-FileCopyrightText: 2023 Niccolò Venerandi <niccolo@venerandi.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QObject> 0012 #include <QPointF> 0013 #include <QString> 0014 #include <QVector2D> 0015 0016 #include <KLocalizedString> 0017 0018 #include <SDL2/SDL_events.h> 0019 #include <SDL2/SDL_gamecontroller.h> 0020 #include <SDL2/SDL_joystick.h> 0021 0022 class Gamepad : public QObject 0023 { 0024 Q_OBJECT 0025 0026 Q_PROPERTY(QVector2D axisValue READ axisValue NOTIFY axisValueChanged) 0027 0028 public: 0029 Gamepad(SDL_Joystick *joystick, SDL_GameController *controller, QObject *parent = nullptr); 0030 0031 QString name() const; 0032 QString path() const; 0033 0034 SDL_Joystick *joystick() const; 0035 SDL_GameController *gamecontroller() const; 0036 0037 QVector2D axisValue() const; 0038 0039 Q_SIGNALS: 0040 void buttonStateChanged(SDL_GameControllerButton button); 0041 void axisStateChanged(int index); 0042 void axisValueChanged(); 0043 0044 private: 0045 friend class DeviceModel; 0046 0047 void onButtonEvent(SDL_ControllerButtonEvent sdlEvent); 0048 void onAxisEvent(SDL_ControllerAxisEvent sdlEvent); 0049 0050 SDL_Joystick *m_joystick = nullptr; 0051 SDL_GameController *m_gameController = nullptr; 0052 0053 QString m_name; 0054 QString m_path; 0055 QPointF m_axis = QPointF(0.0, 0.0); 0056 };