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.

91 lines
2.7KB

  1. #pragma once
  2. #include <map>
  3. #include <app/common.hpp>
  4. #include <widget/OpaqueWidget.hpp>
  5. #include <widget/FramebufferWidget.hpp>
  6. #include <app/ModuleWidget.hpp>
  7. #include <app/CableWidget.hpp>
  8. #include <app/PortWidget.hpp>
  9. #include <app/ParamWidget.hpp>
  10. #include <history.hpp>
  11. namespace rack {
  12. namespace app {
  13. /** Container for ModuleWidget and CableWidget. */
  14. struct RackWidget : widget::OpaqueWidget {
  15. struct Internal;
  16. Internal* internal;
  17. widget::Widget* moduleContainer;
  18. widget::Widget* cableContainer;
  19. CableWidget* incompleteCable = NULL;
  20. /** The last mouse position in the RackWidget */
  21. math::Vec mousePos;
  22. ParamWidget* touchedParam = NULL;
  23. int nextCableColorId = 0;
  24. RackWidget();
  25. ~RackWidget();
  26. void step() override;
  27. void draw(const DrawArgs& args) override;
  28. void onHover(const HoverEvent& e) override;
  29. void onHoverKey(const HoverKeyEvent& e) override;
  30. void onDragHover(const DragHoverEvent& e) override;
  31. void onButton(const ButtonEvent& e) override;
  32. /** Completely clear the rack's modules and cables */
  33. void clear();
  34. void mergeJson(json_t* rootJ);
  35. void fromJson(json_t* rootJ);
  36. void pastePresetClipboardAction();
  37. // Module methods
  38. /** Adds a module and adds it to the Engine
  39. Ownership rules work like add/removeChild()
  40. */
  41. void addModule(ModuleWidget* mw);
  42. void addModuleAtMouse(ModuleWidget* mw);
  43. /** Removes the module and transfers ownership to the caller */
  44. void removeModule(ModuleWidget* mw);
  45. /** Sets a module's box if non-colliding. Returns true if set */
  46. bool requestModulePos(ModuleWidget* mw, math::Vec pos);
  47. /** Moves a module to the closest non-colliding position */
  48. void setModulePosNearest(ModuleWidget* mw, math::Vec pos);
  49. void setModulePosForce(ModuleWidget* mw, math::Vec pos);
  50. ModuleWidget* getModule(int64_t moduleId);
  51. bool isEmpty();
  52. void updateModuleOldPositions();
  53. history::ComplexAction* getModuleDragAction();
  54. // Cable methods
  55. void clearCables();
  56. void clearCablesAction();
  57. /** Removes all complete cables connected to the port */
  58. void clearCablesOnPort(PortWidget* port);
  59. /** Adds a complete cable.
  60. Ownership rules work like add/removeChild()
  61. */
  62. void addCable(CableWidget* cw);
  63. void removeCable(CableWidget* cw);
  64. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  65. void setIncompleteCable(CableWidget* cw);
  66. CableWidget* releaseIncompleteCable();
  67. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  68. CableWidget* getTopCable(PortWidget* port);
  69. CableWidget* getCable(int64_t cableId);
  70. /** Returns all cables attached to port, complete or not. */
  71. std::list<CableWidget*> getCablesOnPort(PortWidget* port);
  72. };
  73. } // namespace app
  74. } // namespace rack