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.

118 lines
3.2KB

  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. /** Manages an engine::Module in the rack. */
  12. struct ModuleWidget : widget::OpaqueWidget {
  13. struct Internal;
  14. Internal* internal;
  15. plugin::Model* model = NULL;
  16. /** Owned */
  17. engine::Module* module = NULL;
  18. ModuleWidget();
  19. DEPRECATED ModuleWidget(engine::Module* module) : ModuleWidget() {
  20. setModule(module);
  21. }
  22. ~ModuleWidget();
  23. plugin::Model* getModel();
  24. void setModel(plugin::Model* model);
  25. engine::Module* getModule();
  26. /** Associates this ModuleWidget with the Module.
  27. Transfers ownership.
  28. */
  29. void setModule(engine::Module* module);
  30. /** Sets the panel and sets the size of the ModuleWidget from the panel.
  31. Transfers ownership.
  32. */
  33. void setPanel(widget::Widget* panel);
  34. /** Use `setPanel(createPanel(svg))` instead. */
  35. void setPanel(std::shared_ptr<Svg> svg);
  36. /** Convenience functions for adding special widgets.
  37. Just calls addChild() with additional checking.
  38. It is not required to call this method. You may instead use addChild() in a child widget for example.
  39. */
  40. void addParam(ParamWidget* param);
  41. void addInput(PortWidget* input);
  42. void addOutput(PortWidget* output);
  43. /** Scans children widgets recursively for a ParamWidget with the given paramId. */
  44. ParamWidget* getParam(int paramId);
  45. PortWidget* getInput(int portId);
  46. PortWidget* getOutput(int portId);
  47. void draw(const DrawArgs& args) override;
  48. void drawShadow(const DrawArgs& args);
  49. /** Override to add context menu entries to your subclass.
  50. It is recommended to add a blank ui::MenuEntry first for spacing.
  51. */
  52. virtual void appendContextMenu(ui::Menu* menu) {}
  53. void onButton(const ButtonEvent& e) override;
  54. void onHoverKey(const HoverKeyEvent& e) override;
  55. void onDragStart(const DragStartEvent& e) override;
  56. void onDragEnd(const DragEndEvent& e) override;
  57. void onDragMove(const DragMoveEvent& e) override;
  58. json_t* toJson();
  59. void fromJson(json_t* rootJ);
  60. void copyClipboard();
  61. void pasteClipboardAction();
  62. void load(std::string filename);
  63. void loadAction(std::string filename);
  64. void loadTemplate();
  65. void loadDialog();
  66. void save(std::string filename);
  67. void saveTemplate();
  68. void saveTemplateDialog();
  69. bool hasTemplate();
  70. void clearTemplate();
  71. void clearTemplateDialog();
  72. void saveDialog();
  73. /** Disconnects cables from all ports
  74. Called when the user clicks Disconnect Cables in the context menu.
  75. */
  76. void disconnect();
  77. /** Resets the parameters of the module and calls the Module's randomize().
  78. Called when the user clicks Initialize in the context menu.
  79. */
  80. void resetAction();
  81. /** Randomizes the parameters of the module and calls the Module's randomize().
  82. Called when the user clicks Randomize in the context menu.
  83. */
  84. void randomizeAction();
  85. void disconnectAction();
  86. void cloneAction();
  87. void bypassAction();
  88. /** Deletes `this` */
  89. void removeAction();
  90. void createContextMenu();
  91. INTERNAL math::Vec& dragOffset();
  92. INTERNAL bool& dragEnabled();
  93. INTERNAL math::Vec& oldPos();
  94. INTERNAL engine::Module* releaseModule();
  95. INTERNAL bool& selected();
  96. };
  97. } // namespace app
  98. } // namespace rack