Benutzer
How do I make my own control?
How do I make my own control?
Creating your own control in iPlug2 involves subclassing the IControl class and overriding specific methods to define your control's behavior and appearance. Here's a step-by-step guide on how to do this:
First, include the IControl.h header in your source file where you intend to define the custom control.
#include "IControl.h"
Create a class that inherits from IControl. Override the Draw method to define how your control should be rendered. You can also override other event handling methods like OnMouseDown, OnMouseUp, OnMouseMove, etc., to define how your control responds to user interactions.
Here's an example of a simple custom control that draws a colored rectangle:
class MyCustomControl : public IControl {
public:
MyCustomControl(const IRECT& bounds, const IColor& color)
: IControl(bounds), mColor(color) {}
void Draw(IGraphics& g) override {
g.FillRect(mColor, mRECT);
}
private:
IColor mColor;
};
In this example, MyCustomControl takes a rectangle (IRECT) defining its bounds and a color (IColor) for the fill. The Draw method uses these to draw a simple rectangle.
In your plugin's layout initialization function, create an instance of your custom control and add it to the graphics context. This is typically done in the constructor of your plugin class or a dedicated layout initialization method.
mLayoutFunc = [&](IGraphics* pGraphics) {
// ... other UI setup ...
// Add your custom control
pGraphics->AttachControl(new MyCustomControl(bounds, COLOR_RED));
};
Ensure that bounds is an IRECT object defining where on the UI your control should appear.
Compile your plugin and test the custom control in your plugin's UI. Make sure it behaves as expected and renders correctly.
OnMouseDown, OnMouseDrag, OnMouseUp, etc.SetActionFunction to define actions that should occur when the control's value changes (e.g., modifying a parameter).SetParamIdx to link it to a specific parameter.This is a basic template. Depending on what you want your control to do (display text, handle user input, animate, etc.), you might need to override additional methods or add more member variables. Remember, the key is to define how your control looks and behaves in the overridden methods of the IControl class.