0
|
1 |
"
|
6
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
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 |
|
|
13 |
Object subclass:#DisplayObject
|
|
14 |
instanceVariableNames:'frame'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Display Objects'
|
|
18 |
!
|
|
19 |
|
|
20 |
DisplayObject comment:'
|
21
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
|
23 |
'!
|
0
|
24 |
|
21
|
25 |
!DisplayObject class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
30 |
All Rights Reserved
|
|
31 |
|
21
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
0
|
40 |
|
21
|
41 |
version
|
|
42 |
"
|
|
43 |
$Header: /cvs/stx/stx/libview2/DisplayObject.st,v 1.7 1994-06-03 00:52:07 claus Exp $
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
documentation
|
|
48 |
"
|
|
49 |
generic superclass for Display Objects held in ObjectViews
|
|
50 |
see DrawObject/LogicObject/DeskTopObject and subclasses for example use
|
|
51 |
"
|
|
52 |
! !
|
0
|
53 |
|
|
54 |
!DisplayObject class methodsFor:'instance creation'!
|
|
55 |
|
|
56 |
new
|
|
57 |
^ self basicNew initialize
|
|
58 |
! !
|
|
59 |
|
|
60 |
!DisplayObject class methodsFor:'behavior'!
|
|
61 |
|
|
62 |
dragOutline
|
|
63 |
"if true, dragging is done by drawing outline only;
|
|
64 |
if false, dragging is done by full draw (fast servers only)
|
|
65 |
- can be redefined in subclasses"
|
|
66 |
|
|
67 |
^ true
|
|
68 |
! !
|
|
69 |
|
|
70 |
!DisplayObject methodsFor:'initialization'!
|
|
71 |
|
|
72 |
initialize
|
|
73 |
^ self
|
7
|
74 |
!
|
|
75 |
|
|
76 |
computeBoundingBox
|
|
77 |
self subclassResponsibility
|
0
|
78 |
! !
|
|
79 |
|
|
80 |
!DisplayObject methodsFor:'queries'!
|
|
81 |
|
|
82 |
canBeMoved
|
|
83 |
"return true, if the receiver can be moved around"
|
|
84 |
|
|
85 |
^ true
|
|
86 |
!
|
|
87 |
|
|
88 |
hasFixedSize
|
|
89 |
"return true, if the receiver has fixed size i.e. cannot be
|
|
90 |
resized
|
|
91 |
- by default, we do not allow resizing"
|
|
92 |
|
|
93 |
^ true
|
|
94 |
!
|
|
95 |
|
|
96 |
isContainedIn:aRectangle
|
|
97 |
"object must decide, if its within a rectangle"
|
|
98 |
|
|
99 |
^ aRectangle contains:frame
|
|
100 |
!
|
|
101 |
|
|
102 |
containsPoint: aPoint
|
7
|
103 |
^ frame containsPoint: aPoint
|
0
|
104 |
!
|
|
105 |
|
|
106 |
intersects:aRectangle
|
|
107 |
"object must decide, if its intersecting a rectangle"
|
|
108 |
|
|
109 |
^ frame intersects:aRectangle
|
7
|
110 |
!
|
|
111 |
|
|
112 |
isOpaque
|
|
113 |
"return true, if the object fully covers its frame (i.e. is rectangular
|
|
114 |
and has no 'holes'. Since we dont know, return false here"
|
|
115 |
|
|
116 |
^ false
|
0
|
117 |
! !
|
|
118 |
|
|
119 |
!DisplayObject methodsFor:'accessing'!
|
|
120 |
|
|
121 |
frame
|
|
122 |
"object must return a frame boundary rectangle"
|
|
123 |
|
|
124 |
frame isNil ifTrue:[
|
|
125 |
frame := self computeBoundingBox
|
|
126 |
].
|
|
127 |
^ frame
|
|
128 |
!
|
|
129 |
|
|
130 |
width
|
|
131 |
"return the width of the frame"
|
|
132 |
|
|
133 |
frame isNil ifTrue:[
|
|
134 |
frame := self computeBoundingBox
|
|
135 |
].
|
|
136 |
^ frame width
|
|
137 |
!
|
|
138 |
|
|
139 |
height
|
|
140 |
"return the height of the frame"
|
|
141 |
|
|
142 |
frame isNil ifTrue:[
|
|
143 |
frame := self computeBoundingBox
|
|
144 |
].
|
|
145 |
^ frame height
|
|
146 |
!
|
|
147 |
|
|
148 |
extent
|
|
149 |
"return the extent of the frame"
|
|
150 |
|
|
151 |
frame isNil ifTrue:[
|
|
152 |
frame := self computeBoundingBox
|
|
153 |
].
|
|
154 |
^ frame extent
|
|
155 |
!
|
|
156 |
|
|
157 |
origin
|
|
158 |
"return the frame origin"
|
|
159 |
|
|
160 |
frame isNil ifTrue:[
|
|
161 |
frame := self computeBoundingBox
|
|
162 |
].
|
|
163 |
^ frame origin
|
|
164 |
!
|
|
165 |
|
|
166 |
corner
|
|
167 |
"return the frame corner"
|
|
168 |
|
|
169 |
frame isNil ifTrue:[
|
|
170 |
frame := self computeBoundingBox
|
|
171 |
].
|
|
172 |
^ frame corner
|
|
173 |
!
|
|
174 |
|
|
175 |
origin:origin
|
|
176 |
"object must calculate its dimension from outline"
|
|
177 |
|
|
178 |
^ self subclassResponsibility
|
|
179 |
!
|
|
180 |
|
|
181 |
origin:origin corner:corner
|
|
182 |
"object must calculate its dimension from outline"
|
|
183 |
|
|
184 |
^ self subclassResponsibility
|
|
185 |
! !
|
|
186 |
|
|
187 |
!DisplayObject methodsFor:'users actions'!
|
|
188 |
|
|
189 |
moveTo:aPoint
|
|
190 |
"object must move to new origin
|
|
191 |
- default is to stay; ought to be redefined in subclass"
|
|
192 |
|
|
193 |
^ self
|
|
194 |
!
|
|
195 |
|
|
196 |
keyInput:akey
|
|
197 |
^ self
|
|
198 |
! !
|
|
199 |
|
|
200 |
!DisplayObject methodsFor:'queries'!
|
|
201 |
|
|
202 |
isHitBy:aPoint withDelta:delta
|
|
203 |
"object must decide, if hit by a click at aPoint;
|
|
204 |
usually this method is redefined in subclasses for a more complete
|
|
205 |
check (i.e. if objects boundary is not rectangular)"
|
|
206 |
|
|
207 |
|org left right top bott px py d2|
|
|
208 |
|
|
209 |
(delta == 0) ifTrue:[
|
|
210 |
^ frame containsPoint:aPoint
|
|
211 |
].
|
|
212 |
|
21
|
213 |
"
|
|
214 |
its quicker to not create a new rectangle for the test
|
|
215 |
(which is not obvious for simple lines, but complex polygons may
|
|
216 |
call this for many of its components)
|
|
217 |
"
|
0
|
218 |
org := frame origin.
|
|
219 |
left := org x - delta.
|
|
220 |
|
|
221 |
px := aPoint x.
|
21
|
222 |
(px < left) ifTrue:[^ false]. "aPoint is to the left of my left edge"
|
0
|
223 |
|
|
224 |
d2 := delta * 2.
|
|
225 |
right := left + frame width + d2.
|
21
|
226 |
(px > right) ifTrue:[^ false]. "aPoint is to the right of my right edge"
|
0
|
227 |
|
|
228 |
top := org y - delta.
|
|
229 |
py := aPoint y.
|
21
|
230 |
(py < top) ifTrue:[^ false]. "aPoint is above my top edge"
|
0
|
231 |
|
|
232 |
bott := top + frame height + d2.
|
21
|
233 |
(py > bott) ifTrue:[^ false]. "aPoint is below my bottom edge"
|
0
|
234 |
|
|
235 |
^ true
|
|
236 |
!
|
|
237 |
|
|
238 |
isHitBy:aPoint
|
|
239 |
"object must decide, if hit by a click at aPoint"
|
|
240 |
|
|
241 |
^ self isHitBy:aPoint withDelta:0
|
|
242 |
! !
|
|
243 |
|
|
244 |
!DisplayObject methodsFor:'ST-80 drawing'!
|
|
245 |
|
|
246 |
displayOn: aDisplayMedium
|
|
247 |
self displayOn:aDisplayMedium
|
|
248 |
at:0@0
|
|
249 |
clippingBox:nil
|
|
250 |
rule:#copy
|
|
251 |
mask:nil
|
1
|
252 |
!
|
|
253 |
|
|
254 |
displayOn:aDisplayMedium at:aPoint
|
|
255 |
self displayOn:aDisplayMedium
|
|
256 |
at:aPoint
|
|
257 |
clippingBox:nil
|
|
258 |
rule:#copy
|
|
259 |
mask:nil
|
0
|
260 |
!
|
|
261 |
|
|
262 |
displayOn:aDisplayMedium at:aPoint clippingBox:clipRectangle
|
|
263 |
^ self displayOn:aDisplayMedium
|
|
264 |
at:aPoint
|
|
265 |
clippingBox:clipRectangle
|
|
266 |
rule:#copy
|
|
267 |
mask:nil
|
|
268 |
!
|
|
269 |
|
|
270 |
displayOn:aDisplayMedium at:aPoint clippingBox:clip rule:rule mask: aForm
|
1
|
271 |
"in ST-80 programs, this is redefined"
|
|
272 |
|
0
|
273 |
aDisplayMedium function:rule.
|
|
274 |
^ self drawIn:aDisplayMedium
|
|
275 |
at:(aPoint + self origin)
|
|
276 |
! !
|
|
277 |
|
|
278 |
!DisplayObject methodsFor:'drawing'!
|
|
279 |
|
|
280 |
drawIn:aView offset:anOffset
|
|
281 |
"draw the receiver at its origin offset by anOffset, aPoint"
|
|
282 |
|
1
|
283 |
^ self subclassResponsibility
|
0
|
284 |
!
|
|
285 |
|
|
286 |
drawIn:aView
|
|
287 |
"draw the receiver at its origin"
|
|
288 |
|
|
289 |
self drawIn:aView offset:(0@0)
|
|
290 |
!
|
|
291 |
|
|
292 |
drawIn:aView at:drawOrigin
|
|
293 |
"draw the receiver at drawOrigin, aPoint"
|
|
294 |
|
|
295 |
self drawIn:aView offset:(drawOrigin - (self origin))
|
|
296 |
!
|
|
297 |
|
|
298 |
drawSelectedIn:aView offset:anOffset
|
|
299 |
"draw the receiver highlighted - this is usually redefined"
|
|
300 |
|
|
301 |
self drawIn:aView offset:anOffset.
|
|
302 |
self drawOutlineIn:aView offset:anOffset
|
|
303 |
!
|
|
304 |
|
|
305 |
drawSelectedIn:aView
|
|
306 |
"draw the receiver highlighted at its position"
|
|
307 |
|
|
308 |
self drawSelectedIn:aView offset:(0@0)
|
|
309 |
!
|
|
310 |
|
|
311 |
drawOutlineIn:aView offset:anOffset
|
|
312 |
"draw the receivers outline at its origin offset by anOffset, aPoint"
|
|
313 |
|
|
314 |
|org|
|
|
315 |
org := self origin + anOffset - aView viewOrigin.
|
17
|
316 |
aView displayRectangleX:(org x) y:(org y)
|
|
317 |
width:(frame width) height:(frame height)
|
0
|
318 |
!
|
|
319 |
|
|
320 |
drawOutlineIn:aView
|
|
321 |
"draw the receivers outline at its origin"
|
|
322 |
|
|
323 |
self drawOutlineIn:aView offset:(0@0)
|
|
324 |
!
|
|
325 |
|
|
326 |
drawOutlineIn:aView at:drawOrigin
|
|
327 |
"draw the receivers outline at drawOrigin, aPoint"
|
|
328 |
|
|
329 |
self drawOutlineIn:aView offset:(drawOrigin - (self origin))
|
|
330 |
!
|
|
331 |
|
|
332 |
drawDragIn:aView at:drawOrigin
|
|
333 |
"draw the receiver for dragging"
|
|
334 |
|
|
335 |
self class dragOutline ifTrue:[
|
|
336 |
self drawOutlineIn:aView offset:(drawOrigin - (self origin))
|
|
337 |
] ifFalse: [
|
|
338 |
self drawIn:aView offset:(drawOrigin - (self origin))
|
|
339 |
]
|
|
340 |
!
|
|
341 |
|
|
342 |
drawDragIn:aView offset:drawOrigin
|
|
343 |
self class dragOutline ifTrue:[
|
|
344 |
self drawOutlineIn:aView offset:drawOrigin
|
|
345 |
] ifFalse: [
|
|
346 |
self drawIn:aView offset:drawOrigin
|
|
347 |
]
|
|
348 |
!
|
|
349 |
|
|
350 |
drawDragIn:aView
|
|
351 |
self class dragOutline ifTrue:[
|
|
352 |
self drawOutlineIn:aView offset:(0 @ 0)
|
|
353 |
] ifFalse: [
|
|
354 |
self drawIn:aView offset:(0 @ 0)
|
|
355 |
]
|
|
356 |
! !
|