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.

138 lines
4.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* 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. ModuleWidget* getModule(int64_t moduleId);
  56. std::vector<ModuleWidget*> getModules();
  57. bool hasModules();
  58. void updateModuleOldPositions();
  59. history::ComplexAction* getModuleDragAction();
  60. // Module selection methods
  61. void updateSelectionFromRect();
  62. void selectAll();
  63. void deselectAll();
  64. void select(ModuleWidget* mw, bool selected = true);
  65. bool hasSelection();
  66. const std::set<ModuleWidget*>& getSelected();
  67. bool isSelected(ModuleWidget* mw);
  68. json_t* selectionToJson(bool cables = true);
  69. void loadSelection(std::string path);
  70. void loadSelectionDialog();
  71. void saveSelection(std::string path);
  72. void saveSelectionDialog();
  73. void copyClipboardSelection();
  74. void resetSelectionAction();
  75. void randomizeSelectionAction();
  76. void disconnectSelectionAction();
  77. void cloneSelectionAction(bool cloneCables = true);
  78. void bypassSelectionAction(bool bypassed);
  79. bool isSelectionBypassed();
  80. void deleteSelectionAction();
  81. bool requestSelectionPos(math::Vec delta);
  82. void setSelectionPosNearest(math::Vec delta);
  83. void appendSelectionContextMenu(ui::Menu* menu);
  84. // Cable methods
  85. void clearCables();
  86. void clearCablesAction();
  87. /** Removes all cables connected to the port */
  88. void clearCablesOnPort(PortWidget* port);
  89. /** Adds a complete cable and adopts ownership.
  90. */
  91. void addCable(CableWidget* cw);
  92. /** Removes cable and releases ownership to caller.
  93. */
  94. void removeCable(CableWidget* cw);
  95. CableWidget* getIncompleteCable();
  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. std::vector<CableWidget*> getCompleteCablesOnPort(PortWidget* port);
  106. /** Returns but does not advance the next cable color. */
  107. int getNextCableColorId();
  108. void setNextCableColorId(int id);
  109. /** Returns and advances the next cable color. */
  110. NVGcolor getNextCableColor();
  111. ParamWidget* getTouchedParam();
  112. void setTouchedParam(ParamWidget* pw);
  113. PRIVATE void updateExpanders();
  114. };
  115. } // namespace app
  116. } // namespace rack