ComponentDragger in a MagnifierComponent


#1

Jules,

it looks like the amount of drag isn’t getting scaled properly, maybe? Or is getting scaled and shouldn’t be? Seems like a 10 second fix for you. For reference, this code in my component seems to work - I pushed around where the global to relative conversion happens.

Bruce

[code] void mouseDrag (const MouseEvent& e)
{
if (e.mods.isPopupMenu())
{
dragging = false;
//showPopupMenu();
return; // this may be deleted now…
}
else
{
if (!dragging)
{
dragging = ! e.mouseWasClicked();

			if (dragging)
			{
				startX		= 0;
				startY		= 0;
				
				relativePositionToGlobal (startX, startY);
			}
		}
		
		if (dragging)
		{
			int x = startX;
			int y = startY;
			int w = getWidth();
			int h = getHeight();
			
			const Component* const parentComp = getParentComponent();
			if (parentComp != 0)
				parentComp->globalPositionToRelative (x, y);
			
			setBounds (x + e.getDistanceFromDragStartX(), y + e.getDistanceFromDragStartY(), w, h);
		}
	}
}

[/code]


#2

I’m not sure I quite understand… I think the scaling is ok in the magnifier comp, otherwise you wouldn’t be able to drag items around in the jucer correctly when it’s zoomed-in?


#3

Jucer doesn’t use ComponentDraggers, it has custom drag code - at least it did last time I looked. If you attach that class to a Component as a drag begins, as described in the docs (and the Component is in a magnifier) then the drags are ‘magnified’, at least if the view is zoomed smaller.

Bruce


#4

Sorry, I was being a bit slow on the uptake there - yes, of course you’re right, and a little tweak should fix it:

[code]void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
{
jassert (componentToDrag->isValidComponent());
jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event…)

if (componentToDrag->isValidComponent())
{
    int x = originalX;
    int y = originalY;
    int w = componentToDrag->getWidth();
    int h = componentToDrag->getHeight();

    const Component* const parentComp = componentToDrag->getParentComponent();
    if (parentComp != 0)
        parentComp->globalPositionToRelative (x, y);

    x += e.getDistanceFromDragStartX();
    y += e.getDistanceFromDragStartY();

    if (constrainer != 0)
        constrainer->setBoundsForComponent (componentToDrag, x, y, w, h,
                                            false, false, false, false);
    else
        componentToDrag->setBounds (x, y, w, h);
}

}
[/code]


#5

That did it, thanks.

Neat class.

Bruce