Browse Source

Remove useless `e.consume(this)` from events that no longer need it. Fix bugs introduced by change of event system behavior.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
faa96068af
24 changed files with 64 additions and 103 deletions
  1. +8
    -8
      include/event.hpp
  2. +0
    -1
      include/ui/MenuItem.hpp
  3. +0
    -1
      include/ui/RadioButton.hpp
  4. +0
    -3
      include/ui/TextField.hpp
  5. +0
    -1
      src/Core/Blank.cpp
  6. +0
    -1
      src/Core/MIDI_Map.cpp
  7. +0
    -1
      src/app/Knob.cpp
  8. +0
    -1
      src/app/ModuleBrowser.cpp
  9. +8
    -11
      src/app/ModuleWidget.cpp
  10. +0
    -1
      src/app/ParamWidget.cpp
  11. +1
    -4
      src/app/PortWidget.cpp
  12. +17
    -19
      src/app/RackScrollWidget.cpp
  13. +1
    -1
      src/app/RackWidget.cpp
  14. +2
    -0
      src/app/Scene.cpp
  15. +0
    -1
      src/app/SvgButton.cpp
  16. +0
    -1
      src/app/Switch.cpp
  17. +24
    -12
      src/event.cpp
  18. +0
    -2
      src/ui/Button.cpp
  19. +0
    -8
      src/ui/MenuItem.cpp
  20. +0
    -8
      src/ui/RadioButton.cpp
  21. +0
    -1
      src/ui/ScrollBar.cpp
  22. +0
    -1
      src/ui/Slider.cpp
  23. +0
    -14
      src/ui/TextField.cpp
  24. +3
    -2
      src/window.cpp

+ 8
- 8
include/event.hpp View File

@@ -346,14 +346,14 @@ struct State {
/** Prepares a widget for deletion */
void finalizeWidget(widget::Widget *w);

void handleButton(math::Vec pos, int button, int action, int mods);
void handleHover(math::Vec pos, math::Vec mouseDelta);
void handleLeave();
void handleScroll(math::Vec pos, math::Vec scrollDelta);
void handleText(math::Vec pos, int codepoint);
void handleKey(math::Vec pos, int key, int scancode, int action, int mods);
void handleDrop(math::Vec pos, const std::vector<std::string> &paths);
void handleZoom();
bool handleButton(math::Vec pos, int button, int action, int mods);
bool handleHover(math::Vec pos, math::Vec mouseDelta);
bool handleLeave();
bool handleScroll(math::Vec pos, math::Vec scrollDelta);
bool handleText(math::Vec pos, int codepoint);
bool handleKey(math::Vec pos, int key, int scancode, int action, int mods);
bool handleDrop(math::Vec pos, const std::vector<std::string> &paths);
bool handleZoom();
};




+ 0
- 1
include/ui/MenuItem.hpp View File

