I’m working on a simple component that I want to be resizable and draggable, using a ResizableBorderComponent and a ComponentDragger. My component seems to be working fine in most cases, but after I resize, the next drag makes the component jump. If the component starts at (10,10), and I start dragging, the mouse cursor moves as expected but the component itself moves to (20,20). Subsequent calls to mouseDrag work as expected. I’m guessing setBounds is being called twice in a row or something like that, but I just can’t figure it out.
[code]class ResizableTextButton : public TextButton
{
public:
ResizableBorderComponent* resizer;
ComponentDragger dragger;
ResizableTextButton(String name) : TextButton(name)
{
resizer = new ResizableBorderComponent(this, 0);
addAndMakeVisible(resizer);
}
void resized()
{
resizer->setBounds(this->getBounds());
}
void paint(Graphics& g)
{
TextButton::paint(g);
Rectangle dims = this->getBounds();
g.drawRoundedRectangle(0, 0, dims.getWidth(), dims.getHeight(),5,3);
}
void mouseDown(const MouseEvent &e)
{
if(e.mods.isRightButtonDown())
{
dragger.startDraggingComponent(this,0);
dragger.startDraggingComponent(resizer,0);
}
else
{
TextButton::mouseDown(e);
}
}
void mouseDrag(const MouseEvent &e)
{
if(e.mods.isRightButtonDown())
{
dragger.dragComponent(this,e);
dragger.dragComponent(resizer,e);
}
else
{
TextButton::mouseDown(e);
}
}
};[/code]