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.

97 lines
2.0KB

  1. #include "app.hpp"
  2. #include "gui.hpp"
  3. namespace rack {
  4. Port::~Port() {
  5. gRackWidget->wireContainer->removeAllWires(this);
  6. }
  7. void Port::draw(NVGcontext *vg) {
  8. WireWidget *activeWire = gRackWidget->wireContainer->activeWire;
  9. if (activeWire) {
  10. // Dim the Port if the active wire cannot plug into this Port
  11. if (type == INPUT ? activeWire->inputPort : activeWire->outputPort)
  12. nvgGlobalAlpha(vg, 0.5);
  13. }
  14. }
  15. void Port::onMouseDownOpaque(int button) {
  16. if (button == 1) {
  17. gRackWidget->wireContainer->removeTopWire(this);
  18. // HACK
  19. // Update hovered*Port of active wire if applicable
  20. onDragEnter(NULL);
  21. }
  22. }
  23. void Port::onDragEnd() {
  24. // FIXME
  25. // If the source Port is deleted, this will be called, removing the cable
  26. gRackWidget->wireContainer->commitActiveWire();
  27. }
  28. void Port::onDragStart() {
  29. // Try to grab wire on top of stack
  30. WireWidget *wire = gRackWidget->wireContainer->getTopWire(this);
  31. if (guiIsModPressed()) {
  32. if (type == INPUT)
  33. return;
  34. else
  35. wire = NULL;
  36. }
  37. if (wire) {
  38. // Disconnect existing wire
  39. if (type == INPUT)
  40. wire->inputPort = NULL;
  41. else
  42. wire->outputPort = NULL;
  43. wire->updateWire();
  44. }
  45. else {
  46. // Create a new wire
  47. wire = new WireWidget();
  48. if (type == INPUT)
  49. wire->inputPort = this;
  50. else
  51. wire->outputPort = this;
  52. }
  53. gRackWidget->wireContainer->setActiveWire(wire);
  54. }
  55. void Port::onDragDrop(Widget *origin) {
  56. }
  57. void Port::onDragEnter(Widget *origin) {
  58. // Reject ports if this is an input port and something is already plugged into it
  59. if (type == INPUT) {
  60. WireWidget *topWire = gRackWidget->wireContainer->getTopWire(this);
  61. if (topWire)
  62. return;
  63. }
  64. WireWidget *activeWire = gRackWidget->wireContainer->activeWire;
  65. if (activeWire) {
  66. if (type == INPUT)
  67. activeWire->hoveredInputPort = this;
  68. else
  69. activeWire->hoveredOutputPort = this;
  70. }
  71. }
  72. void Port::onDragLeave(Widget *origin) {
  73. WireWidget *activeWire = gRackWidget->wireContainer->activeWire;
  74. if (activeWire) {
  75. if (type == INPUT)
  76. activeWire->hoveredInputPort = NULL;
  77. else
  78. activeWire->hoveredOutputPort = NULL;
  79. }
  80. }
  81. } // namespace rack