Thanks, Oleg. Very clean technique, Oleg, very smart. In this version the timer-initiated message doesn't interfere with the ijx window. You can even type: anim_run '' and you get a second window. But it doesn't animate. I guess this would need support for multiple timers in: wd.
I recall from coding for the Mac in the mid-1980s that invalidating a window region was the ideal way to refresh it. The system can then schedule the appropriate events as part of its routine housekeeping. It's the difference between leaving the towel on the bathroom floor, and phoning reception to send you up a clean towel. In this case the "towel" is the result of executing: gltext MESSAGE. A bonus of leaving the system to do its work and not getting in its way is that your window can even be resized without disrupting the animation effect. And no redundant redraws. Very important when there's a complex display to redraw. Another thing I notice is where the Mac has improved a lot in recent years. You can now cover and uncover the animation window with another app's window and the system remembers what was underneath without asking the app to redraw. Formerly you'd see a blank space until the app got around to filling it. You can see this effect (or lack of it on the newer Macs) by slowing the timer right down, eg: TIMER_INTERVAL =: 2 * 1000 and inserting a line in anim_isi_paint to announce whenever it gets run, eg: anim_isi_paint =: verb define glfont '"courier new" 36' gltext MESSAGE =: DIRECTION |. MESSAGE NB. paint MESSAGE rotated in DIRECTION (1!:2&2) 'nextframe: ',MESSAGE NB. Ian's probe ) Then try dragging (eg) a Finder window onto the Hello-World window and off again. It occurs to me this example would make an excellent lab for instructing on basic gui principles. Few of us learn how to handle even a button-press properly. Ian Clark On Fri, Dec 18, 2009 at 8:59 AM, Oleg Kobchenko <[email protected]> wrote: > Here's another version. See if it works better on Mac. > > Invalidated WD is considered more proper way to update UI. > > NB. > =============================================================================================================== > NB. olegyk: invalidated wd update; remove unneeded code; normalized spaces > > coinsert 'jgl2' [ require 'gl2' > > MESSAGE =: 'Hello World! ' > TIMER_INTERVAL =: 0.5 * 1000 NB. > milliseconds > DIRECTION =: 1 NB. > initial direction is right --> > > ANIM =: noun define > pc anim nomax;pn "Basic Animation in J"; > xywh 1 1 174 24;cc isi isigraph rightmove bottommove; > pas 0 0;pcenter;pshow; > ) > > anim_run =: verb def ' wd ANIM,''; timer '',":TIMER_INTERVAL ' > sys_timer_z_ =: verb def ' wd ''psel anim; setinvalid isi'' ' NB. > rotate MESSAGE according to DIRECTION > anim_isi_mbldown =: verb def ' DIRECTION=: - DIRECTION ' NB. > reverse direction when user clicks > anim_close =: verb def ' wd ''timer 0; pclose'' ' NB. > shut down timer > > anim_isi_paint =: verb define > glfont '"courier new" 36' > gltext MESSAGE =: DIRECTION |. MESSAGE NB. > paint MESSAGE rotated in DIRECTION > ) > > anim_run '' > NB. > =============================================================================================================== > > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
