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.

156 lines
5.2KB

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