View Full Version : [CLOSED] Value jitter with x and y coordinates in DndDropEvent?

13 Feb 2012, 8:44 AM
Dear Sencha,

I created a drop target which is required to listen in to the absolute x and y coordinates associated with the drop event.

From what I can tell after writing a proof-of-concept is that it would appear the reported values show jitter: there seems to be some variation on the x and y values which is much larger than the actual drag 'n drop action can account for.

The jitter seems determined by the actual mouse movements during the drag 'n drop action. Different trajectories to the same drop position produce different x and y values. I access the actual x and y values through:

protected void onDragDrop(DndDropEvent event) {
int x = event.getDragEndEvent().getX();
int y = event.getDragEndEvent().getY();

I'm using Ext GWT 3.0.0-beta2.

Your feedback would be appreciated!


Colin Alworth
17 Feb 2012, 2:38 PM
It is possible there is some jitter, but check out where those values are being read from - the DragEndEvent is created in Draggable.stopDrag, where it uses the lastX, lastY fields. Those are set based on some math that starts with the native event, and tries to adjust it following a few rules:

Make sure user has dragged far enough to consider it a drag
Don't change value if constrained
Adjust values to fit the dragged item's initial bounds, so the distance the mouse moved is consistent with the distance the dragged thing moved
If needed, keep within the given bounds (container, and assigned bounds)

Draggable is what is used to get the behavior seen at http://sencha.com/examples-dev/#ExamplePlace:draggable where items can be dragged directly - the items themselves end up being positioned relative to where the mouse held them when the drag began, not relative to the final position of the mouse.

To get the exact position of the mouse, instead of the new relarive position of the item, use the native event instance - event.getNativeEvent().getClientX() and getClientY() - these give you the raw x/y coords of the client's mouse when the drop occurred, instead of the adjusted values of from the drag.

If you think there is a bug, can you give us a specific case/example? You might find the BaseEventPreview class helpful to see what the event looked like before it was passed into the widget's event handling system.

18 Feb 2012, 2:53 AM
Thanks, Colin, for your great explanation.

In fact, it would appear that I have made the wrong assumption in terms of what those drag x and y coordinates apply to. In my application, I'm positioning icons on a map widget by dragging them from a palette. Since the starting position of an icon is always fixed, I failed to understand why dragging it to the same spot on the map would produce 'jittery' results. The 'jitter' is simply the normal variation of the actual pixel position when picking the icon, to start the drag. Which also explains why the jitter appears bounded by the actual icon size.