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
|
|
71 |
self displayOn:aDisplayMedium
|
|
72 |
at:0@0
|
|
73 |
clippingBox:nil
|
|
74 |
rule:#copy
|
|
75 |
mask:nil
|
0
|
76 |
!
|
|
77 |
|
122
|
78 |
displayOn:aDisplayMedium at:aPoint
|
|
79 |
self displayOn:aDisplayMedium
|
|
80 |
at:aPoint
|
|
81 |
clippingBox:nil
|
|
82 |
rule:#copy
|
|
83 |
mask:nil
|
0
|
84 |
!
|
|
85 |
|
122
|
86 |
displayOn:aDisplayMedium at:aPoint clippingBox:clipRectangle
|
|
87 |
^ self displayOn:aDisplayMedium
|
|
88 |
at:aPoint
|
|
89 |
clippingBox:clipRectangle
|
|
90 |
rule:#copy
|
|
91 |
mask:nil
|
7
|
92 |
!
|
|
93 |
|
122
|
94 |
displayOn:aDisplayMedium at:aPoint clippingBox:clip rule:rule mask: aForm
|
|
95 |
"in ST-80 programs, this is redefined"
|
7
|
96 |
|
122
|
97 |
aDisplayMedium function:rule.
|
|
98 |
^ self drawIn:aDisplayMedium
|
|
99 |
at:(aPoint + self origin)
|
34
|
100 |
! !
|
|
101 |
|
0
|
102 |
!DisplayObject methodsFor:'accessing'!
|
|
103 |
|
122
|
104 |
corner
|
|
105 |
"return the frame corner"
|
|
106 |
|
|
107 |
frame isNil ifTrue:[
|
|
108 |
frame := self computeBoundingBox
|
|
109 |
].
|
|
110 |
^ frame corner
|
|
111 |
!
|
|
112 |
|
|
113 |
extent
|
|
114 |
"return the extent of the frame"
|
|
115 |
|
|
116 |
frame isNil ifTrue:[
|
|
117 |
frame := self computeBoundingBox
|
|
118 |
].
|
|
119 |
^ frame extent
|
|
120 |
!
|
|
121 |
|
0
|
122 |
frame
|
|
123 |
"object must return a frame boundary rectangle"
|
|
124 |
|
|
125 |
frame isNil ifTrue:[
|
31
|
126 |
frame := self computeBoundingBox
|
0
|
127 |
].
|
|
128 |
^ frame
|
|
129 |
!
|
|
130 |
|
|
131 |
height
|
|
132 |
"return the height of the frame"
|
|
133 |
|
|
134 |
frame isNil ifTrue:[
|
31
|
135 |
frame := self computeBoundingBox
|
0
|
136 |
].
|
|
137 |
^ frame height
|
|
138 |
!
|
|
139 |
|
|
140 |
origin
|
|
141 |
"return the frame origin"
|
|
142 |
|
|
143 |
frame isNil ifTrue:[
|
31
|
144 |
frame := self computeBoundingBox
|
0
|
145 |
].
|
|
146 |
^ frame origin
|
|
147 |
!
|
|
148 |
|
|
149 |
origin:origin
|
|
150 |
"object must calculate its dimension from outline"
|
|
151 |
|
|
152 |
^ self subclassResponsibility
|
|
153 |
!
|
|
154 |
|
|
155 |
origin:origin corner:corner
|
|
156 |
"object must calculate its dimension from outline"
|
|
157 |
|
|
158 |
^ self subclassResponsibility
|
122
|
159 |
!
|
|
160 |
|
|
161 |
width
|
|
162 |
"return the width of the frame"
|
|
163 |
|
|
164 |
frame isNil ifTrue:[
|
|
165 |
frame := self computeBoundingBox
|
|
166 |
].
|
|
167 |
^ frame width
|
|
168 |
! !
|
|
169 |
|
|
170 |
!DisplayObject methodsFor:'converting'!
|
|
171 |
|
|
172 |
asDisplayObject
|
|
173 |
^ self
|
0
|
174 |
! !
|
|
175 |
|
122
|
176 |
!DisplayObject methodsFor:'drawing'!
|
|
177 |
|
|
178 |
drawDragIn:aView
|
|
179 |
self class dragOutline ifTrue:[
|
|
180 |
self drawOutlineIn:aView offset:(0 @ 0)
|
|
181 |
] ifFalse: [
|
|
182 |
self drawIn:aView offset:(0 @ 0)
|
|
183 |
]
|
|
184 |
!
|
|
185 |
|
|
186 |
drawDragIn:aView at:drawOrigin
|
|
187 |
"draw the receiver for dragging"
|
|
188 |
|
|
189 |
self class dragOutline ifTrue:[
|
|
190 |
self drawOutlineIn:aView offset:(drawOrigin - (self origin))
|
|
191 |
] ifFalse: [
|
|
192 |
self drawIn:aView offset:(drawOrigin - (self origin))
|
|
193 |
]
|
|
194 |
!
|
0
|
195 |
|
122
|
196 |
drawDragIn:aView offset:drawOrigin
|
|
197 |
self class dragOutline ifTrue:[
|
|
198 |
self drawOutlineIn:aView offset:drawOrigin
|
|
199 |
] ifFalse: [
|
|
200 |
self drawIn:aView offset:drawOrigin
|
|
201 |
]
|
|
202 |
!
|
|
203 |
|
|
204 |
drawIn:aView
|
|
205 |
"draw the receiver at its origin"
|
0
|
206 |
|
122
|
207 |
self drawIn:aView offset:(0@0)
|
|
208 |
!
|
|
209 |
|
|
210 |
drawIn:aView at:drawOrigin
|
|
211 |
"draw the receiver at drawOrigin, aPoint"
|
|
212 |
|
|
213 |
self drawIn:aView offset:(drawOrigin - (self origin))
|
|
214 |
!
|
|
215 |
|
|
216 |
drawIn:aView offset:anOffset
|
|
217 |
"draw the receiver at its origin offset by anOffset, aPoint"
|
|
218 |
|
|
219 |
^ self subclassResponsibility
|
0
|
220 |
!
|
|
221 |
|
122
|
222 |
drawOutlineIn:aView
|
|
223 |
"draw the receivers outline at its origin"
|
|
224 |
|
|
225 |
self drawOutlineIn:aView offset:(0@0)
|
|
226 |
!
|
|
227 |
|
|
228 |
drawOutlineIn:aView at:drawOrigin
|
|
229 |
"draw the receivers outline at drawOrigin, aPoint"
|
|
230 |
|
|
231 |
self drawOutlineIn:aView offset:(drawOrigin - self origin)
|
|
232 |
!
|
|
233 |
|
|
234 |
drawOutlineIn:aView offset:anOffset
|
|
235 |
"draw the receivers outline at its origin offset by anOffset, aPoint"
|
|
236 |
|
|
237 |
|org|
|
|
238 |
org := self origin + anOffset.
|
|
239 |
aView displayRectangleX:org x y:org y
|
|
240 |
width:frame width height:frame height
|
|
241 |
!
|
|
242 |
|
|
243 |
drawSelectedIn:aView
|
|
244 |
"draw the receiver highlighted at its position"
|
|
245 |
|
|
246 |
self drawSelectedIn:aView offset:(0@0)
|
|
247 |
!
|
|
248 |
|
|
249 |
drawSelectedIn:aView offset:anOffset
|
|
250 |
"draw the receiver highlighted - this is usually redefined"
|
|
251 |
|
|
252 |
self drawIn:aView offset:anOffset.
|
|
253 |
self drawOutlineIn:aView offset:anOffset
|
|
254 |
! !
|
|
255 |
|
|
256 |
!DisplayObject methodsFor:'initialization'!
|
|
257 |
|
|
258 |
computeBoundingBox
|
|
259 |
"compute my boundingBox into the local variable 'frame'.
|
|
260 |
The box should be computed for Display."
|
|
261 |
|
|
262 |
^ self subclassResponsibility
|
|
263 |
!
|
|
264 |
|
|
265 |
computeBoundingBoxFor:aDevice
|
|
266 |
"compute my boundingBox into the local variable 'frame'.
|
|
267 |
The box is to be computed for aDevice."
|
|
268 |
|
|
269 |
"/ for backward compatibility, fall back to Display box computation
|
|
270 |
|
|
271 |
^ self computeBoundingBox
|
|
272 |
!
|
|
273 |
|
|
274 |
initialize
|
0
|
275 |
^ self
|
|
276 |
! !
|
|
277 |
|
|
278 |
!DisplayObject methodsFor:'queries'!
|
|
279 |
|
122
|
280 |
canBeMoved
|
|
281 |
"return true, if the receiver can be moved around"
|
|
282 |
|
|
283 |
^ true
|
|
284 |
!
|
|
285 |
|
|
286 |
containsPoint: aPoint
|
|
287 |
^ frame containsPoint: aPoint
|
|
288 |
!
|
|
289 |
|
|
290 |
handlesKeyboardInput
|
|
291 |
"return true, if the receiver handles keyboard input"
|
|
292 |
|
|
293 |
^ false
|
|
294 |
!
|
|
295 |
|
|
296 |
hasFixedSize
|
|
297 |
"return true, if the receiver has fixed size i.e. cannot be
|
|
298 |
resized
|
|
299 |
- by default, we do not allow resizing"
|
|
300 |
|
|
301 |
^ true
|
|
302 |
!
|
|
303 |
|
|
304 |
intersects:aRectangle
|
|
305 |
"object must decide, if its intersecting a rectangle"
|
|
306 |
|
|
307 |
^ frame intersects:aRectangle
|
|
308 |
!
|
|
309 |
|
|
310 |
isContainedIn:aRectangle
|
|
311 |
"object must decide, if its within a rectangle"
|
|
312 |
|
|
313 |
^ aRectangle contains:frame
|
|
314 |
!
|
|
315 |
|
|
316 |
isHitBy:aPoint
|
|
317 |
"object must decide, if hit by a click at aPoint"
|
|
318 |
|
|
319 |
^ self isHitBy:aPoint withDelta:0
|
|
320 |
!
|
|
321 |
|
0
|
322 |
isHitBy:aPoint withDelta:delta
|
|
323 |
"object must decide, if hit by a click at aPoint;
|
|
324 |
usually this method is redefined in subclasses for a more complete
|
|
325 |
check (i.e. if objects boundary is not rectangular)"
|
|
326 |
|
|
327 |
|org left right top bott px py d2|
|
|
328 |
|
34
|
329 |
frame isNil ifTrue:[
|
|
330 |
frame := self computeBoundingBox
|
|
331 |
].
|
0
|
332 |
(delta == 0) ifTrue:[
|
31
|
333 |
^ frame containsPoint:aPoint
|
0
|
334 |
].
|
|
335 |
|
21
|
336 |
"
|
|
337 |
its quicker to not create a new rectangle for the test
|
34
|
338 |
(which is not obvious for simple lines, but complex polygons
|
|
339 |
or grouped objects may call this for many of its components)
|
21
|
340 |
"
|
0
|
341 |
org := frame origin.
|
|
342 |
left := org x - delta.
|
|
343 |
|
|
344 |
px := aPoint x.
|
21
|
345 |
(px < left) ifTrue:[^ false]. "aPoint is to the left of my left edge"
|
0
|
346 |
|
|
347 |
d2 := delta * 2.
|
|
348 |
right := left + frame width + d2.
|
21
|
349 |
(px > right) ifTrue:[^ false]. "aPoint is to the right of my right edge"
|
0
|
350 |
|
|
351 |
top := org y - delta.
|
|
352 |
py := aPoint y.
|
21
|
353 |
(py < top) ifTrue:[^ false]. "aPoint is above my top edge"
|
0
|
354 |
|
|
355 |
bott := top + frame height + d2.
|
21
|
356 |
(py > bott) ifTrue:[^ false]. "aPoint is below my bottom edge"
|
0
|
357 |
|
|
358 |
^ true
|
|
359 |
!
|
|
360 |
|
122
|
361 |
isOpaque
|
|
362 |
"return true, if the object fully covers its frame (i.e. is rectangular
|
|
363 |
and has no 'holes'. Since we dont know, return false here"
|
0
|
364 |
|
122
|
365 |
^ false
|
0
|
366 |
! !
|
|
367 |
|
122
|
368 |
!DisplayObject methodsFor:'users actions'!
|
0
|
369 |
|
122
|
370 |
keyInput:akey
|
|
371 |
^ self
|
0
|
372 |
!
|
|
373 |
|
122
|
374 |
moveTo:aPoint
|
|
375 |
"object must move to new origin
|
|
376 |
- default is to stay; ought to be redefined in subclass"
|
0
|
377 |
|
122
|
378 |
^ self
|
|
379 |
! !
|
0
|
380 |
|
134
|
381 |
!DisplayObject class methodsFor:'documentation'!
|
|
382 |
|
|
383 |
version
|
255
|
384 |
^ '$Header: /cvs/stx/stx/libview2/DisplayObject.st,v 1.18 1996-05-09 09:23:15 cg Exp $'
|
134
|
385 |
! !
|