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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #pragma once
  2. #include <app/common.hpp>
  3. #include <widget/OpaqueWidget.hpp>
  4. #include <widget/FramebufferWidget.hpp>
  5. #include <ui/Menu.hpp>
  6. #include <app/RailWidget.hpp>
  7. #include <app/ModuleWidget.hpp>
  8. #include <app/CableWidget.hpp>
  9. #include <app/PortWidget.hpp>
  10. #include <app/ParamWidget.hpp>
  11. #include <history.hpp>
  12. #include <set>
  13. namespace rack {
  14. namespace app {
  15. /** Container for ModuleWidget and CableWidget. */
  16. struct RackWidget : widget::OpaqueWidget {
  17. struct Internal;
  18. Internal* internal;
  19. /** DEPRECATED. Use get/setTouchedParam(). */
  20. ParamWidget* touchedParam = NULL;
  21. PRIVATE RackWidget();
  22. PRIVATE ~RackWidget();
  23. void step() override;
  24. void draw(const DrawArgs& args) override;
  25. void onHover(const HoverEvent& e) override;
  26. void onHoverKey(const HoverKeyEvent& e) override;
  27. void onButton(const ButtonEvent& e) override;
  28. void onDragStart(const DragStartEvent& e) override;
  29. void onDragEnd(const DragEndEvent& e) override;
  30. void onDragHover(const DragHoverEvent& e) override;
  31. // Rack methods
  32. widget::Widget* getModuleContainer();
  33. widget::Widget* getCableContainer();
  34. math::Vec getMousePos();
  35. /** Completely clear the rack's modules and cables */
  36. void clear();
  37. void mergeJson(json_t* rootJ);
  38. void fromJson(json_t* rootJ);
  39. /** Pastes module JSON or selection JSON at the mouse position. */
  40. void pasteJsonAction(json_t* rootJ);
  41. void pasteModuleJsonAction(json_t* moduleJ);
  42. void pasteClipboardAction();
  43. // Module methods
  44. /** Adds a module and adds it to the Engine, adopting ownership.
  45. */
  46. void addModule(ModuleWidget* mw);
  47. void addModuleAtMouse(ModuleWidget* mw);
  48. /** Removes the module and transfers ownership to the caller.
  49. */
  50. void removeModule(ModuleWidget* mw);
  51. ModuleWidget* getModule(int64_t moduleId);
  52. std::vector<ModuleWidget*> getModules();
  53. bool hasModules();
  54. // Module position methods
  55. /** Sets a module's box if non-colliding. Returns true if set */
  56. bool requestModulePos(ModuleWidget* mw, math::Vec pos);
  57. /** Moves a module to the closest non-colliding position */
  58. void setModulePosNearest(ModuleWidget* mw, math::Vec pos);
  59. /** Moves a module to a position, pushing other modules in the same row to the left or right, as needed. */
  60. void setModulePosForce(ModuleWidget* mw, math::Vec pos);
  61. /** Moves a module, contracting old module positions and pushing modules to the right as needed to fit. */
  62. void setModulePosSqueeze(ModuleWidget* mw, math::Vec pos);
  63. PRIVATE void squeezeModulePos(ModuleWidget* mw, math::Vec pos);
  64. PRIVATE void unsqueezeModulePos(ModuleWidget* mw);
  65. /** Saves positions of modules for getModuleDragAction(). */
  66. void updateModuleOldPositions();
  67. history::ComplexAction* getModuleDragAction();
  68. // Module selection methods
  69. void updateSelectionFromRect();
  70. void selectAll();
  71. void deselectAll();
  72. void select(ModuleWidget* mw, bool selected = true);
  73. bool hasSelection();
  74. const std::set<ModuleWidget*>& getSelected();
  75. bool isSelected(ModuleWidget* mw);
  76. json_t* selectionToJson(bool cables = true);
  77. void loadSelection(std::string path);
  78. void loadSelectionDialog();
  79. void saveSelection(std::string path);
  80. void saveSelectionDialog();
  81. void copyClipboardSelection();
  82. void resetSelectionAction();
  83. void randomizeSelectionAction();
  84. void disconnectSelectionAction();
  85. void cloneSelectionAction(bool cloneCables = true);
  86. void bypassSelectionAction(bool bypassed);
  87. bool isSelectionBypassed();
  88. void deleteSelectionAction();
  89. bool requestSelectionPos(math::Vec delta);
  90. void setSelectionPosNearest(math::Vec delta);
  91. void appendSelectionContextMenu(ui::Menu* menu);
  92. // Cable methods
  93. void clearCables();
  94. void clearCablesAction();
  95. /** Removes all cables connected to the port */
  96. void clearCablesOnPort(PortWidget* port);
  97. /** Adds a complete cable and adopts ownership.
  98. */
  99. void addCable(CableWidget* cw);
  100. /** Removes cable and releases ownership to caller.
  101. */
  102. void removeCable(CableWidget* cw);
  103. CableWidget* getIncompleteCable();
  104. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  105. void setIncompleteCable(CableWidget* cw);
  106. CableWidget* releaseIncompleteCable();
  107. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  108. CableWidget* getTopCable(PortWidget* port);
  109. CableWidget* getCable(int64_t cableId);
  110. std::vector<CableWidget*> getCompleteCables();
  111. /** Returns all cables attached to port, complete or not. */
  112. std::vector<CableWidget*> getCablesOnPort(PortWidget* port);
  113. std::vector<CableWidget*> getCompleteCablesOnPort(PortWidget* port);
  114. /** Returns but does not advance the next cable color. */
  115. int getNextCableColorId();
  116. void setNextCableColorId(int id);
  117. /** Returns and advances the next cable color. */
  118. NVGcolor getNextCableColor();
  119. ParamWidget* getTouchedParam();
  120. void setTouchedParam(ParamWidget* pw);
  121. PRIVATE void updateExpanders();
  122. };
  123. } // namespace app
  124. } // namespace rack