@@ -17,7 +17,6 @@ struct MenuItem : MenuEntry {
void draw(const DrawArgs &args) override;
void step() override;
void onEnter(const event::Enter &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragDrop(const event::DragDrop &e) override;
void doAction();
virtual Menu *createChildMenu() {return NULL;}


+ 0
- 1
include/ui/RadioButton.hpp View File

@@ -17,7 +17,6 @@ struct RadioButton : widget::OpaqueWidget {
void draw(const DrawArgs &args) override;
void onEnter(const event::Enter &e) override;
void onLeave(const event::Leave &e) override;
void onDragStart(const event::DragStart &e) override;
void onDragDrop(const event::DragDrop &e) override;
};



+ 0
- 3
include/ui/TextField.hpp View File

@@ -23,9 +23,6 @@ struct TextField : widget::OpaqueWidget {
void draw(const DrawArgs &args) override;
void onHover(const event::Hover &e) override;
void onButton(const event::Button &e) override;
void onDragStart(const event::DragStart &e) override;
void onEnter(const event::Enter &e) override;
void onSelect(const event::Select &e) override;
void onSelectText(const event::SelectText &e) override;
void onSelectKey(const event::SelectKey &e) override;



+ 0
- 1
src/Core/Blank.cpp View File

@@ -44,7 +44,6 @@ struct ModuleResizeHandle : OpaqueWidget {
ModuleWidget *mw = getAncestorOfType<ModuleWidget>();
assert(mw);
originalBox = mw->box;
e.consume(this);
}

void onDragMove(const event::DragMove &e) override {


+ 0
- 1
src/Core/MIDI_Map.cpp View File

@@ -271,7 +271,6 @@ struct MIDI_MapChoice : LedDisplayChoice {
// Reset touchedParam
APP->scene->rack->touchedParam = NULL;
module->enableLearn(id);
e.consume(this);
}

void onDeselect(const event::Deselect &e) override {


+ 0
- 1
src/app/Knob.cpp View File

@@ -40,7 +40,6 @@ void Knob::onDragStart(const event::DragStart &e) {
}

APP->window->cursorLock();
e.consume(this);
}

void Knob::onDragEnd(const event::DragEnd &e) {


+ 0
- 1
src/app/ModuleBrowser.cpp View File

@@ -255,7 +255,6 @@ struct ModelBox : widget::OpaqueWidget {
void onButton(const event::Button &e) override;

void onEnter(const event::Enter &e) override {
e.consume(this);
infoBox->show();
}



+ 8
- 11
src/app/ModuleWidget.cpp View File

@@ -305,15 +305,13 @@ void ModuleWidget::drawShadow(const DrawArgs &args) {
}

void ModuleWidget::onHover(const event::Hover &e) {
if (!APP->event->selectedWidget) {
// 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(APP->window->win, GLFW_KEY_DELETE) == GLFW_PRESS
|| glfwGetKey(APP->window->win, GLFW_KEY_BACKSPACE) == GLFW_PRESS)
&& (APP->window->getMods() & WINDOW_MOD_MASK) == 0) {
removeAction();
e.consume(NULL);
return;
}
// 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(APP->window->win, GLFW_KEY_DELETE) == GLFW_PRESS
|| glfwGetKey(APP->window->win, GLFW_KEY_BACKSPACE) == GLFW_PRESS)
&& (APP->window->getMods() & WINDOW_MOD_MASK) == 0) {
removeAction();
e.consume(NULL);
return;
}

OpaqueWidget::onHover(e);
@@ -326,7 +324,7 @@ void ModuleWidget::onButton(const event::Button &e) {

if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
createContextMenu();
e.consume(this);
e.consume(NULL);
}
}

@@ -389,7 +387,6 @@ void ModuleWidget::onDragStart(const event::DragStart &e) {

oldPos = box.pos;
dragPos = APP->scene->rack->mousePos.minus(box.pos);
e.consume(this);
}

void ModuleWidget::onDragEnd(const event::DragEnd &e) {


+ 0
- 1
src/app/ParamWidget.cpp View File

@@ -167,7 +167,6 @@ void ParamWidget::onEnter(const event::Enter &e) {
paramTooltip->paramWidget = this;
APP->scene->addChild(paramTooltip);
tooltip = paramTooltip;
e.consume(this);
}
}



+ 1
- 4
src/app/PortWidget.cpp View File

@@ -74,13 +74,12 @@ void PortWidget::onButton(const event::Button &e) {
delete cw;
}

e.consume(this);
e.consume(NULL);
}
}

void PortWidget::onEnter(const event::Enter &e) {
hovered = true;
e.consume(this);
}

void PortWidget::onLeave(const event::Leave &e) {
@@ -133,7 +132,6 @@ void PortWidget::onDragStart(const event::DragStart &e) {
}

APP->scene->rack->setIncompleteCable(cw);
e.consume(this);
}

void PortWidget::onDragEnd(const event::DragEnd &e) {
@@ -182,7 +180,6 @@ void PortWidget::onDragEnter(const event::DragEnter &e) {
else
cw->hoveredInputPort = this;
}
e.consume(this);
}

void PortWidget::onDragLeave(const event::DragLeave &e) {


+ 17
- 19
src/app/RackScrollWidget.cpp View File

@@ -75,25 +75,23 @@ void RackScrollWidget::draw(const DrawArgs &args) {
}

void RackScrollWidget::onHover(const event::Hover &e) {
if (!APP->event->selectedWidget) {
// Scroll with arrow keys
float arrowSpeed = 30.0;
if ((APP->window->getMods() & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL |GLFW_MOD_SHIFT))
arrowSpeed /= 16.0;
else if ((APP->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL)
arrowSpeed *= 4.0;
else if ((APP->window->getMods() & WINDOW_MOD_MASK) == GLFW_MOD_SHIFT)
arrowSpeed /= 4.0;

if (glfwGetKey(APP->window->win, GLFW_KEY_LEFT) == GLFW_PRESS)
offset.x -= arrowSpeed;
if (glfwGetKey(APP->window->win, GLFW_KEY_RIGHT) == GLFW_PRESS)
offset.x += arrowSpeed;
if (glfwGetKey(APP->window->win, GLFW_KEY_UP) == GLFW_PRESS)
offset.y -= arrowSpeed;
if (glfwGetKey(APP->window->win, GLFW_KEY_DOWN) == GLFW_PRESS)
offset.y += arrowSpeed;
}
// Scroll with arrow keys
float arrowSpeed = 30.0;
if ((APP->window->getMods() & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL |GLFW_MOD_SHIFT))
arrowSpeed /= 16.0;
else if ((APP->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL)
arrowSpeed *= 4.0;
else if ((APP->window->getMods() & WINDOW_MOD_MASK) == GLFW_MOD_SHIFT)
arrowSpeed /= 4.0;

if (glfwGetKey(APP->window->win, GLFW_KEY_LEFT) == GLFW_PRESS)
offset.x -= arrowSpeed;
if (glfwGetKey(APP->window->win, GLFW_KEY_RIGHT) == GLFW_PRESS)
offset.x += arrowSpeed;
if (glfwGetKey(APP->window->win, GLFW_KEY_UP) == GLFW_PRESS)
offset.y -= arrowSpeed;
if (glfwGetKey(APP->window->win, GLFW_KEY_DOWN) == GLFW_PRESS)
offset.y += arrowSpeed;

ScrollWidget::onHover(e);
}


+ 1
- 1
src/app/RackWidget.cpp View File

@@ -133,8 +133,8 @@ void RackWidget::onHoverKey(const event::HoverKey &e) {
case GLFW_KEY_V: {
if ((e.mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) {
pastePresetClipboardAction();
e.consume(this);
}
e.consume(this);
} break;
}
}


+ 2
- 0
src/app/Scene.cpp View File

@@ -127,6 +127,7 @@ void Scene::onHoverKey(const event::HoverKey &e) {
z = std::ceil(z - 0.01) - 1;
z /= 2;
settings::zoom = std::pow(2, z);
e.consume(this);
}
} break;
case GLFW_KEY_EQUAL: {
@@ -136,6 +137,7 @@ void Scene::onHoverKey(const event::HoverKey &e) {
z = std::floor(z + 0.01) + 1;
z /= 2;
settings::zoom = std::pow(2, z);
e.consume(this);
}
} break;
case GLFW_KEY_ENTER:


+ 0
- 1
src/app/SvgButton.cpp View File

@@ -38,7 +38,6 @@ void SvgButton::onDragStart(const event::DragStart &e) {
sw->setSvg(frames[1]);
fb->dirty = true;
}
e.consume(this);
}

void SvgButton::onDragEnd(const event::DragEnd &e) {


+ 0
- 1
src/app/Switch.cpp View File

@@ -64,7 +64,6 @@ void Switch::onDragStart(const event::DragStart &e) {
}
}
}
e.consume(this);
}

