I'm writing a program in java that has graphical objects that the user can select and then rotate or stretch based on mouse movement. I'm close to getting to work, but the problem I'm having is figuring out a way for the adjustments to the shape to work naturally with the mouse movements.
I have a MouseListener set up something like this:
private class MouseHandler extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
currentClickPoint = e.getPoint();
}
}
and a MouseMotionListener set up something like this:
private class MouseMotionHandler extends MouseMotionAdapter
{
public void mouseDragged(MouseEvent e)
{
objectRotateAngle = currentClickPoint.getY() - e.getY();
objectWidth += currentClickPoint.getX() - e.getX();
}
}
This is a simplified version, obviously, but the problem is that I want the width to increase when the mouse is moved right, and decrease when the mouse is moved left, as well as the rotate angle to increase/decrease based on vertical mouse movement. Right now, the width won't begin to decrease until you've passed the currentClickPoint's X position going left and vise versa. The issue with the rotating based on mouse Y movement is that every time you begin to move the mouse up to rotate, the angle is set back to 0.
The program needs to respond to a change in direction seamlessly, without setting the width or angle to 0 at the start of the adjustment. Does anyone have a better way of detecting the direction of mouse movement for this purpose?