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