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.

78 lines
2.2KB

  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. void toggleBypass();
  34. /** Disconnects cables from all ports
  35. Called when the user clicks Disconnect Cables in the context menu.
  36. */
  37. virtual void disconnect();
  38. /** Resets the parameters of the module and calls the Module's randomize().
  39. Called when the user clicks Initialize in the context menu.
  40. */
  41. virtual void reset();
  42. /** Deprecated */
  43. virtual void initialize() final {}
  44. /** Randomizes the parameters of the module and calls the Module's randomize().
  45. Called when the user clicks Randomize in the context menu.
  46. */
  47. virtual void randomize();
  48. /** Do not subclass this to add context menu entries. Use appendContextMenu() instead */
  49. virtual Menu *createContextMenu();
  50. /** Override to add context menu entries to your subclass.
  51. It is recommended to add a blank MenuEntry first for spacing.
  52. */
  53. virtual void appendContextMenu(Menu *menu) {}
  54. void draw(NVGcontext *vg) override;
  55. void drawShadow(NVGcontext *vg);
  56. math::Vec dragPos;
  57. void onHover(const event::Hover &e) override;
  58. void onButton(const event::Button &e) override;
  59. void onHoverKey(const event::HoverKey &e) override;
  60. void onDragStart(const event::DragStart &e) override;
  61. void onDragEnd(const event::DragEnd &e) override;
  62. void onDragMove(const event::DragMove &e) override;
  63. };
  64. } // namespace rack