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.

84 lines
2.2KB

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