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

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