matthewking
Programmer
Hi,
I have a java applet which allows you to drag n drop shapes.
at the moment the drag code is as follows:
public boolean mouseDrag(Event evt, int x, int y)
{
if (selectedObject != null)
{
selectedObject.x = x;
selectedObject.y = y;
}
repaint();
return true;
}
This isnt exactly what im wanting because if you click on the center of the shape, when you begin to drag, the top left corner is moved to the mouse coordinates.
So to fix this I wanted to calculate the offset, so the mouse stays in the position I clicked while I drag. I've tried a few calculations and I cant seem to get it right.
Any help would be much appreciated.
Matt.
I have a java applet which allows you to drag n drop shapes.
at the moment the drag code is as follows:
public boolean mouseDrag(Event evt, int x, int y)
{
if (selectedObject != null)
{
selectedObject.x = x;
selectedObject.y = y;
}
repaint();
return true;
}
This isnt exactly what im wanting because if you click on the center of the shape, when you begin to drag, the top left corner is moved to the mouse coordinates.
So to fix this I wanted to calculate the offset, so the mouse stays in the position I clicked while I drag. I've tried a few calculations and I cant seem to get it right.
Any help would be much appreciated.
Matt.