author | Claus Gittinger <cg@exept.de> |
Wed, 06 Sep 2000 15:50:23 +0200 | |
changeset 3301 | 1bcebb26ecbb |
parent 3292 | f5cbe9b1dc2a |
child 3490 | 7a560c566b72 |
permissions | -rw-r--r-- |
0 | 1 |
" |
6 | 2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
72 | 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 |
||
3292 | 13 |
"{ Package: 'stx:libview' }" |
14 |
||
135 | 15 |
SimpleView subclass:#ShadowView |
616 | 16 |
instanceVariableNames:'myView shadowLength shadowClr imageUnderShadow' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
626 | 19 |
category:'Views-Special' |
0 | 20 |
! |
21 |
||
1292 | 22 |
!ShadowView class methodsFor:'documentation'! |
46 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
72 | 27 |
All Rights Reserved |
0 | 28 |
|
46 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
0 | 37 |
|
46 | 38 |
documentation |
39 |
" |
|
676 | 40 |
ShadowView exists just to give PopUps and ModalBoxes a shadow. |
41 |
||
72 | 42 |
If shadowClr is nil, the shadowView reads the screen-contents under |
43 |
itself before realization, and uses a greyed version of these pixels |
|
44 |
for its background. If shadowClr is non-nil, that color is used |
|
45 |
as shadow (can be used for solid-black shadows). |
|
46 |
||
47 |
The instance variable myView is the view, for which the shadow is for. |
|
616 | 48 |
|
49 |
[author:] |
|
50 |
Claus Gittinger |
|
46 | 51 |
" |
52 |
! ! |
|
0 | 53 |
|
269 | 54 |
!ShadowView methodsFor:'accessing'! |
55 |
||
56 |
for:aView |
|
676 | 57 |
"set the view I am a shadow for" |
269 | 58 |
|
59 |
myView := aView |
|
676 | 60 |
|
61 |
"Modified: 12.5.1996 / 21:59:17 / cg" |
|
269 | 62 |
! |
63 |
||
64 |
isPopUpView |
|
676 | 65 |
"return true, since I want to come up without decoration" |
66 |
||
269 | 67 |
^ true |
676 | 68 |
|
69 |
"Modified: 12.5.1996 / 21:57:23 / cg" |
|
269 | 70 |
! |
71 |
||
72 |
shadowColor:aColor |
|
676 | 73 |
"set the shadow color" |
269 | 74 |
|
75 |
shadowClr := aColor |
|
676 | 76 |
|
77 |
"Modified: 12.5.1996 / 21:59:25 / cg" |
|
269 | 78 |
! ! |
79 |
||
80 |
!ShadowView methodsFor:'event handling'! |
|
81 |
||
82 |
redraw |
|
676 | 83 |
"if I have a shadowColor, fill all of myself with it; |
84 |
otherwise, draw the saved image under myself." |
|
269 | 85 |
|
86 |
|ws hs| |
|
87 |
||
274 | 88 |
ws := shadowLength x. |
89 |
hs := shadowLength y. |
|
269 | 90 |
shadowClr isNil ifTrue:[ |
676 | 91 |
imageUnderShadow isNil ifTrue:[^ self]. |
269 | 92 |
|
676 | 93 |
self copyFrom:imageUnderShadow x:(width - ws) y:0 |
94 |
toX:(width - ws) y:0 |
|
95 |
width:ws height:height. |
|
96 |
self copyFrom:imageUnderShadow x:0 y:(height - hs) |
|
97 |
toX:0 y:(height - hs) |
|
98 |
width:width height:hs. |
|
269 | 99 |
|
100 |
] ifFalse:[ |
|
676 | 101 |
self paint:shadowClr. |
102 |
self fillRectangleX:(width - ws) y:0 width:ws height:height |
|
269 | 103 |
] |
676 | 104 |
|
105 |
"Modified: 12.5.1996 / 22:00:05 / cg" |
|
269 | 106 |
! ! |
107 |
||
0 | 108 |
!ShadowView methodsFor:'initialization'! |
109 |
||
269 | 110 |
create |
676 | 111 |
"enable saveUnder of the covered view(s). |
112 |
This may not be supported by all devices - these have to redraw then" |
|
113 |
||
269 | 114 |
super create. |
115 |
self backingStore:false. |
|
116 |
self saveUnder:true |
|
676 | 117 |
|
118 |
"Modified: 12.5.1996 / 22:00:47 / cg" |
|
269 | 119 |
! |
120 |
||
0 | 121 |
initialize |
122 |
super initialize. |
|
123 |
borderWidth := 0. |
|
72 | 124 |
|
274 | 125 |
shadowClr := StyleSheet at:#popUpShadowColor. |
0 | 126 |
|
127 |
"the length of the shadow from myView" |
|
128 |
shadowLength := (device pixelPerMillimeter * 1.0) rounded |
|
129 |
! |
|
130 |
||
131 |
realize |
|
54 | 132 |
"realize the shadowView some distance away from myView, |
133 |
get the pixels under the shadow from the screen" |
|
0 | 134 |
|
2916 | 135 |
|root shW shH right bot kludge clr1 clr0 org blackIs0 img| |
0 | 136 |
|
137 |
myView notNil ifTrue:[ |
|
2916 | 138 |
|
743 | 139 |
self origin:(myView origin + (myView borderWidth * 2) + shadowLength) |
140 |
extent:(myView extent). |
|
0 | 141 |
|
743 | 142 |
shadowClr isNil ifTrue:[ |
143 |
" |
|
144 |
get the pixels under the shadow |
|
145 |
(copy from root-view into the 'imageUnderShadow'-form) |
|
146 |
" |
|
147 |
imageUnderShadow := Form width:width height:height depth:device depth on:device. |
|
1727
c2140507ab19
oops - X needs clippedByChildren:false.
Claus Gittinger <cg@exept.de>
parents:
1722
diff
changeset
|
148 |
imageUnderShadow clippedByChildren:false. |
0 | 149 |
|
743 | 150 |
shW := shadowLength x. |
151 |
shH := shadowLength y. |
|
152 |
right := width - shW. |
|
153 |
bot := height - shH. |
|
54 | 154 |
|
743 | 155 |
root := device rootView. |
156 |
||
157 |
clr0 := Color colorId:0. |
|
158 |
clr1 := Color colorId:1. |
|
2 | 159 |
|
743 | 160 |
kludge := device depth == 1. |
161 |
blackIs0 := (device blackpixel == 0). |
|
162 |
(kludge and:[blackIs0]) ifTrue:[ |
|
1727
c2140507ab19
oops - X needs clippedByChildren:false.
Claus Gittinger <cg@exept.de>
parents:
1722
diff
changeset
|
163 |
imageUnderShadow foreground:clr0 background:clr1. |
743 | 164 |
]. |
2 | 165 |
|
743 | 166 |
org := self origin. |
0 | 167 |
|
743 | 168 |
imageUnderShadow copyFrom:root x:(org x + right) y:org y |
169 |
toX:right y:0 width:shW height:height. |
|
0 | 170 |
|
743 | 171 |
imageUnderShadow copyFrom:root x:org x y:(org y + bot) |
172 |
toX:0 y:bot width:width height:shH. |
|
72 | 173 |
|
2916 | 174 |
false "device visualType == #TrueColor" ifTrue:[ |
175 |
" |
|
176 |
grey out the image (by darkening the pixels) |
|
177 |
(thats expensive ...) |
|
178 |
" |
|
179 |
img := Image fromForm:imageUnderShadow. |
|
180 |
0 to:height-1-shH do:[:y | |
|
181 |
right to:right+shW-1 do:[:x | |pix r g b| |
|
182 |
pix := img pixelAtX:x y:y. |
|
183 |
r := img redBitsOf:pix. |
|
184 |
g := img greenBitsOf:pix. |
|
185 |
b := img blueBitsOf:pix. |
|
186 |
r := r // 2. |
|
187 |
g := g // 2. |
|
188 |
b := b // 2. |
|
189 |
pix := img valueFromRedBits:r greenBits:g blueBits:b. |
|
190 |
img pixelAtX:x y:y put:pix. |
|
191 |
]. |
|
192 |
]. |
|
193 |
0 to:width-1 do:[:x | |
|
194 |
bot to:bot+shH-1 do:[:y | |pix r g b| |
|
195 |
pix := img pixelAtX:x y:y. |
|
196 |
r := img redBitsOf:pix. |
|
197 |
g := img greenBitsOf:pix. |
|
198 |
b := img blueBitsOf:pix. |
|
199 |
r := r // 2. |
|
200 |
g := g // 2. |
|
201 |
b := b // 2. |
|
202 |
pix := img valueFromRedBits:r greenBits:g blueBits:b. |
|
203 |
img pixelAtX:x y:y put:pix. |
|
204 |
]. |
|
205 |
]. |
|
206 |
imageUnderShadow := img asFormOn:device. |
|
207 |
] ifFalse:[ |
|
208 |
" |
|
209 |
grey out the image (by oring-in a grey pattern) |
|
210 |
(sometimes we are lucky, and can do it with one raster-op) |
|
211 |
" |
|
0 | 212 |
|
2916 | 213 |
(kludge and:[blackIs0]) ifFalse:[ |
214 |
imageUnderShadow foreground:clr0 background:(Color colorId:-1). |
|
215 |
imageUnderShadow mask:(Form mediumGreyFormOn:device). |
|
216 |
imageUnderShadow function:#and. |
|
217 |
imageUnderShadow fillRectangleX:right y:0 width:shW height:height. |
|
218 |
imageUnderShadow fillRectangleX:0 y:bot width:width height:shH. |
|
219 |
||
220 |
blackIs0 ifFalse:[ |
|
221 |
imageUnderShadow foreground:(Color black onDevice:device) background:clr0. |
|
222 |
imageUnderShadow function:#or. |
|
223 |
imageUnderShadow fillRectangleX:right y:0 width:shW height:height. |
|
224 |
imageUnderShadow fillRectangleX:0 y:bot width:width height:shH. |
|
225 |
] |
|
226 |
] ifTrue:[ |
|
227 |
imageUnderShadow foreground:clr1 background:clr0. |
|
228 |
imageUnderShadow mask:(Form mediumGreyFormOn:device). |
|
743 | 229 |
imageUnderShadow function:#or. |
230 |
imageUnderShadow fillRectangleX:right y:0 width:shW height:height. |
|
231 |
imageUnderShadow fillRectangleX:0 y:bot width:width height:shH. |
|
2916 | 232 |
]. |
743 | 233 |
]. |
234 |
]. |
|
235 |
super realize. |
|
236 |
self raise |
|
0 | 237 |
] |
743 | 238 |
|
1727
c2140507ab19
oops - X needs clippedByChildren:false.
Claus Gittinger <cg@exept.de>
parents:
1722
diff
changeset
|
239 |
"Modified: 12.5.1997 / 21:38:04 / cg" |
0 | 240 |
! |
241 |
||
12 | 242 |
recreate |
3301 | 243 |
"sent after a snapin or a migration, reinit for new device" |
3292 | 244 |
|
72 | 245 |
shadowClr notNil ifTrue:[ |
2830 | 246 |
shadowClr := shadowClr onDevice:device |
72 | 247 |
]. |
12 | 248 |
|
249 |
"the length of the shadow from myView" |
|
250 |
shadowLength := (device pixelPerMillimeter * 1.0) rounded. |
|
251 |
||
252 |
super recreate. |
|
253 |
self backingStore:false. |
|
254 |
self saveUnder:true |
|
269 | 255 |
! |
256 |
||
642 | 257 |
unmap |
2575 | 258 |
"unmap the view - the view stays created (but invisible), and can be remapped again later. |
259 |
relase the saved image of the covered view" |
|
676 | 260 |
|
269 | 261 |
imageUnderShadow := nil. |
642 | 262 |
super unmap. |
263 |
||
264 |
"Modified: 3.5.1996 / 23:45:23 / stefan" |
|
676 | 265 |
"Modified: 12.5.1996 / 22:01:17 / cg" |
0 | 266 |
! ! |
267 |
||
1292 | 268 |
!ShadowView class methodsFor:'documentation'! |
0 | 269 |
|
269 | 270 |
version |
3301 | 271 |
^ '$Header: /cvs/stx/stx/libview/ShadowView.st,v 1.32 2000-09-06 13:50:08 cg Exp $' |
0 | 272 |
! ! |