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

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