| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2018 Torsten Sadowski <tsadowski[at]gmx.net> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#ifndef GUINATIVEEVENT_H |
| 24 |
#define GUINATIVEEVENT_H |
| 25 |
|
| 26 |
#include "GuiAbstractNativeEvent.h" |
| 27 |
|
| 28 |
#include "3Dconnexion/MouseParameters.h" |
| 29 |
|
| 30 |
#include <map> |
| 31 |
|
| 32 |
#include <Windows.h> |
| 33 |
#include "GuiRawInputEventFilter.h" |
| 34 |
|
| 35 |
class QMainWindow; |
| 36 |
class GUIApplicationNativeEventAware; |
| 37 |
|
| 38 |
namespace Gui |
| 39 |
{ |
| 40 |
class GUIApplicationNativeEventAware; |
| 41 |
|
| 42 |
class GuiNativeEvent: public GuiAbstractNativeEvent |
| 43 |
{ |
| 44 |
Q_OBJECT |
| 45 |
public: |
| 46 |
GuiNativeEvent(GUIApplicationNativeEventAware* app); |
| 47 |
~GuiNativeEvent() override; |
| 48 |
void initSpaceball(QMainWindow* window) override final; |
| 49 |
|
| 50 |
private: |
| 51 |
GuiNativeEvent(); |
| 52 |
GuiNativeEvent(const GuiNativeEvent&); |
| 53 |
GuiNativeEvent& operator=(const GuiNativeEvent&); |
| 54 |
|
| 55 |
public: |
| 56 |
static bool Is3dmouseAttached(); |
| 57 |
|
| 58 |
I3dMouseParam& MouseParams(); |
| 59 |
const I3dMouseParam& MouseParams() const; |
| 60 |
|
| 61 |
virtual void Move3d(HANDLE device, std::vector<float>& motionData); |
| 62 |
virtual void On3dmouseKeyDown(HANDLE device, int virtualKeyCode); |
| 63 |
virtual void On3dmouseKeyUp(HANDLE device, int virtualKeyCode); |
| 64 |
|
| 65 |
private: |
| 66 |
bool InitializeRawInput(HWND hwndTarget); |
| 67 |
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 68 |
static bool RawInputEventFilter(void* msg, long* result); |
| 69 |
#else |
| 70 |
static bool RawInputEventFilter(void* msg, qintptr* result); |
| 71 |
#endif |
| 72 |
void OnRawInput(UINT nInputCode, HRAWINPUT hRawInput); |
| 73 |
UINT GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader); |
| 74 |
bool TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput); |
| 75 |
bool TranslateSpaceMouseNewGeneric(UINT nInputCode, PRAWINPUT pRawInput, DWORD dwProductId); |
| 76 |
bool TranslateSpaceMouseEnterprise(UINT nInputCode, PRAWINPUT pRawInput, DWORD dwProductId); |
| 77 |
bool TranslateSpaceMouseOldGeneric(UINT nInputCode, PRAWINPUT pRawInput, DWORD dwProductId); |
| 78 |
void On3dmouseInput(); |
| 79 |
|
| 80 |
class TInputData |
| 81 |
{ |
| 82 |
public: |
| 83 |
TInputData() |
| 84 |
: fAxes(6) |
| 85 |
{} |
| 86 |
|
| 87 |
bool IsZero() |
| 88 |
{ |
| 89 |
return ( |
| 90 |
0. == fAxes[0] && 0. == fAxes[1] && 0. == fAxes[2] && 0. == fAxes[3] |
| 91 |
&& 0. == fAxes[4] && 0. == fAxes[5] |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
int fTimeToLive; // For telling if the device was unplugged while sending data |
| 96 |
bool fIsDirty; |
| 97 |
std::vector<float> fAxes; |
| 98 |
}; |
| 99 |
|
| 100 |
HWND fWindow; |
| 101 |
|
| 102 |
// Data cache to handle multiple rawinput devices |
| 103 |
std::map<HANDLE, TInputData> fDevice2Data; |
| 104 |
std::map<HANDLE, unsigned long> fDevice2Keystate; |
| 105 |
// 3dmouse parameters |
| 106 |
MouseParameters f3dMouseParams; // Rotate, Pan Zoom etc. |
| 107 |
// use to calculate distance traveled since last event |
| 108 |
DWORD fLast3dmouseInputTime; |
| 109 |
static Gui::GuiNativeEvent* gMouseInput; |
| 110 |
}; |
| 111 |
} // namespace Gui |
| 112 |
|
| 113 |
#endif // GUINATIVEEVENT_H |