diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2014-11-29 12:25:27 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2014-11-29 12:25:27 +0100 |
commit | e7d57ba055627e6b6c8f6de61a497894e0caa658 (patch) | |
tree | 1ffe7924840380d3404e2a80d31623428925f5ec /opentrack | |
parent | 8a87e1a658f04eaffa10da30f019a64902f8d917 (diff) |
implement zero shortcut
Diffstat (limited to 'opentrack')
-rw-r--r-- | opentrack/keyboard.ui | 87 | ||||
-rw-r--r-- | opentrack/shortcuts.cpp | 26 | ||||
-rw-r--r-- | opentrack/shortcuts.h | 12 | ||||
-rw-r--r-- | opentrack/tracker.cpp | 24 | ||||
-rw-r--r-- | opentrack/tracker.h | 2 | ||||
-rw-r--r-- | opentrack/work.hpp | 2 |
6 files changed, 130 insertions, 23 deletions
diff --git a/opentrack/keyboard.ui b/opentrack/keyboard.ui index c3c6019e..903bb20f 100644 --- a/opentrack/keyboard.ui +++ b/opentrack/keyboard.ui @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>422</width> + <width>461</width> <height>174</height> </rect> </property> @@ -39,7 +39,49 @@ <enum>QFrame::Plain</enum> </property> <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="4"> + <item row="3" column="0"> + <widget class="QLabel" name="textLabel2_6"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Zero</string> + </property> + <property name="wordWrap"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="3" column="3"> + <widget class="QCheckBox" name="chkZeroAlt"> + <property name="maximumSize"> + <size> + <width>50</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Alt</string> + </property> + </widget> + </item> + <item row="3" column="2"> + <widget class="QCheckBox" name="chkZeroCtrl"> + <property name="maximumSize"> + <size> + <width>50</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Ctrl</string> + </property> + </widget> + </item> + <item row="0" column="5"> <widget class="QLabel" name="textLabel2_4"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> @@ -100,6 +142,35 @@ </property> </widget> </item> + <item row="2" column="3"> + <widget class="QCheckBox" name="chkToggleAlt"> + <property name="maximumSize"> + <size> + <width>50</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Alt</string> + </property> + </widget> + </item> + <item row="2" column="5"> + <widget class="QComboBox" name="cbxToggleKey"> + <property name="minimumSize"> + <size> + <width>90</width> + <height>0</height> + </size> + </property> + <property name="toolTip"> + <string>Select Number</string> + </property> + <property name="insertPolicy"> + <enum>QComboBox::InsertAlphabetically</enum> + </property> + </widget> + </item> <item row="1" column="3"> <widget class="QCheckBox" name="chkCenterAlt"> <property name="maximumSize"> @@ -113,7 +184,7 @@ </property> </widget> </item> - <item row="1" column="4"> + <item row="1" column="5"> <widget class="QComboBox" name="cbxCenterKey"> <property name="minimumSize"> <size> @@ -171,8 +242,8 @@ </property> </widget> </item> - <item row="2" column="3"> - <widget class="QCheckBox" name="chkToggleAlt"> + <item row="3" column="1"> + <widget class="QCheckBox" name="chkZeroShift"> <property name="maximumSize"> <size> <width>50</width> @@ -180,12 +251,12 @@ </size> </property> <property name="text"> - <string>Alt</string> + <string>Shift</string> </property> </widget> </item> - <item row="2" column="4"> - <widget class="QComboBox" name="cbxToggleKey"> + <item row="3" column="5"> + <widget class="QComboBox" name="cbxZeroKey"> <property name="minimumSize"> <size> <width>90</width> diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index 88c6c69d..c9e9ce41 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -11,6 +11,7 @@ KeyboardShortcutDialog::KeyboardShortcutDialog() for ( int i = 0; i < global_key_sequences.size(); i++) { ui.cbxCenterKey->addItem(global_key_sequences.at(i)); ui.cbxToggleKey->addItem(global_key_sequences.at(i)); + ui.cbxZeroKey->addItem(global_key_sequences.at(i)); } tie_setting(s.center.key_index, ui.cbxCenterKey); @@ -23,6 +24,11 @@ KeyboardShortcutDialog::KeyboardShortcutDialog() tie_setting(s.toggle.shift, ui.chkToggleShift); tie_setting(s.toggle.ctrl, ui.chkToggleCtrl); + tie_setting(s.zero.key_index, ui.cbxZeroKey); + tie_setting(s.zero.alt, ui.chkZeroAlt); + tie_setting(s.zero.shift, ui.chkZeroShift); + tie_setting(s.zero.ctrl, ui.chkZeroCtrl); + tie_setting(s.s_main.tray_enabled, ui.trayp); } @@ -40,12 +46,13 @@ void KeyboardShortcutDialog::doCancel() { #if defined(_WIN32) #include <windows.h> -void KeybindingWorker::set_keys(Key kCenter_, Key kToggle_) +void KeybindingWorker::set_keys(Key kCenter_, Key kToggle_, Key kZero_) { QMutexLocker l(&mtx); kCenter = kCenter_; kToggle = kToggle_; + kZero = kZero_; } KeybindingWorker::~KeybindingWorker() { @@ -59,8 +66,8 @@ KeybindingWorker::~KeybindingWorker() { din->Release(); } -KeybindingWorker::KeybindingWorker(Key keyCenter, Key keyToggle, WId handle, Shortcuts& sc) : - sc(sc), din(0), dinkeyboard(0), kCenter(keyCenter), kToggle(keyToggle), should_quit(true) +KeybindingWorker::KeybindingWorker(Key keyCenter, Key keyToggle, Key keyZero, WId handle, Shortcuts& sc) : + sc(sc), din(0), dinkeyboard(0), kCenter(keyCenter), kToggle(keyToggle), kZero(keyZero), should_quit(true) { if (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL) != DI_OK) { qDebug() << "setup DirectInput8 Creation failed!" << GetLastError(); @@ -139,6 +146,9 @@ void KeybindingWorker::run() { if (isKeyPressed(&kToggle, keystate) && kToggle.should_process()) emit sc.toggle(); + if (isKeyPressed(&kZero, keystate) && kZero.should_process()) + emit sc.zero(); + // keypresses get dropped with high values Sleep(15); } @@ -195,17 +205,23 @@ void Shortcuts::reload() { keyToggle->setShortcut(QKeySequence::UnknownKey); keyToggle->setEnabled(false); } + if (keyZero) + { + keyZero->setShortcut(QKeySequence::UnknownKey); + keyZero->setEnabled(false); + } #endif bind_keyboard_shortcut(keyCenter, s.center); bind_keyboard_shortcut(keyToggle, s.toggle); + bind_keyboard_shortcut(keyZero, s.zero); #ifdef _WIN32 bool is_new = keybindingWorker == nullptr; if (is_new) { - keybindingWorker = std::make_shared<KeybindingWorker>(keyCenter, keyToggle, handle, *this); + keybindingWorker = std::make_shared<KeybindingWorker>(keyCenter, keyToggle, keyZero, handle, *this); keybindingWorker->start(); } else - keybindingWorker->set_keys(keyCenter, keyToggle); + keybindingWorker->set_keys(keyCenter, keyToggle, keyZero); #endif } diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 541d7699..7f5f9f1f 100644 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -69,16 +69,17 @@ private: LPDIRECTINPUTDEVICE8 dinkeyboard; Key kCenter; Key kToggle; + Key kZero; QMutex mtx; public: volatile bool should_quit; ~KeybindingWorker(); - KeybindingWorker(Key keyCenter, Key keyToggle, WId handle, Shortcuts& sc); + KeybindingWorker(Key keyCenter, Key keyToggle, Key keyZero, WId handle, Shortcuts& sc); void run(); - void set_keys(Key kCenter, Key kToggle); + void set_keys(Key kCenter, Key kToggle, Key kZero); #else public: - KeybindingWorker(Key, Key, WId) {} + KeybindingWorker(Key, Key, Key, WId) {} void run() {} #endif }; @@ -97,6 +98,7 @@ public: K keyCenter; K keyToggle; + K keyZero; WId handle; #ifdef _WIN32 @@ -105,12 +107,13 @@ public: struct settings { pbundle b; - key_opts center, toggle; + key_opts center, toggle, zero; main_settings s_main; settings() : b(bundle("keyboard-shortcuts")), center(b, "center"), toggle(b, "toggle"), + zero(b, "zero"), s_main(bundle("opentrack-ui")) {} } s; @@ -123,6 +126,7 @@ private: signals: void center(); void toggle(); + void zero(); }; class KeyboardShortcutDialog: public QWidget diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index be0ecd84..a6433da5 100644 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -26,6 +26,7 @@ Tracker::Tracker(main_settings& s, Mappings &m, SelectedLibraries &libs) : m(m), centerp(false), enabledp(true), + zero_(false), should_quit(false), libs(libs), r_b(dmat<3,3>::eye()), @@ -127,12 +128,26 @@ void Tracker::logic() m(5).opts.invert, }; + static constexpr double pi = 3.141592653; + static constexpr double r2d = 180. / pi; + Pose value, raw; - for (int i = 0; i < 6; i++) + if (!zero_) + for (int i = 0; i < 6; i++) + { + value(i) = newpose[i]; + raw(i) = newpose[i]; + } + else { - value(i) = newpose[i]; - raw(i) = newpose[i]; + auto mat = rmat_to_euler(r_b); + + for (int i = 0; i < 3; i++) + { + raw(i+3) = value(i+3) = mat(i, 0) * r2d; + raw(i) = value(i) = t_b[i]; + } } if (centerp) @@ -149,9 +164,6 @@ void Tracker::logic() const dmat<3, 1> euler = rmat_to_euler(m_); for (int i = 0; i < 3; i++) { - static constexpr double pi = 3.141592653; - static constexpr double r2d = 180. / pi; - value(i) -= t_b[i]; value(i+3) = euler(i, 0) * r2d; } diff --git a/opentrack/tracker.h b/opentrack/tracker.h index 84202635..bf0047b4 100644 --- a/opentrack/tracker.h +++ b/opentrack/tracker.h @@ -29,6 +29,7 @@ private: double newpose[6]; std::atomic<bool> centerp; std::atomic<bool> enabledp; + std::atomic<bool> zero_; std::atomic<bool> should_quit; SelectedLibraries const& libs; @@ -48,4 +49,5 @@ public: void start() { QThread::start(); } void toggle_enabled() { enabledp.store(!enabledp.load()); } void center() { centerp.store(!centerp.load()); } + void zero() { zero_.store(!zero_.load()); } }; diff --git a/opentrack/work.hpp b/opentrack/work.hpp index 9a9889a7..b93c71b6 100644 --- a/opentrack/work.hpp +++ b/opentrack/work.hpp @@ -26,9 +26,11 @@ struct Work #ifndef _WIN32 QObject::connect(sc->keyCenter.get(), SIGNAL(activated()), recv, SLOT(shortcutRecentered())); QObject::connect(sc->keyToggle.get(), SIGNAL(activated()), recv, SLOT(shortcutToggled())); + QObject::connect(sc->keyZero.get(), SIGNAL(activated()), recv, SLOT(shortcutZeroed())); #else QObject::connect(sc.get(), SIGNAL(center()), recv, SLOT(shortcutRecentered())); QObject::connect(sc.get(), SIGNAL(toggle()), recv, SLOT(shortcutToggled())); + QObject::connect(sc.get(), SIGNAL(zero()), recv, SLOT(shortcutZeroed())); #endif tracker->start(); } |