@@ -24,6 +24,7 @@ struct RackWidget : widget::OpaqueWidget { | |||||
math::Vec mousePos; | math::Vec mousePos; | ||||
ParamWidget *touchedParam = NULL; | ParamWidget *touchedParam = NULL; | ||||
std::map<int, math::Vec> moduleDragPositions; | std::map<int, math::Vec> moduleDragPositions; | ||||
int nextCableColorId = 0; | |||||
RackWidget(); | RackWidget(); | ||||
~RackWidget(); | ~RackWidget(); | ||||
@@ -22,7 +22,7 @@ struct alignas(32) Port { | |||||
Unstable API. Use set/getChannels() instead. | Unstable API. Use set/getChannels() instead. | ||||
May be 0 to PORT_MAX_CHANNELS. | May be 0 to PORT_MAX_CHANNELS. | ||||
*/ | */ | ||||
uint8_t channels = 0; | |||||
uint8_t channels = 1; | |||||
/** Unstable API. Use isConnected() instead. */ | /** Unstable API. Use isConnected() instead. */ | ||||
bool active = false; | bool active = false; | ||||
/** For rendering plug lights on cables. | /** For rendering plug lights on cables. | ||||
@@ -98,12 +98,7 @@ struct alignas(32) Port { | |||||
}; | }; | ||||
struct Output : Port { | |||||
Output() { | |||||
channels = 1; | |||||
} | |||||
}; | |||||
struct Output : Port {}; | |||||
struct Input : Port {}; | struct Input : Port {}; | ||||
@@ -205,6 +205,9 @@ struct Vec { | |||||
float norm() const { | float norm() const { | ||||
return std::hypot(x, y); | return std::hypot(x, y); | ||||
} | } | ||||
Vec normalize() const { | |||||
return div(norm()); | |||||
} | |||||
float square() const { | float square() const { | ||||
return x * x + y * y; | return x * x + y * y; | ||||
} | } | ||||
@@ -1,5 +1,6 @@ | |||||
#include "app/CableWidget.hpp" | #include "app/CableWidget.hpp" | ||||
#include "app/Scene.hpp" | #include "app/Scene.hpp" | ||||
#include "app/RackWidget.hpp" | |||||
#include "window.hpp" | #include "window.hpp" | ||||
#include "app.hpp" | #include "app.hpp" | ||||
#include "patch.hpp" | #include "patch.hpp" | ||||
@@ -46,6 +47,10 @@ static void drawCable(NVGcontext *vg, math::Vec pos1, math::Vec pos2, NVGcolor c | |||||
slump.y = (1.0 - tension) * (150.0 + 1.0*dist); | slump.y = (1.0 - tension) * (150.0 + 1.0*dist); | ||||
math::Vec pos3 = pos1.plus(pos2).div(2).plus(slump); | math::Vec pos3 = pos1.plus(pos2).div(2).plus(slump); | ||||
// Adjust pos1 and pos2 to not draw over the plug | |||||
pos1 = pos1.plus(pos3.minus(pos1).normalize().mult(9)); | |||||
pos2 = pos2.plus(pos3.minus(pos2).normalize().mult(9)); | |||||
nvgLineJoin(vg, NVG_ROUND); | nvgLineJoin(vg, NVG_ROUND); | ||||
// Shadow | // Shadow | ||||
@@ -81,12 +86,12 @@ static const NVGcolor cableColors[] = { | |||||
nvgRGB(0x0c, 0x8e, 0x15), // green | nvgRGB(0x0c, 0x8e, 0x15), // green | ||||
nvgRGB(0x09, 0x86, 0xad), // blue | nvgRGB(0x09, 0x86, 0xad), // blue | ||||
}; | }; | ||||
static int lastCableColorId = -1; | |||||
CableWidget::CableWidget() { | CableWidget::CableWidget() { | ||||
lastCableColorId = (lastCableColorId + 1) % LENGTHOF(cableColors); | |||||
color = cableColors[lastCableColorId]; | |||||
int id = APP->scene->rack->nextCableColorId++; | |||||
APP->scene->rack->nextCableColorId %= LENGTHOF(cableColors); | |||||
color = cableColors[id]; | |||||
cable = new engine::Cable; | cable = new engine::Cable; | ||||
} | } | ||||
@@ -244,7 +249,6 @@ void CableWidget::draw(const DrawArgs &args) { | |||||
} | } | ||||
void CableWidget::drawPlugs(const DrawArgs &args) { | void CableWidget::drawPlugs(const DrawArgs &args) { | ||||
// TODO Figure out a way to draw plugs first and cables last, and cut the plug portion of the cable off. | |||||
math::Vec outputPos = getOutputPos(); | math::Vec outputPos = getOutputPos(); | ||||
math::Vec inputPos = getInputPos(); | math::Vec inputPos = getInputPos(); | ||||
@@ -63,14 +63,14 @@ struct ModuleContainer : widget::Widget { | |||||
struct CableContainer : widget::TransparentWidget { | struct CableContainer : widget::TransparentWidget { | ||||
void draw(const DrawArgs &args) override { | void draw(const DrawArgs &args) override { | ||||
Widget::draw(args); | |||||
// Draw cable plugs | // Draw cable plugs | ||||
for (widget::Widget *w : children) { | for (widget::Widget *w : children) { | ||||
CableWidget *cw = dynamic_cast<CableWidget*>(w); | CableWidget *cw = dynamic_cast<CableWidget*>(w); | ||||
assert(cw); | assert(cw); | ||||
cw->drawPlugs(args); | cw->drawPlugs(args); | ||||
} | } | ||||
Widget::draw(args); | |||||
} | } | ||||
}; | }; | ||||