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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "app/common.hpp"
  3. #include "widget/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. namespace app {
  11. struct ModuleWidget : widget::OpaqueWidget {
  12. plugin::Model *model = NULL;
  13. /** Owns the module pointer */
  14. engine::Module *module = NULL;
  15. widget::Widget *panel = NULL;
  16. std::vector<ParamWidget*> params;
  17. std::vector<PortWidget*> outputs;
  18. std::vector<PortWidget*> inputs;
  19. /** For RackWidget dragging */
  20. math::Vec dragPos;
  21. math::Vec oldPos;
  22. ModuleWidget() {}
  23. DEPRECATED ModuleWidget(engine::Module *module) {
  24. setModule(module);
  25. }
  26. ~ModuleWidget();
  27. void draw(const widget::DrawContext &ctx) override;
  28. void drawShadow(const widget::DrawContext &ctx);
  29. void onHover(const event::Hover &e) override;
  30. void onButton(const event::Button &e) override;
  31. void onHoverKey(const event::HoverKey &e) override;
  32. void onDragStart(const event::DragStart &e) override;
  33. void onDragEnd(const event::DragEnd &e) override;
  34. void onDragMove(const event::DragMove &e) override;
  35. /** Associates this ModuleWidget with the Module
  36. Transfers ownership
  37. */
  38. void setModule(engine::Module *module);
  39. void setPanel(std::shared_ptr<Svg> svg);
  40. /** Convenience functions for adding special widgets (calls addChild()) */
  41. void addParam(ParamWidget *param);
  42. void addOutput(PortWidget *output);
  43. void addInput(PortWidget *input);
  44. ParamWidget *getParam(int paramId);
  45. PortWidget *getOutput(int outputId);
  46. PortWidget *getInput(int inputId);
  47. /** Overriding these is deprecated.
  48. Use Module::dataToJson() and dataFromJson() instead
  49. */
  50. virtual json_t *toJson();
  51. virtual void fromJson(json_t *rootJ);
  52. /** Serializes/unserializes the module state */
  53. void copyClipboard();
  54. void pasteClipboardAction();
  55. void loadAction(std::string filename);
  56. void save(std::string filename);
  57. void loadDialog();
  58. void saveDialog();
  59. /** Disconnects cables from all ports
  60. Called when the user clicks Disconnect Cables in the context menu.
  61. */
  62. void disconnect();
  63. /** Resets the parameters of the module and calls the Module's randomize().
  64. Called when the user clicks Initialize in the context menu.
  65. */
  66. void resetAction();
  67. /** Randomizes the parameters of the module and calls the Module's randomize().
  68. Called when the user clicks Randomize in the context menu.
  69. */
  70. void randomizeAction();
  71. void disconnectAction();
  72. void cloneAction();
  73. void bypassAction();
  74. /** Deletes `this` */
  75. void removeAction();
  76. void createContextMenu();
  77. /** Override to add context menu entries to your subclass.
  78. It is recommended to add a blank ui::MenuEntry first for spacing.
  79. */
  80. virtual void appendContextMenu(ui::Menu *menu) {}
  81. };
  82. } // namespace app
  83. } // namespace rack