home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprocs / decay.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  85 lines

  1. ############################################################################
  2. #
  3. #    File:     decay.icn
  4. #
  5. #    Subject:  Procedures for decaying-displays for windows
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     August 14, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #    These procedures provide a way to draw objects and then have them
  18. #    automatically redrawn (say, in a lighter color) n steps later.
  19. #    A user routine is called to do the actual drawing.  If a second
  20. #    call to draw an object comes before its time has expired, the
  21. #    object's counter is reset and the drawing routine is not called.
  22. #
  23. #    dpipe() initializes a decay pipeline and returns a pipeline object.
  24. #
  25. #    decay() marks an object, unmarks another, and advances the clock.
  26. #
  27. ############################################################################
  28. #
  29. #   dpipe(proc, length, gc1, gc2) -- create a decay pipeline
  30. #
  31. #    dpipe() initializes a decay pipeline and returns a pipeline object.
  32. #
  33. #    proc    user marking procedure: proc(gc, i) marks entry i using gc
  34. #    length    length of the delay pipeline (number of steps)
  35. #    gc1    gc to mark an entry when it becomes active
  36. #    gc2    gc to mark an entry when it decays (becomes inactive)
  37. #
  38. #   decay(dp, i) -- mark entry i with later decay
  39. #
  40. #    decay() marks an object, unmarks another, and advances the clock.
  41. #
  42. #    Using decay pipe dp, entry i (anything but &null) is drawn in an
  43. #    active state, and the oldest entry in the pipe is drawn in an
  44. #    inactive state.
  45. #
  46. #    Records are kept, though, so that an already-active entry is not
  47. #    redrawn, and a decayed entry reaching the end of the pipe is not
  48. #    drawn as inactive if it was more recently renewed.
  49. #
  50. #    The decay pipe can be flushed by a sufficient number of
  51. #    decay(dp, &null) calls.
  52. #
  53. ############################################################################
  54. #
  55. #  Requires:  Version 9 graphics
  56. #
  57. ############################################################################
  58.  
  59. record Decay_Rec(    # decay pipe record
  60.    pipe,    # queue of active indices
  61.    tab,        # table of activity for each index
  62.    proc,    # marking procedure
  63.    gc1,        # gc to use to turn on
  64.    gc2)        # gc to use to turn off
  65.  
  66.  
  67. ##  dpipe(proc, length, gc1, gc2) -- create a decay pipeline
  68.  
  69. procedure dpipe(proc, length, gc1, gc2)        #: create a decay pipeline
  70.    return Decay_Rec(list(length), table(0), proc, gc1, gc2)
  71. end
  72.  
  73.  
  74. ##  decay(dp, i) -- mark entry i with later decay
  75.  
  76. procedure decay(dp, i)                #: mark entry for later decay
  77.    local j
  78.    j := get(dp.pipe)
  79.    if (dp.tab[\i] +:= 1) = 1 then
  80.       dp.proc(dp.gc1, i)
  81.    if (dp.tab[\j] -:= 1) = 0 then
  82.       dp.proc(dp.gc2, j)
  83.    put(dp.pipe, i)
  84. end
  85.