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