summaryrefslogtreecommitdiff
path: root/ipl/gprocs/select.icn
blob: 9557c00ce3416c35013348c6cf39fd916d3238a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
############################################################################
#
#	File:     select.icn
#
#	Subject:  Procedure to get selection from window
#
#	Author:   Ralph E. Griswold
#
#	Date:     August 30, 1996
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################
#
#  Links: grecords
#
############################################################################

link grecords

procedure select(win)		#: interactive selection from window
   local x0, x1, y0, y1, w, h, state, event

   /win := &window

   WAttrib(win, "drawop=reverse")
   WAttrib(win, "linestyle=onoff")

   state := "wait"
   
   while event := Event(win) do {
      if event == "q" then {
         DrawRectangle(win, \x0, y0, 0, 0)	# clear if already drawn
         fail
         }
      case state of {
         "wait": {			# waiting for selection
            case event of {
               &lpress: {
                  x1 := x0 := &x	# initial coordinates
                  y1 := y0 := &y
                  DrawRectangle(win, x0, y0, 0, 0)	# start selection
                  state := "select"	# now select the rectangle
                  }
               }
            }
         "select": {			# select the rectangle
            case event of {
               &ldrag: {		# selecting ...
                  DrawRectangle(win, x0, y0, x1 - x0, y1 - y0) # erase
                  x1 := &x		# new opposite corner
                  y1 := &y
                  DrawRectangle(win, x0, y0, x1 - x0, y1 - y0) # draw
                  }
               &lrelease: {		# got it!
                  DrawRectangle(win, x0, y0, x1 - x0, y1 - y0) # erase
                  x1 := &x		# new opposite corner
                  y1 := &y
                  if (x0 = x1) | (y0 = y1) then	# no area
                     state := "wait"
                  else {
                     w := x1 - x0	# set up for action
                     h := y1 - y0 
                     DrawRectangle(win, x0, y0, w, h) # draw rectangle
                     state := "act"	# now do something
                     }
                  }
               }
            }
         "act": {
            case event of {
               "n":  {			# new selection
                     state := "wait"
                     DrawRectangle(win, x0, y0, w, h) # try again
                     }
               "q":  {			# quit
                     DrawRectangle(win, x0, y0, w, h)
                     fail
                     }
               "r":  {			# return selection
                     DrawRectangle(win, x0, y0, w, h) #
                     return rect(x0, y0, w, h)
                     }
               }
            }
         }
      }

end