diff options
-rw-r--r-- | cmake/opentrack-platform.cmake | 5 | ||||
-rw-r--r-- | proto-vjoy/CMakeLists.txt | 14 | ||||
-rw-r--r-- | proto-vjoy/ftnoir_protocol_vjoy.cpp | 33 | ||||
-rw-r--r-- | proto-vjoy/ftnoir_protocol_vjoy.h | 91 | ||||
-rw-r--r-- | proto-vjoy/ftnoir_protocol_vjoy_dialog.cpp | 22 | ||||
-rw-r--r-- | proto-vjoy/ftnoir_vjoy_controls.ui | 113 | ||||
-rw-r--r-- | proto-vjoy/images/vjoy.png | bin | 694 -> 0 bytes | |||
-rw-r--r-- | proto-vjoy/vjoy.def | 5 | ||||
-rw-r--r-- | proto-vjoystick/CMakeLists.txt | 16 | ||||
-rw-r--r-- | proto-vjoystick/images/vjoystick.png | bin | 0 -> 6327 bytes | |||
-rw-r--r-- | proto-vjoystick/lang/nl_NL.ts | 57 | ||||
-rw-r--r-- | proto-vjoystick/lang/ru_RU.ts | 57 | ||||
-rw-r--r-- | proto-vjoystick/lang/stub.ts | 57 | ||||
-rw-r--r-- | proto-vjoystick/lang/zh_CN.ts | 57 | ||||
-rw-r--r-- | proto-vjoystick/vjoystick.cpp | 153 | ||||
-rw-r--r-- | proto-vjoystick/vjoystick.h | 68 | ||||
-rw-r--r-- | proto-vjoystick/vjoystick.qrc (renamed from proto-vjoy/vjoy-protocol.qrc) | 2 | ||||
-rw-r--r-- | proto-vjoystick/vjoystick.ui | 56 | ||||
-rw-r--r-- | proto-vjoystick/vjoystick_dialog.cpp | 8 |
19 files changed, 535 insertions, 279 deletions
diff --git a/cmake/opentrack-platform.cmake b/cmake/opentrack-platform.cmake index 2986f12f..bbf079cb 100644 --- a/cmake/opentrack-platform.cmake +++ b/cmake/opentrack-platform.cmake @@ -14,6 +14,11 @@ if(WIN32) ENABLE_LANGUAGE(RC) endif(WIN32) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_DEFAULT 17) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS FALSE) + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_SKIP_INSTALL_RPATH FALSE) diff --git a/proto-vjoy/CMakeLists.txt b/proto-vjoy/CMakeLists.txt deleted file mode 100644 index 22678c32..00000000 --- a/proto-vjoy/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -if(WIN32) - set(SDK_VJOY "" CACHE PATH "VJoy SDK path") - if(SDK_VJOY) - opentrack_boilerplate(opentrack-proto-vjoy GNU-LINK "-Wl,--enable-stdcall-fixup") - if(MSVC) - set(ext .lib) - else() - set(ext .dll) - endif() - target_link_libraries(opentrack-proto-vjoy ${MY_QT_LIBS} ${SDK_VJOY}/VJoy${ext}) - target_include_directories(opentrack-proto-vjoy SYSTEM PUBLIC ${SDK_VJOY}) - install(FILES "${SDK_VJOY}/VJoy.dll" DESTINATION . ${opentrack-perms}) - endif() -endif() diff --git a/proto-vjoy/ftnoir_protocol_vjoy.cpp b/proto-vjoy/ftnoir_protocol_vjoy.cpp deleted file mode 100644 index 24148c63..00000000 --- a/proto-vjoy/ftnoir_protocol_vjoy.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "ftnoir_protocol_vjoy.h" -#include "opentrack/plugin-api.hpp" - -FTNoIR_Protocol::FTNoIR_Protocol() -{ - static char meh[1] = {0}; - VJoy_Initialize(meh, meh); -} - -FTNoIR_Protocol::~FTNoIR_Protocol() -{ - VJoy_Shutdown(); -} - -void FTNoIR_Protocol::pose( const double *headpose ) { -#ifdef __GNUC__ -# pragma GCC diagnostic ignored "-Wmissing-field-initializers" -#endif - JOYSTICK_STATE state[2] = { 0 }; - - state[0].POV = (4 << 12) | (4 << 8) | (4 << 4) | 4; - - state[0].XAxis = std::min<int>(VJOY_AXIS_MAX, std::max<int>(VJOY_AXIS_MIN, headpose[Yaw] * VJOY_AXIS_MAX / 180.0)); - state[0].YAxis = std::min<int>(VJOY_AXIS_MAX, std::max<int>(VJOY_AXIS_MIN, headpose[Pitch] * VJOY_AXIS_MAX / 180.0)); - state[0].ZAxis = std::min<int>(VJOY_AXIS_MAX, std::max<int>(VJOY_AXIS_MIN, headpose[Roll] * VJOY_AXIS_MAX / 180.0)); - state[0].XRotation = std::min<int>(VJOY_AXIS_MAX, std::max<int>(VJOY_AXIS_MIN, headpose[TX] * VJOY_AXIS_MAX / 100.0)); - state[0].YRotation = std::min<int>(VJOY_AXIS_MAX, std::max<int>(VJOY_AXIS_MIN, headpose[TY] * VJOY_AXIS_MAX / 100.0)); - state[0].ZRotation = std::min<int>(VJOY_AXIS_MAX, std::max<int>(VJOY_AXIS_MIN, headpose[TZ] * VJOY_AXIS_MAX / 100.0)); - - VJoy_UpdateJoyState(0, state); -} - -OPENTRACK_DECLARE_PROTOCOL(FTNoIR_Protocol, VJoyControls, FTNoIR_ProtocolDll) diff --git a/proto-vjoy/ftnoir_protocol_vjoy.h b/proto-vjoy/ftnoir_protocol_vjoy.h deleted file mode 100644 index 118306b5..00000000 --- a/proto-vjoy/ftnoir_protocol_vjoy.h +++ /dev/null @@ -1,91 +0,0 @@ -/* Homepage http://facetracknoir.sourceforge.net/home/default.htm * - * * - * ISC License (ISC) * - * * - * Copyright (c) 2015, Wim Vriend * - * * - * Permission to use, copy, modify, and/or distribute this software for any * - * purpose with or without fee is hereby granted, provided that the above * - * copyright notice and this permission notice appear in all copies. * - */ -#pragma once -#include "ui_ftnoir_vjoy_controls.h" -#include <cmath> -#include "opentrack/plugin-api.hpp" - -#define FT_PROGRAMID "FT_ProgramID" - -class FTNoIR_Protocol : public IProtocol -{ -public: - FTNoIR_Protocol(); - ~FTNoIR_Protocol() override; - bool correct() { - return true; - } - void pose( const double *headpose ); - QString game_name() { - return "Virtual joystick"; - } -private: -}; - -// Widget that has controls for FTNoIR protocol client-settings. -class VJoyControls: public IProtocolDialog -{ - Q_OBJECT -public: - - explicit VJoyControls(); - void register_protocol(IProtocol *) {} - void unregister_protocol() {} - -private: - Ui::UICVJoyControls ui; - void save(); - -private slots: - void doOK(); - void doCancel(); -}; - -class FTNoIR_ProtocolDll : public Metadata -{ -public: - QString name() { return QString("Joystick emulation -- VJoy"); } - QIcon icon() { return QIcon(":/images/vjoy.png"); } -}; - -#define VJOY_AXIS_MIN -32768 -#define VJOY_AXIS_NIL 0 -#define VJOY_AXIS_MAX 32767 - -#include <windows.h> - -#include <pshpack1.h> - -typedef struct _JOYSTICK_STATE -{ - UCHAR ReportId; // Report Id - SHORT XAxis; // X Axis - SHORT YAxis; // Y Axis - SHORT ZAxis; // Z Axis - SHORT XRotation; // X Rotation - SHORT YRotation; // Y Rotation - SHORT ZRotation; // Z Rotation - SHORT Slider; // Slider - SHORT Dial; // Dial - USHORT POV; // POV - UINT32 Buttons; // 32 Buttons -} JOYSTICK_STATE, * PJOYSTICK_STATE; - -#ifndef _MSC_VER -EXTERN_C BOOL __stdcall VJoy_Initialize(PCHAR name, PCHAR serial); -EXTERN_C VOID __stdcall VJoy_Shutdown(); -EXTERN_C BOOL __stdcall VJoy_UpdateJoyState(int id, PJOYSTICK_STATE pJoyState); -#else -#define VJOY_API __declspec(dllimport) -VJOY_API BOOL __stdcall VJoy_Initialize(PCHAR name, PCHAR serial); -VJOY_API VOID __stdcall VJoy_Shutdown(); -VJOY_API BOOL __stdcall VJoy_UpdateJoyState(int id, PJOYSTICK_STATE pJoyState); -#endif diff --git a/proto-vjoy/ftnoir_protocol_vjoy_dialog.cpp b/proto-vjoy/ftnoir_protocol_vjoy_dialog.cpp deleted file mode 100644 index 08c65558..00000000 --- a/proto-vjoy/ftnoir_protocol_vjoy_dialog.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "ftnoir_protocol_vjoy.h" -#include "opentrack/plugin-api.hpp" - -VJoyControls::VJoyControls() -{ - ui.setupUi( this ); - connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); - connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); -} - -void VJoyControls::doOK() { - save(); - this->close(); -} - -void VJoyControls::doCancel() { - this->close(); -} - -void VJoyControls::save() { -} - diff --git a/proto-vjoy/ftnoir_vjoy_controls.ui b/proto-vjoy/ftnoir_vjoy_controls.ui deleted file mode 100644 index 2214b887..00000000 --- a/proto-vjoy/ftnoir_vjoy_controls.ui +++ /dev/null @@ -1,113 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>UICVJoyControls</class> - <widget class="QWidget" name="UICVJoyControls"> - <property name="windowModality"> - <enum>Qt::NonModal</enum> - </property> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>228</width> - <height>69</height> - </rect> - </property> - <property name="windowTitle"> - <string>VJoy</string> - </property> - <property name="windowIcon"> - <iconset resource="vjoy-protocol.qrc"> - <normaloff>:/images/vjoy.png</normaloff>:/images/vjoy.png</iconset> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="autoFillBackground"> - <bool>false</bool> - </property> - <layout class="QVBoxLayout" name="_vertical_layout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>No settings necessary</string> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <property name="sizeConstraint"> - <enum>QLayout::SetDefaultConstraint</enum> - </property> - <item> - <widget class="QPushButton" name="btnOK"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>OK</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="btnCancel"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - </layout> - </widget> - <tabstops> - <tabstop>btnOK</tabstop> - <tabstop>btnCancel</tabstop> - </tabstops> - <resources> - <include location="vjoy-protocol.qrc"/> - </resources> - <connections/> - <slots> - <slot>startEngineClicked()</slot> - <slot>stopEngineClicked()</slot> - <slot>cameraSettingsClicked()</slot> - </slots> -</ui> diff --git a/proto-vjoy/images/vjoy.png b/proto-vjoy/images/vjoy.png Binary files differdeleted file mode 100644 index 8eb14be8..00000000 --- a/proto-vjoy/images/vjoy.png +++ /dev/null diff --git a/proto-vjoy/vjoy.def b/proto-vjoy/vjoy.def deleted file mode 100644 index aea590a4..00000000 --- a/proto-vjoy/vjoy.def +++ /dev/null @@ -1,5 +0,0 @@ -LIBRARY vjoy.dll -IMPORTS -VJoy_Initialize = _VJoy_Initialize -VJoy_Shutdown = _VJoy_Shutdown -VJoy_UpdateJoyState = _VJoy_UpdateJoyState diff --git a/proto-vjoystick/CMakeLists.txt b/proto-vjoystick/CMakeLists.txt new file mode 100644 index 00000000..dad21fa4 --- /dev/null +++ b/proto-vjoystick/CMakeLists.txt @@ -0,0 +1,16 @@ +if(WIN32) + set(SDK_VJOYSTICK "" CACHE PATH "vjoystick SDK path") + if(SDK_VJOYSTICK) + #if(opentrack-64bit) + # set(arch "amd64/") + #else() + set(arch "") + #endif() + set(lib "${SDK_VJOYSTICK}/lib/${arch}vJoyInterface.lib") + set(dll "${SDK_VJOYSTICK}/lib/${arch}vJoyInterface.dll") + opentrack_boilerplate(opentrack-proto-vjoy) + target_link_libraries(opentrack-proto-vjoy ${lib}) + target_include_directories(opentrack-proto-vjoy SYSTEM PUBLIC "${SDK_VJOYSTICK}/inc") + install(FILES "${dll}" DESTINATION .) + endif() +endif() diff --git a/proto-vjoystick/images/vjoystick.png b/proto-vjoystick/images/vjoystick.png Binary files differnew file mode 100644 index 00000000..c3def49f --- /dev/null +++ b/proto-vjoystick/images/vjoystick.png diff --git a/proto-vjoystick/lang/nl_NL.ts b/proto-vjoystick/lang/nl_NL.ts new file mode 100644 index 00000000..46d0398d --- /dev/null +++ b/proto-vjoystick/lang/nl_NL.ts @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="nl_NL"> +<context> + <name>vjoystick</name> + <message> + <source>VJoy</source> + <translation type="unfinished"></translation> + </message> + <message> + <source><html><head/><body><p>Go to the <a href="http://vjoystick.sourceforge.net/site/"><span style=" text-decoration: underline; color:#0000ff;">vjoystick</span></a> project site or <a href="https://sourceforge.net/projects/vjoystick/files/latest/download"><span style=" text-decoration: underline; color:#0000ff;">download directly</span></a></p></body></html></source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>vjoystick_metadata</name> + <message> + <source>Joystick emulation -- vjoystick</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>vjoystick_proto</name> + <message> + <source>vjoystick driver missing</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>vjoystick won't work without the driver installed.</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Download the driver</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Visit project site</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>vjoystick not installed or disabled</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>can't initialize vjoystick</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>unknown error</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Virtual joystick</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/proto-vjoystick/lang/ru_RU.ts b/proto-vjoystick/lang/ru_RU.ts new file mode 100644 index 00000000..6a618904 --- /dev/null +++ b/proto-vjoystick/lang/ru_RU.ts @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="ru_RU"> +<context> + <name>vjoystick</name> + <message> + <source>VJoy</source> + <translation type="unfinished"></translation> + </message> + <message> + <source><html><head/><body><p>Go to the <a href="http://vjoystick.sourceforge.net/site/"><span style=" text-decoration: underline; color:#0000ff;">vjoystick</span></a> project site or <a href="https://sourceforge.net/projects/vjoystick/files/latest/download"><span style=" text-decoration: underline; color:#0000ff;">download directly</span></a></p></body></html></source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>vjoystick_metadata</name> + <message> + <source>Joystick emulation -- vjoystick</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>vjoystick_proto</name> + <message> + <source>vjoystick driver missing</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>vjoystick won't work without the driver installed.</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Download the driver</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Visit project site</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>vjoystick not installed or disabled</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>can't initialize vjoystick</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>unknown error</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Virtual joystick</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/proto-vjoystick/lang/stub.ts b/proto-vjoystick/lang/stub.ts new file mode 100644 index 00000000..c8909cfe --- /dev/null +++ b/proto-vjoystick/lang/stub.ts @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1"> +<context> + <name>vjoystick</name> + <message> + <source>VJoy</source> + <translation type="unfinished"></translation> + </message> + <message> + <source><html><head/><body><p>Go to the <a href="http://vjoystick.sourceforge.net/site/"><span style=" text-decoration: underline; color:#0000ff;">vjoystick</span></a> project site or <a href="https://sourceforge.net/projects/vjoystick/files/latest/download"><span style=" text-decoration: underline; color:#0000ff;">download directly</span></a></p></body></html></source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>vjoystick_metadata</name> + <message> + <source>Joystick emulation -- vjoystick</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>vjoystick_proto</name> + <message> + <source>vjoystick driver missing</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>vjoystick won't work without the driver installed.</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Download the driver</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Visit project site</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>vjoystick not installed or disabled</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>can't initialize vjoystick</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>unknown error</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Virtual joystick</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/proto-vjoystick/lang/zh_CN.ts b/proto-vjoystick/lang/zh_CN.ts new file mode 100644 index 00000000..c8909cfe --- /dev/null +++ b/proto-vjoystick/lang/zh_CN.ts @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1"> +<context> + <name>vjoystick</name> + <message> + <source>VJoy</source> + <translation type="unfinished"></translation> + </message> + <message> + <source><html><head/><body><p>Go to the <a href="http://vjoystick.sourceforge.net/site/"><span style=" text-decoration: underline; color:#0000ff;">vjoystick</span></a> project site or <a href="https://sourceforge.net/projects/vjoystick/files/latest/download"><span style=" text-decoration: underline; color:#0000ff;">download directly</span></a></p></body></html></source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>vjoystick_metadata</name> + <message> + <source>Joystick emulation -- vjoystick</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>vjoystick_proto</name> + <message> + <source>vjoystick driver missing</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>vjoystick won't work without the driver installed.</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Download the driver</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Visit project site</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>vjoystick not installed or disabled</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>can't initialize vjoystick</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>unknown error</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Virtual joystick</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/proto-vjoystick/vjoystick.cpp b/proto-vjoystick/vjoystick.cpp new file mode 100644 index 00000000..4ad20599 --- /dev/null +++ b/proto-vjoystick/vjoystick.cpp @@ -0,0 +1,153 @@ +/* Copyright (c) 2016, Stanislaw Halik <sthalik@misaki.pl> + + * Permission to use, copy, modify, and/or distribute this + * software for any purpose with or without fee is hereby granted, + * provided that the above copyright notice and this permission + * notice appear in all copies. + */ +#include "vjoystick.h" + +#include <cmath> +#include <cstring> +#include <QDebug> + +#include <QPushButton> +#include <QMessageBox> +#include <QDesktopServices> +#include <QUrl> + +// required for api headers +#include <windows.h> + +#undef PPJOY_MODE +#include <public.h> +#include <vjoyinterface.h> + +#define OPENTRACK_VJOYSTICK_ID 1 + +static constexpr inline unsigned axis_count = 6; + +static constexpr unsigned char axis_ids[axis_count] = +{ + HID_USAGE_X, + HID_USAGE_Y, + HID_USAGE_Z, + HID_USAGE_RX, + HID_USAGE_RY, + HID_USAGE_RZ, +// HID_USAGE_SL0, +// HID_USAGE_SL1, +// HID_USAGE_WHL, +}; + +static constexpr double val_minmax[axis_count] = +{ + 50, + 50, + 50, + 180, + 180, + 180 +}; + +void handle::init() +{ + for (unsigned i = 0; i < axis_count; i++) + { + if (!GetVJDAxisExist(OPENTRACK_VJOYSTICK_ID, axis_ids[i])) + { + // avoid floating point division by zero + axis_min[i] = 0; + axis_max[i] = 1; + continue; + } + GetVJDAxisMin(OPENTRACK_VJOYSTICK_ID, axis_ids[i], &axis_min[i]); + GetVJDAxisMax(OPENTRACK_VJOYSTICK_ID, axis_ids[i], &axis_max[i]); + } + (void) ResetVJD(OPENTRACK_VJOYSTICK_ID); +} + +handle::handle() +{ + const bool ret = AcquireVJD(OPENTRACK_VJOYSTICK_ID); + if (!ret) + { + if (!isVJDExists(OPENTRACK_VJOYSTICK_ID)) + joy_state = state_notent; + else + joy_state = state_fail; + } + else + { + joy_state = state_success; + init(); + } +} + +handle::~handle() +{ + if (joy_state == state_success) + { + (void) RelinquishVJD(OPENTRACK_VJOYSTICK_ID); + joy_state = state_fail; + } +} + +LONG handle::to_axis_value(unsigned axis_id, double val) +{ + const double minmax = val_minmax[axis_id]; + const double min = axis_min[axis_id]; + const double max = axis_max[axis_id]; + + const double x = (val+minmax) * max / (2*minmax) - min; + return std::fmax(min, std::fmin(x, max)); +} + +vjoystick_proto::vjoystick_proto() +{ +} + +vjoystick_proto::~vjoystick_proto() +{ +} + +bool vjoystick_proto::correct() +{ + if (h.get_state() != state_success) + { + QMessageBox msgbox; + msgbox.setIcon(QMessageBox::Critical); + msgbox.setText(tr("vjoystick driver missing")); + msgbox.setInformativeText(tr("vjoystick won't work without the driver installed.")); + + QPushButton* driver_button = msgbox.addButton(tr("Download the driver"), QMessageBox::ActionRole); + QPushButton* project_site_button = msgbox.addButton(tr("Visit project site"), QMessageBox::ActionRole); + msgbox.addButton(QMessageBox::Close); + + (void) msgbox.exec(); + + if (msgbox.clickedButton() == driver_button) + { + static const char* download_driver_url = "https://sourceforge.net/projects/vjoystick/files/latest/download"; + QDesktopServices::openUrl(QUrl(download_driver_url, QUrl::StrictMode)); + } + else if (msgbox.clickedButton() == project_site_button) + { + static const char* project_site_url = "http://vjoystick.sourceforge.net/site/"; + QDesktopServices::openUrl(QUrl(project_site_url, QUrl::StrictMode)); + } + } + + return h.get_state() == state_success; +} + +void vjoystick_proto::pose(const double *pose) +{ + if (h.get_state() != state_success) + return; + + for (unsigned i = 0; i < axis_count; i++) + SetAxis(h.to_axis_value(i, pose[i]), OPENTRACK_VJOYSTICK_ID, axis_ids[i]); +} + +OPENTRACK_DECLARE_PROTOCOL(vjoystick_proto, vjoystick_dialog, vjoystick_metadata) diff --git a/proto-vjoystick/vjoystick.h b/proto-vjoystick/vjoystick.h new file mode 100644 index 00000000..6d4062f0 --- /dev/null +++ b/proto-vjoystick/vjoystick.h @@ -0,0 +1,68 @@ +/* Copyright (c) 2016, Stanislaw Halik <sthalik@misaki.pl> + + * Permission to use, copy, modify, and/or distribute this + * software for any purpose with or without fee is hereby granted, + * provided that the above copyright notice and this permission + * notice appear in all copies. + */ +#pragma once +#include "ui_vjoystick.h" +#include "opentrack/plugin-api.hpp" + +#include <QObject> +#include <QString> + +#include <windows.h> + +enum state : signed char +{ + state_notent = -1, + state_fail = -2, + state_success = 1, +}; + +class handle final +{ + state joy_state; + LONG axis_min[6] {}; + LONG axis_max[6] {}; + + void init(); +public: + handle(); + ~handle(); + state get_state() { return joy_state; } + LONG to_axis_value(unsigned axis_id, double val); +}; + +class vjoystick_proto : public QObject, public IProtocol +{ + Q_OBJECT + + handle h; +public: + vjoystick_proto(); + ~vjoystick_proto() override; + bool correct() override; + void pose( const double *headpose ) override; + QString game_name() override { return tr("Virtual joystick"); } +private: +}; + +class vjoystick_dialog final : public IProtocolDialog +{ + Q_OBJECT +public: + + vjoystick_dialog(); + void register_protocol(IProtocol *) override {} + void unregister_protocol() override {} +private: + Ui::vjoystick ui; +}; + +class vjoystick_metadata : public Metadata +{ + QString name() override { return "Joystick emulation -- vjoystick"; } + QIcon icon() override { return QIcon(":/images/vjoystick.png"); } +}; diff --git a/proto-vjoy/vjoy-protocol.qrc b/proto-vjoystick/vjoystick.qrc index 7b3741f1..9c73169f 100644 --- a/proto-vjoy/vjoy-protocol.qrc +++ b/proto-vjoystick/vjoystick.qrc @@ -1,5 +1,5 @@ <RCC> <qresource prefix="/"> - <file>images/vjoy.png</file> + <file>images/vjoystick.png</file> </qresource> </RCC> diff --git a/proto-vjoystick/vjoystick.ui b/proto-vjoystick/vjoystick.ui new file mode 100644 index 00000000..6e6a2b33 --- /dev/null +++ b/proto-vjoystick/vjoystick.ui @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>vjoystick</class> + <widget class="QWidget" name="vjoystick"> + <property name="windowModality"> + <enum>Qt::NonModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>283</width> + <height>66</height> + </rect> + </property> + <property name="windowTitle"> + <string>VJoy</string> + </property> + <property name="windowIcon"> + <iconset resource="vjoystick.qrc"> + <normaloff>:/images/vjoystick.png</normaloff>:/images/vjoystick.png</iconset> + </property> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string><html><head/><body><p>Go to the <a href="http://vjoystick.sourceforge.net/site/"><span style=" text-decoration: underline; color:#0000ff;">vjoystick</span></a> project site or <a href="https://sourceforge.net/projects/vjoystick/files/latest/download"><span style=" text-decoration: underline; color:#0000ff;">download directly</span></a></p></body></html></string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="openExternalLinks"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources> + <include location="vjoystick.qrc"/> + </resources> + <connections/> +</ui> diff --git a/proto-vjoystick/vjoystick_dialog.cpp b/proto-vjoystick/vjoystick_dialog.cpp new file mode 100644 index 00000000..136e898b --- /dev/null +++ b/proto-vjoystick/vjoystick_dialog.cpp @@ -0,0 +1,8 @@ +#include "vjoystick.h" +#include "opentrack/plugin-api.hpp" + +vjoystick_dialog::vjoystick_dialog() +{ + ui.setupUi(this); + connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &QWidget::close); +} |