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.

73 lines
2.1KB

  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 onDragHover(const event::DragHover &e) override;
  22. void onButton(const event::Button &e) override;
  23. void onZoom(const event::Zoom &e) override;
  24. /** Completely clear the rack's modules and cables */
  25. void clear();
  26. json_t *toJson();
  27. void fromJson(json_t *rootJ);
  28. void pastePresetClipboard();
  29. // Module methods
  30. /** Adds a module and adds it to the Engine
  31. Ownership rules work like add/removeChild()
  32. */
  33. void addModule(ModuleWidget *mw);
  34. void addModuleAtMouse(ModuleWidget *mw);
  35. /** Removes the module and transfers ownership to the caller */
  36. void removeModule(ModuleWidget *mw);
  37. /** Sets a module's box if non-colliding. Returns true if set */
  38. bool requestModuleBox(ModuleWidget *mw, math::Rect requestedBox);
  39. /** Moves a module to the closest non-colliding position */
  40. bool requestModuleBoxNearest(ModuleWidget *mw, math::Rect requestedBox);
  41. ModuleWidget *getModule(int moduleId);
  42. // Cable methods
  43. void clearCables();
  44. /** Removes all complete cables connected to the port */
  45. void clearCablesOnPort(PortWidget *port);
  46. /** Adds a complete cable and adds it to the Engine.
  47. Ownership rules work like add/removeChild()
  48. */
  49. void addCable(CableWidget *w);
  50. void removeCable(CableWidget *w);
  51. /** Takes ownership of `w` and adds it as a child if it isn't already */
  52. void setIncompleteCable(CableWidget *w);
  53. CableWidget *releaseIncompleteCable();
  54. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack */
  55. CableWidget *getTopCable(PortWidget *port);
  56. CableWidget *getCable(int cableId);
  57. };
  58. } // namespace rack