Re: David Fanning's rubberband box [message #11107 is a reply to message #11097] |
Thu, 12 March 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Joseph Scott Stuart (nospam@ll.mit.edu) writes:
> I've recently gotten David Fanning's book, and I like it quite a bit.
> Good job, David! I am having a problem though with the rubberband box
> code on page 117. I'm using IDL 5.0.2 on an SGI. When I am finished
> drawing the rubberband box and release the mouse button, the program
> does not exit the repeat loop. I have to push another button before it
> will register that I've released the first button.
I am skiing this week and I...well...forgot to bring a book
with me. An oversight I will not soon repeat, even if I have
to smuggle it up here in my dirty clothes bag. :-(
I presume you are working with the code that can be found
in the rubberbox.pro program. As it happens, this code is
designed to act *exactly* as it is acting. That is to say,
it is designed NOT to exit the loop until you click some
button OTHER than the left mouse button.
The point of the exercise is to show you that you can hold
the button down and drag (the way you are using it), or
you can simply click different locations in the window and
the box is drawn correctly, too. This is a benefit of the
Wait keyword to the Cursor command.
I am NOT saying this is the best user interface. In fact,
it is probably not. In my programming courses, we sometimes
try to make the rubberband box act as you prefer it to.
Some programmers can get it to work, but not very many.
It involves some pretty convoluted code. (I'm sorry I
don't have an example and I doubt I can code it up
in the time I have before my wife returns from an errand.
Perhaps some of the people who have made it work in my
course could offer us an example.)
I introduce the coding exercise in my courses not because
I want people to write code like this, but because I want
people to work really, really hard to do something that
is trivially easy to do with widget programs. After
struggling with the rubberband-thing-in-normal-IDL for
an hour, most people are highly motivated to learn how
to write a widget program. :-)
(For an example of how this is done in a widget program,
see the program ZIMAGE. The advantage of doing this in
a widget program is that it is also trivially easy to
make the program do something else if you use the right
or middle button instead of the left. You simply switch
event handlers appropriately. One of my associates is
currently working on some code that will do this in a
generalized way so that widget programmers don't have
to write similar code in each program they write.)
Whoops! I think that is my wife pulling up. I've got
to go out in this beautiful Colorado weather and ski. :-)
If you are still struggling next week, contact me and
I'll figure something out for you.
Cheers!
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|