Browse Source

Draw plugs under wires for CableWidgets in CableContainer.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
2cd29d62f0
5 changed files with 16 additions and 13 deletions
  1. +1
    -0
      include/app/RackWidget.hpp
  2. +2
    -7
      include/engine/Port.hpp
  3. +3
    -0
      include/math.hpp
  4. +8
    -4
      src/app/CableWidget.cpp
  5. +2
    -2
      src/app/RackWidget.cpp

+ 1
- 0
include/app/RackWidget.hpp View File

@@ -24,6 +24,7 @@ struct RackWidget : widget::OpaqueWidget {
math::Vec mousePos;
ParamWidget *touchedParam = NULL;
std::map<int, math::Vec> moduleDragPositions;
int nextCableColorId = 0;

RackWidget();
~RackWidget();


+ 2
- 7
include/engine/Port.hpp View File

@@ -22,7 +22,7 @@ struct alignas(32) Port {
Unstable API. Use set/getChannels() instead.
May be 0 to PORT_MAX_CHANNELS.
*/
uint8_t channels = 0;
uint8_t channels = 1;
/** Unstable API. Use isConnected() instead. */
bool active = false;
/** 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 {};



+ 3
- 0
include/math.hpp View File

@@ -205,6 +205,9 @@ struct Vec {
float norm() const {
return std::hypot(x, y);
}
Vec normalize() const {
return div(norm());
}
float square() const {
return x * x + y * y;
}


+ 8
- 4
src/app/CableWidget.cpp View File

@@ -1,5 +1,6 @@
#include "app/CableWidget.hpp"
#include "app/Scene.hpp"
#include "app/RackWidget.hpp"
#include "window.hpp"
#include "app.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);
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);

// Shadow
@@ -81,12 +86,12 @@ static const NVGcolor cableColors[] = {
nvgRGB(0x0c, 0x8e, 0x15), // green
nvgRGB(0x09, 0x86, 0xad), // blue
};
static int lastCableColorId = -1;


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;
}
@@ -244,7 +249,6 @@ void CableWidget::draw(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 inputPos = getInputPos();



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

@@ -63,14 +63,14 @@ struct ModuleContainer : widget::Widget {

struct CableContainer : widget::TransparentWidget {
void draw(const DrawArgs &args) override {
Widget::draw(args);

// Draw cable plugs
for (widget::Widget *w : children) {
CableWidget *cw = dynamic_cast<CableWidget*>(w);
assert(cw);
cw->drawPlugs(args);
}

Widget::draw(args);
}
};



Loading…
Cancel
Save