summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-09-14 17:59:21 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-09-14 17:59:21 +0200
commitf5a465e829ce817e8b0fdaf2d240a34f37ca1c35 (patch)
tree14681bfff4776ad5ef9eca78483d4adc782401b4 /facetracknoir
parent475df2d12176e906d99822f4517fbb85579f8683 (diff)
Move keyboard shortcuts to a new file
Windows build could be interminently broken. Will resolve in following commits.
Diffstat (limited to 'facetracknoir')
-rw-r--r--facetracknoir/facetracknoir.cpp106
-rw-r--r--facetracknoir/facetracknoir.h80
-rw-r--r--facetracknoir/shortcuts.cpp102
-rw-r--r--facetracknoir/shortcuts.h89
4 files changed, 193 insertions, 184 deletions
diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp
index 313673c6..2d5fe4a0 100644
--- a/facetracknoir/facetracknoir.cpp
+++ b/facetracknoir/facetracknoir.cpp
@@ -22,12 +22,14 @@
* with this program; if not, see <http://www.gnu.org/licenses/>. *
*********************************************************************************/
#include "facetracknoir.h"
+#include "shortcuts.h"
#include "tracker.h"
#include <ftnoir_tracker_ht/ht-api.h>
#include <QDebug>
#if defined(__WIN32) || defined(_WIN32)
# include <windows.h>
+# include <dshow.h>
#endif
#if defined(__APPLE__)
@@ -40,110 +42,6 @@
#include <iostream>
-#if defined(__WIN32) || defined(_WIN32)
-#undef DIRECTINPUT_VERSION
-#define DIRECTINPUT_VERSION 0x0800
-#include <dshow.h>
-#include <dinput.h>
-
-KeybindingWorkerDummy::~KeybindingWorkerDummy() {
- if (dinkeyboard) {
- dinkeyboard->Unacquire();
- dinkeyboard->Release();
- }
- if (din)
- din->Release();
-}
-
-KeybindingWorkerDummy::KeybindingWorkerDummy(FaceTrackNoIR& w, Key keyCenter)
-: kCenter(keyCenter), window(w), should_quit(true), din(0), dinkeyboard(0)
-{
- if (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL) != DI_OK) {
- qDebug() << "setup DirectInput8 Creation failed!" << GetLastError();
- return;
- }
- if (din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, NULL) != DI_OK) {
- din->Release();
- din = 0;
- qDebug() << "setup CreateDevice function failed!" << GetLastError();
- return;
- }
- if (dinkeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK) {
- qDebug() << "setup SetDataFormat function failed!" << GetLastError();
- dinkeyboard->Release();
- dinkeyboard = 0;
- din->Release();
- din = 0;
- return;
- }
-
- if (dinkeyboard->SetCooperativeLevel(window.winId(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) {
- dinkeyboard->Release();
- din->Release();
- din = 0;
- dinkeyboard = 0;
- qDebug() << "setup SetCooperativeLevel function failed!" << GetLastError();
- return;
- }
- if (dinkeyboard->Acquire() != DI_OK)
- {
- dinkeyboard->Release();
- din->Release();
- din = 0;
- dinkeyboard = 0;
- qDebug() << "setup dinkeyboard Acquire failed!" << GetLastError();
- return;
- }
- should_quit = false;
-}
-
-#define PROCESS_KEY(k, s) \
- if (isKeyPressed(&k, keystate) && (!k.ever_pressed ? (k.timer.start(), k.ever_pressed = true) : k.timer.restart() > 100)) \
- window.s();
-
-static bool isKeyPressed( const Key *key, const BYTE *keystate ) {
- bool shift;
- bool ctrl;
- bool alt;
-
- if (keystate[key->keycode] & 0x80) {
- shift = ( (keystate[DIK_LSHIFT] & 0x80) || (keystate[DIK_RSHIFT] & 0x80) );
- ctrl = ( (keystate[DIK_LCONTROL] & 0x80) || (keystate[DIK_RCONTROL] & 0x80) );
- alt = ( (keystate[DIK_LALT] & 0x80) || (keystate[DIK_RALT] & 0x80) );
-
- //
- // If one of the modifiers is needed and not pressed, return false.
- //
- if (key->shift && !shift) return false;
- if (key->ctrl && !ctrl) return false;
- if (key->alt && !alt) return false;
-
- //
- // All is well!
- //
- return true;
- }
- return false;
-}
-
-void KeybindingWorkerDummy::run() {
- BYTE keystate[256];
- while (!should_quit)
- {
- if (dinkeyboard->GetDeviceState(256, (LPVOID)keystate) != DI_OK) {
- qDebug() << "Tracker::run GetDeviceState function failed!" << GetLastError();
- Sleep(25);
- continue;
- }
-
- PROCESS_KEY(kCenter, shortcutRecentered);
-
- Sleep(25);
- }
-}
-#else
-#endif
-
#ifdef _MSC_VER
# define LIB_PREFIX ""
#else
diff --git a/facetracknoir/facetracknoir.h b/facetracknoir/facetracknoir.h
index ab0b8bc5..b1a1cb42 100644
--- a/facetracknoir/facetracknoir.h
+++ b/facetracknoir/facetracknoir.h
@@ -53,9 +53,7 @@
#include <QDebug>
#include <QElapsedTimer>
-
#include "ui_facetracknoir.h"
-#include "ui_ftnoir_keyboardshortcuts.h"
#include "ftnoir_protocol_base/ftnoir_protocol_base.h"
#include "ftnoir_tracker_base/ftnoir_tracker_base.h"
@@ -70,28 +68,6 @@ class FaceTrackNoIR;
class KeybindingWorker;
-#if defined(__WIN32) || defined(_WIN32)
-extern QList<int> global_windows_key_sequences;
-#undef DIRECTINPUT_VERSION
-#define DIRECTINPUT_VERSION 0x0800
-#include <dinput.h>
-struct Key {
- BYTE keycode;
- bool shift;
- bool ctrl;
- bool alt;
- bool ever_pressed;
- QElapsedTimer timer;
-public:
- Key() : keycode(0), shift(false), ctrl(false), alt(false), ever_pressed(false)
- {
- }
-};
-#else
-typedef unsigned char BYTE;
-struct Key { int foo; };
-#endif
-
class FaceTrackNoIR : public QMainWindow, IDynamicLibraryProvider
{
Q_OBJECT
@@ -209,60 +185,4 @@ private slots:
};
-class KeyboardShortcutDialog: public QWidget
-{
- Q_OBJECT
-public:
-
- explicit KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget *parent=0, Qt::WindowFlags f=0 );
- virtual ~KeyboardShortcutDialog();
- void showEvent ( QShowEvent * event );
-
-private:
- Ui::UICKeyboardShortcutDialog ui;
- void loadSettings();
- void save();
-
- /** helper **/
- bool settingsDirty;
- FaceTrackNoIR *mainApp;
-
-private slots:
- void doOK();
- void doCancel();
-};
-
-extern QList<QString> global_key_sequences;
-#if defined(__WIN32) || defined(_WIN32)
-class KeybindingWorkerDummy {
-private:
- LPDIRECTINPUT8 din;
- LPDIRECTINPUTDEVICE8 dinkeyboard;
- Key kCenter;
- FaceTrackNoIR& window;
-public:
- volatile bool should_quit;
- ~KeybindingWorkerDummy();
- KeybindingWorkerDummy(FaceTrackNoIR& w, Key keyCenter);
- void run();
-};
-#else
-class KeybindingWorkerDummy {
-public:
- KeybindingWorkerDummy(FaceTrackNoIR& w, Key keyCenter);
- void run() {}
-};
-#endif
-
-class KeybindingWorker : public QThread, public KeybindingWorkerDummy {
- Q_OBJECT
-public:
- KeybindingWorker(FaceTrackNoIR& w, Key keyCenter) : KeybindingWorkerDummy(w, keyCenter)
- {
- }
- void run() {
- KeybindingWorkerDummy::run();
- }
-};
-
#endif // FaceTrackNoIR_H
diff --git a/facetracknoir/shortcuts.cpp b/facetracknoir/shortcuts.cpp
new file mode 100644
index 00000000..1a80c8dc
--- /dev/null
+++ b/facetracknoir/shortcuts.cpp
@@ -0,0 +1,102 @@
+#if defined(__WIN32) || defined(_WIN32)
+#include "facetracknoir/facetracknoir.h"
+#include "facetracknoir/shortcut-dialog.h"
+#include <windows.h>
+
+KeybindingWorkerDummy::~KeybindingWorkerDummy() {
+ if (dinkeyboard) {
+ dinkeyboard->Unacquire();
+ dinkeyboard->Release();
+ }
+ if (din)
+ din->Release();
+}
+
+KeybindingWorkerDummy::KeybindingWorkerDummy(FaceTrackNoIR& w, Key keyCenter)
+: kCenter(keyCenter), window(w), should_quit(true), din(0), dinkeyboard(0)
+{
+ if (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL) != DI_OK) {
+ qDebug() << "setup DirectInput8 Creation failed!" << GetLastError();
+ return;
+ }
+ if (din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, NULL) != DI_OK) {
+ din->Release();
+ din = 0;
+ qDebug() << "setup CreateDevice function failed!" << GetLastError();
+ return;
+ }
+ if (dinkeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK) {
+ qDebug() << "setup SetDataFormat function failed!" << GetLastError();
+ dinkeyboard->Release();
+ dinkeyboard = 0;
+ din->Release();
+ din = 0;
+ return;
+ }
+
+ if (dinkeyboard->SetCooperativeLevel(window.winId(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) {
+ dinkeyboard->Release();
+ din->Release();
+ din = 0;
+ dinkeyboard = 0;
+ qDebug() << "setup SetCooperativeLevel function failed!" << GetLastError();
+ return;
+ }
+ if (dinkeyboard->Acquire() != DI_OK)
+ {
+ dinkeyboard->Release();
+ din->Release();
+ din = 0;
+ dinkeyboard = 0;
+ qDebug() << "setup dinkeyboard Acquire failed!" << GetLastError();
+ return;
+ }
+ should_quit = false;
+}
+
+#define PROCESS_KEY(k, s) \
+ if (isKeyPressed(&k, keystate) && (!k.ever_pressed ? (k.timer.start(), k.ever_pressed = true) : k.timer.restart() > 100)) \
+ window.s();
+
+static bool isKeyPressed( const Key *key, const BYTE *keystate ) {
+ bool shift;
+ bool ctrl;
+ bool alt;
+
+ if (keystate[key->keycode] & 0x80) {
+ shift = ( (keystate[DIK_LSHIFT] & 0x80) || (keystate[DIK_RSHIFT] & 0x80) );
+ ctrl = ( (keystate[DIK_LCONTROL] & 0x80) || (keystate[DIK_RCONTROL] & 0x80) );
+ alt = ( (keystate[DIK_LALT] & 0x80) || (keystate[DIK_RALT] & 0x80) );
+
+ //
+ // If one of the modifiers is needed and not pressed, return false.
+ //
+ if (key->shift && !shift) return false;
+ if (key->ctrl && !ctrl) return false;
+ if (key->alt && !alt) return false;
+
+ //
+ // All is well!
+ //
+ return true;
+ }
+ return false;
+}
+
+void KeybindingWorkerDummy::run() {
+ BYTE keystate[256];
+ while (!should_quit)
+ {
+ if (dinkeyboard->GetDeviceState(256, (LPVOID)keystate) != DI_OK) {
+ qDebug() << "Tracker::run GetDeviceState function failed!" << GetLastError();
+ Sleep(25);
+ continue;
+ }
+
+ PROCESS_KEY(kCenter, shortcutRecentered);
+
+ Sleep(25);
+ }
+}
+#else
+#endif
diff --git a/facetracknoir/shortcuts.h b/facetracknoir/shortcuts.h
new file mode 100644
index 00000000..9f2fd5f6
--- /dev/null
+++ b/facetracknoir/shortcuts.h
@@ -0,0 +1,89 @@
+#pragma once
+#include <QWidget>
+#include <QElapsedTimer>
+#include <QThread>
+#include "ui_ftnoir_keyboardshortcuts.h"
+
+class FaceTrackNoIR;
+
+class KeyboardShortcutDialog: public QWidget
+{
+ Q_OBJECT
+public:
+
+ explicit KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget *parent=0, Qt::WindowFlags f=0 );
+ virtual ~KeyboardShortcutDialog();
+ void showEvent ( QShowEvent * event );
+
+private:
+ Ui::UICKeyboardShortcutDialog ui;
+ void loadSettings();
+ void save();
+
+ bool settingsDirty;
+ FaceTrackNoIR *mainApp;
+
+private slots:
+ void doOK();
+ void doCancel();
+};
+
+extern QList<QString> global_key_sequences;
+
+#if defined(__WIN32) || defined(_WIN32)
+extern QList<int> global_windows_key_sequences;
+# undef DIRECTINPUT_VERSION
+# define DIRECTINPUT_VERSION 0x0800
+# include <windows.h>
+# undef DIRECTINPUT_VERSION
+# define DIRECTINPUT_VERSION 0x0800
+# include <dinput.h>
+
+struct Key {
+ BYTE keycode;
+ bool shift;
+ bool ctrl;
+ bool alt;
+ bool ever_pressed;
+ QElapsedTimer timer;
+public:
+ Key() : keycode(0), shift(false), ctrl(false), alt(false), ever_pressed(false)
+ {
+ }
+};
+#else
+typedef unsigned char BYTE;
+struct Key { int foo; };
+#endif
+
+#if defined(__WIN32) || defined(_WIN32)
+class KeybindingWorkerImpl {
+private:
+ LPDIRECTINPUT8 din;
+ LPDIRECTINPUTDEVICE8 dinkeyboard;
+ Key kCenter;
+ FaceTrackNoIR& window;
+public:
+ volatile bool should_quit;
+ ~KeybindingWorkerImpl();
+ KeybindingWorkerImpl(FaceTrackNoIR& w, Key keyCenter);
+ void run();
+};
+#else
+class KeybindingWorkerImpl {
+public:
+ KeybindingWorkerImpl(FaceTrackNoIR& w, Key keyCenter);
+ void run() {}
+};
+#endif
+
+class KeybindingWorker : public QThread, public KeybindingWorkerImpl {
+ Q_OBJECT
+public:
+ KeybindingWorker(FaceTrackNoIR& w, Key keyCenter) : KeybindingWorkerImpl(w, keyCenter)
+ {
+ }
+ void run() {
+ KeybindingWorkerImpl::run();
+ }
+};