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