diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp index c359e227d9be39ab98df2cd8e816323b6a0ecbef..2dbfd2d54c4b1f30f17dc0e0e26274d986286ad3 100644 --- a/applications/gui/src/screen.cpp +++ b/applications/gui/src/screen.cpp @@ -86,6 +86,8 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl pos_y_ = root_->value("position_y", 0.0f); }); + shortcuts_ = ftl::create<ftl::Configurable>(root_, "shortcuts"); + setSize(Vector2i(1280,720)); toolbuttheme = new Theme(*theme()); @@ -431,12 +433,31 @@ bool ftl::gui::Screen::mouseButtonEvent(const nanogui::Vector2i &p, int button, } } +static std::string generateKeyComboStr(int key, int modifiers) { + std::string res = ""; + + switch(modifiers) { + case 1: res += "Shift+"; break; + case 2: res += "Ctrl+"; break; + case 3: res += "Ctrl+Shift+"; break; + case 4: res += "Alt+"; break; + default: break; + } + + if (key < 127 && key >= 32) { + char buf[2] = { (char)key, 0 }; + return res + std::string(buf); + } else { + return ""; + } +} + bool ftl::gui::Screen::keyboardEvent(int key, int scancode, int action, int modifiers) { using namespace Eigen; if (nanogui::Screen::keyboardEvent(key, scancode, action, modifiers)) { return true; } else { - LOG(INFO) << "Key press " << key << " - " << action << " - " << modifiers; + //LOG(INFO) << "Key press " << key << " - " << action << " - " << modifiers; if (key >= 262 && key <= 267) { if (camera_) camera_->keyMovement(key, modifiers); @@ -444,9 +465,31 @@ bool ftl::gui::Screen::keyboardEvent(int key, int scancode, int action, int modi } else if (action == 1 && key == 'H') { swindow_->setVisible(false); cwindow_->setVisible(false); - } else if (action == 1 && key == 32) { - ctrl_->pause(); - return true; + } else if (action == 1) { + std::string combo = generateKeyComboStr(key, modifiers); + + if (combo.size() > 0) { + LOG(INFO) << "Key combo = " << combo; + + auto s = shortcuts_->get<nlohmann::json>(combo); + if (s) { + LOG(INFO) << "FOUND KEYBOARD SHORTCUT"; + std::string op = (*s).value("op",std::string("=")); + std::string uri = (*s).value("uri",std::string("")); + + if (op == "toggle") { + auto v = ftl::config::resolve(uri, false); + if (v.is_boolean()) { + ftl::config::update(uri, !v.get<bool>()); + } + } else if (op == "+=") { + auto v = ftl::config::resolve(uri, false); + if (v.is_number_float()) { + ftl::config::update(uri, v.get<float>() + (*s).value("value",0.0f)); + } + } + } + } } return false; } diff --git a/applications/gui/src/screen.hpp b/applications/gui/src/screen.hpp index a195f4ccdd45500c534039709ba6762fdd640b22..1a9ea2aa396958c328dc4ae9e309bd6346422fac 100644 --- a/applications/gui/src/screen.hpp +++ b/applications/gui/src/screen.hpp @@ -102,6 +102,8 @@ class Screen : public nanogui::Screen { bool show_two_images_ = false; + ftl::Configurable *shortcuts_; + #ifdef HAVE_OPENVR bool has_vr_; vr::IVRSystem *HMD_;