mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-03-12 05:25:23 -07:00
97 lines
2.0 KiB
C++
97 lines
2.0 KiB
C++
/*
|
|
* This file is part of Chiaki.
|
|
*
|
|
* Chiaki is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Chiaki is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef CHIAKI_CONTROLLERMANAGER_H
|
|
#define CHIAKI_CONTROLLERMANAGER_H
|
|
|
|
#include <chiaki/controller.h>
|
|
|
|
#include <QObject>
|
|
#include <QSet>
|
|
#include <QMap>
|
|
#include <QString>
|
|
|
|
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
|
|
#include <SDL.h>
|
|
#endif
|
|
|
|
class Controller;
|
|
|
|
class ControllerManager : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
friend class Controller;
|
|
|
|
private:
|
|
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
|
|
QSet<SDL_JoystickID> available_controllers;
|
|
#endif
|
|
QMap<int, Controller *> open_controllers;
|
|
|
|
void ControllerClosed(Controller *controller);
|
|
|
|
private slots:
|
|
void UpdateAvailableControllers();
|
|
void HandleEvents();
|
|
void ControllerEvent(int device_id);
|
|
|
|
public:
|
|
static ControllerManager *GetInstance();
|
|
|
|
ControllerManager(QObject *parent = nullptr);
|
|
~ControllerManager();
|
|
|
|
QList<int> GetAvailableControllers();
|
|
Controller *OpenController(int device_id);
|
|
|
|
signals:
|
|
void AvailableControllersUpdated();
|
|
};
|
|
|
|
class Controller : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
friend class ControllerManager;
|
|
|
|
private:
|
|
Controller(int device_id, ControllerManager *manager);
|
|
|
|
void UpdateState();
|
|
|
|
ControllerManager *manager;
|
|
int id;
|
|
|
|
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
|
|
SDL_GameController *controller;
|
|
#endif
|
|
|
|
public:
|
|
~Controller();
|
|
|
|
bool IsConnected();
|
|
int GetDeviceID();
|
|
QString GetName();
|
|
ChiakiControllerState GetState();
|
|
|
|
signals:
|
|
void StateChanged();
|
|
};
|
|
|
|
#endif // CHIAKI_CONTROLLERMANAGER_H
|