1321
|
1 |
Object subclass:#Border
|
|
2 |
instanceVariableNames:'left right top bottom leftColor rightColor topColor bottomColor'
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Interface-Support'
|
|
6 |
!
|
|
7 |
|
|
8 |
!Border class methodsFor:'documentation'!
|
|
9 |
|
|
10 |
documentation
|
|
11 |
"
|
|
12 |
a border holdes the values of a views (or components) border.
|
|
13 |
It is (currently) not used by ST/X, but provided as a comatibility hook.
|
|
14 |
(... however, ST/X is being rewritten to make use of it soon).
|
|
15 |
Notice:
|
|
16 |
this class was implemented using protocol information
|
|
17 |
from alpha testers, from reading PD programs and
|
|
18 |
from the Hopkins/Horan book.
|
|
19 |
- it may not be complete or compatible to the corresponding ST-80 class.
|
|
20 |
If you encounter any incompatibilities, please forward a note
|
|
21 |
describing the incompatibility verbal (i.e. no code) to the ST/X team.
|
|
22 |
|
|
23 |
[see also:]
|
|
24 |
Wrapper SimpleView
|
|
25 |
|
|
26 |
[author:]
|
|
27 |
Claus Gittinger
|
|
28 |
"
|
|
29 |
|
|
30 |
|
1324
|
31 |
!
|
|
32 |
|
|
33 |
examples
|
|
34 |
"
|
|
35 |
|v b|
|
|
36 |
|
|
37 |
v := StandardSystemView extent:10@10.
|
|
38 |
v openAndWait.
|
|
39 |
|
|
40 |
b := Border width:2 color:Color red.
|
|
41 |
b displayOn:v forDisplayBox:(0@0 corner:9@9).
|
|
42 |
|
|
43 |
Delay waitForSeconds:1.
|
|
44 |
b setLeftColor:Color blue.
|
|
45 |
b displayOn:v forDisplayBox:(0@0 corner:9@9).
|
|
46 |
Delay waitForSeconds:1.
|
|
47 |
b setTopColor:Color green.
|
|
48 |
b displayOn:v forDisplayBox:(0@0 corner:9@9).
|
|
49 |
Delay waitForSeconds:1.
|
|
50 |
b setRightColor:Color magenta.
|
|
51 |
b displayOn:v forDisplayBox:(0@0 corner:9@9).
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|v b|
|
|
56 |
|
|
57 |
v := StandardSystemView extent:100@100.
|
|
58 |
v openAndWait.
|
|
59 |
|
|
60 |
b := Border width:2 color:Color red.
|
|
61 |
b displayOn:v forDisplayBox:(0@0 corner:99@99).
|
|
62 |
|
|
63 |
Delay waitForSeconds:1.
|
|
64 |
b setLeft:5.
|
|
65 |
v clear.
|
|
66 |
b displayOn:v forDisplayBox:(0@0 corner:99@99).
|
|
67 |
Delay waitForSeconds:1.
|
|
68 |
b setTop:3.
|
|
69 |
v clear.
|
|
70 |
b displayOn:v forDisplayBox:(0@0 corner:99@99).
|
|
71 |
Delay waitForSeconds:1.
|
|
72 |
b setRight:1.
|
|
73 |
v clear.
|
|
74 |
b displayOn:v forDisplayBox:(0@0 corner:99@99).
|
|
75 |
"
|
1321
|
76 |
! !
|
|
77 |
|
|
78 |
!Border class methodsFor:'instance creation'!
|
|
79 |
|
|
80 |
width:borderWidth
|
|
81 |
"create a new instance of the receiver with a border of the given width
|
|
82 |
(and default color)."
|
|
83 |
|
|
84 |
^ self width:borderWidth color:View defaultBorderColor
|
|
85 |
|
|
86 |
"Modified: 10.2.1997 / 15:19:57 / cg"
|
|
87 |
!
|
|
88 |
|
|
89 |
width:borderWidth color:aColor
|
|
90 |
"create a new instance of the receiver with a border of the given width
|
|
91 |
and color."
|
|
92 |
|
|
93 |
^ self new
|
|
94 |
setBorderWidth:borderWidth color:aColor
|
|
95 |
|
|
96 |
"Modified: 10.2.1997 / 15:20:32 / cg"
|
|
97 |
! !
|
|
98 |
|
|
99 |
!Border methodsFor:'accessing'!
|
|
100 |
|
|
101 |
bottom
|
|
102 |
"return the bottom border width"
|
|
103 |
|
|
104 |
^ bottom
|
|
105 |
|
|
106 |
"Created: 10.2.1997 / 14:51:34 / cg"
|
|
107 |
"Modified: 10.2.1997 / 15:39:01 / cg"
|
|
108 |
!
|
|
109 |
|
|
110 |
bottomColor
|
|
111 |
"return the value of the instance variable 'bottomColor' (automatically generated)"
|
|
112 |
|
|
113 |
^ bottomColor
|
|
114 |
|
|
115 |
"Created: 10.2.1997 / 14:51:34 / cg"
|
|
116 |
!
|
|
117 |
|
|
118 |
color:newColor
|
|
119 |
"set all four colors"
|
|
120 |
|
|
121 |
leftColor := rightColor := topColor := bottomColor := newColor
|
|
122 |
|
|
123 |
"Created: 10.2.1997 / 15:27:01 / cg"
|
|
124 |
!
|
|
125 |
|
|
126 |
left
|
|
127 |
"return the left border width"
|
|
128 |
|
|
129 |
^ left
|
|
130 |
|
|
131 |
"Created: 10.2.1997 / 14:51:34 / cg"
|
|
132 |
"Modified: 10.2.1997 / 15:39:05 / cg"
|
|
133 |
!
|
|
134 |
|
|
135 |
leftColor
|
|
136 |
"return the value of the instance variable 'leftColor' (automatically generated)"
|
|
137 |
|
|
138 |
^ leftColor
|
|
139 |
|
|
140 |
"Created: 10.2.1997 / 14:51:34 / cg"
|
|
141 |
!
|
|
142 |
|
|
143 |
right
|
|
144 |
"return the right border width"
|
|
145 |
|
|
146 |
^ right
|
|
147 |
|
|
148 |
"Created: 10.2.1997 / 14:51:34 / cg"
|
|
149 |
"Modified: 10.2.1997 / 15:39:08 / cg"
|
|
150 |
!
|
|
151 |
|
|
152 |
rightColor
|
|
153 |
"return the value of the instance variable 'rightColor' (automatically generated)"
|
|
154 |
|
|
155 |
^ rightColor
|
|
156 |
|
|
157 |
"Created: 10.2.1997 / 14:51:34 / cg"
|
|
158 |
!
|
|
159 |
|
|
160 |
setBottom:aSmallInteger
|
|
161 |
"set the bottom border width"
|
|
162 |
|
|
163 |
bottom := aSmallInteger
|
|
164 |
|
|
165 |
"Created: 10.2.1997 / 15:38:50 / cg"
|
|
166 |
!
|
|
167 |
|
|
168 |
setBottomColor:aColor
|
|
169 |
"set the bottomColor"
|
|
170 |
|
|
171 |
bottomColor := aColor
|
|
172 |
|
|
173 |
"Created: 10.2.1997 / 15:37:51 / cg"
|
|
174 |
!
|
|
175 |
|
|
176 |
setLeft:aSmallInteger
|
|
177 |
"set the left border width"
|
|
178 |
|
|
179 |
left := aSmallInteger
|
|
180 |
|
|
181 |
"Created: 10.2.1997 / 15:39:33 / cg"
|
|
182 |
!
|
|
183 |
|
|
184 |
setLeftColor:aColor
|
|
185 |
"set the leftColor"
|
|
186 |
|
|
187 |
leftColor := aColor
|
|
188 |
|
|
189 |
"Created: 10.2.1997 / 15:38:02 / cg"
|
|
190 |
!
|
|
191 |
|
|
192 |
setRight:aSmallInteger
|
|
193 |
"set the right border width"
|
|
194 |
|
|
195 |
right := aSmallInteger
|
|
196 |
|
|
197 |
"Created: 10.2.1997 / 15:39:44 / cg"
|
|
198 |
!
|
|
199 |
|
|
200 |
setRightColor:aColor
|
|
201 |
"set the rightColor"
|
|
202 |
|
|
203 |
rightColor := aColor
|
|
204 |
|
|
205 |
"Created: 10.2.1997 / 15:38:08 / cg"
|
|
206 |
!
|
|
207 |
|
|
208 |
setTop:aSmallInteger
|
|
209 |
"set the top border width"
|
|
210 |
|
|
211 |
top := aSmallInteger
|
|
212 |
|
|
213 |
"Created: 10.2.1997 / 15:39:27 / cg"
|
|
214 |
!
|
|
215 |
|
|
216 |
setTopColor:aColor
|
|
217 |
"set the topColor"
|
|
218 |
|
|
219 |
topColor := aColor
|
|
220 |
|
|
221 |
"Created: 10.2.1997 / 15:38:17 / cg"
|
|
222 |
!
|
|
223 |
|
|
224 |
top
|
|
225 |
"return the top border width"
|
|
226 |
|
|
227 |
^ top
|
|
228 |
|
|
229 |
"Created: 10.2.1997 / 14:51:34 / cg"
|
|
230 |
"Modified: 10.2.1997 / 15:39:11 / cg"
|
|
231 |
!
|
|
232 |
|
|
233 |
topColor
|
|
234 |
"return the value of the instance variable 'topColor' (automatically generated)"
|
|
235 |
|
|
236 |
^ topColor
|
|
237 |
|
|
238 |
"Created: 10.2.1997 / 14:51:34 / cg"
|
|
239 |
! !
|
|
240 |
|
|
241 |
!Border methodsFor:'displaying'!
|
|
242 |
|
|
243 |
displayOn:aGC forDisplayBox:aRectangle
|
|
244 |
"display the borders represented by the receiver in the specified rectangle.
|
|
245 |
The gc is restored after the draw."
|
|
246 |
|
|
247 |
self displayOn:aGC forDisplayBox:aRectangle using:nil
|
|
248 |
|
|
249 |
"Modified: 10.2.1997 / 14:56:10 / cg"
|
|
250 |
!
|
|
251 |
|
|
252 |
displayOn:aGC forDisplayBox:aRectangle using:colorSource
|
|
253 |
"display the borders represented by the receiver borders in the given rectangle.
|
|
254 |
colorSource is ignored here, but subclasses (i.e. 3D-borders) may use
|
|
255 |
it to ask for shadow/lightColors.
|
|
256 |
The gc's state is restored after the drawing."
|
|
257 |
|
|
258 |
|clipRectangle paint oldPaint
|
|
259 |
t r l b rL rR rT rB rW rH|
|
|
260 |
|
|
261 |
"/ clipRectangle := aGC clippingBounds.
|
|
262 |
"/ ((self insetDisplayBoxFor: aRectangle) contains: clipRectangle) ifTrue: [^self].
|
|
263 |
|
|
264 |
oldPaint := aGC paint.
|
|
265 |
r := aRectangle copy.
|
|
266 |
|
|
267 |
t := self top.
|
|
268 |
l := self left.
|
|
269 |
r := self right.
|
|
270 |
b := self bottom.
|
|
271 |
|
|
272 |
rL := aRectangle left.
|
|
273 |
rT := aRectangle top.
|
|
274 |
rR := aRectangle right.
|
|
275 |
rB := aRectangle bottom.
|
|
276 |
rH := aRectangle height.
|
|
277 |
rW := aRectangle width.
|
|
278 |
|
|
279 |
(l ~~ 0 and: [(paint := self leftColor) notNil]) ifTrue:[
|
|
280 |
aGC paint:paint.
|
1324
|
281 |
aGC fillRectangleX:rL
|
|
282 |
y:rT
|
|
283 |
width:l
|
|
284 |
height:rH + 1 - b
|
1321
|
285 |
].
|
|
286 |
|
|
287 |
(t ~~ 0 and: [(paint := self topColor) notNil]) ifTrue:[
|
|
288 |
aGC paint:paint.
|
1324
|
289 |
aGC fillRectangleX:(rL + l)
|
|
290 |
y:rT
|
|
291 |
width:rW - l
|
|
292 |
height:t
|
1321
|
293 |
].
|
|
294 |
|
|
295 |
(r ~~ 0 and: [(paint := self rightColor) notNil]) ifTrue:[
|
|
296 |
aGC paint:paint.
|
1324
|
297 |
aGC fillRectangleX:(rR - r)
|
|
298 |
y:(rT + t)
|
|
299 |
width:r
|
|
300 |
height:rH + 1 - t
|
1321
|
301 |
].
|
|
302 |
|
|
303 |
(b ~~ 0 and: [(paint := self bottomColor) notNil]) ifTrue:[
|
|
304 |
aGC paint:paint.
|
1324
|
305 |
aGC fillRectangleX:(rL)
|
|
306 |
y:(rB + 1 - b)
|
|
307 |
width:rW - r
|
|
308 |
height:b
|
1321
|
309 |
].
|
|
310 |
|
|
311 |
aGC paint: oldPaint
|
|
312 |
|
1324
|
313 |
"Modified: 10.2.1997 / 15:55:04 / cg"
|
1321
|
314 |
! !
|
|
315 |
|
|
316 |
!Border methodsFor:'private accessing'!
|
|
317 |
|
|
318 |
setBorderWidth:aWidth color:aColor
|
|
319 |
left := right := top := bottom := aWidth.
|
|
320 |
leftColor := rightColor := topColor := bottomColor := aColor
|
|
321 |
|
|
322 |
"Created: 10.2.1997 / 15:21:27 / cg"
|
|
323 |
! !
|
|
324 |
|
|
325 |
!Border methodsFor:'queries'!
|
|
326 |
|
|
327 |
allSidesEqual:aSmallInteger
|
|
328 |
left ~~ aSmallInteger ifTrue:[^ false].
|
|
329 |
top ~~ aSmallInteger ifTrue:[^ false].
|
|
330 |
right ~~ aSmallInteger ifTrue:[^ false].
|
|
331 |
bottom ~~ aSmallInteger ifTrue:[^ false].
|
|
332 |
^ true
|
|
333 |
|
|
334 |
"Created: 10.2.1997 / 14:53:13 / cg"
|
|
335 |
!
|
|
336 |
|
|
337 |
displayBoxFor:aRectangle
|
|
338 |
"return a rectangle representing the overall display box of a component
|
|
339 |
bordered by the receiver, which has bounds of aRectangle.
|
|
340 |
That is, the argument outset by the receivers borders."
|
|
341 |
|
|
342 |
|insetRectangle|
|
|
343 |
|
|
344 |
insetRectangle := aRectangle copy.
|
|
345 |
insetRectangle left:(insetRectangle left - self left).
|
|
346 |
insetRectangle right:(insetRectangle right + self right).
|
|
347 |
insetRectangle top:(insetRectangle top - self top).
|
|
348 |
insetRectangle bottom:(insetRectangle bottom + self bottom).
|
|
349 |
^ insetRectangle
|
|
350 |
|
|
351 |
"Created: 10.2.1997 / 15:43:00 / cg"
|
|
352 |
!
|
|
353 |
|
|
354 |
insetDisplayBoxFor:aRectangle
|
|
355 |
"return a rectangle representing the display box of a component
|
|
356 |
bordered by the receiver in the outer bounds, aRectangle.
|
|
357 |
That is, the argument inset by the receivers borders."
|
|
358 |
|
|
359 |
|insetRectangle|
|
|
360 |
|
|
361 |
insetRectangle := aRectangle copy.
|
|
362 |
insetRectangle left:(insetRectangle left + self left).
|
|
363 |
insetRectangle right:(insetRectangle right - self right).
|
|
364 |
insetRectangle top:(insetRectangle top + self top).
|
|
365 |
insetRectangle bottom:(insetRectangle bottom - self bottom).
|
|
366 |
^ insetRectangle
|
|
367 |
|
|
368 |
"Created: 10.2.1997 / 15:42:06 / cg"
|
|
369 |
! !
|
|
370 |
|
|
371 |
!Border class methodsFor:'documentation'!
|
|
372 |
|
|
373 |
version
|
1324
|
374 |
^ '$Header: /cvs/stx/stx/libview/Border.st,v 1.3 1997-02-10 14:56:16 cg Exp $'
|
1321
|
375 |
! !
|