Thread: mouse click coords and moving a rect

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    35

    mouse click coords and moving a rect

    I was wondering what a good way to get the difference between a rectangle's x, y position and a mouse click coord. I want to have something where you can click on a rectangle and move it, but the shape position is incremented by some difference of mouse x, y and shape x,y coords. Something like this is what I mean:
    Code:
    				double dx = (e.getX()-shape.getX());
    				double dy = (e.getY()-shape.getY());
    				
    shape._x+=dx;
    shape._y+=dy;
    shape._x2+=dx;
    shape._y2+=dy;

    the problem with this is that the shape then makes its position at the coord of the mouse click...Thanks alot!

    EDIT: This effect is like when you move an application window, the position of the window is relative to some difference of the mouse pos and its own xy.
    Last edited by techrolla; 03-07-2004 at 06:23 PM.
    you make me rery ascared

  2. #2
    You might want to look up ScreenToClient()..

Popular pages Recent additions subscribe to a feed