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.

83 lines
2.6KB

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