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.

110 lines
3.3KB

  1. #pragma once
  2. #include <map>
  3. #include <app/common.hpp>
  4. #include <widget/OpaqueWidget.hpp>
  5. #include <widget/FramebufferWidget.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 pastePresetClipboardAction();
  40. // Module methods
  41. /** Adds a module and adds it to the Engine, adopting ownership.
  42. */
  43. void addModule(ModuleWidget* mw);
  44. void addModuleAtMouse(ModuleWidget* mw);
  45. /** Removes the module and transfers ownership to the caller.
  46. */
  47. void removeModule(ModuleWidget* mw);
  48. /** Sets a module's box if non-colliding. Returns true if set */
  49. bool requestModulePos(ModuleWidget* mw, math::Vec pos);
  50. /** Moves a module to the closest non-colliding position */
  51. void setModulePosNearest(ModuleWidget* mw, math::Vec pos);
  52. void setModulePosForce(ModuleWidget* mw, math::Vec pos);
  53. ModuleWidget* getModule(int64_t moduleId);
  54. std::list<ModuleWidget*> getModules();
  55. bool hasModules();
  56. void updateModuleOldPositions();
  57. history::ComplexAction* getModuleDragAction();
  58. void updateModuleSelections();
  59. int getNumSelectedModules();
  60. std::list<ModuleWidget*> getSelectedModules();
  61. void resetSelectedModulesAction();
  62. void randomizeSelectedModulesAction();
  63. void disconnectSelectedModulesAction();
  64. void bypassSelectedModulesAction(bool bypassed);
  65. bool areSelectedModulesBypassed();
  66. void deleteSelectedModulesAction();
  67. bool requestSelectedModulePos(math::Vec delta);
  68. // Cable methods
  69. void clearCables();
  70. void clearCablesAction();
  71. /** Removes all cables connected to the port */
  72. void clearCablesOnPort(PortWidget* port);
  73. /** Adds a complete cable and adopts ownership.
  74. */
  75. void addCable(CableWidget* cw);
  76. /** Removes cable and releases ownership to caller.
  77. */
  78. void removeCable(CableWidget* cw);
  79. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  80. void setIncompleteCable(CableWidget* cw);
  81. CableWidget* releaseIncompleteCable();
  82. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  83. CableWidget* getTopCable(PortWidget* port);
  84. CableWidget* getCable(int64_t cableId);
  85. std::list<CableWidget*> getCompleteCables();
  86. /** Returns all cables attached to port, complete or not. */
  87. std::list<CableWidget*> getCablesOnPort(PortWidget* port);
  88. };
  89. } // namespace app
  90. } // namespace rack