VCV Rack API v2
Loading...
Searching...
No Matches
RackWidget.hpp
Go to the documentation of this file.
1#pragma once
2#include <app/common.hpp>
5#include <ui/Menu.hpp>
6#include <app/RailWidget.hpp>
8#include <app/CableWidget.hpp>
9#include <app/PortWidget.hpp>
10#include <app/ParamWidget.hpp>
11#include <history.hpp>
12
13#include <set>
14
15
16namespace rack {
17namespace app {
18
19
22 struct Internal;
23 Internal* internal;
24
27
30
31 void step() override;
32 void draw(const DrawArgs& args) override;
33
34 void onHover(const HoverEvent& e) override;
35 void onHoverKey(const HoverKeyEvent& e) override;
36 void onButton(const ButtonEvent& e) override;
37 void onDragStart(const DragStartEvent& e) override;
38 void onDragEnd(const DragEndEvent& e) override;
39 void onDragHover(const DragHoverEvent& e) override;
40
41 // Rack methods
42
47
49 void clear();
50 void mergeJson(json_t* rootJ);
51 void fromJson(json_t* rootJ);
53 void pasteJsonAction(json_t* rootJ);
54 void pasteModuleJsonAction(json_t* moduleJ);
56
57 // Module methods
58
66 ModuleWidget* getModule(int64_t moduleId);
67 std::vector<ModuleWidget*> getModules();
68 bool hasModules();
69
70 // Module position methods
71
85
86 // Module selection methods
87
89 void selectAll();
91 void select(ModuleWidget* mw, bool selected = true);
93 const std::set<ModuleWidget*>& getSelected();
95 json_t* selectionToJson(bool cables = true);
96 void loadSelection(std::string path);
98 void saveSelection(std::string path);
104 void cloneSelectionAction(bool cloneCables = true);
105 void bypassSelectionAction(bool bypassed);
111
112 // Cable methods
113
130 CableWidget* getCable(int64_t cableId);
131 CableWidget* getCable(PortWidget* outputPort, PortWidget* inputPort);
133 std::vector<CableWidget*> getCables();
135 std::vector<CableWidget*> getCompleteCables();
137 std::vector<CableWidget*> getIncompleteCables();
139 std::vector<CableWidget*> getCablesOnPort(PortWidget* port);
141 std::vector<CableWidget*> getCompleteCablesOnPort(PortWidget* port);
149
151};
152
153
154} // namespace app
155} // namespace rack
#define PRIVATE
Attribute for private functions not intended to be called by plugins.
Definition common.hpp:32
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:26
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Definition CableWidget.hpp:31
Manages an engine::Module in the rack.
Definition ModuleWidget.hpp:17
Manages an engine::Param on a ModuleWidget.
Definition ParamWidget.hpp:14
Definition CableWidget.hpp:16
Manages an engine::Port on a ModuleWidget.
Definition PortWidget.hpp:14
Container for ModuleWidget and CableWidget.
Definition RackWidget.hpp:21
PRIVATE void unsqueezeModulePos(ModuleWidget *mw)
void pasteModuleJsonAction(json_t *moduleJ)
widget::Widget * getPlugContainer()
bool requestSelectionPos(math::Vec delta)
Internal * internal
Definition RackWidget.hpp:23
PRIVATE void squeezeModulePos(ModuleWidget *mw, math::Vec pos)
history::ComplexAction * getModuleDragAction()
void setNextCableColorId(int id)
void cloneSelectionAction(bool cloneCables=true)
math::Vec getMousePos()
void pasteJsonAction(json_t *rootJ)
Pastes module JSON or selection JSON at the mouse position.
void clear()
Completely clear the rack's modules and cables.
std::vector< CableWidget * > getCablesOnPort(PortWidget *port)
Returns all cables attached to the port, complete or not.
void step() override
Advances the module by one frame.
void setModulePosNearest(ModuleWidget *mw, math::Vec pos)
Moves a module to the closest non-colliding position.
const std::set< ModuleWidget * > & getSelected()
void setSelectionPosNearest(math::Vec delta)
ModuleWidget * getModule(int64_t moduleId)
void bypassSelectionAction(bool bypassed)
void setModulePosForce(ModuleWidget *mw, math::Vec pos)
Moves a module to a position, pushing other modules in the same row to the left or right,...
CableWidget * getCable(PortWidget *outputPort, PortWidget *inputPort)
void onHoverKey(const HoverKeyEvent &e) override
void onHover(const HoverEvent &e) override
void onButton(const ButtonEvent &e) override
void mergeJson(json_t *rootJ)
PlugWidget * getTopPlug(PortWidget *port)
Returns the topmost plug stacked on the port.
DEPRECATED CableWidget * getIncompleteCable()
Returns the top incomplete cable.
void onDragHover(const DragHoverEvent &e) override
void draw(const DrawArgs &args) override
Draws the widget to the NanoVG context.
ParamWidget * touchedParam
DEPRECATED.
Definition RackWidget.hpp:26
CableWidget * getTopCable(PortWidget *port)
Returns the cable with the topmost plug stacked on the port.
void removeModule(ModuleWidget *mw)
Removes the module and transfers ownership to the caller.
void addModuleAtMouse(ModuleWidget *mw)
void setTouchedParam(ParamWidget *pw)
bool isSelected(ModuleWidget *mw)
bool requestModulePos(ModuleWidget *mw, math::Vec pos)
Sets a module's box if non-colliding.
void addCable(CableWidget *cw)
Adds a cable and adopts ownership.
ParamWidget * getTouchedParam()
std::vector< CableWidget * > getCompleteCablesOnPort(PortWidget *port)
Returns all complete cables attached to the port.
void appendSelectionContextMenu(ui::Menu *menu)
void setModulePosSqueeze(ModuleWidget *mw, math::Vec pos)
Moves a module, contracting old module positions and pushing modules to the right as needed to fit.
json_t * selectionToJson(bool cables=true)
void onDragStart(const DragStartEvent &e) override
void select(ModuleWidget *mw, bool selected=true)
widget::Widget * getModuleContainer()
void fromJson(json_t *rootJ)
PRIVATE void updateExpanders()
void updateModuleOldPositions()
Saves positions of modules for getModuleDragAction().
std::vector< CableWidget * > getIncompleteCables()
Returns all cables attached to less than 2 ports.
std::vector< ModuleWidget * > getModules()
void onDragEnd(const DragEndEvent &e) override
std::vector< CableWidget * > getCompleteCables()
Returns all cables attached to 2 ports.
void saveSelection(std::string path)
void loadSelection(std::string path)
void disconnectSelectionAction()
void clearCablesOnPort(PortWidget *port)
Removes all cables connected to the port.
CableWidget * getCable(int64_t cableId)
void addModule(ModuleWidget *mw)
Adds a module and adds it to the Engine, adopting ownership.
std::vector< CableWidget * > getCables()
Returns all cables, complete and incomplete.
int getNextCableColorId()
Returns but does not advance the next cable color.
void removeCable(CableWidget *cw)
Removes cable and releases ownership to caller.
widget::Widget * getCableContainer()
NVGcolor getNextCableColor()
Returns and advances the next cable color.
Batches multiple actions into one.
Definition history.hpp:52
2-dimensional vector of floats, representing a point on the plane for graphics.
Definition math.hpp:189
Definition Menu.hpp:11
A Widget that stops propagation of all recursive PositionEvents (such as ButtonEvent) but gives a cha...
Definition OpaqueWidget.hpp:12
Occurs each mouse button press or release.
Definition Widget.hpp:237
Occurs when a Widget stops being dragged by releasing the mouse button.
Definition Widget.hpp:375
Occurs every frame when the mouse is hovering over a Widget while another Widget (possibly the same o...
Definition Widget.hpp:391
Occurs when a Widget begins being dragged.
Definition Widget.hpp:369
Definition Widget.hpp:141
Occurs every frame when the mouse is hovering over a Widget.
Definition Widget.hpp:225
Occurs when a key is pressed, released, or repeated while the mouse is hovering a Widget.
Definition Widget.hpp:294
A node in the 2D scene graph.
Definition Widget.hpp:21