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.5KB

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