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

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