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.

120 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 fromJsonAction(json_t* rootJ);
  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 updateModuleSelections();
  61. void deselectModules();
  62. void selectAllModules();
  63. bool hasSelectedModules();
  64. int getNumSelectedModules();
  65. std::vector<ModuleWidget*> getSelectedModules();
  66. json_t* selectedModulesToJson();
  67. void resetSelectedModulesAction();
  68. void randomizeSelectedModulesAction();
  69. void disconnectSelectedModulesAction();
  70. void cloneSelectedModulesAction();
  71. void bypassSelectedModulesAction(bool bypassed);
  72. bool areSelectedModulesBypassed();
  73. void copyClipboardSelectedModules();
  74. void deleteSelectedModulesAction();
  75. bool requestSelectedModulePos(math::Vec delta);
  76. void setSelectedModulesPosNearest(math::Vec delta);
  77. void appendSelectionContextMenu(ui::Menu* menu);
  78. // Cable methods
  79. void clearCables();
  80. void clearCablesAction();
  81. /** Removes all cables connected to the port */
  82. void clearCablesOnPort(PortWidget* port);
  83. /** Adds a complete cable and adopts ownership.
  84. */
  85. void addCable(CableWidget* cw);
  86. /** Removes cable and releases ownership to caller.
  87. */
  88. void removeCable(CableWidget* cw);
  89. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  90. void setIncompleteCable(CableWidget* cw);
  91. CableWidget* releaseIncompleteCable();
  92. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  93. CableWidget* getTopCable(PortWidget* port);
  94. CableWidget* getCable(int64_t cableId);
  95. std::vector<CableWidget*> getCompleteCables();
  96. /** Returns all cables attached to port, complete or not. */
  97. std::vector<CableWidget*> getCablesOnPort(PortWidget* port);
  98. };
  99. } // namespace app
  100. } // namespace rack