Browse Source

Fix event and Wire bugs

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
04f53901b2
5 changed files with 34 additions and 27 deletions
  1. +1
    -0
      include/event.hpp
  2. +0
    -1
      src/app/ModuleWidget.cpp
  3. +26
    -22
      src/app/Port.cpp
  4. +4
    -4
      src/app/WireContainer.cpp
  5. +3
    -0
      src/event.cpp

+ 1
- 0
include/event.hpp View File

@@ -155,6 +155,7 @@ struct DragMove : Event {
/** Occurs every frame when the mouse is hovering over a Widget while dragging.
*/
struct DragHover : Event, Position {
Widget *origin = NULL;
/** Change in mouse position since the last frame. Can be zero. */
math::Vec mouseDelta;
};


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

@@ -393,7 +393,6 @@ void ModuleWidget::onDragMove(event::DragMove &e) {
if (!settings::lockModules) {
math::Rect newBox = box;
newBox.pos = context()->scene->rackWidget->lastMousePos.minus(dragPos);
DEBUG("%f %f", newBox.pos.x, newBox.pos.y);
context()->scene->rackWidget->requestModuleBoxNearest(this, newBox);
}
}


+ 26
- 22
src/app/Port.cpp View File

@@ -51,39 +51,33 @@ void Port::draw(NVGcontext *vg) {
}

void Port::onButton(event::Button &e) {
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
context()->scene->rackWidget->wireContainer->removeTopWire(this);

// HACK
// Update hovered*Port of active wire if applicable
event::DragEnter eDragEnter;
onDragEnter(eDragEnter);
// event::DragEnter eDragEnter;
// onDragEnter(eDragEnter);
}
e.target = this;
}

void Port::onDragStart(event::DragStart &e) {
// Try to grab wire on top of stack
WireWidget *wire = context()->scene->rackWidget->wireContainer->getTopWire(this);
if (type == OUTPUT && context()->window->isModPressed()) {
wire = NULL;
WireWidget *wire = NULL;
if (type == INPUT || !context()->window->isModPressed()) {
wire = context()->scene->rackWidget->wireContainer->getTopWire(this);
}

if (wire) {
// Disconnect existing wire
if (type == INPUT)
wire->inputPort = NULL;
else
wire->outputPort = NULL;
(type == INPUT ? wire->inputPort : wire->outputPort) = NULL;
wire->updateWire();
}
else {
// Create a new wire
wire = new WireWidget;
if (type == INPUT)
wire->inputPort = this;
else
wire->outputPort = this;
(type == INPUT ? wire->inputPort : wire->outputPort) = this;
}
context()->scene->rackWidget->wireContainer->setActiveWire(wire);
}
@@ -95,9 +89,21 @@ void Port::onDragEnd(event::DragEnd &e) {
}

void Port::onDragDrop(event::DragDrop &e) {
Port *originPort = dynamic_cast<Port*>(e.origin);
if (!originPort)
return;

// Fake onDragEnter because onDragLeave is triggered immediately before this one
event::DragEnter eDragEnter;
eDragEnter.origin = e.origin;
onDragEnter(eDragEnter);
}

void Port::onDragEnter(event::DragEnter &e) {
Port *originPort = dynamic_cast<Port*>(e.origin);
if (!originPort)
return;

// Reject ports if this is an input port and something is already plugged into it
if (type == INPUT) {
WireWidget *topWire = context()->scene->rackWidget->wireContainer->getTopWire(this);
@@ -107,20 +113,18 @@ void Port::onDragEnter(event::DragEnter &e) {

WireWidget *activeWire = context()->scene->rackWidget->wireContainer->activeWire;
if (activeWire) {
if (type == INPUT)
activeWire->hoveredInputPort = this;
else
activeWire->hoveredOutputPort = this;
(type == INPUT ? activeWire->hoveredInputPort : activeWire->hoveredOutputPort) = this;
}
}

void Port::onDragLeave(event::DragLeave &e) {
Port *originPort = dynamic_cast<Port*>(e.origin);
if (!originPort)
return;

WireWidget *activeWire = context()->scene->rackWidget->wireContainer->activeWire;
if (activeWire) {
if (type == INPUT)
activeWire->hoveredInputPort = NULL;
else
activeWire->hoveredOutputPort = NULL;
(type == INPUT ? activeWire->hoveredInputPort : activeWire->hoveredOutputPort) = NULL;
}
}



+ 4
- 4
src/app/WireContainer.cpp View File

@@ -20,14 +20,14 @@ void WireContainer::commitActiveWire() {
if (!activeWire)
return;

if (activeWire->hoveredInputPort) {
activeWire->inputPort = activeWire->hoveredInputPort;
activeWire->hoveredInputPort = NULL;
}
if (activeWire->hoveredOutputPort) {
activeWire->outputPort = activeWire->hoveredOutputPort;
activeWire->hoveredOutputPort = NULL;
}
if (activeWire->hoveredInputPort) {
activeWire->inputPort = activeWire->hoveredInputPort;
activeWire->hoveredInputPort = NULL;
}
activeWire->updateWire();

// Did it successfully connect?


+ 3
- 0
src/event.cpp View File

@@ -51,6 +51,7 @@ void Context::setDragHovered(Widget *w) {
if (dragHoveredWidget) {
// event::DragLeave
event::DragLeave eDragLeave;
eDragLeave.origin = draggedWidget;
dragHoveredWidget->onDragLeave(eDragLeave);
}

@@ -59,6 +60,7 @@ void Context::setDragHovered(Widget *w) {
if (dragHoveredWidget) {
// event::DragEnter
event::DragEnter eDragEnter;
eDragEnter.origin = draggedWidget;
dragHoveredWidget->onDragEnter(eDragEnter);
}
}
@@ -144,6 +146,7 @@ void Context::handleHover(math::Vec pos, math::Vec mouseDelta) {
event::DragHover eDragHover;
eDragHover.pos = pos;
eDragHover.mouseDelta = mouseDelta;
eDragHover.origin = draggedWidget;
rootWidget->onDragHover(eDragHover);

setDragHovered(eDragHover.target);


Loading…
Cancel
Save