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.

RackWidget.hpp 2.7KB

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