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.

ModuleWidget.hpp 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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*> outputs;
  17. std::vector<PortWidget*> inputs;
  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. void setPanel(std::shared_ptr<SVG> svg);
  39. /** Convenience functions for adding special widgets (calls addChild()) */
  40. void addParam(ParamWidget *param);
  41. void addOutput(PortWidget *output);
  42. void addInput(PortWidget *input);
  43. ParamWidget *getParam(int paramId);
  44. PortWidget *getOutput(int outputId);
  45. PortWidget *getInput(int inputId);
  46. /** Overriding these is deprecated.
  47. Use Module::dataToJson() and dataFromJson() instead
  48. */
  49. virtual json_t *toJson();
  50. virtual void fromJson(json_t *rootJ);
  51. /** Serializes/unserializes the module state */
  52. void copyClipboard();
  53. void pasteClipboardAction();
  54. void loadAction(std::string filename);
  55. void save(std::string filename);
  56. void loadDialog();
  57. void saveDialog();
  58. /** Disconnects cables from all ports
  59. Called when the user clicks Disconnect Cables in the context menu.
  60. */
  61. void disconnect();
  62. /** Resets the parameters of the module and calls the Module's randomize().
  63. Called when the user clicks Initialize in the context menu.
  64. */
  65. void resetAction();
  66. /** Randomizes the parameters of the module and calls the Module's randomize().
  67. Called when the user clicks Randomize in the context menu.
  68. */
  69. void randomizeAction();
  70. void disconnectAction();
  71. void cloneAction();
  72. void bypassAction();
  73. /** Deletes `this` */
  74. void removeAction();
  75. void createContextMenu();
  76. /** Override to add context menu entries to your subclass.
  77. It is recommended to add a blank MenuEntry first for spacing.
  78. */
  79. virtual void appendContextMenu(Menu *menu) {}
  80. };
  81. } // namespace rack