Browse Source

Move ModuleWidget delete/backspace key to onMouseMove so it doesn't

rely on key repeat
tags/v0.4.0
Andrew Belt 7 years ago
parent
commit
fc3cf452ff
2 changed files with 15 additions and 9 deletions
  1. +1
    -0
      include/app.hpp
  2. +14
    -9
      src/app/ModuleWidget.cpp

+ 1
- 0
include/app.hpp View File

@@ -58,6 +58,7 @@ struct ModuleWidget : OpaqueWidget {
bool requested = false;
Vec requestedPos;
Vec dragPos;
Widget *onMouseMove(Vec pos, Vec mouseRel);
Widget *onHoverKey(Vec pos, int key);
void onDragStart();
void onDragMove(Vec mouseRel);


+ 14
- 9
src/app/ModuleWidget.cpp View File

@@ -151,17 +151,22 @@ void ModuleWidget::draw(NVGcontext *vg) {
nvgResetScissor(vg);
}

Widget *ModuleWidget::onMouseMove(Vec pos, Vec mouseRel) {
// Instead of checking key-down events, delete the module even if key-repeat hasn't fired yet and the cursor is hovering over the widget.
if (glfwGetKey(gWindow, GLFW_KEY_DELETE) == GLFW_PRESS || glfwGetKey(gWindow, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
if (!guiIsModPressed() && !guiIsShiftPressed()) {
gRackWidget->deleteModule(this);
this->finalizeEvents();
delete this;
// Kinda sketchy because events will be passed further down the tree
return NULL;
}
}
return OpaqueWidget::onMouseMove(pos, mouseRel);
}

Widget *ModuleWidget::onHoverKey(Vec pos, int key) {
switch (key) {
case GLFW_KEY_DELETE:
case GLFW_KEY_BACKSPACE:
if (!guiIsModPressed() && !guiIsShiftPressed()) {
gRackWidget->deleteModule(this);
this->finalizeEvents();
delete this;
return NULL;
}
break;
case GLFW_KEY_I:
if (guiIsModPressed() && !guiIsShiftPressed())
initialize();


Loading…
Cancel
Save