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.

140 lines
4.3KB

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