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.

63 lines
1.7KB

  1. #pragma once
  2. #include "app/common.hpp"
  3. #include "widgets/OpaqueWidget.hpp"
  4. #include "widgets/FramebufferWidget.hpp"
  5. #include "app/WireContainer.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 WireWidgets in here
  13. WireContainer *wireContainer;
  14. std::string lastPath;
  15. math::Vec lastMousePos;
  16. bool lockModules = false;
  17. RackWidget();
  18. ~RackWidget();
  19. /** Completely clear the rack's modules and wires */
  20. void clear();
  21. /** Clears the rack and loads the template patch */
  22. void reset();
  23. void loadDialog();
  24. void saveDialog();
  25. void saveAsDialog();
  26. /** If `lastPath` is defined, ask the user to reload it */
  27. void revert();
  28. /** Disconnects all wires */
  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. /** Removes the module and transfers ownership to the caller */
  39. void deleteModule(ModuleWidget *m);
  40. void cloneModule(ModuleWidget *m);
  41. /** Sets a module's box if non-colliding. Returns true if set */
  42. bool requestModuleBox(ModuleWidget *m, math::Rect box);
  43. /** Moves a module to the closest non-colliding position */
  44. bool requestModuleBoxNearest(ModuleWidget *m, math::Rect box);
  45. void step() override;
  46. void draw(NVGcontext *vg) override;
  47. void onHover(event::Hover &e) override;
  48. void onButton(event::Button &e) override;
  49. void onZoom(event::Zoom &e) override;
  50. };
  51. } // namespace rack