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.

80 lines
2.4KB

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