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.

82 lines
2.0KB

  1. #pragma once
  2. #include <map>
  3. #include <app/common.hpp>
  4. #include <widget/Widget.hpp>
  5. #include <app/PortWidget.hpp>
  6. #include <engine/Cable.hpp>
  7. namespace rack {
  8. namespace app {
  9. struct CableWidget;
  10. struct PlugWidget : widget::Widget {
  11. struct Internal;
  12. Internal* internal;
  13. PlugWidget();
  14. ~PlugWidget();
  15. void step() override;
  16. PRIVATE void setColor(NVGcolor color);
  17. PRIVATE void setAngle(float angle);
  18. PRIVATE void setTop(bool top);
  19. CableWidget* getCable();
  20. engine::Port::Type getType();
  21. };
  22. struct CableWidget : widget::Widget {
  23. struct Internal;
  24. Internal* internal;
  25. /** Owned. */
  26. engine::Cable* cable = NULL;
  27. NVGcolor color;
  28. PlugWidget* inputPlug;
  29. PlugWidget* outputPlug;
  30. PortWidget* inputPort = NULL;
  31. PortWidget* outputPort = NULL;
  32. PortWidget* hoveredInputPort = NULL;
  33. PortWidget* hoveredOutputPort = NULL;
  34. CableWidget();
  35. ~CableWidget();
  36. /** Returns whether cable is connected to 2 ports. */
  37. bool isComplete();
  38. /** Based on the input/output ports, re-creates the cable and removes/adds it to the Engine. */
  39. void updateCable();
  40. /** From a cable, sets the input/output ports.
  41. Cable must already be added to the Engine.
  42. Adopts ownership.
  43. */
  44. void setCable(engine::Cable* cable);
  45. engine::Cable* getCable();
  46. PlugWidget*& getPlug(engine::Port::Type type) {
  47. return type == engine::Port::INPUT ? inputPlug : outputPlug;
  48. }
  49. PortWidget*& getPort(engine::Port::Type type) {
  50. return type == engine::Port::INPUT ? inputPort : outputPort;
  51. }
  52. PortWidget*& getHoveredPort(engine::Port::Type type) {
  53. return type == engine::Port::INPUT ? hoveredInputPort : hoveredOutputPort;
  54. }
  55. math::Vec getInputPos();
  56. math::Vec getOutputPos();
  57. void mergeJson(json_t* rootJ);
  58. void fromJson(json_t* rootJ);
  59. void step() override;
  60. void draw(const DrawArgs& args) override;
  61. void drawLayer(const DrawArgs& args, int layer) override;
  62. engine::Cable* releaseCable();
  63. void onAdd(const AddEvent& e) override;
  64. void onRemove(const RemoveEvent& e) override;
  65. };
  66. } // namespace app
  67. } // namespace rack