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.

88 lines
2.7KB

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