Browse Source

Rename Port to PortWidget

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
7c04ff0abf
14 changed files with 75 additions and 79 deletions
  1. +5
    -5
      include/app/ModuleWidget.hpp
  2. +3
    -3
      include/app/PortWidget.hpp
  3. +2
    -2
      include/app/SVGPort.hpp
  4. +0
    -1
      include/app/SVGScrew.hpp
  5. +4
    -4
      include/app/WireContainer.hpp
  6. +5
    -8
      include/app/WireWidget.hpp
  7. +17
    -17
      include/helpers.hpp
  8. +1
    -1
      include/rack.hpp
  9. +6
    -6
      src/app/ModuleWidget.cpp
  10. +18
    -18
      src/app/PortWidget.cpp
  11. +7
    -7
      src/app/RackWidget.cpp
  12. +1
    -1
      src/app/SVGPort.cpp
  13. +3
    -3
      src/app/WireContainer.cpp
  14. +3
    -3
      src/app/WireWidget.cpp

+ 5
- 5
include/app/ModuleWidget.hpp View File

@@ -2,7 +2,7 @@
#include "app/common.hpp"
#include "widgets/OpaqueWidget.hpp"
#include "ui/Menu.hpp"
#include "app/Port.hpp"
#include "app/PortWidget.hpp"
#include "app/ParamWidget.hpp"
#include "plugin/Model.hpp"
#include "engine/Module.hpp"
@@ -18,14 +18,14 @@ struct ModuleWidget : OpaqueWidget {

Widget *panel = NULL;
std::vector<ParamWidget*> params;
std::vector<Port*> inputs;
std::vector<Port*> outputs;
std::vector<PortWidget*> inputs;
std::vector<PortWidget*> outputs;

ModuleWidget(Module *module);
~ModuleWidget();
/** Convenience functions for adding special widgets (calls addChild()) */
void addInput(Port *input);
void addOutput(Port *output);
void addInput(PortWidget *input);
void addOutput(PortWidget *output);
void addParam(ParamWidget *param);
void setPanel(std::shared_ptr<SVG> svg);



include/app/Port.hpp → include/app/PortWidget.hpp View File

@@ -8,7 +8,7 @@
namespace rack {


struct Port : OpaqueWidget {
struct PortWidget : OpaqueWidget {
Module *module = NULL;
int portId;

@@ -19,8 +19,8 @@ struct Port : OpaqueWidget {
PortType type = INPUT;
MultiLightWidget *plugLight;

Port();
~Port();
PortWidget();
~PortWidget();
void step() override;
void draw(NVGcontext *vg) override;
void onButton(event::Button &e) override;

+ 2
- 2
include/app/SVGPort.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "app/common.hpp"
#include "app/Port.hpp"
#include "app/PortWidget.hpp"
#include "widgets/FramebufferWidget.hpp"
#include "widgets/SVGWidget.hpp"
#include "app/CircularShadow.hpp"
@@ -9,7 +9,7 @@
namespace rack {


struct SVGPort : Port, FramebufferWidget {
struct SVGPort : PortWidget, FramebufferWidget {
SVGWidget *background;
CircularShadow *shadow;



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

@@ -1,6 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/Port.hpp"
#include "widgets/FramebufferWidget.hpp"
#include "widgets/SVGWidget.hpp"



+ 4
- 4
include/app/WireContainer.hpp View File

@@ -2,7 +2,7 @@
#include "app/common.hpp"
#include "widgets/TransparentWidget.hpp"
#include "app/WireWidget.hpp"
#include "app/Port.hpp"
#include "app/PortWidget.hpp"


namespace rack {
@@ -14,10 +14,10 @@ struct WireContainer : TransparentWidget {
void setActiveWire(WireWidget *w);
/** "Drops" the wire onto the port, making an engine connection if successful */
void commitActiveWire();
void removeTopWire(Port *port);
void removeAllWires(Port *port);
void removeTopWire(PortWidget *port);
void removeAllWires(PortWidget *port);
/** Returns the most recently added wire connected to the given Port, i.e. the top of the stack */
WireWidget *getTopWire(Port *port);
WireWidget *getTopWire(PortWidget *port);
void draw(NVGcontext *vg) override;
};



+ 5
- 8
include/app/WireWidget.hpp View File

@@ -1,21 +1,18 @@
#pragma once
#include "app/common.hpp"
#include "widgets/OpaqueWidget.hpp"
#include "app/Port.hpp"
#include "app/PortWidget.hpp"
#include "engine/Wire.hpp"


namespace rack {


struct Port;


struct WireWidget : OpaqueWidget {
Port *outputPort = NULL;
Port *inputPort = NULL;
Port *hoveredOutputPort = NULL;
Port *hoveredInputPort = NULL;
PortWidget *outputPort = NULL;
PortWidget *inputPort = NULL;
PortWidget *hoveredOutputPort = NULL;
PortWidget *hoveredInputPort = NULL;
Wire *wire = NULL;
NVGcolor color;



+ 17
- 17
include/helpers.hpp View File

@@ -2,7 +2,7 @@
#include "ui/MenuLabel.hpp"
#include "ui/MenuItem.hpp"
#include "ui/Menu.hpp"
#include "app/Port.hpp"
#include "app/PortWidget.hpp"
#include "app/ParamQuantity.hpp"
#include "app/ParamWidget.hpp"
#include "app/Scene.hpp"
@@ -75,42 +75,42 @@ TParamWidget *createParamCentered(math::Vec pos, Module *module, int paramId) {
return o;
}

template <class TPort>
TPort *createInput(math::Vec pos, Module *module, int inputId) {
TPort *o = new TPort;
template <class TPortWidget>
TPortWidget *createInput(math::Vec pos, Module *module, int inputId) {
TPortWidget *o = new TPortWidget;
o->box.pos = pos;
o->module = module;
o->type = Port::INPUT;
o->type = PortWidget::INPUT;
o->portId = inputId;
return o;
}

template <class TPort>
TPort *createInputCentered(math::Vec pos, Module *module, int inputId) {
TPort *o = new TPort;
template <class TPortWidget>
TPortWidget *createInputCentered(math::Vec pos, Module *module, int inputId) {
TPortWidget *o = new TPortWidget;
o->box.pos = pos.minus(o->box.size.div(2));
o->module = module;
o->type = Port::INPUT;
o->type = PortWidget::INPUT;
o->portId = inputId;
return o;
}

template <class TPort>
TPort *createOutput(math::Vec pos, Module *module, int outputId) {
TPort *o = new TPort;
template <class TPortWidget>
TPortWidget *createOutput(math::Vec pos, Module *module, int outputId) {
TPortWidget *o = new TPortWidget;
o->box.pos = pos;
o->module = module;
o->type = Port::OUTPUT;
o->type = PortWidget::OUTPUT;
o->portId = outputId;
return o;
}

template <class TPort>
TPort *createOutputCentered(math::Vec pos, Module *module, int outputId) {
TPort *o = new TPort;
template <class TPortWidget>
TPortWidget *createOutputCentered(math::Vec pos, Module *module, int outputId) {
TPortWidget *o = new TPortWidget;
o->box.pos = pos.minus(o->box.size.div(2));
o->module = module;
o->type = Port::OUTPUT;
o->type = PortWidget::OUTPUT;
o->portId = outputId;
return o;
}


+ 1
- 1
include/rack.hpp View File

@@ -51,7 +51,7 @@
#include "app/MomentarySwitch.hpp"
#include "app/MultiLightWidget.hpp"
#include "app/ParamWidget.hpp"
#include "app/Port.hpp"
#include "app/PortWidget.hpp"
#include "app/RackRail.hpp"
#include "app/Scene.hpp"
#include "app/RackScrollWidget.hpp"


+ 6
- 6
src/app/ModuleWidget.cpp View File

@@ -32,14 +32,14 @@ ModuleWidget::~ModuleWidget() {
}
}

void ModuleWidget::addInput(Port *input) {
assert(input->type == Port::INPUT);
void ModuleWidget::addInput(PortWidget *input) {
assert(input->type == PortWidget::INPUT);
inputs.push_back(input);
addChild(input);
}

void ModuleWidget::addOutput(Port *output) {
assert(output->type == Port::OUTPUT);
void ModuleWidget::addOutput(PortWidget *output) {
assert(output->type == PortWidget::OUTPUT);
outputs.push_back(output);
addChild(output);
}
@@ -251,10 +251,10 @@ void ModuleWidget::saveDialog() {
}

void ModuleWidget::disconnect() {
for (Port *input : inputs) {
for (PortWidget *input : inputs) {
context()->scene->rackWidget->wireContainer->removeAllWires(input);
}
for (Port *output : outputs) {
for (PortWidget *output : outputs) {
context()->scene->rackWidget->wireContainer->removeAllWires(output);
}
}


src/app/Port.cpp → src/app/PortWidget.cpp View File

@@ -1,4 +1,4 @@
#include "app/Port.hpp"
#include "app/PortWidget.hpp"
#include "app/Scene.hpp"
#include "window.hpp"
#include "context.hpp"
@@ -18,17 +18,17 @@ struct PlugLight : MultiLightWidget {
};


Port::Port() {
PortWidget::PortWidget() {
plugLight = new PlugLight;
}

Port::~Port() {
// plugLight is not a child and is thus owned by the Port, so we need to delete it here
PortWidget::~PortWidget() {
// plugLight is not a child and is thus owned by the PortWidget, so we need to delete it here
delete plugLight;
context()->scene->rackWidget->wireContainer->removeAllWires(this);
}

void Port::step() {
void PortWidget::step() {
std::vector<float> values(2);
if (type == INPUT) {
values[0] = module->inputs[portId].plugLights[0].getBrightness();
@@ -41,28 +41,28 @@ void Port::step() {
plugLight->setValues(values);
}

void Port::draw(NVGcontext *vg) {
void PortWidget::draw(NVGcontext *vg) {
WireWidget *activeWire = context()->scene->rackWidget->wireContainer->activeWire;
if (activeWire) {
// Dim the Port if the active wire cannot plug into this Port
// Dim the PortWidget if the active wire cannot plug into this PortWidget
if (type == INPUT ? activeWire->inputPort : activeWire->outputPort)
nvgGlobalAlpha(vg, 0.5);
}
}

void Port::onButton(event::Button &e) {
void PortWidget::onButton(event::Button &e) {
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
// Update hovered*PortWidget of active wire if applicable
// event::DragEnter eDragEnter;
// onDragEnter(eDragEnter);
}
e.target = this;
}

void Port::onDragStart(event::DragStart &e) {
void PortWidget::onDragStart(event::DragStart &e) {
// Try to grab wire on top of stack
WireWidget *wire = NULL;
if (type == INPUT || !context()->window->isModPressed()) {
@@ -82,14 +82,14 @@ void Port::onDragStart(event::DragStart &e) {
context()->scene->rackWidget->wireContainer->setActiveWire(wire);
}

void Port::onDragEnd(event::DragEnd &e) {
void PortWidget::onDragEnd(event::DragEnd &e) {
// FIXME
// If the source Port is deleted, this will be called, removing the cable
// If the source PortWidget is deleted, this will be called, removing the cable
context()->scene->rackWidget->wireContainer->commitActiveWire();
}

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

@@ -99,8 +99,8 @@ void Port::onDragDrop(event::DragDrop &e) {
onDragEnter(eDragEnter);
}

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

@@ -117,8 +117,8 @@ void Port::onDragEnter(event::DragEnter &e) {
}
}

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


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

@@ -240,8 +240,8 @@ json_t *RackWidget::toJson() {
WireWidget *wireWidget = dynamic_cast<WireWidget*>(w);
assert(wireWidget);

Port *outputPort = wireWidget->outputPort;
Port *inputPort = wireWidget->inputPort;
PortWidget *outputPort = wireWidget->outputPort;
PortWidget *inputPort = wireWidget->inputPort;
// Only serialize WireWidgets connected on both ends
if (!(outputPort && inputPort))
continue;
@@ -362,21 +362,21 @@ void RackWidget::fromJson(json_t *rootJ) {
if (!inputModuleWidget) continue;

// Get port widgets
Port *outputPort = NULL;
Port *inputPort = NULL;
PortWidget *outputPort = NULL;
PortWidget *inputPort = NULL;
if (legacy && legacy <= 1) {
// Before 0.6, the index of the "ports" array was the index of the Port in the `outputs` and `inputs` vector.
// Before 0.6, the index of the "ports" array was the index of the PortWidget in the `outputs` and `inputs` vector.
outputPort = outputModuleWidget->outputs[outputId];
inputPort = inputModuleWidget->inputs[inputId];
}
else {
for (Port *port : outputModuleWidget->outputs) {
for (PortWidget *port : outputModuleWidget->outputs) {
if (port->portId == outputId) {
outputPort = port;
break;
}
}
for (Port *port : inputModuleWidget->inputs) {
for (PortWidget *port : inputModuleWidget->inputs) {
if (port->portId == inputId) {
inputPort = port;
break;


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

@@ -24,7 +24,7 @@ void SVGPort::setSVG(std::shared_ptr<SVG> svg) {
}

void SVGPort::draw(NVGcontext *vg) {
Port::draw(vg);
PortWidget::draw(vg);
FramebufferWidget::draw(vg);
}



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

@@ -41,7 +41,7 @@ void WireContainer::commitActiveWire() {
}
}

void WireContainer::removeTopWire(Port *port) {
void WireContainer::removeTopWire(PortWidget *port) {
WireWidget *wire = getTopWire(port);
if (wire) {
removeChild(wire);
@@ -49,7 +49,7 @@ void WireContainer::removeTopWire(Port *port) {
}
}

void WireContainer::removeAllWires(Port *port) {
void WireContainer::removeAllWires(PortWidget *port) {
// As a convenience, de-hover the active wire so we don't attach them once it is dropped.
if (activeWire) {
if (activeWire->hoveredInputPort == port)
@@ -80,7 +80,7 @@ void WireContainer::removeAllWires(Port *port) {
}
}

WireWidget *WireContainer::getTopWire(Port *port) {
WireWidget *WireContainer::getTopWire(PortWidget *port) {
for (auto it = children.rbegin(); it != children.rend(); it++) {
WireWidget *wire = dynamic_cast<WireWidget*>(*it);
assert(wire);


+ 3
- 3
src/app/WireWidget.cpp View File

@@ -101,8 +101,8 @@ WireWidget::~WireWidget() {
void WireWidget::updateWire() {
if (inputPort && outputPort) {
// Check correct types
assert(inputPort->type == Port::INPUT);
assert(outputPort->type == Port::OUTPUT);
assert(inputPort->type == PortWidget::INPUT);
assert(outputPort->type == PortWidget::OUTPUT);

if (!wire) {
wire = new Wire;
@@ -173,7 +173,7 @@ void WireWidget::draw(NVGcontext *vg) {
opacity = 1.0;
}
else {
Port *hoveredPort = dynamic_cast<Port*>(context()->event->hoveredWidget);
PortWidget *hoveredPort = dynamic_cast<PortWidget*>(context()->event->hoveredWidget);
if (hoveredPort && (hoveredPort == outputPort || hoveredPort == inputPort))
opacity = 1.0;
}


Loading…
Cancel
Save