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

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