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.

119 lines
3.5KB

  1. #pragma once
  2. #include <map>
  3. #include <app/common.hpp>
  4. #include <widget/OpaqueWidget.hpp>
  5. #include <widget/FramebufferWidget.hpp>
  6. #include <ui/Menu.hpp>
  7. #include <app/RailWidget.hpp>
  8. #include <app/ModuleWidget.hpp>
  9. #include <app/CableWidget.hpp>
  10. #include <app/PortWidget.hpp>
  11. #include <app/ParamWidget.hpp>
  12. #include <history.hpp>
  13. namespace rack {
  14. namespace app {
  15. /** Container for ModuleWidget and CableWidget. */
  16. struct RackWidget : widget::OpaqueWidget {
  17. struct Internal;
  18. Internal* internal;
  19. CableWidget* incompleteCable = NULL;
  20. ParamWidget* touchedParam = NULL;
  21. int nextCableColorId = 0;
  22. RackWidget();
  23. ~RackWidget();
  24. void step() override;
  25. void draw(const DrawArgs& args) override;
  26. void onHover(const HoverEvent& e) override;
  27. void onHoverKey(const HoverKeyEvent& e) override;
  28. void onButton(const ButtonEvent& e) override;
  29. void onDragStart(const DragStartEvent& e) override;
  30. void onDragEnd(const DragEndEvent& e) override;
  31. void onDragHover(const DragHoverEvent& e) override;
  32. // Rack methods
  33. widget::Widget* getModuleContainer();
  34. widget::Widget* getCableContainer();
  35. math::Vec getMousePos();
  36. /** Completely clear the rack's modules and cables */
  37. void clear();
  38. void mergeJson(json_t* rootJ);
  39. void fromJson(json_t* rootJ);
  40. void pastePresetClipboardAction();
  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::list<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::list<ModuleWidget*> getSelectedModules();
  66. void resetSelectedModulesAction();
  67. void randomizeSelectedModulesAction();
  68. void disconnectSelectedModulesAction();
  69. void cloneSelectedModulesAction();
  70. void bypassSelectedModulesAction(bool bypassed);
  71. bool areSelectedModulesBypassed();
  72. void deleteSelectedModulesAction();
  73. bool requestSelectedModulePos(math::Vec delta);
  74. void setSelectedModulesPosNearest(math::Vec delta);
  75. void appendSelectionContextMenu(ui::Menu* menu);
  76. // Cable methods
  77. void clearCables();
  78. void clearCablesAction();
  79. /** Removes all cables connected to the port */
  80. void clearCablesOnPort(PortWidget* port);
  81. /** Adds a complete cable and adopts ownership.
  82. */
  83. void addCable(CableWidget* cw);
  84. /** Removes cable and releases ownership to caller.
  85. */
  86. void removeCable(CableWidget* cw);
  87. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  88. void setIncompleteCable(CableWidget* cw);
  89. CableWidget* releaseIncompleteCable();
  90. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  91. CableWidget* getTopCable(PortWidget* port);
  92. CableWidget* getCable(int64_t cableId);
  93. std::list<CableWidget*> getCompleteCables();
  94. /** Returns all cables attached to port, complete or not. */
  95. std::list<CableWidget*> getCablesOnPort(PortWidget* port);
  96. };
  97. } // namespace app
  98. } // namespace rack