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.

125 lines
3.7KB

  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. namespace rack {
  13. namespace app {
  14. /** Container for ModuleWidget and CableWidget. */
  15. struct RackWidget : widget::OpaqueWidget {
  16. struct Internal;
  17. Internal* internal;
  18. CableWidget* incompleteCable = NULL;
  19. ParamWidget* touchedParam = NULL;
  20. int nextCableColorId = 0;
  21. RackWidget();
  22. ~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 deselect();
  64. bool hasSelection();
  65. int getNumSelected();
  66. std::vector<ModuleWidget*> getSelectedModules();
  67. json_t* selectionToJson();
  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();
  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. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  95. void setIncompleteCable(CableWidget* cw);
  96. CableWidget* releaseIncompleteCable();
  97. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  98. CableWidget* getTopCable(PortWidget* port);
  99. CableWidget* getCable(int64_t cableId);
  100. std::vector<CableWidget*> getCompleteCables();
  101. /** Returns all cables attached to port, complete or not. */
  102. std::vector<CableWidget*> getCablesOnPort(PortWidget* port);
  103. };
  104. } // namespace app
  105. } // namespace rack