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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. void pasteJsonAction(json_t* rootJ);
  40. void pasteModuleJsonAction(json_t* moduleJ);
  41. void pasteClipboardAction();
  42. // Module methods
  43. /** Adds a module and adds it to the Engine, adopting ownership.
  44. */
  45. void addModule(ModuleWidget* mw);
  46. void addModuleAtMouse(ModuleWidget* mw);
  47. /** Removes the module and transfers ownership to the caller.
  48. */
  49. void removeModule(ModuleWidget* mw);
  50. ModuleWidget* getModule(int64_t moduleId);
  51. std::vector<ModuleWidget*> getModules();
  52. bool hasModules();
  53. // Module position methods
  54. /** Sets a module's box if non-colliding. Returns true if set */
  55. bool requestModulePos(ModuleWidget* mw, math::Vec pos);
  56. /** Moves a module to the closest non-colliding position */
  57. void setModulePosNearest(ModuleWidget* mw, math::Vec pos);
  58. /** Moves a module to a position, pushing other modules in the same row to the left or right, as needed. */
  59. void setModulePosForce(ModuleWidget* mw, math::Vec pos);
  60. /** Moves a module, contracting old module positions and pushing modules to the right as needed to fit. */
  61. void setModulePosSqueeze(ModuleWidget* mw, math::Vec pos);
  62. PRIVATE void squeezeModulePos(ModuleWidget* mw, math::Vec pos);
  63. PRIVATE void unsqueezeModulePos(ModuleWidget* mw);
  64. /** Saves positions of modules for getModuleDragAction(). */
  65. void updateModuleOldPositions();
  66. history::ComplexAction* getModuleDragAction();
  67. // Module selection methods
  68. void updateSelectionFromRect();
  69. void selectAll();
  70. void deselectAll();
  71. void select(ModuleWidget* mw, bool selected = true);
  72. bool hasSelection();
  73. const std::set<ModuleWidget*>& getSelected();
  74. bool isSelected(ModuleWidget* mw);
  75. json_t* selectionToJson(bool cables = true);
  76. void loadSelection(std::string path);
  77. void loadSelectionDialog();
  78. void saveSelection(std::string path);
  79. void saveSelectionDialog();
  80. void copyClipboardSelection();
  81. void resetSelectionAction();
  82. void randomizeSelectionAction();
  83. void disconnectSelectionAction();
  84. void cloneSelectionAction(bool cloneCables = true);
  85. void bypassSelectionAction(bool bypassed);
  86. bool isSelectionBypassed();
  87. void deleteSelectionAction();
  88. bool requestSelectionPos(math::Vec delta);
  89. void setSelectionPosNearest(math::Vec delta);
  90. void appendSelectionContextMenu(ui::Menu* menu);
  91. // Cable methods
  92. void clearCables();
  93. void clearCablesAction();
  94. /** Removes all cables connected to the port */
  95. void clearCablesOnPort(PortWidget* port);
  96. /** Adds a complete cable and adopts ownership.
  97. */
  98. void addCable(CableWidget* cw);
  99. /** Removes cable and releases ownership to caller.
  100. */
  101. void removeCable(CableWidget* cw);
  102. CableWidget* getIncompleteCable();
  103. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  104. void setIncompleteCable(CableWidget* cw);
  105. CableWidget* releaseIncompleteCable();
  106. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  107. CableWidget* getTopCable(PortWidget* port);
  108. CableWidget* getCable(int64_t cableId);
  109. std::vector<CableWidget*> getCompleteCables();
  110. /** Returns all cables attached to port, complete or not. */
  111. std::vector<CableWidget*> getCablesOnPort(PortWidget* port);
  112. std::vector<CableWidget*> getCompleteCablesOnPort(PortWidget* port);
  113. /** Returns but does not advance the next cable color. */
  114. int getNextCableColorId();
  115. void setNextCableColorId(int id);
  116. /** Returns and advances the next cable color. */
  117. NVGcolor getNextCableColor();
  118. ParamWidget* getTouchedParam();
  119. void setTouchedParam(ParamWidget* pw);
  120. PRIVATE void updateExpanders();
  121. };
  122. } // namespace app
  123. } // namespace rack