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.3KB

  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 setModule(Module *module);
  27. /** Convenience functions for adding special widgets (calls addChild()) */
  28. void addInput(PortWidget *input);
  29. void addOutput(PortWidget *output);
  30. void addParam(ParamWidget *param);
  31. void setPanel(std::shared_ptr<SVG> svg);
  32. virtual json_t *toJson();
  33. virtual void fromJson(json_t *rootJ);
  34. void copyClipboard();
  35. void pasteClipboard();
  36. void load(std::string filename);
  37. void save(std::string filename);
  38. void loadDialog();
  39. void saveDialog();
  40. /** Disconnects cables from all ports
  41. Called when the user clicks Disconnect Cables in the context menu.
  42. */
  43. virtual void disconnect();
  44. /** Resets the parameters of the module and calls the Module's randomize().
  45. Called when the user clicks Initialize in the context menu.
  46. */
  47. virtual void reset();
  48. /** Deprecated */
  49. virtual void initialize() final {}
  50. /** Randomizes the parameters of the module and calls the Module's randomize().
  51. Called when the user clicks Randomize in the context menu.
  52. */
  53. virtual void randomize();
  54. /** Do not subclass this to add context menu entries. Use appendContextMenu() instead */
  55. virtual Menu *createContextMenu();
  56. /** Override to add context menu entries to your subclass.
  57. It is recommended to add a blank MenuEntry first for spacing.
  58. */
  59. virtual void appendContextMenu(Menu *menu) {}
  60. void draw(NVGcontext *vg) override;
  61. void drawShadow(NVGcontext *vg);
  62. void onHover(const event::Hover &e) override;
  63. void onButton(const event::Button &e) override;
  64. void onHoverKey(const event::HoverKey &e) override;
  65. void onDragStart(const event::DragStart &e) override;
  66. void onDragEnd(const event::DragEnd &e) override;
  67. void onDragMove(const event::DragMove &e) override;
  68. };
  69. } // namespace rack