Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Added support for Qt with a demo application. #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gainput.sln
gainput.unsuccessfulbuild
*.opensdf
cmakebuild*/
gainput.pro.user*

.idea
.gradle
Expand Down
3 changes: 3 additions & 0 deletions gainput.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG += ordered
TEMPLATE = subdirs
SUBDIRS = lib samples
114 changes: 114 additions & 0 deletions lib/lib.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
TARGET = gainput
TEMPLATE = lib
CONFIG += staticlib

DESTDIR = $${OUT_PWD}

#win32:DEFINES += GAINPUT_LIB_DYNAMIC=1
#win32:LIBS += -lws2_32 -luser32 -lxinput

INCLUDEPATH += include

HEADERS += include\gainput\gainput.h \
include\gainput\GainputAllocator.h \
include\gainput\GainputContainers.h \
include\gainput\GainputDebugRenderer.h \
include\gainput\GainputHelpers.h \
include\gainput\GainputInputDeltaState.h \
include\gainput\GainputInputDevice.h \
include\gainput\GainputInputDeviceBuiltIn.h \
include\gainput\GainputInputDeviceKeyboard.h \
include\gainput\GainputInputDeviceMouse.h \
include\gainput\GainputInputDevicePad.h \
include\gainput\GainputInputDeviceTouch.h \
include\gainput\GainputInputListener.h \
include\gainput\GainputInputManager.h \
include\gainput\GainputInputMap.h \
include\gainput\GainputInputState.h \
include\gainput\GainputIos.h \
include\gainput\GainputLog.h \
include\gainput\GainputMapFilters.h \
include\gainput\gestures\GainputButtonStickGesture.h \
include\gainput\gestures\GainputDoubleClickGesture.h \
include\gainput\gestures\GainputGestures.h \
include\gainput\gestures\GainputHoldGesture.h \
include\gainput\gestures\GainputPinchGesture.h \
include\gainput\gestures\GainputRotateGesture.h \
include\gainput\gestures\GainputSimultaneouslyDownGesture.h \
include\gainput\gestures\GainputTapGesture.h \
include\gainput\recorder\GainputInputPlayer.h \
include\gainput\recorder\GainputInputRecorder.h \
include\gainput\recorder\GainputInputRecording.h \
source\gainput\GainputHelpersEvdev.h \
source\gainput\GainputWindows.h \
source\gainput\builtin\GainputInputDeviceBuiltInAndroid.h \
source\gainput\builtin\GainputInputDeviceBuiltInImpl.h \
source\gainput\builtin\GainputInputDeviceBuiltInIos.h \
source\gainput\builtin\GainputInputDeviceBuiltInNull.h \
source\gainput\dev\GainputDev.h \
source\gainput\dev\GainputDevProtocol.h \
source\gainput\dev\GainputMemoryStream.h \
source\gainput\dev\GainputNetAddress.h \
source\gainput\dev\GainputNetConnection.h \
source\gainput\dev\GainputNetListener.h \
source\gainput\dev\GainputStream.h \
source\gainput\keyboard\GainputInputDeviceKeyboardAndroid.h \
source\gainput\keyboard\GainputInputDeviceKeyboardEvdev.h \
source\gainput\keyboard\GainputInputDeviceKeyboardImpl.h \
source\gainput\keyboard\GainputInputDeviceKeyboardLinux.h \
source\gainput\keyboard\GainputInputDeviceKeyboardMac.h \
source\gainput\keyboard\GainputInputDeviceKeyboardNull.h \
source\gainput\keyboard\GainputInputDeviceKeyboardWin.h \
source\gainput\keyboard\GainputInputDeviceKeyboardWinRaw.h \
source\gainput\keyboard\GainputKeyboardKeyNames.h \
source\gainput\mouse\GainputInputDeviceMouseEvdev.h \
source\gainput\mouse\GainputInputDeviceMouseImpl.h \
source\gainput\mouse\GainputInputDeviceMouseLinux.h \
source\gainput\mouse\GainputInputDeviceMouseMac.h \
source\gainput\mouse\GainputInputDeviceMouseNull.h \
source\gainput\mouse\GainputInputDeviceMouseWin.h \
source\gainput\mouse\GainputInputDeviceMouseWinRaw.h \
source\gainput\mouse\GainputMouseInfo.h \
source\gainput\pad\GainputInputDevicePadAndroid.h \
source\gainput\pad\GainputInputDevicePadImpl.h \
source\gainput\pad\GainputInputDevicePadIos.h \
source\gainput\pad\GainputInputDevicePadLinux.h \
source\gainput\pad\GainputInputDevicePadMac.h \
source\gainput\pad\GainputInputDevicePadNull.h \
source\gainput\pad\GainputInputDevicePadWin.h \
source\gainput\touch\GainputInputDeviceTouchAndroid.h \
source\gainput\touch\GainputInputDeviceTouchImpl.h \
source\gainput\touch\GainputInputDeviceTouchIos.h \
source\gainput\touch\GainputInputDeviceTouchNull.h \
source\gainput\touch\GainputTouchInfo.h

