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.

75 lines
2.0KB

  1. #pragma once
  2. #include "widgets/OpaqueWidget.hpp"
  3. #include "app/SVGPanel.hpp"
  4. #include "plugin.hpp"
  5. #include "engine.hpp"
  6. namespace rack {
  7. struct ModuleWidget : OpaqueWidget {
  8. Model *model = NULL;
  9. /** Owns the module pointer */
  10. Module *module = NULL;
  11. SVGPanel *panel = NULL;
  12. std::vector<Port*> inputs;
  13. std::vector<Port*> outputs;
  14. std::vector<ParamWidget*> params;
  15. ModuleWidget(Module *module);
  16. ~ModuleWidget();
  17. /** Convenience functions for adding special widgets (calls addChild()) */
  18. void addInput(Port *input);
  19. void addOutput(Port *output);
  20. void addParam(ParamWidget *param);
  21. void setPanel(std::shared_ptr<SVG> svg);
  22. virtual json_t *toJson();
  23. virtual void fromJson(json_t *rootJ);
  24. void copyClipboard();
  25. void pasteClipboard();
  26. void save(std::string filename);
  27. void load(std::string filename);
  28. void loadDialog();
  29. void saveDialog();
  30. virtual void create();
  31. virtual void _delete();
  32. /** Disconnects cables from all ports
  33. Called when the user clicks Disconnect Cables in the context menu.
  34. */
  35. virtual void disconnect();
  36. /** Resets the parameters of the module and calls the Module's randomize().
  37. Called when the user clicks Initialize in the context menu.
  38. */
  39. virtual void reset();
  40. /** Deprecated */
  41. virtual void initialize() final {}
  42. /** Randomizes the parameters of the module and calls the Module's randomize().
  43. Called when the user clicks Randomize in the context menu.
  44. */
  45. virtual void randomize();
  46. /** Do not subclass this to add context menu entries. Use appendContextMenu() instead */
  47. virtual Menu *createContextMenu();
  48. /** Override to add context menu entries to your subclass.
  49. It is recommended to add a blank MenuEntry first for spacing.
  50. */
  51. virtual void appendContextMenu(Menu *menu) {}
  52. void draw(NVGcontext *vg) override;
  53. void drawShadow(NVGcontext *vg);
  54. math::Vec dragPos;
  55. void on(event::Hover &e) override;
  56. void on(event::Button &e) override;
  57. void on(event::HoverKey &e) override;
  58. void on(event::DragStart &e) override;
  59. void on(event::DragEnd &e) override;
  60. void on(event::DragMove &e) override;
  61. };
  62. } // namespace rack