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.

98 lines
2.9KB

  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 onButton(const ButtonEvent& e) override;
  33. void onDragStart(const DragStartEvent& e) override;
  34. void onDragEnd(const DragEndEvent& e) override;
  35. void onDragHover(const DragHoverEvent& e) override;
  36. // Rack methods
  37. /** Completely clear the rack's modules and cables */
  38. void clear();
  39. void mergeJson(json_t* rootJ);
  40. void fromJson(json_t* rootJ);
  41. void pastePresetClipboardAction();
  42. // Module methods
  43. /** Adds a module and adds it to the Engine
  44. Ownership rules work like add/removeChild()
  45. */
  46. void addModule(ModuleWidget* mw);
  47. void addModuleAtMouse(ModuleWidget* mw);
  48. /** Removes the module and transfers ownership to the caller */
  49. void removeModule(ModuleWidget* mw);
  50. /** Sets a module's box if non-colliding. Returns true if set */
  51. bool requestModulePos(ModuleWidget* mw, math::Vec pos);
  52. /** Moves a module to the closest non-colliding position */
  53. void setModulePosNearest(ModuleWidget* mw, math::Vec pos);
  54. void setModulePosForce(ModuleWidget* mw, math::Vec pos);
  55. ModuleWidget* getModule(int64_t moduleId);
  56. bool isEmpty();
  57. void updateModuleOldPositions();
  58. history::ComplexAction* getModuleDragAction();
  59. void updateModuleSelections();
  60. // Cable methods
  61. void clearCables();
  62. void clearCablesAction();
  63. /** Removes all complete cables connected to the port */
  64. void clearCablesOnPort(PortWidget* port);
  65. /** Adds a complete cable.
  66. Ownership rules work like add/removeChild()
  67. */
  68. void addCable(CableWidget* cw);
  69. void removeCable(CableWidget* cw);
  70. /** Takes ownership of `cw` and adds it as a child if it isn't already. */
  71. void setIncompleteCable(CableWidget* cw);
  72. CableWidget* releaseIncompleteCable();
  73. /** Returns the most recently added complete cable connected to the given Port, i.e. the top of the stack. */
  74. CableWidget* getTopCable(PortWidget* port);
  75. CableWidget* getCable(int64_t cableId);
  76. /** Returns all cables attached to port, complete or not. */
  77. std::list<CableWidget*> getCablesOnPort(PortWidget* port);
  78. };
  79. } // namespace app
  80. } // namespace rack