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.

62 lines
1.6KB

  1. #pragma once
  2. #include "common.hpp"
  3. #include "WireWidget.hpp"
  4. #include "WireContainer.hpp"
  5. #include "engine.hpp"
  6. namespace rack {
  7. struct RackWidget : OpaqueWidget {
  8. FramebufferWidget *rails;
  9. // Only put ModuleWidgets in here
  10. Widget *moduleContainer;
  11. // Only put WireWidgets in here
  12. WireContainer *wireContainer;
  13. std::string lastPath;
  14. Vec lastMousePos;
  15. bool lockModules = false;
  16. RackWidget();
  17. ~RackWidget();
  18. /** Completely clear the rack's modules and wires */
  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. /** If `lastPath` is defined, ask the user to reload it */
  26. void revert();
  27. /** Disconnects all wires */
  28. void disconnect();
  29. void save(std::string filename);
  30. void load(std::string filename);
  31. json_t *toJson();
  32. void fromJson(json_t *rootJ);
  33. /** Creates a module and adds it to the rack */
  34. ModuleWidget *moduleFromJson(json_t *moduleJ);
  35. void pastePresetClipboard();
  36. void addModule(ModuleWidget *m);
  37. /** Removes the module and transfers ownership to the caller */
  38. void deleteModule(ModuleWidget *m);
  39. void cloneModule(ModuleWidget *m);
  40. /** Sets a module's box if non-colliding. Returns true if set */
  41. bool requestModuleBox(ModuleWidget *m, Rect box);
  42. /** Moves a module to the closest non-colliding position */
  43. bool requestModuleBoxNearest(ModuleWidget *m, Rect box);
  44. void step() override;
  45. void draw(NVGcontext *vg) override;
  46. void onHover(event::Hover &e) override;
  47. void onButton(event::Button &e) override;
  48. void onZoom(event::Zoom &e) override;
  49. };
  50. } // namespace rack