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.

68 lines
1.5KB

  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 PlugWidget : widget::Widget {
  10. struct Internal;
  11. Internal* internal;
  12. PlugWidget();
  13. ~PlugWidget();
  14. void step() override;
  15. PRIVATE void setColor(NVGcolor color);
  16. PRIVATE void setAngle(float angle);
  17. PRIVATE void setPortWidget(PortWidget* portWidget);
  18. PRIVATE void setTop(bool top);
  19. };
  20. struct CableWidget : widget::Widget {
  21. struct Internal;
  22. Internal* internal;
  23. /** Owned. */
  24. engine::Cable* cable = NULL;
  25. NVGcolor color;
  26. PlugWidget* inputPlug;
  27. PlugWidget* outputPlug;
  28. PortWidget* inputPort = NULL;
  29. PortWidget* outputPort = NULL;
  30. PortWidget* hoveredInputPort = NULL;
  31. PortWidget* hoveredOutputPort = NULL;
  32. CableWidget();
  33. ~CableWidget();
  34. bool isComplete();
  35. /** Based on the input/output ports, re-creates the cable and removes/adds it to the Engine. */
  36. void updateCable();
  37. /** From a cable, sets the input/output ports.
  38. Cable must already be added to the Engine.
  39. Adopts ownership.
  40. */
  41. void setCable(engine::Cable* cable);
  42. engine::Cable* getCable();
  43. math::Vec getInputPos();
  44. math::Vec getOutputPos();
  45. void mergeJson(json_t* rootJ);
  46. void fromJson(json_t* rootJ);
  47. void step() override;
  48. void draw(const DrawArgs& args) override;
  49. void drawLayer(const DrawArgs& args, int layer) override;
  50. engine::Cable* releaseCable();
  51. void onAdd(const AddEvent& e) override;
  52. void onRemove(const RemoveEvent& e) override;
  53. };
  54. } // namespace app
  55. } // namespace rack