Snap clip image during drag operation

Hello,
I am trying to implement a drag and drop mechanism for clips.
My goal is to apply a snap ( for example to the beat ) to the image I am currently dragging.
To do this I have currently modified the DragAndDropContainer and DragAndDropTarget classes by implementing a mechanism directly on the DragImageComponent managed by the container.
So I was wondering if there was a method to implement such a mechanism without having to modify the classes mentioned before.

In my case i have 3 classes :
ClipComponent : the object that needs to be dragged
TrackComponent : the object that accepts ClipComponent drop and so extends the DragAndDropTarget class
EditComponent : the object that contains the TrackComponent instances and extends the DragAndDropContainer

So in the practise i need to change the position of the current dragged image

I woudn’t use the DragImage for this. Instead use the paintOverChildren() callback for drawing a snapshot of your clip component at a certain position. In your itemDragMove() function you can update the position and call repaint() for updating.

mhh so you’re saying that when i call the method from DragAndDropContainer

void startDragging (const var& sourceDescription, Component* sourceComponent, const ScaledImage& dragImage = ScaledImage(), bool allowDraggingToOtherJuceWindows = false, const Point<int>* imageOffsetFromMouse = nullptr, const MouseInputSource* inputSourceCausingDrag = nullptr);

i’ll pass an empty - trasparent image as parameter.
Then i need to override the paintOverChildren() and draw a snapshot of item under mouse updating it’s position during the itemDragMove() callback ?

The other option is to note use any of the drag / drop stuff. When the user starts the drag on the ClipComponent move it to the required track and position and snap it’s start. This is what we do in Waveform.

BUt you may not have a ClipComponent around, like when you are dragging a file in from the OS or a file browser, then I’d use the method suggested by @baramgb

I’ve studied the Waveform mechanism and i don’t really like that when you drag a clip in a track you effectively move it and not it’s shadow image.
Just because to do that i think that you need to change the model parameters ( the start of the clip for example ) and then the graphics will follow this changes.

I thounght to implements something similiar to abelton/bit wig so i think i’ll follow his suggestion.
I think that move around the shadow image of a component and only when the drag operation is finished then the model will be updated and the GUI will follow it’s changes. this way is just simpler and even general performances maybe will be better.

Thaks for your quickly response !

1 Like