void Switch::onDragEnd(const event::DragEnd &e) {


+ 24
- 12
src/event.cpp View File

@@ -110,7 +110,7 @@ void State::finalizeWidget(widget::Widget *w) {
if (lastClickedWidget == w) lastClickedWidget = NULL;
}

void State::handleButton(math::Vec pos, int button, int action, int mods) {
bool State::handleButton(math::Vec pos, int button, int action, int mods) {
// Button
Context cButton;
Button eButton;
@@ -164,9 +164,11 @@ void State::handleButton(math::Vec pos, int button, int action, int mods) {
}
}
}

return !!clickedWidget;
}

void State::handleHover(math::Vec pos, math::Vec mouseDelta) {
bool State::handleHover(math::Vec pos, math::Vec mouseDelta) {
if (draggedWidget) {
// DragMove
DragMove eDragMove;
@@ -185,8 +187,8 @@ void State::handleHover(math::Vec pos, math::Vec mouseDelta) {
rootWidget->onDragHover(eDragHover);

setDragHovered(cDragHover.target);
return;
if (cDragHover.target)
return true;
}

// Hover
@@ -198,14 +200,16 @@ void State::handleHover(math::Vec pos, math::Vec mouseDelta) {
rootWidget->onHover(eHover);

setHovered(cHover.target);
return !!cHover.target;
}

void State::handleLeave() {
bool State::handleLeave() {
setDragHovered(NULL);
setHovered(NULL);
return true;
}

void State::handleScroll(math::Vec pos, math::Vec scrollDelta) {
bool State::handleScroll(math::Vec pos, math::Vec scrollDelta) {
// HoverScroll
Context cHoverScroll;
HoverScroll eHoverScroll;
@@ -213,18 +217,22 @@ void State::handleScroll(math::Vec pos, math::Vec scrollDelta) {
eHoverScroll.pos = pos;
eHoverScroll.scrollDelta = scrollDelta;
rootWidget->onHoverScroll(eHoverScroll);

return !!cHoverScroll.target;
}

void State::handleDrop(math::Vec pos, const std::vector<std::string> &paths) {
bool State::handleDrop(math::Vec pos, const std::vector<std::string> &paths) {
// PathDrop
Context cPathDrop;
PathDrop ePathDrop(paths);
ePathDrop.context = &cPathDrop;
ePathDrop.pos = pos;
rootWidget->onPathDrop(ePathDrop);

return !!cPathDrop.target;
}

void State::handleText(math::Vec pos, int codepoint) {
bool State::handleText(math::Vec pos, int codepoint) {
if (selectedWidget) {
// SelectText
Context cSelectText;
@@ -233,7 +241,7 @@ void State::handleText(math::Vec pos, int codepoint) {
eSelectText.codepoint = codepoint;
selectedWidget->onSelectText(eSelectText);
if (cSelectText.target)
return;
return true;
}

// HoverText
@@ -243,9 +251,11 @@ void State::handleText(math::Vec pos, int codepoint) {
eHoverText.pos = pos;
eHoverText.codepoint = codepoint;
rootWidget->onHoverText(eHoverText);

return !!cHoverText.target;
}

void State::handleKey(math::Vec pos, int key, int scancode, int action, int mods) {
bool State::handleKey(math::Vec pos, int key, int scancode, int action, int mods) {
if (selectedWidget) {
// SelectKey
Context cSelectKey;
@@ -257,7 +267,7 @@ void State::handleKey(math::Vec pos, int key, int scancode, int action, int mods
eSelectKey.mods = mods;
selectedWidget->onSelectKey(eSelectKey);
if (cSelectKey.target)
return;
return true;
}

// HoverKey
@@ -270,14 +280,16 @@ void State::handleKey(math::Vec pos, int key, int scancode, int action, int mods
eHoverKey.action = action;
eHoverKey.mods = mods;
rootWidget->onHoverKey(eHoverKey);
return !!cHoverKey.target;
}

void State::handleZoom() {
bool State::handleZoom() {
// Zoom
Context cZoom;
Zoom eZoom;
eZoom.context = &cZoom;
rootWidget->onZoom(eZoom);
return true;
}




+ 0
- 2
src/ui/Button.cpp View File

@@ -15,7 +15,6 @@ void Button::draw(const DrawArgs &args) {

void Button::onEnter(const event::Enter &e) {
state = BND_HOVER;
e.consume(this);
}

void Button::onLeave(const event::Leave &e) {
@@ -29,7 +28,6 @@ void Button::onDragStart(const event::DragStart &e) {
state = BND_ACTIVE;
if (quantity)
quantity->setMax();
e.consume(this);
}

void Button::onDragEnd(const event::DragEnd &e) {


+ 0
- 8
src/ui/MenuItem.cpp View File

@@ -42,7 +42,6 @@ void MenuItem::step() {
}

void MenuItem::onEnter(const event::Enter &e) {
e.consume(this);
Menu *parentMenu = dynamic_cast<Menu*>(parent);
if (!parentMenu)
return;
@@ -58,13 +57,6 @@ void MenuItem::onEnter(const event::Enter &e) {
parentMenu->setChildMenu(childMenu);
}

void MenuItem::onDragStart(const event::DragStart &e) {
if (e.button != GLFW_MOUSE_BUTTON_LEFT)
return;

e.consume(this);
}

void MenuItem::onDragDrop(const event::DragDrop &e) {
if (e.origin != this)
return;


+ 0
- 8
src/ui/RadioButton.cpp View File

@@ -22,20 +22,12 @@ void RadioButton::draw(const DrawArgs &args) {

void RadioButton::onEnter(const event::Enter &e) {
state = BND_HOVER;
e.consume(this);
}

void RadioButton::onLeave(const event::Leave &e) {
state = BND_DEFAULT;
}

void RadioButton::onDragStart(const event::DragStart &e) {
if (e.button != GLFW_MOUSE_BUTTON_LEFT)
return;

e.consume(this);
}

void RadioButton::onDragDrop(const event::DragDrop &e) {
if (e.origin == this) {
if (quantity) {


+ 0
- 1
src/ui/ScrollBar.cpp View File

@@ -22,7 +22,6 @@ void ScrollBar::onDragStart(const event::DragStart &e) {

state = BND_ACTIVE;
APP->window->cursorLock();
e.consume(this);
}

void ScrollBar::onDragMove(const event::DragMove &e) {


+ 0
- 1
src/ui/Slider.cpp View File

@@ -24,7 +24,6 @@ void Slider::onDragStart(const event::DragStart &e) {

state = BND_ACTIVE;
APP->window->cursorLock();
e.consume(this);
}

void Slider::onDragMove(const event::DragMove &e) {


+ 0
- 14
src/ui/TextField.cpp View File

@@ -34,7 +34,6 @@ void TextField::onHover(const event::Hover &e) {
OpaqueWidget::onHover(e);

if (this == APP->event->draggedWidget) {
DEBUG("asdf");
int pos = getTextPosition(e.pos);
if (pos != selection) {
cursor = pos;
@@ -50,19 +49,6 @@ void TextField::onButton(const event::Button &e) {
}
}

void TextField::onDragStart(const event::DragStart &e) {
// Enable dragging so onHover can set the cursor position.
e.consume(this);
}

void TextField::onEnter(const event::Enter &e) {
e.consume(this);
}

void TextField::onSelect(const event::Select &e) {
e.consume(this);
}

void TextField::onSelectText(const event::SelectText &e) {
if (e.codepoint < 128) {
std::string newText(1, (char) e.codepoint);


+ 3
- 2
src/window.cpp View File

@@ -155,10 +155,11 @@ static void charCallback(GLFWwindow *win, unsigned int codepoint) {

static void keyCallback(GLFWwindow *win, int key, int scancode, int action, int mods) {
Window *window = (Window*) glfwGetWindowUserPointer(win);
APP->event->handleKey(window->mousePos, key, scancode, action, mods);
if (APP->event->handleKey(window->mousePos, key, scancode, action, mods))
return;

// Keyboard MIDI driver
if (!APP->event->selectedWidget && (mods & WINDOW_MOD_MASK) == 0) {
if ((mods & WINDOW_MOD_MASK) == 0) {
if (action == GLFW_PRESS) {
keyboard::press(key);
}


Loading…
Cancel
Save