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.

97 lines
2.8KB

  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
  42. Ownership rules work like add/removeChild()
  43. */
  44. void addModule(ModuleWidget* mw);
  45. void addModuleAtMouse(ModuleWidget* mw);
  46. /** Removes the module and transfers ownership to the caller */
  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. bool isEmpty();
  55. void updateModuleOldPositions();
  56. history::ComplexAction* getModuleDragAction();
  57. void updateModuleSelections();
  58. // Cable methods
  59. void clearCables();
  60. void clearCablesAction();
  61. /** Removes all complete cables connected to the port */
  62. void clearCablesOnPort(PortWidget* port);
  63. /** Adds a complete cable.
  64. Ownership rules work like add/removeChild()
  65. */
  66. void addCable(CableWidget* cw);
  67. void removeCable(CableWidget* cw);
  68. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  69. void setIncompleteCable(CableWidget* cw);
  70. CableWidget* releaseIncompleteCable();
  71. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  72. CableWidget* getTopCable(PortWidget* port);
  73. CableWidget* getCable(int64_t cableId);
  74. /** Returns all cables attached to port, complete or not. */
  75. std::list<CableWidget*> getCablesOnPort(PortWidget* port);
  76. };
  77. } // namespace app
  78. } // namespace rack