SOURCES += source\gainput\gainput.cpp \
source\gainput\GainputAllocator.cpp \
source\gainput\GainputInputDeltaState.cpp \
source\gainput\GainputInputDevice.cpp \
source\gainput\GainputInputManager.cpp \
source\gainput\GainputInputMap.cpp \
source\gainput\GainputInputState.cpp \
source\gainput\GainputMapFilters.cpp \
source\gainput\builtin\GainputInputDeviceBuiltIn.cpp \
source\gainput\dev\GainputDev.cpp \
source\gainput\dev\GainputMemoryStream.cpp \
source\gainput\dev\GainputNetAddress.cpp \
source\gainput\dev\GainputNetConnection.cpp \
source\gainput\dev\GainputNetListener.cpp \
source\gainput\gestures\GainputButtonStickGesture.cpp \
source\gainput\gestures\GainputDoubleClickGesture.cpp \
source\gainput\gestures\GainputHoldGesture.cpp \
source\gainput\gestures\GainputPinchGesture.cpp \
source\gainput\gestures\GainputRotateGesture.cpp \
source\gainput\gestures\GainputSimultaneouslyDownGesture.cpp \
source\gainput\gestures\GainputTapGesture.cpp \
source\gainput\keyboard\GainputInputDeviceKeyboard.cpp \
source\gainput\keyboard\GainputInputDeviceKeyboardMac.cpp \
source\gainput\mouse\GainputInputDeviceMouse.cpp \
source\gainput\pad\GainputInputDevicePad.cpp \
source\gainput\pad\GainputInputDevicePadMac.cpp \
source\gainput\recorder\GainputInputPlayer.cpp \
source\gainput\recorder\GainputInputRecorder.cpp \
source\gainput\recorder\GainputInputRecording.cpp \
source\gainput\touch\GainputInputDeviceTouch.cpp
11 changes: 11 additions & 0 deletions samples/qt-example/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "widget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();

return a.exec();
}
17 changes: 17 additions & 0 deletions samples/qt-example/qt-example.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = qt-example
TEMPLATE = app

LIBS += -L$${OUT_PWD}/../../lib -lgainput
win32:LIBS += -lws2_32 -luser32 -lxinput

INCLUDEPATH += $${PWD}/../../lib/include

SOURCES += main.cpp widget.cpp

HEADERS += widget.h

FORMS += widget.ui
143 changes: 143 additions & 0 deletions samples/qt-example/widget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include "widget.h"


Widget::Widget(QWidget* parent)
: QWidget(parent)
, _gamepad(Q_NULLPTR)
{
setupUi(this);

_labelDefault = _labelA->palette();
_labelActive = _labelDefault;
_labelActive.setColor(QPalette::Window, Qt::green);

connect(&_timer, SIGNAL(timeout()), this, SLOT(onTimerTimeout()));

_gamepad = _manager.CreateAndGetDevice<gainput::InputDevicePad>();

if (_gamepad)
_timer.start(1);
}

