SelectedItemSet & dragging multiple components


#1

Hi again!

I’d like to implement the lasso component for selecting multiple controls on my panel to move several around at once. Currently they drag with the simple ComponentDragger system.

I’ve got an idea of how i’ll find myself with a valid SelectableItemSet, but then when it comes to actually dragging around multiple Components, i must say i’m a little stumped. Just wondering if anyone can point me in the right direction.


#2

Yes, it’s harder than it sounds…

On the mouse-down, I normally make a list of the original positions of all the items, then use those as the anchor from which to calculate their new position each time the mouse drags - using MouseEvent::getDistanceFromDragStart() to see how far to move them.


#3

ah, that sounds sensible. i’m still a bit lost though:

(1) How do you handle the drag events? Obviously when you’re dragging on a Component, the other potential selected Components aren’t aware of it. I suppose the ‘selectionManager’ part can be told to recieve the MouseEvents from them…

(2) How do you actually ‘move’ these Components? With the ComponentDragger you just do a startDragging(), but that’s only going to be on one. Do you bypass that altogether and just call setTopLeftPosition() for each selected component when a drag event happens?

Let me know if I’ve just answered my questions myself!


#4

yes, I think for multiple items you’ll probably write your own dragger. Any of the components could receive the mouse events and process them as long as they know about all the other items, or they could pass the events up to some other object to handle. Depends on exactly what you’re doing, really.


#5

Dusty old thread I know, I needed this for two projects, so i rewrote ComponentDragger like this so it supports multi-selection and multi-component dragging.

https://github.com/jcredland/juce-multi-component-dragger/blob/master/Source/jcf_multi_component_dragger.h

So if anyone ever needs this ... dive in.  There's a demo app:

https://github.com/jcredland/juce-multi-component-dragger

I need to add grids and snapping to it at some point as well. 


#6

Nice one, this will come in handy for a project I'm planning - it'll be a grid with selectable intersection points that the user can move or transform. 


#7

This looks a lot neater than the mess I made of the same task not too long ago! My implementation is held together with sticky tape and super glue, but manages to do the job. Perhaps I should update it. Thanks for sharing. 


#8

It should probably have used the ComponentBoundsConstrainer but I couldn't make that work with the way I was doing the multi-selection constraining ... there's probably a modification to ComponentBoundsConstrainer that'd fix it.  Or maybe some solution I missed...


#9