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.

123 lines
3.6KB

  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 loadSelectionDialog();
  69. void saveSelectionDialog();
  70. void copyClipboardSelection();
  71. void resetSelectionAction();
  72. void randomizeSelectionAction();
  73. void disconnectSelectionAction();
  74. void cloneSelectionAction();
  75. void bypassSelectionAction(bool bypassed);
  76. bool isSelectionBypassed();
  77. void deleteSelectionAction();
  78. bool requestSelectionPos(math::Vec delta);
  79. void setSelectionPosNearest(math::Vec delta);
  80. void appendSelectionContextMenu(ui::Menu* menu);
  81. // Cable methods
  82. void clearCables();
  83. void clearCablesAction();
  84. /** Removes all cables connected to the port */
  85. void clearCablesOnPort(PortWidget* port);
  86. /** Adds a complete cable and adopts ownership.
  87. */
  88. void addCable(CableWidget* cw);
  89. /** Removes cable and releases ownership to caller.
  90. */
  91. void removeCable(CableWidget* cw);
  92. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  93. void setIncompleteCable(CableWidget* cw);
  94. CableWidget* releaseIncompleteCable();
  95. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  96. CableWidget* getTopCable(PortWidget* port);
  97. CableWidget* getCable(int64_t cableId);
  98. std::vector<CableWidget*> getCompleteCables();
  99. /** Returns all cables attached to port, complete or not. */
  100. std::vector<CableWidget*> getCablesOnPort(PortWidget* port);
  101. };
  102. } // namespace app
  103. } // namespace rack