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.

128 lines
3.8KB

  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. CableWidget* incompleteCable = NULL;
  20. ParamWidget* touchedParam = NULL;
  21. int nextCableColorId = 0;
  22. RackWidget();
  23. ~RackWidget();
  24. void step() override;
  25. void draw(const DrawArgs& args) override;
  26. void onHover(const HoverEvent& e) override;
  27. void onHoverKey(const HoverKeyEvent& e) override;
  28. void onButton(const ButtonEvent& e) override;
  29. void onDragStart(const DragStartEvent& e) override;
  30. void onDragEnd(const DragEndEvent& e) override;
  31. void onDragHover(const DragHoverEvent& e) override;
  32. // Rack methods
  33. widget::Widget* getModuleContainer();
  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. 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. /** Sets a module's box if non-colliding. Returns true if set */
  52. bool requestModulePos(ModuleWidget* mw, math::Vec pos);
  53. /** Moves a module to the closest non-colliding position */
  54. void setModulePosNearest(ModuleWidget* mw, math::Vec pos);
  55. void setModulePosForce(ModuleWidget* mw, math::Vec pos);
  56. ModuleWidget* getModule(int64_t moduleId);
  57. std::vector<ModuleWidget*> getModules();
  58. bool hasModules();
  59. void updateModuleOldPositions();
  60. history::ComplexAction* getModuleDragAction();
  61. // Module selection methods
  62. void updateSelectionFromRect();
  63. void selectAll();
  64. void deselectAll();
  65. void select(ModuleWidget* mw, bool selected = true);
  66. bool hasSelection();
  67. const std::set<ModuleWidget*>& getSelected();
  68. bool isSelected(ModuleWidget* mw);
  69. json_t* selectionToJson();
  70. void loadSelection(std::string path);
  71. void loadSelectionDialog();
  72. void saveSelection(std::string path);
  73. void saveSelectionDialog();
  74. void copyClipboardSelection();
  75. void resetSelectionAction();
  76. void randomizeSelectionAction();
  77. void disconnectSelectionAction();
  78. void cloneSelectionAction();
  79. void bypassSelectionAction(bool bypassed);
  80. bool isSelectionBypassed();
  81. void deleteSelectionAction();
  82. bool requestSelectionPos(math::Vec delta);
  83. void setSelectionPosNearest(math::Vec delta);
  84. void appendSelectionContextMenu(ui::Menu* menu);
  85. // Cable methods
  86. void clearCables();
  87. void clearCablesAction();
  88. /** Removes all cables connected to the port */
  89. void clearCablesOnPort(PortWidget* port);
  90. /** Adds a complete cable and adopts ownership.
  91. */
  92. void addCable(CableWidget* cw);
  93. /** Removes cable and releases ownership to caller.
  94. */
  95. void removeCable(CableWidget* cw);
  96. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  97. void setIncompleteCable(CableWidget* cw);
  98. CableWidget* releaseIncompleteCable();
  99. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  100. CableWidget* getTopCable(PortWidget* port);
  101. CableWidget* getCable(int64_t cableId);
  102. std::vector<CableWidget*> getCompleteCables();
  103. /** Returns all cables attached to port, complete or not. */
  104. std::vector<CableWidget*> getCablesOnPort(PortWidget* port);
  105. };
  106. } // namespace app
  107. } // namespace rack