mirror of
https://github.com/leozide/leocad
synced 2024-12-26 21:58:44 +01:00
Initial gamepad implementation. Closes #237.
This commit is contained in:
parent
c8952c9147
commit
3276b9b320
3 changed files with 51 additions and 1 deletions
|
@ -24,6 +24,10 @@
|
|||
#include "lc_colors.h"
|
||||
#include <functional>
|
||||
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5, 7, 0))
|
||||
#include <QtGamepad/QGamepad>
|
||||
#endif
|
||||
|
||||
lcMainWindow* gMainWindow;
|
||||
#define LC_TAB_LAYOUT_VERSION 0x0001
|
||||
|
||||
|
@ -81,6 +85,12 @@ lcMainWindow::lcMainWindow()
|
|||
for (int FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; 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;
|
||||
}
|
||||
|
||||
|
@ -777,6 +787,34 @@ QMenu* lcMainWindow::createPopupMenu()
|
|||
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)
|
||||
{
|
||||
QMenu* Menu = new QMenu;
|
||||
|
|
|
@ -327,6 +327,7 @@ public slots:
|
|||
void ProjectFileChanged(const QString& Path);
|
||||
|
||||
protected slots:
|
||||
void UpdateGamepads();
|
||||
void ModelTabContextMenuRequested(const QPoint& Point);
|
||||
void ModelTabCloseOtherTabs();
|
||||
void ModelTabResetViews();
|
||||
|
@ -368,6 +369,9 @@ protected:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
QTimer mGamepadTimer;
|
||||
QDateTime mLastGamepadUpdate;
|
||||
|
||||
bool mAddKeys;
|
||||
lcTool mTool;
|
||||
lcTransformType mTransformType;
|
||||
|
|
10
leocad.pro
10
leocad.pro
|
@ -1,11 +1,19 @@
|
|||
QT += core gui opengl network xml
|
||||
TEMPLATE = app
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
greaterThan(QT_MAJOR_VERSION, 4)
|
||||
{
|
||||
QT *= printsupport
|
||||
QT += concurrent
|
||||
}
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 5)
|
||||
{
|
||||
QT += gamepad
|
||||
}
|
||||
|
||||
equals(QT_MAJOR_VERSION, 5) : greaterThan(QT_MINOR_VERSION, 7): QT += gamepad
|
||||
|
||||
INCLUDEPATH += qt common
|
||||
CONFIG += precompile_header incremental c++11
|
||||
win32 {
|
||||
|
|
Loading…
Reference in a new issue