1. How to drag graphic elements

I'm looking for any advice on how to go about accomplishing the following:

I wish to display two points in a window and draw a line between them. Then I
would like to be able to drag either of the points around the window while
maintaining the line between them. If necessary, the points could be represented
by a bitmap, icon, control or whatever works, though I wish to keep the object
small (perhaps 10x10 pixels). Any help is appreciated.

I am currently using the Win32Lib, but am open to other resources.

Thanks for your time,
Joel Garcia

new topic     » topic index » view message » categorize

2. Re: How to drag graphic elements

Joel Garcia wrote:
> 
> I'm looking for any advice on how to go about accomplishing the following:
> 
> I wish to display two points in a window and draw a line between them. Then
> I would like to be able to drag either of the points around the window while
> maintaining the line between them. If necessary, the points could be
> represented
> by a bitmap, icon, control or whatever works, though I wish to keep the object
> small (perhaps 10x10 pixels). Any help is appreciated.
> 
> I am currently using the Win32Lib, but am open to other resources.

Easy enough. Firstly, use a Pixmap as the drawing surface and during the onPaint
event bitblt the pixmap to the Window.

After drawing the initial points and the line, watch for mouse button down
events on the window. If one occurs near or on a point, then watch for mouse
movements events until the mouse button up event happens. During the movement
events, clear the pixmap and redraw the points at the new location determined by
where the mouse currently is, and redraw the line between them. That's basically
it.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

3. Re: How to drag graphic elements

Derek Parnell wrote:
> 
> Joel Garcia wrote:
> > 
> > I'm looking for any advice on how to go about accomplishing the following:
> > 
> > I wish to display two points in a window and draw a line between them. Then
> > I would like to be able to drag either of the points around the window while
> > maintaining the line between them. If necessary, the points could be
> > represented
> > by a bitmap, icon, control or whatever works, though I wish to keep the
> > object
> > small (perhaps 10x10 pixels). Any help is appreciated.
> > 
> > I am currently using the Win32Lib, but am open to other resources.
> 
> Easy enough. Firstly, use a Pixmap as the drawing surface and during the
> onPaint
> event bitblt the pixmap to the Window. 
> 
> After drawing the initial points and the line, watch for mouse button down
> events
> on the window. If one occurs near or on a point, then watch for mouse
> movements
> events until the mouse button up event happens. During the movement events,
> clear the pixmap and redraw the points at the new location determined by where
> the mouse currently is, and redraw the line between them. That's basically it.
> 
> -- 
> Derek Parnell
> Melbourne, Australia
> Skype name: derek.j.parnell

Thanks, Derek.

That is exactly the push I needed.

Joel

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu