Re: selection box in widget program [message #55989 is a reply to message #55988] |
Wed, 26 September 2007 09:59   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
markb77@gmail.com writes:
> I'm writing a program that needs to ask the user to select a region of
> an image. I'd like to have a routine that would allow the user to
> click and drag a selection box (a rubber band box), returning the
> coordinates of the box to the program once the user has made a
> selection.
>
> This is a widget program using object graphics.
>
> The draw window displaying the widget has its own event handler,
> handling keyboard, motion, and button click events.
>
> What I want to do, essentially, is temporarily have all of the motion
> and button click events handled by the drawbox routine. This way I
> can loop on a call to widget_event, obtaining all of the mouse events,
> and continually redrawing the selection box, until the user is done.
> So, what I am going to try to do is UNSET the EVENT_PRO keyword to the
> draw widget, loop on widget_event as described, and then re-set the
> EVENT_PRO keyword to the original event handler.
>
> Is this how people usually go about handling these situations?
No. This is how people who don't fully understand widget programming
yet go about it. :-)
> It seems like clicking and dragging a selection box would be the world's
> most common routine, but I haven't found many examples of it when
> using object graphics and widget programs with event handlers.. etc.
Well, the actual mechanics of responding to events in your event
handler is pretty much the same, and can be gleaned from this article:
http://www.dfanning.com/widget_tips/rubberband_widget.html
What is different in object graphics is how you display the actual
graphics. Typically, on the DOWN event you take a "snapshot" of what
you want to be the "background" of your image", and then during the
MOTION events, you simple display your "box" on top of the background.
You can find the essentials in this article:
http://www.dfanning.com/ographics_tips/objectbox.html
In any case, you will find a program there (Zoombox) that
will illustrate how it can be done.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|