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.

93 lines
2.4KB

  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. /** For RackWidget dragging */
  19. math::Vec dragPos;
  20. math::Vec oldPos;
  21. ModuleWidget() {}
  22. DEPRECATED ModuleWidget(Module *module) {
  23. setModule(module);
  24. }
  25. ~ModuleWidget();
  26. void draw(NVGcontext *vg) override;
  27. void drawShadow(NVGcontext *vg);
  28. void onHover(const event::Hover &e) override;
  29. void onButton(const event::Button &e) override;
  30. void onHoverKey(const event::HoverKey &e) override;
  31. void onDragStart(const event::DragStart &e) override;
  32. void onDragEnd(const event::DragEnd &e) override;
  33. void onDragMove(const event::DragMove &e) override;
  34. /** Associates this ModuleWidget with the Module
  35. Transfers ownership
  36. */
  37. void setModule(Module *module);
  38. /** Convenience functions for adding special widgets (calls addChild()) */
  39. void addInput(PortWidget *input);
  40. void addOutput(PortWidget *output);
  41. void addParam(ParamWidget *param);
  42. void setPanel(std::shared_ptr<SVG> svg);
  43. /** Overriding these is deprecated.
  44. Use Module::dataToJson() and dataFromJson() instead
  45. */
  46. virtual json_t *toJson();
  47. virtual void fromJson(json_t *rootJ);
  48. /** Serializes/unserializes the module state */
  49. void copyClipboard();
  50. void pasteClipboard();
  51. void load(std::string filename);
  52. void save(std::string filename);
  53. void loadDialog();
  54. void saveDialog();
  55. /** Disconnects cables from all ports
  56. Called when the user clicks Disconnect Cables in the context menu.
  57. */
  58. void disconnect();
  59. /** Resets the parameters of the module and calls the Module's randomize().
  60. Called when the user clicks Initialize in the context menu.
  61. */
  62. void reset();
  63. /** Randomizes the parameters of the module and calls the Module's randomize().
  64. Called when the user clicks Randomize in the context menu.
  65. */
  66. void randomize();
  67. void removeAction();
  68. void bypassAction();
  69. void cloneAction();
  70. void createContextMenu();
  71. /** Override to add context menu entries to your subclass.
  72. It is recommended to add a blank MenuEntry first for spacing.
  73. */
  74. virtual void appendContextMenu(Menu *menu) {}
  75. };
  76. } // namespace rack