void Widget::onTimerTimeout()
{
if (!_gamepad)
{
_timer.stop();
return;
}

_manager.Update();

if (!_gamepad->IsAvailable())
{
_labelL1->setPalette(_labelDefault);
_labelR1->setPalette(_labelDefault);

_progressL2->setValue(0);
_progressR2->setValue(0);

_labelA->setPalette(_labelDefault);
_labelB->setPalette(_labelDefault);
_labelX->setPalette(_labelDefault);
_labelY->setPalette(_labelDefault);

_labelTop->setPalette(_labelDefault);
_labelBottom->setPalette(_labelDefault);
_labelRight->setPalette(_labelDefault);
_labelLeft->setPalette(_labelDefault);

_labelL3->setPalette(_labelDefault);
_progressL3T->setValue(0);
_progressL3B->setValue(0);
_progressL3R->setValue(0);
_progressL3L->setValue(0);


_labelR3->setPalette(_labelDefault);
_progressR3T->setValue(0);
_progressR3B->setValue(0);
_progressR3R->setValue(0);
_progressR3L->setValue(0);

_labelSelect->setPalette(_labelDefault);
_labelStart->setPalette(_labelDefault);
}

_labelL1->setPalette(_gamepad->GetBool(gainput::PadButtonL1) ? _labelActive : _labelDefault);
_labelR1->setPalette(_gamepad->GetBool(gainput::PadButtonR1) ? _labelActive : _labelDefault);

_progressL2->setValue(static_cast<int>(_gamepad->GetFloat(gainput::PadButtonAxis4) * 100.0f));
_progressR2->setValue(static_cast<int>(_gamepad->GetFloat(gainput::PadButtonAxis5) * 100.0f));

_labelA->setPalette(_gamepad->GetBool(gainput::PadButtonA) ? _labelActive : _labelDefault);
_labelB->setPalette(_gamepad->GetBool(gainput::PadButtonB) ? _labelActive : _labelDefault);
_labelX->setPalette(_gamepad->GetBool(gainput::PadButtonX) ? _labelActive : _labelDefault);
_labelY->setPalette(_gamepad->GetBool(gainput::PadButtonY) ? _labelActive : _labelDefault);

_labelTop->setPalette(_gamepad->GetBool(gainput::PadButtonUp) ? _labelActive : _labelDefault);
_labelBottom->setPalette(_gamepad->GetBool(gainput::PadButtonDown) ? _labelActive : _labelDefault);
_labelRight->setPalette(_gamepad->GetBool(gainput::PadButtonRight) ? _labelActive : _labelDefault);
_labelLeft->setPalette(_gamepad->GetBool(gainput::PadButtonLeft) ? _labelActive : _labelDefault);

// Left Stick
_labelL3->setPalette(_gamepad->GetBool(gainput::PadButtonL3) ? _labelActive : _labelDefault);

float l3Y = _gamepad->GetFloat(gainput::PadButtonLeftStickY);

if (l3Y > 0.0f)
{
_progressL3T->setValue(static_cast<int>(l3Y * 100.0f));
_progressL3B->setValue(0);
}
else
{
_progressL3T->setValue(0);
_progressL3B->setValue(static_cast<int>(l3Y * -100.0f));
}

float l3X = _gamepad->GetFloat(gainput::PadButtonLeftStickX);

if (l3X > 0.0f)
{
_progressL3R->setValue(static_cast<int>(l3X * 100.0f));
_progressL3L->setValue(0);
}
else
{
_progressL3R->setValue(0);
_progressL3L->setValue(static_cast<int>(l3X * -100.0f));
}

// Right Stick
_labelR3->setPalette(_gamepad->GetBool(gainput::PadButtonR3) ? _labelActive : _labelDefault);

float r3Y = _gamepad->GetFloat(gainput::PadButtonRightStickY);

if (r3Y > 0.0f)
{
_progressR3T->setValue(static_cast<int>(r3Y * 100.0f));
_progressR3B->setValue(0);
}
else
{
_progressR3T->setValue(0);
_progressR3B->setValue(static_cast<int>(r3Y * -100.0f));
}

float r3X = _gamepad->GetFloat(gainput::PadButtonRightStickX);

if (r3X > 0.0f)
{
_progressR3R->setValue(static_cast<int>(r3X * 100.0f));
_progressR3L->setValue(0);
}
else
{
_progressR3R->setValue(0);
_progressR3L->setValue(static_cast<int>(r3X * -100.0f));
}

_labelSelect->setPalette(_gamepad->GetBool(gainput::PadButtonSelect) ? _labelActive : _labelDefault);
_labelStart->setPalette(_gamepad->GetBool(gainput::PadButtonStart) ? _labelActive : _labelDefault);
}
33 changes: 33 additions & 0 deletions samples/qt-example/widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef WIDGET_H
#define WIDGET_H


#include "ui_widget.h"

#include <QTimer>
#include <QPalette>

#include <gainput/gainput.h>


class Widget : public QWidget, private Ui::Widget
{
Q_OBJECT

public:
explicit Widget(QWidget* parent = 0);

private slots:
void onTimerTimeout();

private:
QTimer _timer;
QPalette _labelDefault;
QPalette _labelActive;

gainput::InputManager _manager;
gainput::InputDevicePad* _gamepad;
};


#endif // WIDGET_H
Loading