Skip to content
Snippets Groups Projects
Commit f2fd9723 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Initial shortcuts code

parent 4c894248
No related branches found
No related tags found
1 merge request!181Implements #240 custom shortcuts
Pipeline #16430 passed
...@@ -86,6 +86,8 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl ...@@ -86,6 +86,8 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
pos_y_ = root_->value("position_y", 0.0f); pos_y_ = root_->value("position_y", 0.0f);
}); });
shortcuts_ = ftl::create<ftl::Configurable>(root_, "shortcuts");
setSize(Vector2i(1280,720)); setSize(Vector2i(1280,720));
toolbuttheme = new Theme(*theme()); toolbuttheme = new Theme(*theme());
...@@ -431,12 +433,31 @@ bool ftl::gui::Screen::mouseButtonEvent(const nanogui::Vector2i &p, int button, ...@@ -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) { bool ftl::gui::Screen::keyboardEvent(int key, int scancode, int action, int modifiers) {
using namespace Eigen; using namespace Eigen;
if (nanogui::Screen::keyboardEvent(key, scancode, action, modifiers)) { if (nanogui::Screen::keyboardEvent(key, scancode, action, modifiers)) {
return true; return true;
} else { } else {
LOG(INFO) << "Key press " << key << " - " << action << " - " << modifiers; //LOG(INFO) << "Key press " << key << " - " << action << " - " << modifiers;
if (key >= 262 && key <= 267) { if (key >= 262 && key <= 267) {
if (camera_) camera_->keyMovement(key, modifiers); if (camera_) camera_->keyMovement(key, modifiers);
...@@ -444,9 +465,31 @@ bool ftl::gui::Screen::keyboardEvent(int key, int scancode, int action, int modi ...@@ -444,9 +465,31 @@ bool ftl::gui::Screen::keyboardEvent(int key, int scancode, int action, int modi
} else if (action == 1 && key == 'H') { } else if (action == 1 && key == 'H') {
swindow_->setVisible(false); swindow_->setVisible(false);
cwindow_->setVisible(false); cwindow_->setVisible(false);
} else if (action == 1 && key == 32) { } else if (action == 1) {
ctrl_->pause(); std::string combo = generateKeyComboStr(key, modifiers);
return true;
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; return false;
} }
......
...@@ -102,6 +102,8 @@ class Screen : public nanogui::Screen { ...@@ -102,6 +102,8 @@ class Screen : public nanogui::Screen {
bool show_two_images_ = false; bool show_two_images_ = false;
ftl::Configurable *shortcuts_;
#ifdef HAVE_OPENVR #ifdef HAVE_OPENVR
bool has_vr_; bool has_vr_;
vr::IVRSystem *HMD_; vr::IVRSystem *HMD_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment