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.

66 lines
1.8KB

  1. #pragma once
  2. #include "app/common.hpp"
  3. #include "widgets/OpaqueWidget.hpp"
  4. #include "widgets/FramebufferWidget.hpp"
  5. #include "app/CableContainer.hpp"
  6. #include "app/ModuleWidget.hpp"
  7. namespace rack {
  8. struct RackWidget : OpaqueWidget {
  9. FramebufferWidget *rails;
  10. // Only put ModuleWidgets in here
  11. Widget *moduleContainer;
  12. // Only put CableWidgets in here
  13. CableContainer *cableContainer;
  14. std::string lastPath;
  15. math::Vec lastMousePos;
  16. RackWidget();
  17. ~RackWidget();
  18. /** Completely clear the rack's modules and cables */
  19. void clear();
  20. /** Clears the rack and loads the template patch */
  21. void reset();
  22. void loadDialog();
  23. void saveDialog();
  24. void saveAsDialog();
  25. void saveTemplate();
  26. /** If `lastPath` is defined, ask the user to reload it */
  27. void revert();
  28. /** Disconnects all cables */
  29. void disconnect();
  30. void save(std::string filename);
  31. void load(std::string filename);
  32. json_t *toJson();
  33. void fromJson(json_t *rootJ);
  34. /** Creates a module and adds it to the rack */
  35. ModuleWidget *moduleFromJson(json_t *moduleJ);
  36. void pastePresetClipboard();
  37. void addModule(ModuleWidget *m);
  38. void addModuleAtMouse(ModuleWidget *m);
  39. /** Removes the module and transfers ownership to the caller */
  40. void removeModule(ModuleWidget *m);
  41. void cloneModule(ModuleWidget *m);
  42. /** Sets a module's box if non-colliding. Returns true if set */
  43. bool requestModuleBox(ModuleWidget *m, math::Rect box);
  44. /** Moves a module to the closest non-colliding position */
  45. bool requestModuleBoxNearest(ModuleWidget *m, math::Rect box);
  46. ModuleWidget *getModule(int moduleId);
  47. void step() override;
  48. void draw(NVGcontext *vg) override;
  49. void onHover(const event::Hover &e) override;
  50. void onDragHover(const event::DragHover &e) override;
  51. void onButton(const event::Button &e) override;
  52. void onZoom(const event::Zoom &e) override;
  53. };
  54. } // namespace rack