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.

78 lines
2.3KB

  1. #pragma once
  2. #include "app/common.hpp"
  3. #include "widgets/OpaqueWidget.hpp"
  4. #include "widgets/FramebufferWidget.hpp"
  5. #include "app/ModuleWidget.hpp"
  6. #include "app/CableWidget.hpp"
  7. #include "app/PortWidget.hpp"
  8. namespace rack {
  9. struct RackWidget : OpaqueWidget {
  10. FramebufferWidget *rails;
  11. Widget *moduleContainer;
  12. Widget *cableContainer;
  13. CableWidget *incompleteCable = NULL;
  14. /** The last mouse position in the RackWidget */
  15. math::Vec mousePos;
  16. RackWidget();
  17. ~RackWidget();
  18. void step() override;
  19. void draw(NVGcontext *vg) override;
  20. void onHover(const event::Hover &e) override;
  21. void onHoverKey(const event::HoverKey &e) override;
  22. void onDragHover(const event::DragHover &e) override;
  23. void onButton(const event::Button &e) override;
  24. void onZoom(const event::Zoom &e) override;
  25. /** Completely clear the rack's modules and cables */
  26. void clear();
  27. json_t *toJson();
  28. void fromJson(json_t *rootJ);
  29. void pastePresetClipboardAction();
  30. // Module methods
  31. /** Adds a module and adds it to the Engine
  32. Ownership rules work like add/removeChild()
  33. */
  34. void addModule(ModuleWidget *mw);
  35. void addModuleAtMouse(ModuleWidget *mw);
  36. /** Removes the module and transfers ownership to the caller */
  37. void removeModule(ModuleWidget *mw);
  38. /** Sets a module's box if non-colliding. Returns true if set */
  39. bool requestModuleBox(ModuleWidget *mw, math::Rect requestedBox);
  40. /** Moves a module to the closest non-colliding position */
  41. bool requestModuleBoxNearest(ModuleWidget *mw, math::Rect requestedBox);
  42. ModuleWidget *getModule(int moduleId);
  43. bool isEmpty();
  44. // Cable methods
  45. void clearCables();
  46. void clearCablesAction();
  47. /** Removes all complete cables connected to the port */
  48. void clearCablesOnPort(PortWidget *port);
  49. /** Adds a complete cable and adds it to the Engine.
  50. Ownership rules work like add/removeChild()
  51. */
  52. void addCable(CableWidget *w);
  53. void removeCable(CableWidget *w);
  54. /** Takes ownership of `w` and adds it as a child if it isn't already */
  55. void setIncompleteCable(CableWidget *w);
  56. CableWidget *releaseIncompleteCable();
  57. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack */
  58. CableWidget *getTopCable(PortWidget *port);
  59. CableWidget *getCable(int cableId);
  60. /** Returns all cables attached to port, complete or not */
  61. std::list<CableWidget*> getCablesOnPort(PortWidget *port);
  62. };
  63. } // namespace rack