@@ -285,7 +285,7 @@ struct ModelBox : widget::OpaqueWidget { | |||||
void onHoverKey(const HoverKeyEvent& e) override { | void onHoverKey(const HoverKeyEvent& e) override { | ||||
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | ||||
if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_F1, RACK_MOD_CTRL)) { | |||||
system::openBrowser(model->getManualUrl()); | system::openBrowser(model->getManualUrl()); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
@@ -799,7 +799,7 @@ struct Browser : widget::OpaqueWidget { | |||||
void onHoverKey(const HoverKeyEvent& e) override { | void onHoverKey(const HoverKeyEvent& e) override { | ||||
if (e.action == GLFW_PRESS) { | if (e.action == GLFW_PRESS) { | ||||
// Secret key command to dump all visible modules into rack | // Secret key command to dump all visible modules into rack | ||||
if (e.key == GLFW_KEY_F2 && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT | GLFW_MOD_ALT)) { | |||||
if (e.isKeyCommand(GLFW_KEY_F2, RACK_MOD_CTRL | GLFW_MOD_SHIFT | GLFW_MOD_ALT)) { | |||||
int count = 0; | int count = 0; | ||||
for (widget::Widget* w : modelContainer->children) { | for (widget::Widget* w : modelContainer->children) { | ||||
ModelBox* mb = dynamic_cast<ModelBox*>(w); | ModelBox* mb = dynamic_cast<ModelBox*>(w); | ||||
@@ -841,7 +841,7 @@ inline void ClearButton::onAction(const ActionEvent& e) { | |||||
inline void BrowserSearchField::onSelectKey(const SelectKeyEvent& e) { | inline void BrowserSearchField::onSelectKey(const SelectKeyEvent& e) { | ||||
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | ||||
// Backspace when the field is empty to clear filters. | // Backspace when the field is empty to clear filters. | ||||
if (e.key == GLFW_KEY_BACKSPACE) { | |||||
if (e.isKeyCommand(GLFW_KEY_BACKSPACE) || e.isKeyCommand(GLFW_KEY_BACKSPACE, RACK_MOD_CTRL)) { | |||||
if (text == "") { | if (text == "") { | ||||
browser->clear(); | browser->clear(); | ||||
e.consume(this); | e.consume(this); | ||||
@@ -315,52 +315,52 @@ void ModuleWidget::onHover(const HoverEvent& e) { | |||||
void ModuleWidget::onHoverKey(const HoverKeyEvent& e) { | void ModuleWidget::onHoverKey(const HoverKeyEvent& e) { | ||||
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | ||||
if (e.key == GLFW_KEY_C && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_C, RACK_MOD_CTRL)) { | |||||
copyClipboard(); | copyClipboard(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_V && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_V, RACK_MOD_CTRL)) { | |||||
if (pasteClipboardAction()) { | if (pasteClipboardAction()) { | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if (e.key == GLFW_KEY_D && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_D, RACK_MOD_CTRL)) { | |||||
cloneAction(false); | cloneAction(false); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_D && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
if (e.isKeyCommand(GLFW_KEY_D, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
cloneAction(true); | cloneAction(true); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_I && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_I, RACK_MOD_CTRL)) { | |||||
resetAction(); | resetAction(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_R && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_R, RACK_MOD_CTRL)) { | |||||
randomizeAction(); | randomizeAction(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_U && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_U, RACK_MOD_CTRL)) { | |||||
disconnectAction(); | disconnectAction(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_E && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_E, RACK_MOD_CTRL)) { | |||||
bypassAction(!module->isBypassed()); | bypassAction(!module->isBypassed()); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if ((e.key == GLFW_KEY_DELETE || e.key == GLFW_KEY_BACKSPACE) && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_DELETE) || e.isKeyCommand(GLFW_KEY_BACKSPACE)) { | |||||
// Deletes `this` | // Deletes `this` | ||||
removeAction(); | removeAction(); | ||||
e.consume(NULL); | e.consume(NULL); | ||||
return; | return; | ||||
} | } | ||||
if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_F1, RACK_MOD_CTRL)) { | |||||
std::string manualUrl = model->getManualUrl(); | std::string manualUrl = model->getManualUrl(); | ||||
if (!manualUrl.empty()) | if (!manualUrl.empty()) | ||||
system::openBrowser(manualUrl); | system::openBrowser(manualUrl); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_F4 && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_F4, RACK_MOD_CTRL)) { | |||||
APP->scene->rackScroll->zoomToBound(getBox()); | APP->scene->rackScroll->zoomToBound(getBox()); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
@@ -33,7 +33,7 @@ struct ParamField : ui::TextField { | |||||
} | } | ||||
void onSelectKey(const SelectKeyEvent& e) override { | void onSelectKey(const SelectKeyEvent& e) override { | ||||
if (e.action == GLFW_PRESS && (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER)) { | |||||
if (e.action == GLFW_PRESS && (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER))) { | |||||
engine::ParamQuantity* pq = paramWidget->getParamQuantity(); | engine::ParamQuantity* pq = paramWidget->getParamQuantity(); | ||||
assert(pq); | assert(pq); | ||||
float oldValue = pq->getValue(); | float oldValue = pq->getValue(); | ||||
@@ -170,40 +170,40 @@ void Scene::onDragHover(const DragHoverEvent& e) { | |||||
void Scene::onHoverKey(const HoverKeyEvent& e) { | void Scene::onHoverKey(const HoverKeyEvent& e) { | ||||
// Key commands that override children | // Key commands that override children | ||||
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | ||||
// DEBUG("key '%d '%c' scancode %d '%c' keyName '%s'", e.key, e.key, e.scancode, e.scancode, e.keyName.c_str()); | |||||
if (e.key == GLFW_KEY_N && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
// DEBUG("key %d '%c' scancode %d keyName '%s'", e.key, e.key, e.scancode, e.keyName.c_str()); | |||||
if (e.isKeyCommand(GLFW_KEY_N, RACK_MOD_CTRL)) { | |||||
APP->patch->loadTemplateDialog(); | APP->patch->loadTemplateDialog(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_Q && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_Q, RACK_MOD_CTRL)) { | |||||
APP->window->close(); | APP->window->close(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_O && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_O, RACK_MOD_CTRL)) { | |||||
APP->patch->loadDialog(); | APP->patch->loadDialog(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_O && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
if (e.isKeyCommand(GLFW_KEY_O, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
APP->patch->revertDialog(); | APP->patch->revertDialog(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_S && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_S, RACK_MOD_CTRL)) { | |||||
APP->patch->saveDialog(); | APP->patch->saveDialog(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_S && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
if (e.isKeyCommand(GLFW_KEY_S, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
APP->patch->saveAsDialog(); | APP->patch->saveAsDialog(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_Z && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_Z, RACK_MOD_CTRL)) { | |||||
APP->history->undo(); | APP->history->undo(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_Z && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
if (e.isKeyCommand(GLFW_KEY_Z, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
APP->history->redo(); | APP->history->redo(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if ((e.key == GLFW_KEY_MINUS || e.key == GLFW_KEY_KP_SUBTRACT) && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_MINUS, RACK_MOD_CTRL) || e.isKeyCommand(GLFW_KEY_KP_SUBTRACT, RACK_MOD_CTRL)) { | |||||
float zoom = std::log2(APP->scene->rackScroll->getZoom()); | float zoom = std::log2(APP->scene->rackScroll->getZoom()); | ||||
zoom *= 2; | zoom *= 2; | ||||
zoom = std::ceil(zoom - 0.01f) - 1; | zoom = std::ceil(zoom - 0.01f) - 1; | ||||
@@ -212,7 +212,7 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Numpad has a "+" key, but the main keyboard section hides it under "=" | // Numpad has a "+" key, but the main keyboard section hides it under "=" | ||||
if ((e.key == GLFW_KEY_EQUAL || e.key == GLFW_KEY_KP_ADD) && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_EQUAL, RACK_MOD_CTRL) || e.isKeyCommand(GLFW_KEY_KP_ADD, RACK_MOD_CTRL)) { | |||||
float zoom = std::log2(APP->scene->rackScroll->getZoom()); | float zoom = std::log2(APP->scene->rackScroll->getZoom()); | ||||
zoom *= 2; | zoom *= 2; | ||||
zoom = std::floor(zoom + 0.01f) + 1; | zoom = std::floor(zoom + 0.01f) + 1; | ||||
@@ -220,23 +220,23 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { | |||||
APP->scene->rackScroll->setZoom(std::pow(2.f, zoom)); | APP->scene->rackScroll->setZoom(std::pow(2.f, zoom)); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if ((e.key == GLFW_KEY_0 || e.key == GLFW_KEY_KP_0) && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_0, RACK_MOD_CTRL) || e.isKeyCommand(GLFW_KEY_KP_0, RACK_MOD_CTRL)) { | |||||
APP->scene->rackScroll->setZoom(1.f); | APP->scene->rackScroll->setZoom(1.f); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_F1)) { | |||||
system::openBrowser("https://vcvrack.com/manual/"); | system::openBrowser("https://vcvrack.com/manual/"); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_F3 && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_F3)) { | |||||
settings::cpuMeter ^= true; | settings::cpuMeter ^= true; | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_F4 && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_F4)) { | |||||
APP->scene->rackScroll->zoomToModules(); | APP->scene->rackScroll->zoomToModules(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_F11 && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_F11)) { | |||||
APP->window->setFullScreen(!APP->window->isFullScreen()); | APP->window->setFullScreen(!APP->window->isFullScreen()); | ||||
// The MenuBar will be hidden when the mouse moves over the RackScrollWidget. | // The MenuBar will be hidden when the mouse moves over the RackScrollWidget. | ||||
// menuBar->hide(); | // menuBar->hide(); | ||||
@@ -244,57 +244,57 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { | |||||
} | } | ||||
// Module selections | // Module selections | ||||
if (e.key == GLFW_KEY_A && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_A, RACK_MOD_CTRL)) { | |||||
rack->selectAll(); | rack->selectAll(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_A && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
if (e.isKeyCommand(GLFW_KEY_A, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
rack->deselectAll(); | rack->deselectAll(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_C && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_C, RACK_MOD_CTRL)) { | |||||
if (rack->hasSelection()) { | if (rack->hasSelection()) { | ||||
rack->copyClipboardSelection(); | rack->copyClipboardSelection(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if (e.key == GLFW_KEY_I && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_I, RACK_MOD_CTRL)) { | |||||
if (rack->hasSelection()) { | if (rack->hasSelection()) { | ||||
rack->resetSelectionAction(); | rack->resetSelectionAction(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if (e.key == GLFW_KEY_R && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_R, RACK_MOD_CTRL)) { | |||||
if (rack->hasSelection()) { | if (rack->hasSelection()) { | ||||
rack->randomizeSelectionAction(); | rack->randomizeSelectionAction(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if (e.key == GLFW_KEY_U && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_U, RACK_MOD_CTRL)) { | |||||
if (rack->hasSelection()) { | if (rack->hasSelection()) { | ||||
rack->disconnectSelectionAction(); | rack->disconnectSelectionAction(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if (e.key == GLFW_KEY_E && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_E, RACK_MOD_CTRL)) { | |||||
if (rack->hasSelection()) { | if (rack->hasSelection()) { | ||||
rack->bypassSelectionAction(!rack->isSelectionBypassed()); | rack->bypassSelectionAction(!rack->isSelectionBypassed()); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if (e.key == GLFW_KEY_D && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_D, RACK_MOD_CTRL)) { | |||||
if (rack->hasSelection()) { | if (rack->hasSelection()) { | ||||
rack->cloneSelectionAction(false); | rack->cloneSelectionAction(false); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if (e.key == GLFW_KEY_D && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
if (e.isKeyCommand(GLFW_KEY_D, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
if (rack->hasSelection()) { | if (rack->hasSelection()) { | ||||
rack->cloneSelectionAction(true); | rack->cloneSelectionAction(true); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if ((e.key == GLFW_KEY_DELETE || e.key == GLFW_KEY_BACKSPACE) && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_DELETE) || e.isKeyCommand(GLFW_KEY_BACKSPACE)) { | |||||
if (rack->hasSelection()) { | if (rack->hasSelection()) { | ||||
rack->deleteSelectionAction(); | rack->deleteSelectionAction(); | ||||
e.consume(this); | e.consume(this); | ||||
@@ -331,17 +331,17 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { | |||||
// Key commands that can be overridden by children | // Key commands that can be overridden by children | ||||
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | ||||
// Alternative key command for exiting fullscreen, since F11 doesn't work reliably on Mac due to "Show desktop" OS binding. | // Alternative key command for exiting fullscreen, since F11 doesn't work reliably on Mac due to "Show desktop" OS binding. | ||||
if (e.key == GLFW_KEY_ESCAPE && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_ESCAPE, 0)) { | |||||
if (APP->window->isFullScreen()) { | if (APP->window->isFullScreen()) { | ||||
APP->window->setFullScreen(false); | APP->window->setFullScreen(false); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} | } | ||||
if (e.key == GLFW_KEY_V && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_V, RACK_MOD_CTRL)) { | |||||
rack->pasteClipboardAction(); | rack->pasteClipboardAction(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER)) { | |||||
browser->show(); | browser->show(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
@@ -133,7 +133,7 @@ struct CcChoice : LedDisplayChoice { | |||||
} | } | ||||
void onSelectKey(const SelectKeyEvent& e) override { | void onSelectKey(const SelectKeyEvent& e) override { | ||||
if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && e.action == GLFW_PRESS && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.action == GLFW_PRESS && (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER))) { | |||||
DeselectEvent eDeselect; | DeselectEvent eDeselect; | ||||
onDeselect(eDeselect); | onDeselect(eDeselect); | ||||
APP->event->selectedWidget = NULL; | APP->event->selectedWidget = NULL; | ||||
@@ -235,7 +235,7 @@ struct NoteChoice : LedDisplayChoice { | |||||
} | } | ||||
void onSelectKey(const SelectKeyEvent& e) override { | void onSelectKey(const SelectKeyEvent& e) override { | ||||
if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && e.action == GLFW_PRESS && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.action == GLFW_PRESS && (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER))) { | |||||
DeselectEvent eDeselect; | DeselectEvent eDeselect; | ||||
onDeselect(eDeselect); | onDeselect(eDeselect); | ||||
APP->event->selectedWidget = NULL; | APP->event->selectedWidget = NULL; | ||||
@@ -50,7 +50,7 @@ void MenuOverlay::onHoverKey(const HoverKeyEvent& e) { | |||||
if (e.isConsumed()) | if (e.isConsumed()) | ||||
return; | return; | ||||
if (e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) { | |||||
if (e.action == GLFW_PRESS && e.isKeyCommand(GLFW_KEY_ESCAPE)) { | |||||
ActionEvent eAction; | ActionEvent eAction; | ||||
onAction(eAction); | onAction(eAction); | ||||
} | } | ||||
@@ -178,38 +178,38 @@ void ScrollWidget::onHoverKey(const HoverKeyEvent& e) { | |||||
return; | return; | ||||
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | ||||
if (e.key == GLFW_KEY_PAGE_UP && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_PAGE_UP)) { | |||||
offset.y -= box.size.y * 0.5; | offset.y -= box.size.y * 0.5; | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_PAGE_UP && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | |||||
if (e.isKeyCommand(GLFW_KEY_PAGE_UP, GLFW_MOD_SHIFT)) { | |||||
offset.x -= box.size.x * 0.5; | offset.x -= box.size.x * 0.5; | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_PAGE_DOWN && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_PAGE_DOWN)) { | |||||
offset.y += box.size.y * 0.5; | offset.y += box.size.y * 0.5; | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_PAGE_DOWN && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | |||||
if (e.isKeyCommand(GLFW_KEY_PAGE_DOWN, GLFW_MOD_SHIFT)) { | |||||
offset.x += box.size.x * 0.5; | offset.x += box.size.x * 0.5; | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_HOME)) { | |||||
math::Rect containerBox = container->getVisibleChildrenBoundingBox(); | math::Rect containerBox = container->getVisibleChildrenBoundingBox(); | ||||
offset.y = containerBox.getTop(); | offset.y = containerBox.getTop(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | |||||
if (e.isKeyCommand(GLFW_KEY_HOME, GLFW_MOD_SHIFT)) { | |||||
math::Rect containerBox = container->getVisibleChildrenBoundingBox(); | math::Rect containerBox = container->getVisibleChildrenBoundingBox(); | ||||
offset.x = containerBox.getLeft(); | offset.x = containerBox.getLeft(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_END)) { | |||||
math::Rect containerBox = container->getVisibleChildrenBoundingBox(); | math::Rect containerBox = container->getVisibleChildrenBoundingBox(); | ||||
offset.y = containerBox.getBottom(); | offset.y = containerBox.getBottom(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | |||||
if (e.isKeyCommand(GLFW_KEY_END, GLFW_MOD_SHIFT)) { | |||||
math::Rect containerBox = container->getVisibleChildrenBoundingBox(); | math::Rect containerBox = container->getVisibleChildrenBoundingBox(); | ||||
offset.x = containerBox.getRight(); | offset.x = containerBox.getRight(); | ||||
e.consume(this); | e.consume(this); | ||||
@@ -120,7 +120,7 @@ void TextField::onSelectText(const SelectTextEvent& e) { | |||||
void TextField::onSelectKey(const SelectKeyEvent& e) { | void TextField::onSelectKey(const SelectKeyEvent& e) { | ||||
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { | ||||
// Backspace | // Backspace | ||||
if (e.key == GLFW_KEY_BACKSPACE && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_BACKSPACE)) { | |||||
if (cursor == selection) { | if (cursor == selection) { | ||||
cursor = std::max(cursor - 1, 0); | cursor = std::max(cursor - 1, 0); | ||||
} | } | ||||
@@ -128,7 +128,7 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Ctrl+Backspace | // Ctrl+Backspace | ||||
if (e.key == GLFW_KEY_BACKSPACE && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_BACKSPACE, RACK_MOD_CTRL)) { | |||||
if (cursor == selection) { | if (cursor == selection) { | ||||
cursorToPrevWord(); | cursorToPrevWord(); | ||||
} | } | ||||
@@ -136,7 +136,7 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Delete | // Delete | ||||
if (e.key == GLFW_KEY_DELETE && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_DELETE)) { | |||||
if (cursor == selection) { | if (cursor == selection) { | ||||
cursor = std::min(cursor + 1, (int) text.size()); | cursor = std::min(cursor + 1, (int) text.size()); | ||||
} | } | ||||
@@ -144,7 +144,7 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Ctrl+Delete | // Ctrl+Delete | ||||
if (e.key == GLFW_KEY_DELETE && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_DELETE, RACK_MOD_CTRL)) { | |||||
if (cursor == selection) { | if (cursor == selection) { | ||||
cursorToNextWord(); | cursorToNextWord(); | ||||
} | } | ||||
@@ -152,81 +152,93 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Left | // Left | ||||
if (e.key == GLFW_KEY_LEFT) { | |||||
if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
cursorToPrevWord(); | |||||
} | |||||
else { | |||||
cursor = std::max(cursor - 1, 0); | |||||
} | |||||
if (!(e.mods & GLFW_MOD_SHIFT)) { | |||||
selection = cursor; | |||||
} | |||||
if (e.isKeyCommand(GLFW_KEY_LEFT)) { | |||||
cursor = std::max(cursor - 1, 0); | |||||
selection = cursor; | |||||
e.consume(this); | |||||
} | |||||
if (e.isKeyCommand(GLFW_KEY_LEFT, RACK_MOD_CTRL)) { | |||||
cursorToPrevWord(); | |||||
selection = cursor; | |||||
e.consume(this); | |||||
} | |||||
if (e.isKeyCommand(GLFW_KEY_LEFT, GLFW_MOD_SHIFT)) { | |||||
cursor = std::max(cursor - 1, 0); | |||||
e.consume(this); | |||||
} | |||||
if (e.isKeyCommand(GLFW_KEY_LEFT, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
cursorToPrevWord(); | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Right | // Right | ||||
if (e.key == GLFW_KEY_RIGHT) { | |||||
if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
cursorToNextWord(); | |||||
} | |||||
else { | |||||
cursor = std::min(cursor + 1, (int) text.size()); | |||||
} | |||||
if (!(e.mods & GLFW_MOD_SHIFT)) { | |||||
selection = cursor; | |||||
} | |||||
if (e.isKeyCommand(GLFW_KEY_RIGHT)) { | |||||
cursor = std::min(cursor + 1, (int) text.size()); | |||||
selection = cursor; | |||||
e.consume(this); | |||||
} | |||||
if (e.isKeyCommand(GLFW_KEY_RIGHT, RACK_MOD_CTRL)) { | |||||
cursorToNextWord(); | |||||
selection = cursor; | |||||
e.consume(this); | |||||
} | |||||
if (e.isKeyCommand(GLFW_KEY_RIGHT, GLFW_MOD_SHIFT)) { | |||||
cursor = std::min(cursor + 1, (int) text.size()); | |||||
e.consume(this); | |||||
} | |||||
if (e.isKeyCommand(GLFW_KEY_RIGHT, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { | |||||
cursorToNextWord(); | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Up (placeholder) | // Up (placeholder) | ||||
if (e.key == GLFW_KEY_UP) { | |||||
if (e.isKeyCommand(GLFW_KEY_UP)) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Down (placeholder) | // Down (placeholder) | ||||
if (e.key == GLFW_KEY_DOWN) { | |||||
if (e.isKeyCommand(GLFW_KEY_DOWN)) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Home | // Home | ||||
if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_HOME)) { | |||||
selection = cursor = 0; | selection = cursor = 0; | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Shift+Home | // Shift+Home | ||||
if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | |||||
if (e.isKeyCommand(GLFW_KEY_HOME, GLFW_MOD_SHIFT)) { | |||||
cursor = 0; | cursor = 0; | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// End | // End | ||||
if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_END)) { | |||||
selection = cursor = text.size(); | selection = cursor = text.size(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Shift+End | // Shift+End | ||||
if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | |||||
if (e.isKeyCommand(GLFW_KEY_END, GLFW_MOD_SHIFT)) { | |||||
cursor = text.size(); | cursor = text.size(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Ctrl+V | // Ctrl+V | ||||
if (e.key == GLFW_KEY_V && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_V, RACK_MOD_CTRL)) { | |||||
pasteClipboard(); | pasteClipboard(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Ctrl+X | // Ctrl+X | ||||
if (e.key == GLFW_KEY_X && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_X, RACK_MOD_CTRL)) { | |||||
cutClipboard(); | cutClipboard(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Ctrl+C | // Ctrl+C | ||||
if (e.key == GLFW_KEY_C && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_C, RACK_MOD_CTRL)) { | |||||
copyClipboard(); | copyClipboard(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Ctrl+A | // Ctrl+A | ||||
if (e.key == GLFW_KEY_A && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { | |||||
if (e.isKeyCommand(GLFW_KEY_A, RACK_MOD_CTRL)) { | |||||
selectAll(); | selectAll(); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Enter | // Enter | ||||
if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER)) { | |||||
if (multiline) { | if (multiline) { | ||||
insertText("\n"); | insertText("\n"); | ||||
} | } | ||||
@@ -237,19 +249,19 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Tab | // Tab | ||||
if (e.key == GLFW_KEY_TAB && (e.mods & RACK_MOD_MASK) == 0) { | |||||
if (e.isKeyCommand(GLFW_KEY_TAB)) { | |||||
if (nextField) | if (nextField) | ||||
APP->event->setSelectedWidget(nextField); | APP->event->setSelectedWidget(nextField); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Shift+Tab | // Shift+Tab | ||||
if (e.key == GLFW_KEY_TAB && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | |||||
if (e.isKeyCommand(GLFW_KEY_TAB, GLFW_MOD_SHIFT)) { | |||||
if (prevField) | if (prevField) | ||||
APP->event->setSelectedWidget(prevField); | APP->event->setSelectedWidget(prevField); | ||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
// Consume all printable keys unless Ctrl is held | // Consume all printable keys unless Ctrl is held | ||||
if ((GLFW_KEY_SPACE <= e.key && e.key <= GLFW_KEY_GRAVE_ACCENT) && (e.mods & RACK_MOD_CTRL) == 0) { | |||||
if (GLFW_KEY_SPACE <= e.key && e.key < 128 && (e.mods & RACK_MOD_CTRL) == 0) { | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||