Hi, I use animationDemo exemple to help me in the making of “ADSR/envelope” class. I hope limit the left and right drag of my “anchors” component (class Hook), but the constrainer limits don’t make the job ! What can I do ?
class Hook : public Component, public ChangeBroadcaster
{
public:
Hook()
{
// In your constructor, you should add any child components, and
// initialise any special settings that your component needs.
}
~Hook()
{
}
void paint (Graphics& g) override
{
auto area = getLocalBounds();
g.setColour (Colour(0xf0ffffff));
g.drawRoundedRectangle (area.toFloat(), 5.0f, 3.0f);
g.setColour(Colour(0x20303030));
g.fillRoundedRectangle(area.toFloat(), 5.0f);
}
void setConstrainer()
{
}
void resized() override
{
// Just set the limits of our constrainer so that we don't drag ourselves off the screen
constrainer.setMinimumOnscreenAmounts (getHeight(), getWidth(),
getHeight(), getWidth());
}
void setLimit ( int left, int right )
{
constrainer.setMinimumOnscreenAmounts(0, left, getHeight(), right);
// constrainer.setSizeLimits(left, 0, right, getHeight());
}
void mouseDown (const MouseEvent& e) override
{
// Prepares our dragger to drag this Component
dragger.startDraggingComponent (this, e);
}
void mouseDrag (const MouseEvent& e) override
{
// Moves this Component according to the mouse drag event and applies our constraints to it
dragger.dragComponent (this, e, &constrainer);
sendChangeMessage();
}
private:
ComponentBoundsConstrainer constrainer;
ComponentDragger dragger;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Hook)
};



