[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: draw window mouse events

"Rick Towler" <rtowler@u.washington.edu> wrote in message
> I have been trying to implement middle and third button events in my
> draw widget in much the same way as in the IDL demo d_objworld2.pro.  I
> have not found it easy to understand how everything happens in this demo
> program.
> I am interested in getting one of these buttons to utilize the TRANSLATE
> feature of the trackball object so I can translate my models.    I did
> have the left button transforming the model but I have broken that in my
> quest to understand this whole process which obviously I don't since I
> can't get it working again.
> Hints and/or pointers to examples that are a wee bit simpler than
> d_objworld2 are much appreciated.

Well if you like you can look at my MGHgrWindow class:


It calls a number of other routines, all of which you can find in


MGHgrWindow provides for a range of manipulations with the mouse (rotate,
translate, scale). In particular see methods EventTrack, EventScale and
EventTranslate. But I don't guarantee that its code is any simpler or easier
to understand than the IDL demo.

Looking through the code again, I note that I have used the Trackball object
for rotation only. Scaling and translation are done through calls to the
model's Translate and Scale methods. The basic logic for handling mouse
events is pretty simple:

    Press events
        Reduce window's QUALITY for faster redraws
        Store event.x and event.y (say as x0, y0)

    Motion events
        Scale/translate according to values of [event.x-x0, event.y-y0]
        Set x0 = event.x, y0 = event.y

    Release events
        Restore window quality
        Forget x0 & y0

Hope this helps

Mark Hadfield
m.hadfield@niwa.cri.nz  http://katipo.niwa.cri.nz/~hadfield/
National Institute for Water and Atmospheric Research
PO Box 14-901, Wellington, New Zealand