comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: vertical line that moves with cursor in draw widget
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: vertical line that moves with cursor in draw widget [message #60713] Sun, 08 June 2008 15:56
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
cgoethel@igpp.ucla.edu wrote:
> Hello, I have a draw_widget with motion events set up. I draw a
> vertical line (using plots) which follows the cursor as it moves
> through the draw area. I can get the vertical line to follow the
> cursor easily enough - but I can't seem to figure out how to erase the
> previous lines. All the lines remain drawn. Any suggestions?
> Thanks! Cindy

Use a pixmap (created with "window, /pixmap"). All drawing that you
currently do should go to the pixmap. Then copy the pixmap to the actual
draw window (with "device, copy=r"). This copy can be done very quickly.
Finally draw your lines on that. Every time the cursor moves, copy the
pixmap again and draw the new lines.

Mike
--
www.michaelgalloy.com
Tech-X Corporation
Software Developer II
Re: vertical line that moves with cursor in draw widget [message #60723 is a reply to message #60713] Sat, 07 June 2008 00:49 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
cgoethel@igpp.ucla.edu writes:

> Hello, I have a draw_widget with motion events set up. I draw a
> vertical line (using plots) which follows the cursor as it moves
> through the draw area. I can get the vertical line to follow the
> cursor easily enough - but I can't seem to figure out how to erase the
> previous lines. All the lines remain drawn. Any suggestions?
> Thanks! Cindy

Hello--

My personal favorite would be to use the DEVICE, SET_GRAPHICS_FUNCTION=
function to change to XOR drawing mode. In this mode you should be able
to draw the line once to make it appear and then repeat the operation
to make it disappear.

Something like,

DEVICE, GET_GRAPHICS_FUNCTION=oldg, SET_GRAPHICS_FUNCTION=6
;; Erase previous symbol
if n_elements(old_posx) then plots, old_posx, old_posy
;; Plot new symbol
plots, new_posx, new_posy
DEVICE, SET_GRAPHICS_FUNCTION=oldg

;; Save the new position for the next call
old_posx = new_posx
old_posy = new_posy


Good luck!
Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: vertical line that moves with cursor in draw widget [message #60724 is a reply to message #60723] Fri, 06 June 2008 19:51 Go to previous message
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
On Jun 6, 5:14 pm, cgoet...@igpp.ucla.edu wrote:
> Hello, I have a draw_widget with motion events set up. I draw a
> vertical line (using plots) which follows the cursor as it moves
> through the draw area. I can get the vertical line to follow the
> cursor easily enough - but I can't seem to figure out how to erase the
> previous lines. All the lines remain drawn. Any suggestions?
> Thanks! Cindy


Hi,

If you are using direct graphics, then your best bet is create a
"pixmap" copy of the window contained inthe draw widget. Then use the
DEVICE, copy = [blah, blah, blah...] to copy the contents of the
pixmap quickly to the the exposed draw window. This is pretty fast
and less expensive than trying to erase before plotting.

Here's an example. [By the way, you should consider buying on the of
the many fine intro to IDL books available. I like them all.]


Cheers,
Ben


PRO PLOT_EXAMPLE_DRAW_EVENT, ev

WIDGET_CONTROL, ev.id, GET_UVALUE = info

WSET, info.drawWin
DEVICE, copy = [0,0, info.dim[0], info.dim[1], 0,0, info.pixWin]

xy = CONVERT_COORD(ev.x, ev.y, /DEVICE, /TO_DATA)

PLOTS, [xy[0], xy[0]], !Y.CRANGE
PLOTS, !X.CRANGE, 30 + 5*[xy[0],xy[0]] - 11*([xy[0],xy[0]])^2
END


PRO PLOT_EXAMPLE

xsize = 400
ysize = 400

tlb = WIDGET_BASE()
drawID = WIDGET_DRAW(tlb, $
xsize = xsize, ysize = ysize, MOTION_EVENTS = 1, $
EVENT_PRO = "PLOT_EXAMPLE_DRAW_EVENT")
WINDOW,/FREE, xsize = xsize, ysize = ysize, /PIXMAP
pixWin = !D.window

WIDGET_CONTROL, tlb, /REALIZE
WIDGET_CONTROL, drawID, GET_VALUE = drawWin

WSET, drawWin
x = FINDGEN(100) - 50
y = 30 + 5*x - 11*(x^2)
PLOT, x,y
WSET, pixWin
DEVICE, COPY = [0,0,xsize, ysize, 0,0, drawWin]

info = {DRAWID: drawID, $
drawWin: drawWin, $
pixWin: pixWin, $
dim: [xsize, ysize]}
WIDGET_CONTROL, drawID, SET_UVALUE = info

XMANAGER, "PLOT_EXAMPLE", tlb
END
Re: vertical line that moves with cursor in draw widget [message #60727 is a reply to message #60724] Fri, 06 June 2008 14:55 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
cgoethel wrote:
> Hello, I have a draw_widget with motion events set up. I draw a
> vertical line (using plots) which follows the cursor as it moves
> through the draw area. I can get the vertical line to follow the
> cursor easily enough - but I can't seem to figure out how to erase the
> previous lines. All the lines remain drawn. Any suggestions?

The easiest way is to redraw your background before you draw the new
vertical line in your motion event handler. Depending on what your
doing this can be quite costly in direct graphics. If re-plotting is
too slow you can create a copy of your draw widget background (using
something like tvread from www.dfanning.com) and simply re-draw this
image instead of running thru all of your plotting code. Either way
you'll want to work hard to minimize the drawing to only when it is
absolutely necessary.

The best way to do this is to use object graphics which is far better
suited for this type of application. The problem here is that there's a
bit of a learning curve...

-Rick
Re: vertical line that moves with cursor in draw widget [message #60728 is a reply to message #60727] Fri, 06 June 2008 14:28 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
cgoethel@igpp.ucla.edu wrote:
> Hello, I have a draw_widget with motion events set up. I draw a
> vertical line (using plots) which follows the cursor as it moves
> through the draw area. I can get the vertical line to follow the
> cursor easily enough - but I can't seem to figure out how to erase the
> previous lines. All the lines remain drawn. Any suggestions?
> Thanks! Cindy

re-draw your image / data plots.. or use "erase" if you have nothing on
the draw area.

Jean
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Labelling the axes on a log plot
Next Topic: Re: widget, draw and file pickup

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:10:48 PDT 2025

Total time taken to generate the page: 0.00685 seconds