1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

OP-1263 moved SDLGamepad members to new private class SDLGamepadPrivate so as to not expose SDL.h to users of this lib

This commit is contained in:
Philippe Renon 2014-03-19 23:05:40 +01:00
parent 2903fb9ea7
commit 9e9673cde4
5 changed files with 60 additions and 56 deletions

View File

@ -21,6 +21,25 @@
/**********************************************************************/
#include "sdlgamepad.h"
#include <SDL/SDL.h>
//#undef main
class SDLGamepadPrivate
{
public:
SDLGamepadPrivate() : gamepad(0)
{
}
/**
* SDL_Joystick object.
*
* This represents the currently opened SDL_Joystick object.
*/
SDL_Joystick *gamepad;
};
/**********************************************************************/
SDLGamepad::SDLGamepad()
{
@ -29,7 +48,7 @@ SDLGamepad::SDLGamepad()
index = -1;
loop = false;
tick = MIN_RATE;
gamepad = 0;
priv = new SDLGamepadPrivate;
}
/**********************************************************************/
@ -37,8 +56,8 @@ SDLGamepad::~SDLGamepad()
{
loop = false;
if (gamepad) {
SDL_JoystickClose(gamepad);
if (priv->gamepad) {
SDL_JoystickClose(priv->gamepad);
}
SDL_Quit();
@ -84,14 +103,14 @@ bool SDLGamepad::setGamepad(qint16 index)
{
if (index != this->index) {
if (SDL_JoystickOpened(this->index)) {
SDL_JoystickClose(gamepad);
SDL_JoystickClose(priv->gamepad);
}
gamepad = SDL_JoystickOpen(index);
priv->gamepad = SDL_JoystickOpen(index);
if (gamepad) {
buttons = SDL_JoystickNumButtons(gamepad);
axes = SDL_JoystickNumAxes(gamepad);
if (priv->gamepad) {
buttons = SDL_JoystickNumButtons(priv->gamepad);
axes = SDL_JoystickNumAxes(priv->gamepad);
if (axes >= 4) {
this->index = index;
@ -122,12 +141,12 @@ void SDLGamepad::setTickRate(qint16 ms)
/**********************************************************************/
void SDLGamepad::updateAxes()
{
if (gamepad) {
if (priv->gamepad) {
QListInt16 values;
SDL_JoystickUpdate();
for (qint8 i = 0; i < axes; i++) {
qint16 value = SDL_JoystickGetAxis(gamepad, i);
qint16 value = SDL_JoystickGetAxis(priv->gamepad, i);
if (value > -NULL_RANGE && value < NULL_RANGE) {
value = 0;
@ -143,11 +162,11 @@ void SDLGamepad::updateAxes()
/**********************************************************************/
void SDLGamepad::updateButtons()
{
if (gamepad) {
if (priv->gamepad) {
SDL_JoystickUpdate();
for (qint8 i = 0; i < buttons; i++) {
qint16 state = SDL_JoystickGetButton(gamepad, i);
qint16 state = SDL_JoystickGetButton(priv->gamepad, i);
if (buttonStates.at(i) != state) {
if (state > 0) {

View File

@ -20,18 +20,13 @@
* mail.nalla@gmail.com
*/
/**********************************************************************/
#ifndef SDLGAMEPAD_H
#define SDLGAMEPAD_H
/**********************************************************************/
#include <SDL/SDL.h>
#undef main
/**********************************************************************/
#include <QThread>
#include "sdlgamepad_global.h"
#include <QThread>
/**
* The Axis range that is treated as null.
*
@ -114,6 +109,8 @@ enum ButtonNumber {
*/
typedef QList<qint16> QListInt16;
class SDLGamepadPrivate;
/**
* A class for communication with a sdl gamepad.
*
@ -226,17 +223,6 @@ public slots:
private:
/**
* Variable to control thread.
*
* This class member variable is false at construction time. If
* the sdl init was successfull it will be set to true. The quit
* slot will false it again.
*
* @see quit()
*/
bool loop;
/**
* Get new axes information from the SDL system.
*
@ -261,6 +247,17 @@ private:
*/
void updateButtons();
/**
* Variable to control thread.
*
* This class member variable is false at construction time. If
* the SDL init was successful it will be set to true. The quit
* slot will false it again.
*
* @see quit()
*/
bool loop;
/**
* Number of buttons.
*
@ -295,20 +292,18 @@ private:
*/
qint16 index;
/**
* SDL_Joystick object.
*
* This represents the currently opend SDL_Joystick object.
*/
SDL_Joystick *gamepad;
/**
* A QList to store the current button states.
*
* This list stores the current states of all avaliable buttons.
* This list stores the current states of all available buttons.
*/
QList<qint16> buttonStates;
/**
* Variable that holds private members.
*/
SDLGamepadPrivate *priv;
signals:
/**
@ -354,5 +349,4 @@ signals:
void axesValues(QListInt16 values);
};
/**********************************************************************/
#endif // SDLGAMEPAD_H

View File

@ -1,16 +1 @@
macx {
# Ensures that SDL framework and header files are found when compiled with Qt5.1.1
INCLUDEPATH += /Library/Frameworks/SDL.framework/Headers
SDL = -F/Library/Frameworks
# Add SDL to CFLAGS fixes build problems on mac
QMAKE_CFLAGS += $$SDL
QMAKE_CXXFLAGS += $$SDL
# Let the linker know where to find the frameworks
LIBS += $$SDL
}
win32 {
INCLUDEPATH += $(SDL_DIR)/include
}
LIBS *= -l$$qtLibraryName(sdlgamepad)

View File

@ -23,14 +23,21 @@ TARGET = sdlgamepad
DEFINES += SDLGAMEPAD_LIBRARY
include(../../openpilotgcslibrary.pri)
include(../../sdlgamepad.pri)
macx {
# Ensures that SDL framework and header files are found when compiled with Qt5.2.1
INCLUDEPATH += /Library/Frameworks/SDL.framework/Headers
SDL = -F/Library/Frameworks
# Add SDL to CFLAGS fixes build problems on mac
QMAKE_CFLAGS += $$SDL
QMAKE_CXXFLAGS += $$SDL
# Let the linker know where to find the frameworks
LIBS += $$SDL
LIBS += -framework OpenGL -framework SDL -framework Cocoa
}
win32 {
INCLUDEPATH += $(SDL_DIR)/include
LIBS += -L$(SDL_DIR)/lib
}

View File

@ -31,7 +31,6 @@
#include "coreplugin/dialogs/ioptionspage.h"
#include "gcscontrolplugin.h"
#include "sdlgamepad/sdlgamepad.h"
#include <SDL/SDL.h>
#include <QDebug>
#include <QCheckBox>