mouse click coords and moving a rect

This is a discussion on mouse click coords and moving a rect within the Windows Programming forums, part of the Platform Specific Boards category; I was wondering what a good way to get the difference between a rectangle's x, y position and a mouse ...

  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
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    You might want to look up ScreenToClient()..

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21