6121
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2017 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libwidg' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
ButtonController subclass:#PointFromUserController
|
|
17 |
instanceVariableNames:'action pressPoint'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Support-Controllers'
|
|
21 |
!
|
|
22 |
|
|
23 |
!PointFromUserController class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2017 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
drags a rectangle.
|
|
42 |
|
|
43 |
An instance of me can be installed temporarily as controller of any view,
|
|
44 |
to let the user select a rectangular area from the view.
|
|
45 |
|
|
46 |
Use the utility method:
|
|
47 |
dragRectangleIn:aView thenDo:action
|
|
48 |
which does exactly that for your (and cares to restore any original controller)
|
|
49 |
|
|
50 |
"
|
|
51 |
!
|
|
52 |
|
|
53 |
examples
|
|
54 |
"
|
|
55 |
|v c|
|
|
56 |
|
|
57 |
v := View new openAndWait.
|
|
58 |
c := PointFromuserController new.
|
|
59 |
c action:[:point | Transcript showCR:point ].
|
|
60 |
v openAndWait.
|
|
61 |
|
|
62 |
v controller:c.
|
|
63 |
"
|
|
64 |
! !
|
|
65 |
|
|
66 |
!PointFromUserController class methodsFor:'utilities'!
|
|
67 |
|
|
68 |
pointFromUserIn:aView thenDo:action
|
|
69 |
"wait for a button press in aView"
|
|
70 |
|
|
71 |
|pickController oldController oldCursor|
|
|
72 |
|
|
73 |
pickController := self new.
|
|
74 |
pickController view:aView.
|
|
75 |
oldController := aView controller.
|
|
76 |
oldCursor := aView cursor.
|
|
77 |
|
|
78 |
aView cursor:Cursor crossHair.
|
|
79 |
pickController action:[:pointOrNil |
|
|
80 |
|image|
|
|
81 |
|
|
82 |
aView controller:oldController.
|
|
83 |
aView cursor:oldCursor.
|
|
84 |
action value:pointOrNil.
|
|
85 |
].
|
|
86 |
|
|
87 |
aView controller:pickController.
|
|
88 |
|
|
89 |
"Created: / 07-03-2017 / 18:29:28 / cg"
|
|
90 |
! !
|
|
91 |
|
|
92 |
!PointFromUserController methodsFor:'accessing'!
|
|
93 |
|
|
94 |
action:aBlock
|
|
95 |
"set the block which will be called when the point has been picked.
|
|
96 |
The block will be called with a nil arg, if escape is pressed"
|
|
97 |
|
|
98 |
action := aBlock
|
|
99 |
|
|
100 |
"Modified (comment): / 07-03-2017 / 18:26:34 / cg"
|
|
101 |
!
|
|
102 |
|
|
103 |
pressPoint
|
|
104 |
^ pressPoint
|
|
105 |
|
|
106 |
"Created: / 07-03-2017 / 18:28:36 / cg"
|
|
107 |
! !
|
|
108 |
|
|
109 |
!PointFromUserController methodsFor:'event handling'!
|
|
110 |
|
|
111 |
buttonPress:button x:x y:y
|
|
112 |
pressPoint := x@y.
|
|
113 |
view cursor:(Cursor normal).
|
|
114 |
|
|
115 |
"Modified: / 07-03-2017 / 18:27:46 / cg"
|
|
116 |
!
|
|
117 |
|
|
118 |
buttonRelease:button x:x y:y
|
|
119 |
|point|
|
|
120 |
|
|
121 |
pressPoint isNil ifTrue:[
|
|
122 |
super buttonRelease:button x:x y:y.
|
|
123 |
^ self
|
|
124 |
].
|
6143
|
125 |
|
6121
|
126 |
point := pressPoint.
|
|
127 |
pressPoint := nil.
|
|
128 |
action value:point.
|
|
129 |
|
|
130 |
"Modified: / 07-03-2017 / 18:28:24 / cg"
|
6143
|
131 |
"Modified (format): / 10-04-2017 / 08:41:13 / cg"
|
6121
|
132 |
!
|
|
133 |
|
|
134 |
keyPress:key x:x y:y
|
6143
|
135 |
"actually, this is for the escape key (to abort a drag operation)"
|
|
136 |
|
6121
|
137 |
pressPoint isNil ifTrue:[
|
|
138 |
super keyPress:key x:x y:y.
|
|
139 |
^ self
|
|
140 |
].
|
|
141 |
|
|
142 |
pressPoint := nil.
|
|
143 |
action value:nil.
|
|
144 |
|
|
145 |
"Modified: / 07-03-2017 / 18:27:19 / cg"
|
6143
|
146 |
"Modified (comment): / 10-04-2017 / 08:41:08 / cg"
|
6121
|
147 |
! !
|
|
148 |
|
|
149 |
!PointFromUserController class methodsFor:'documentation'!
|
|
150 |
|
|
151 |
version
|
|
152 |
^ '$Header$'
|
|
153 |
!
|
|
154 |
|
|
155 |
version_CVS
|
|
156 |
^ '$Header$'
|
|
157 |
! !
|
|
158 |
|