From 8cf8e402b1f6d7392995282f26e0472a04819286 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 8 Oct 2017 05:50:53 -0400 Subject: [PATCH 1/2] Define VERSION_*, so running `make VERSION=0.4.0` for example defines the macro VERSION_0_4_0 --- compile.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compile.mk b/compile.mk index 9624f6ad..edfcee9a 100644 --- a/compile.mk +++ b/compile.mk @@ -1,5 +1,5 @@ VERSION ?= dev -FLAGS += -DVERSION=$(VERSION) +FLAGS += -DVERSION=$(VERSION) -DVERSION_$(subst .,_,$(VERSION)) # Generate dependency files alongside the object files FLAGS += -MMD From 2cbe7c39a79beeca081f23c560d1e4dc0d1ea706 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 8 Oct 2017 08:39:18 -0400 Subject: [PATCH 2/2] Set gFocusedWidget only if Widget::onFocus() returns true, make ModuleWidget respond to Backspace/Delete only if no widget is focused --- include/widgets.hpp | 4 ++-- src/app/ModuleWidget.cpp | 18 ++++++++++-------- src/gui.cpp | 8 ++++++-- src/widgets/TextField.cpp | 3 ++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/widgets.hpp b/include/widgets.hpp index 1487f2d2..5f8f3a94 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -112,7 +112,7 @@ struct Widget { virtual void onMouseEnter() {} /** Called when another widget begins responding to `onMouseMove` events */ virtual void onMouseLeave() {} - virtual void onFocus() {} + virtual bool onFocus() {return false;} virtual void onDefocus() {} virtual bool onFocusText(int codepoint) {return false;} virtual bool onFocusKey(int key) {return false;} @@ -409,7 +409,7 @@ struct TextField : OpaqueWidget { Widget *onMouseDown(Vec pos, int button); bool onFocusText(int codepoint); bool onFocusKey(int scancode); - void onFocus(); + bool onFocus(); void insertText(std::string newText); }; diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index ca486bf9..daa944f5 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -152,14 +152,16 @@ void ModuleWidget::draw(NVGcontext *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; + if (!gFocusedWidget) { + // 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); diff --git a/src/gui.cpp b/src/gui.cpp index 4c3b2b83..8487002c 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -59,12 +59,16 @@ void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) { if (w != gFocusedWidget) { if (gFocusedWidget) { + // onDefocus w->onDefocus(); } + gFocusedWidget = NULL; if (w) { - w->onFocus(); + // onFocus + if (w->onFocus()) { + gFocusedWidget = w; + } } - gFocusedWidget = w; } } } diff --git a/src/widgets/TextField.cpp b/src/widgets/TextField.cpp index c223b657..e1d3585c 100644 --- a/src/widgets/TextField.cpp +++ b/src/widgets/TextField.cpp @@ -103,9 +103,10 @@ bool TextField::onFocusKey(int key) { return true; } -void TextField::onFocus() { +bool TextField::onFocus() { begin = 0; end = text.size(); + return true; } void TextField::insertText(std::string newText) {