Initial gamepad implementation. Closes #237.

This commit is contained in:
Leonardo Zide 2018-05-13 17:09:06 -07:00
parent c8952c9147
commit 3276b9b320
3 changed files with 51 additions and 1 deletions

View file

@ -24,6 +24,10 @@
#include "lc_colors.h" #include "lc_colors.h"
#include <functional> #include <functional>
#if (QT_VERSION > QT_VERSION_CHECK(5, 7, 0))
#include <QtGamepad/QGamepad>
#endif
lcMainWindow* gMainWindow; lcMainWindow* gMainWindow;
#define LC_TAB_LAYOUT_VERSION 0x0001 #define LC_TAB_LAYOUT_VERSION 0x0001
@ -81,6 +85,12 @@ lcMainWindow::lcMainWindow()
for (int FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++) for (int FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++)
mRecentFiles[FileIdx] = lcGetProfileString((LC_PROFILE_KEY)(LC_PROFILE_RECENT_FILE1 + FileIdx)); mRecentFiles[FileIdx] = lcGetProfileString((LC_PROFILE_KEY)(LC_PROFILE_RECENT_FILE1 + FileIdx));
#if (QT_VERSION > QT_VERSION_CHECK(5, 7, 0))
connect(&mGamepadTimer, &QTimer::timeout, this, &lcMainWindow::UpdateGamepads);
mLastGamepadUpdate = QDateTime::currentDateTime();
mGamepadTimer.start(33);
#endif
gMainWindow = this; gMainWindow = this;
} }
@ -777,6 +787,34 @@ QMenu* lcMainWindow::createPopupMenu()
return Menu; return Menu;
} }
void lcMainWindow::UpdateGamepads()
{
#if (QT_VERSION > QT_VERSION_CHECK(5, 7, 0))
QDateTime Now = QDateTime::currentDateTime();
quint64 Elapsed = mLastGamepadUpdate.msecsTo(Now);
mLastGamepadUpdate = Now;
if (!gMainWindow)
return;
View* ActiveView = GetActiveView();
if (!ActiveView)
return;
const QList<int> Gamepads = QGamepadManager::instance()->connectedGamepads();
if (Gamepads.isEmpty())
return;
QGamepad Gamepad(Gamepads[0]);
float Scale = (float)Elapsed / 20.0f;
lcVector3 Distance(Scale * Gamepad.axisLeftX(), 0.0f, -Scale * Gamepad.axisLeftY());
if (fabsf(Distance.LengthSquared()) > 0.01f)
ActiveView->MoveCamera(Distance);
#endif
}
void lcMainWindow::ModelTabContextMenuRequested(const QPoint& Point) void lcMainWindow::ModelTabContextMenuRequested(const QPoint& Point)
{ {
QMenu* Menu = new QMenu; QMenu* Menu = new QMenu;

View file

@ -327,6 +327,7 @@ public slots:
void ProjectFileChanged(const QString& Path); void ProjectFileChanged(const QString& Path);
protected slots: protected slots:
void UpdateGamepads();
void ModelTabContextMenuRequested(const QPoint& Point); void ModelTabContextMenuRequested(const QPoint& Point);
void ModelTabCloseOtherTabs(); void ModelTabCloseOtherTabs();
void ModelTabResetViews(); void ModelTabResetViews();
@ -368,6 +369,9 @@ protected:
return nullptr; return nullptr;
} }
QTimer mGamepadTimer;
QDateTime mLastGamepadUpdate;
bool mAddKeys; bool mAddKeys;
lcTool mTool; lcTool mTool;
lcTransformType mTransformType; lcTransformType mTransformType;

View file

@ -1,11 +1,19 @@
QT += core gui opengl network xml QT += core gui opengl network xml
TEMPLATE = app TEMPLATE = app
greaterThan(QT_MAJOR_VERSION, 4) { greaterThan(QT_MAJOR_VERSION, 4)
{
QT *= printsupport QT *= printsupport
QT += concurrent QT += concurrent
} }
greaterThan(QT_MAJOR_VERSION, 5)
{
QT += gamepad
}
equals(QT_MAJOR_VERSION, 5) : greaterThan(QT_MINOR_VERSION, 7): QT += gamepad
INCLUDEPATH += qt common INCLUDEPATH += qt common
CONFIG += precompile_header incremental c++11 CONFIG += precompile_header incremental c++11
win32 { win32 {