You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1KB

  1. #include "Rack.hpp"
  2. namespace rack {
  3. Port::Port() {
  4. box.size = Vec(20, 20);
  5. spriteOffset = Vec(-18, -18);
  6. spriteSize = Vec(56, 56);
  7. spriteFilename = "res/port.png";
  8. std::uniform_int_distribution<> dist(0, 4);
  9. index = dist(rng);
  10. }
  11. Port::~Port() {
  12. disconnect();
  13. }
  14. void Port::disconnect() {
  15. if (connectedWire) {
  16. gRackWidget->wireContainer->removeChild(connectedWire);
  17. // On destruction, Wire automatically sets connectedWire to NULL
  18. delete connectedWire;
  19. }
  20. }
  21. void Port::drawGlow(NVGcontext *vg) {
  22. Vec c = box.getCenter();
  23. NVGcolor icol = nvgRGBAf(1, 1, 1, 0.5);
  24. NVGcolor ocol = nvgRGBAf(1, 1, 1, 0);
  25. NVGpaint paint = nvgRadialGradient(vg, c.x, c.y, 0, 20, icol, ocol);
  26. nvgFillPaint(vg, paint);
  27. nvgBeginPath(vg);
  28. nvgRect(vg, box.pos.x - 10, box.pos.y - 10, box.size.x + 20, box.size.y + 20);
  29. nvgFill(vg);
  30. }
  31. void Port::onMouseDown(int button) {
  32. if (button == 1) {
  33. disconnect();
  34. }
  35. }
  36. void Port::onDragEnd() {
  37. WireWidget *w = gRackWidget->activeWire;
  38. assert(w);
  39. w->updateWire();
  40. if (!w->wire) {
  41. gRackWidget->wireContainer->removeChild(w);
  42. delete w;
  43. }
  44. gRackWidget->activeWire = NULL;
  45. }
  46. } // namespace rack