|
1 " |
|
2 COPYRIGHT (c) 1989-92 by Claus Gittinger |
|
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 |
|
22 COPYRIGHT (c) 1989-92 by Claus Gittinger |
|
23 All Rights Reserved |
|
24 |
|
25 generic superclass for Display Objects held in ObjectViews |
|
26 see DrawObject/LogicObject/DeskTopObject and subclasses for example use |
|
27 |
|
28 %W% %E% |
|
29 written fall/winter 89 by claus |
|
30 '! |
|
31 |
|
32 !DisplayObject class methodsFor:'instance creation'! |
|
33 |
|
34 new |
|
35 ^ self basicNew initialize |
|
36 ! ! |
|
37 |
|
38 !DisplayObject class methodsFor:'behavior'! |
|
39 |
|
40 dragOutline |
|
41 "if true, dragging is done by drawing outline only; |
|
42 if false, dragging is done by full draw (fast servers only) |
|
43 - can be redefined in subclasses" |
|
44 |
|
45 ^ true |
|
46 ! ! |
|
47 |
|
48 !DisplayObject methodsFor:'initialization'! |
|
49 |
|
50 initialize |
|
51 ^ self |
|
52 ! ! |
|
53 |
|
54 !DisplayObject methodsFor:'queries'! |
|
55 |
|
56 canBeMoved |
|
57 "return true, if the receiver can be moved around" |
|
58 |
|
59 ^ true |
|
60 ! |
|
61 |
|
62 hasFixedSize |
|
63 "return true, if the receiver has fixed size i.e. cannot be |
|
64 resized |
|
65 - by default, we do not allow resizing" |
|
66 |
|
67 ^ true |
|
68 ! |
|
69 |
|
70 isContainedIn:aRectangle |
|
71 "object must decide, if its within a rectangle" |
|
72 |
|
73 ^ aRectangle contains:frame |
|
74 ! |
|
75 |
|
76 containsPoint: aPoint |
|
77 ^ frame containsPoint: aPoint |
|
78 ! |
|
79 |
|
80 intersects:aRectangle |
|
81 "object must decide, if its intersecting a rectangle" |
|
82 |
|
83 ^ frame intersects:aRectangle |
|
84 ! ! |
|
85 |
|
86 !DisplayObject methodsFor:'accessing'! |
|
87 |
|
88 frame |
|
89 "object must return a frame boundary rectangle" |
|
90 |
|
91 frame isNil ifTrue:[ |
|
92 frame := self computeBoundingBox |
|
93 ]. |
|
94 ^ frame |
|
95 ! |
|
96 |
|
97 width |
|
98 "return the width of the frame" |
|
99 |
|
100 frame isNil ifTrue:[ |
|
101 frame := self computeBoundingBox |
|
102 ]. |
|
103 ^ frame width |
|
104 ! |
|
105 |
|
106 height |
|
107 "return the height of the frame" |
|
108 |
|
109 frame isNil ifTrue:[ |
|
110 frame := self computeBoundingBox |
|
111 ]. |
|
112 ^ frame height |
|
113 ! |
|
114 |
|
115 extent |
|
116 "return the extent of the frame" |
|
117 |
|
118 frame isNil ifTrue:[ |
|
119 frame := self computeBoundingBox |
|
120 ]. |
|
121 ^ frame extent |
|
122 ! |
|
123 |
|
124 origin |
|
125 "return the frame origin" |
|
126 |
|
127 frame isNil ifTrue:[ |
|
128 frame := self computeBoundingBox |
|
129 ]. |
|
130 ^ frame origin |
|
131 ! |
|
132 |
|
133 corner |
|
134 "return the frame corner" |
|
135 |
|
136 frame isNil ifTrue:[ |
|
137 frame := self computeBoundingBox |
|
138 ]. |
|
139 ^ frame corner |
|
140 ! |
|
141 |
|
142 origin:origin |
|
143 "object must calculate its dimension from outline" |
|
144 |
|
145 ^ self subclassResponsibility |
|
146 ! |
|
147 |
|
148 origin:origin corner:corner |
|
149 "object must calculate its dimension from outline" |
|
150 |
|
151 ^ self subclassResponsibility |
|
152 ! ! |
|
153 |
|
154 !DisplayObject methodsFor:'users actions'! |
|
155 |
|
156 moveTo:aPoint |
|
157 "object must move to new origin |
|
158 - default is to stay; ought to be redefined in subclass" |
|
159 |
|
160 ^ self |
|
161 ! |
|
162 |
|
163 keyInput:akey |
|
164 ^ self |
|
165 ! ! |
|
166 |
|
167 !DisplayObject methodsFor:'queries'! |
|
168 |
|
169 isHitBy:aPoint withDelta:delta |
|
170 "object must decide, if hit by a click at aPoint; |
|
171 usually this method is redefined in subclasses for a more complete |
|
172 check (i.e. if objects boundary is not rectangular)" |
|
173 |
|
174 |org left right top bott px py d2| |
|
175 |
|
176 (delta == 0) ifTrue:[ |
|
177 ^ frame containsPoint:aPoint |
|
178 ]. |
|
179 |
|
180 "its quicker to not create a new rectangle for the test" |
|
181 org := frame origin. |
|
182 left := org x - delta. |
|
183 |
|
184 px := aPoint x. |
|
185 (px < left) ifTrue:[^ false]. |
|
186 |
|
187 d2 := delta * 2. |
|
188 right := left + frame width + d2. |
|
189 (px > right) ifTrue:[^ false]. |
|
190 |
|
191 top := org y - delta. |
|
192 py := aPoint y. |
|
193 (py < top) ifTrue:[^ false]. |
|
194 |
|
195 bott := top + frame height + d2. |
|
196 (py > bott) ifTrue:[^ false]. |
|
197 |
|
198 ^ true |
|
199 ! |
|
200 |
|
201 isHitBy:aPoint |
|
202 "object must decide, if hit by a click at aPoint" |
|
203 |
|
204 ^ self isHitBy:aPoint withDelta:0 |
|
205 ! ! |
|
206 |
|
207 !DisplayObject methodsFor:'ST-80 drawing'! |
|
208 |
|
209 displayOn: aDisplayMedium |
|
210 self drawIn:aDisplayMedium offset:0@0 |
|
211 " |
|
212 self displayOn:aDisplayMedium |
|
213 at:0@0 |
|
214 clippingBox:nil |
|
215 rule:#copy |
|
216 mask:nil |
|
217 " |
|
218 ! |
|
219 |
|
220 displayOn:aDisplayMedium at:aPoint clippingBox:clipRectangle |
|
221 ^ self displayOn:aDisplayMedium |
|
222 at:aPoint |
|
223 clippingBox:clipRectangle |
|
224 rule:#copy |
|
225 mask:nil |
|
226 ! |
|
227 |
|
228 displayOn:aDisplayMedium at:aPoint clippingBox:clip rule:rule mask: aForm |
|
229 aDisplayMedium function:rule. |
|
230 ^ self drawIn:aDisplayMedium |
|
231 at:(aPoint + self origin) |
|
232 ! |
|
233 |
|
234 displayOn:aDisplayMedium at:aPoint |
|
235 ^ self drawIn:aDisplayMedium |
|
236 at:(aPoint + self origin) |
|
237 ! ! |
|
238 |
|
239 !DisplayObject methodsFor:'drawing'! |
|
240 |
|
241 drawIn:aView offset:anOffset |
|
242 "draw the receiver at its origin offset by anOffset, aPoint" |
|
243 |
|
244 ^ self subclassResponsiblitity |
|
245 ! |
|
246 |
|
247 drawIn:aView |
|
248 "draw the receiver at its origin" |
|
249 |
|
250 self drawIn:aView offset:(0@0) |
|
251 ! |
|
252 |
|
253 drawIn:aView at:drawOrigin |
|
254 "draw the receiver at drawOrigin, aPoint" |
|
255 |
|
256 self drawIn:aView offset:(drawOrigin - (self origin)) |
|
257 ! |
|
258 |
|
259 drawSelectedIn:aView offset:anOffset |
|
260 "draw the receiver highlighted - this is usually redefined" |
|
261 |
|
262 self drawIn:aView offset:anOffset. |
|
263 self drawOutlineIn:aView offset:anOffset |
|
264 ! |
|
265 |
|
266 drawSelectedIn:aView |
|
267 "draw the receiver highlighted at its position" |
|
268 |
|
269 self drawSelectedIn:aView offset:(0@0) |
|
270 ! |
|
271 |
|
272 drawOutlineIn:aView offset:anOffset |
|
273 "draw the receivers outline at its origin offset by anOffset, aPoint" |
|
274 |
|
275 |org| |
|
276 org := self origin + anOffset - aView viewOrigin. |
|
277 aView drawRectangleX:(org x) y:(org y) |
|
278 width:(frame width) height:(frame height) |
|
279 ! |
|
280 |
|
281 drawOutlineIn:aView |
|
282 "draw the receivers outline at its origin" |
|
283 |
|
284 self drawOutlineIn:aView offset:(0@0) |
|
285 ! |
|
286 |
|
287 drawOutlineIn:aView at:drawOrigin |
|
288 "draw the receivers outline at drawOrigin, aPoint" |
|
289 |
|
290 self drawOutlineIn:aView offset:(drawOrigin - (self origin)) |
|
291 ! |
|
292 |
|
293 drawDragIn:aView at:drawOrigin |
|
294 "draw the receiver for dragging" |
|
295 |
|
296 self class dragOutline ifTrue:[ |
|
297 self drawOutlineIn:aView offset:(drawOrigin - (self origin)) |
|
298 ] ifFalse: [ |
|
299 self drawIn:aView offset:(drawOrigin - (self origin)) |
|
300 ] |
|
301 ! |
|
302 |
|
303 drawDragIn:aView offset:drawOrigin |
|
304 self class dragOutline ifTrue:[ |
|
305 self drawOutlineIn:aView offset:drawOrigin |
|
306 ] ifFalse: [ |
|
307 self drawIn:aView offset:drawOrigin |
|
308 ] |
|
309 ! |
|
310 |
|
311 drawDragIn:aView |
|
312 self class dragOutline ifTrue:[ |
|
313 self drawOutlineIn:aView offset:(0 @ 0) |
|
314 ] ifFalse: [ |
|
315 self drawIn:aView offset:(0 @ 0) |
|
316 ] |
|
317 ! ! |