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.

107 lines
3.0KB

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