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.

RackWidget.hpp 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // Cable methods
  44. void clearCables();
  45. void clearCablesAction();
  46. /** Removes all complete cables connected to the port */
  47. void clearCablesOnPort(PortWidget *port);
  48. /** Adds a complete cable and adds it to the Engine.
  49. Ownership rules work like add/removeChild()
  50. */
  51. void addCable(CableWidget *w);
  52. void removeCable(CableWidget *w);
  53. /** Takes ownership of `w` and adds it as a child if it isn't already */
  54. void setIncompleteCable(CableWidget *w);
  55. CableWidget *releaseIncompleteCable();
  56. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack */
  57. CableWidget *getTopCable(PortWidget *port);
  58. CableWidget *getCable(int cableId);
  59. /** Returns all cables attached to port, complete or not */
  60. std::list<CableWidget*> getCablesOnPort(PortWidget *port);
  61. };
  62. } // namespace rack