2026-04-20 07:43:11 +00:00
|
|
|
// SPDX-FileCopyrightText: 2026 Marco Allegretti
|
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <qqmlregistration.h>
|
|
|
|
|
|
|
|
|
|
struct SDL_Gamepad;
|
|
|
|
|
|
|
|
|
|
class GamepadDevice : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
QML_ELEMENT
|
|
|
|
|
QML_UNCREATABLE("")
|
|
|
|
|
|
|
|
|
|
Q_PROPERTY(int deviceId READ deviceId CONSTANT)
|
|
|
|
|
Q_PROPERTY(QString name READ name CONSTANT)
|
|
|
|
|
Q_PROPERTY(QString type READ type CONSTANT)
|
|
|
|
|
Q_PROPERTY(int batteryPercent READ batteryPercent NOTIFY batteryPercentChanged)
|
|
|
|
|
Q_PROPERTY(bool hasRumble READ hasRumble CONSTANT)
|
2026-04-21 07:57:51 +00:00
|
|
|
Q_PROPERTY(bool hasTriggerRumble READ hasTriggerRumble CONSTANT)
|
2026-04-20 07:43:11 +00:00
|
|
|
Q_PROPERTY(bool hasLED READ hasLED CONSTANT)
|
2026-04-21 07:57:51 +00:00
|
|
|
Q_PROPERTY(int touchpadCount READ touchpadCount CONSTANT)
|
|
|
|
|
Q_PROPERTY(bool hasGyro READ hasGyro CONSTANT)
|
|
|
|
|
Q_PROPERTY(bool hasAccelerometer READ hasAccelerometer CONSTANT)
|
2026-04-20 07:43:11 +00:00
|
|
|
Q_PROPERTY(int playerIndex READ playerIndex WRITE setPlayerIndex NOTIFY playerIndexChanged)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit GamepadDevice(SDL_Gamepad *pad, int id, QObject *parent = nullptr);
|
|
|
|
|
~GamepadDevice() override;
|
|
|
|
|
|
|
|
|
|
int deviceId() const;
|
|
|
|
|
QString name() const;
|
|
|
|
|
QString type() const;
|
|
|
|
|
int batteryPercent() const;
|
|
|
|
|
bool hasRumble() const;
|
2026-04-21 07:57:51 +00:00
|
|
|
bool hasTriggerRumble() const;
|
2026-04-20 07:43:11 +00:00
|
|
|
bool hasLED() const;
|
2026-04-21 07:57:51 +00:00
|
|
|
int touchpadCount() const;
|
|
|
|
|
bool hasGyro() const;
|
|
|
|
|
bool hasAccelerometer() const;
|
2026-04-20 07:43:11 +00:00
|
|
|
int playerIndex() const;
|
|
|
|
|
void setPlayerIndex(int index);
|
|
|
|
|
|
2026-04-20 12:09:33 +00:00
|
|
|
Q_INVOKABLE bool rumble(int lowIntensity, int highIntensity, int durationMs);
|
2026-04-21 07:57:51 +00:00
|
|
|
Q_INVOKABLE bool rumbleTriggers(int leftIntensity, int rightIntensity, int durationMs);
|
2026-04-20 07:43:11 +00:00
|
|
|
Q_INVOKABLE bool setLED(int r, int g, int b);
|
2026-04-21 07:57:51 +00:00
|
|
|
Q_INVOKABLE QString buttonLabel(int button) const;
|
2026-04-20 07:43:11 +00:00
|
|
|
|
|
|
|
|
SDL_Gamepad *sdlGamepad() const;
|
|
|
|
|
void refreshBattery();
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
void batteryPercentChanged();
|
|
|
|
|
void playerIndexChanged();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
SDL_Gamepad *m_pad = nullptr;
|
|
|
|
|
int m_id = 0;
|
|
|
|
|
int m_batteryPercent = -1;
|
|
|
|
|
};
|