Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
David Sheerin wrote: > > Hi > I would like to be able to place my cursor over a picture in a draw > widget, tap the left mouse button and a square of n x n (defined in > software) white pixels drawn on the picture and all x and y coordinate > values sent to an array. I have selected the BUTTONS_EVENTS keyword in > the draw widget and used the WSet command to make it the current > graphic window but what else?? How do I use the event structure?? David - First, a gentle reminder to RTFM, specifically, the section under WIDGET_DRAW where it discusses the event structure. You will use EVENT.TYPE to determine the type of event; this will be 0 for a button press. For a left button press, EVENT.PRESS should be 1. EVENT.PRESS and EVENT.RELEASE are bitmasks for the three buttons, so the values are associated like so: 1 : left button 2 : middle button 4 : right button A typical event handler dealing with draw widget events might have a section that looks something like: TYPE = STRMID( TAG_NAMES(EVENT, /STRUCTURE_NAME), 7, 100) CASE ( TYPE ) OF "BUTTON": BEGIN ... END "DRAW": BEGIN CASE ( EVENT.TYPE ) OF 0: BEGIN ;*** BUTTON PRESS/RELEASE *** CASE ( EVENT.PRESS ) OF 1: BEGIN ;*** LEFT *** ... END 2: BEGIN ;*** MIDDLE *** ... END 4: BEGIN ;*** RIGHT *** ... END ELSE: ENDCASE END 1: BEGIN ;*** BUTTON RELEASE *** ... END 2: BEGIN ;*** MOTION *** ... END 3: BEGIN ;*** VIEWPORT (SCROLLBAR) MOVED **** ... END 4: BEGIN ;*** VISIBILITY CHANGED *** ... END ELSE: ENDCASE END ENDCASE Yours may be quite different if you want to process button presses and releases similarly. Once you have determined that you have a left button press, you use EVENT.X and EVENT.Y to build a list of vertices for your square that you pass to POLYFILL to fill your polygon. You can then use POLYFILLV to return the subscripts of the array elements inside the polygon. Note that these will be one-dimensional subscripts! You can convert these to 2D subscripts with: xcoors = indices mod xdim ycoors = indices / xdim where indices are the 1D subscripts and xdim is the x dimension of the window. Hope this helps. Dave -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ David S. Foster Univ. of California, San Diego Programmer/Analyst Brain Image Analysis Laboratory foster@bial1.ucsd.edu Department of Psychiatry (619) 622-5892 8950 Via La Jolla Drive, Suite 2240 La Jolla, CA 92037 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~