|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #pragma once
- #include <app/common.hpp>
- #include <widget/OpaqueWidget.hpp>
- #include <ui/Menu.hpp>
- #include <app/PortWidget.hpp>
- #include <app/ParamWidget.hpp>
- #include <plugin/Model.hpp>
- #include <engine/Module.hpp>
-
-
- namespace rack {
- namespace app {
-
-
- /** Manages an engine::Module in the rack. */
- struct ModuleWidget : widget::OpaqueWidget {
- struct Internal;
- Internal* internal;
-
- plugin::Model* model = NULL;
- /** Owned. */
- engine::Module* module = NULL;
-
- ModuleWidget();
- DEPRECATED ModuleWidget(engine::Module* module) : ModuleWidget() {
- setModule(module);
- }
- ~ModuleWidget();
-
- void draw(const DrawArgs& args) override;
- void drawShadow(const DrawArgs& args);
-
- void onButton(const ButtonEvent& e) override;
- void onHoverKey(const HoverKeyEvent& e) override;
- void onDragStart(const DragStartEvent& e) override;
- void onDragEnd(const DragEndEvent& e) override;
- void onDragMove(const DragMoveEvent& e) override;
-
- /** Associates this ModuleWidget with the Module.
- Transfers ownership.
- */
- void setModule(engine::Module* module);
- /** Sets the panel and sets the size of the ModuleWidget from the panel.
- Transfers ownership.
- */
- void setPanel(widget::Widget* panel);
- /** Use `setPanel(createPanel(svg))` instead. */
- void setPanel(std::shared_ptr<Svg> svg);
-
- /** Convenience functions for adding special widgets.
- Just calls addChild() with additional checking.
- It is not required to call this method. You may instead use addChild() in a child widget for example.
- */
- void addParam(ParamWidget* param);
- void addInput(PortWidget* input);
- void addOutput(PortWidget* output);
- /** Scans children widgets recursively for a ParamWidget with the given paramId. */
- ParamWidget* getParam(int paramId);
- PortWidget* getInput(int portId);
- PortWidget* getOutput(int portId);
-
- json_t* toJson();
- void fromJson(json_t* rootJ);
- void copyClipboard();
- void pasteClipboardAction();
- void load(std::string filename);
- void loadAction(std::string filename);
- void loadTemplate();
- void loadDialog();
- void save(std::string filename);
- void saveTemplate();
- void saveTemplateDialog();
- bool hasTemplate();
- void clearTemplate();
- void clearTemplateDialog();
- void saveDialog();
-
- /** Disconnects cables from all ports
- Called when the user clicks Disconnect Cables in the context menu.
- */
- void disconnect();
-
- /** Resets the parameters of the module and calls the Module's randomize().
- Called when the user clicks Initialize in the context menu.
- */
- void resetAction();
- /** Randomizes the parameters of the module and calls the Module's randomize().
- Called when the user clicks Randomize in the context menu.
- */
- void randomizeAction();
- void disconnectAction();
- void cloneAction();
- void bypassAction();
- /** Deletes `this` */
- void removeAction();
- void createContextMenu();
- /** Override to add context menu entries to your subclass.
- It is recommended to add a blank ui::MenuEntry first for spacing.
- */
- virtual void appendContextMenu(ui::Menu* menu) {}
-
- INTERNAL math::Vec& dragOffset();
- INTERNAL bool& dragEnabled();
- INTERNAL math::Vec& oldPos();
- INTERNAL engine::Module* releaseModule();
- };
-
-
- } // namespace app
- } // namespace rack
|