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 / select.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  100 lines

  1. ############################################################################
  2. #
  3. #    File:     select.icn
  4. #
  5. #    Subject:  Procedure to get selection from window
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     August 30, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #
  18. #
  19. ############################################################################
  20. #
  21. #  Requires:  Version 9 graphics
  22. #
  23. ############################################################################
  24. #
  25. #  Links: grecords
  26. #
  27. ############################################################################
  28.  
  29. link grecords
  30.  
  31. procedure select(win)        #: interactive selection from window
  32.    local x0, x1, y0, y1, w, h, state, event
  33.  
  34.    /win := &window
  35.  
  36.    WAttrib(win, "drawop=reverse")
  37.    WAttrib(win, "linestyle=onoff")
  38.  
  39.    state := "wait"
  40.    
  41.    while event := Event(win) do {
  42.       if event == "q" then {
  43.          DrawRectangle(win, \x0, y0, 0, 0)    # clear if already drawn
  44.          fail
  45.          }
  46.       case state of {
  47.          "wait": {            # waiting for selection
  48.             case event of {
  49.                &lpress: {
  50.                   x1 := x0 := &x    # initial coordinates
  51.                   y1 := y0 := &y
  52.                   DrawRectangle(win, x0, y0, 0, 0)    # start selection
  53.                   state := "select"    # now select the rectangle
  54.                   }
  55.                }
  56.             }
  57.          "select": {            # select the rectangle
  58.             case event of {
  59.                &ldrag: {        # selecting ...
  60.                   DrawRectangle(win, x0, y0, x1 - x0, y1 - y0) # erase
  61.                   x1 := &x        # new opposite corner
  62.                   y1 := &y
  63.                   DrawRectangle(win, x0, y0, x1 - x0, y1 - y0) # draw
  64.                   }
  65.                &lrelease: {        # got it!
  66.                   DrawRectangle(win, x0, y0, x1 - x0, y1 - y0) # erase
  67.                   x1 := &x        # new opposite corner
  68.                   y1 := &y
  69.                   if (x0 = x1) | (y0 = y1) then    # no area
  70.                      state := "wait"
  71.                   else {
  72.                      w := x1 - x0    # set up for action
  73.                      h := y1 - y0 
  74.                      DrawRectangle(win, x0, y0, w, h) # draw rectangle
  75.                      state := "act"    # now do something
  76.                      }
  77.                   }
  78.                }
  79.             }
  80.          "act": {
  81.             case event of {
  82.                "n":  {            # new selection
  83.                      state := "wait"
  84.                      DrawRectangle(win, x0, y0, w, h) # try again
  85.                      }
  86.                "q":  {            # quit
  87.                      DrawRectangle(win, x0, y0, w, h)
  88.                      fail
  89.                      }
  90.                "r":  {            # return selection
  91.                      DrawRectangle(win, x0, y0, w, h) #
  92.                      return rect(x0, y0, w, h)
  93.                      }
  94.                }
  95.             }
  96.          }
  97.       }
  98.  
  99. end
  100.