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.

77 lines
2.1KB

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