8278
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
7784
|
3 |
"
|
7942
|
4 |
COPYRIGHT (c) 1999 by Claus Gittinger / eXept Software AG
|
7784
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
4791
|
14 |
"{ Package: 'stx:libview' }"
|
|
15 |
|
7784
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
2941
|
18 |
Color subclass:#TranslucentColor
|
|
19 |
instanceVariableNames:'alpha'
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Graphics-Support'
|
|
23 |
!
|
|
24 |
|
|
25 |
!TranslucentColor class methodsFor:'documentation'!
|
|
26 |
|
7784
|
27 |
copyright
|
|
28 |
"
|
7942
|
29 |
COPYRIGHT (c) 1999 by Claus Gittinger / eXept Software AG
|
7784
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
2941
|
41 |
documentation
|
|
42 |
"
|
7797
|
43 |
TranslucentColor represents colors with an alpha (transparency) channel.
|
2941
|
44 |
This is experimental and not yet used by the system.
|
|
45 |
|
|
46 |
[Instance variables:]
|
|
47 |
|
4791
|
48 |
alpha <Integer> the internal alpha value (0..255)
|
2941
|
49 |
"
|
|
50 |
! !
|
|
51 |
|
|
52 |
!TranslucentColor class methodsFor:'instance creation'!
|
|
53 |
|
|
54 |
red:r green:g blue:b alpha:alpha
|
|
55 |
alpha = 1 ifTrue:[
|
6354
|
56 |
^ super red:r green:g blue:b
|
2941
|
57 |
].
|
6354
|
58 |
^ (super
|
|
59 |
scaledRed:(r * MaxValue // 100)
|
|
60 |
scaledGreen:(g * MaxValue // 100)
|
|
61 |
scaledBlue:(b * MaxValue // 100)) alpha:alpha
|
2941
|
62 |
|
8278
|
63 |
!
|
|
64 |
|
|
65 |
scaledRed:r scaledGreen:g scaledBlue:b alpha:alpha
|
|
66 |
^ self new
|
|
67 |
setScaledRed:r
|
|
68 |
scaledGreen:g
|
|
69 |
scaledBlue:b
|
|
70 |
alpha:alpha
|
|
71 |
|
|
72 |
"
|
|
73 |
TranslucentColor scaledRed:0 scaledGreen:0 scaledBlue:0
|
|
74 |
TranslucentColor scaledRed:0 scaledGreen:0 scaledBlue:0 alpha:1
|
|
75 |
TranslucentColor scaledRed:0 scaledGreen:0 scaledBlue:0 alpha:0.5
|
|
76 |
(TranslucentColor scaledRed:0 scaledGreen:0 scaledBlue:0 alpha:0.5) lightened
|
|
77 |
"
|
2941
|
78 |
! !
|
|
79 |
|
|
80 |
!TranslucentColor methodsFor:'accessing'!
|
|
81 |
|
|
82 |
alpha
|
|
83 |
"return the alpha value (0..1),
|
|
84 |
where 0 is completely transparent and 1 is completely opaque"
|
|
85 |
|
|
86 |
^ alpha asFloat / 255.0
|
|
87 |
|
|
88 |
|
|
89 |
!
|
|
90 |
|
|
91 |
alpha:alphaFraction
|
|
92 |
"set the alpha value (0..1),
|
|
93 |
where 0 is completely transparent and 1 is completely opaque"
|
|
94 |
|
8167
|
95 |
"/ self assert:(alphaFraction between:0 and:1).
|
2941
|
96 |
alpha := (alphaFraction * 255) rounded
|
8167
|
97 |
|
|
98 |
"Modified: / 05-09-2017 / 16:46:11 / cg"
|
2941
|
99 |
!
|
|
100 |
|
6279
|
101 |
alphaByte
|
|
102 |
"return the alpha value as byte 0..255,
|
|
103 |
where 0 is completely transparent and 255 is completely opaque"
|
|
104 |
|
8278
|
105 |
^ alpha ? 255
|
6279
|
106 |
!
|
|
107 |
|
2946
|
108 |
privateAlpha
|
|
109 |
"return the internal alpha value (0..255),
|
|
110 |
where 0 is completely transparent and 255 is completely opaque"
|
|
111 |
|
6354
|
112 |
^ alpha
|
|
113 |
!
|
2946
|
114 |
|
6354
|
115 |
scaledAlpha
|
|
116 |
"return the alpha value (0..16rFFFF),
|
|
117 |
where 0 is completely transparent and 16rFFFF is completely opaque"
|
2946
|
118 |
|
6354
|
119 |
^ alpha * 16rFFFF // 255
|
2946
|
120 |
!
|
|
121 |
|
2941
|
122 |
setAlphaByte:aByteValuedInteger
|
|
123 |
"set the alpha value (0..255),
|
|
124 |
where 0 is completely transparent and 255 is completely opaque"
|
|
125 |
|
|
126 |
alpha := aByteValuedInteger
|
|
127 |
|
|
128 |
|
8278
|
129 |
!
|
|
130 |
|
|
131 |
setScaledRed:r scaledGreen:g scaledBlue:b
|
|
132 |
"r,g,b must be 0..MAXVALUE"
|
|
133 |
|
|
134 |
super setScaledRed:r scaledGreen:g scaledBlue:b.
|
|
135 |
alpha isNil ifTrue:[
|
|
136 |
alpha := 255 "/ opaque
|
|
137 |
].
|
|
138 |
|
|
139 |
"
|
|
140 |
self scaledRed:0 scaledGreen:0 scaledBlue:0
|
|
141 |
"
|
|
142 |
!
|
|
143 |
|
|
144 |
setScaledRed:r scaledGreen:g scaledBlue:b alpha:alphaFraction
|
|
145 |
"alphaFraction must be 0..1;
|
|
146 |
r,g,b must be 0..MAXVALUE"
|
|
147 |
|
|
148 |
self setScaledRed:r scaledGreen:g scaledBlue:b.
|
|
149 |
self alpha:alphaFraction.
|
|
150 |
|
|
151 |
"
|
|
152 |
self scaledRed:0 scaledGreen:0 scaledBlue:0 alpha:0.5
|
|
153 |
"
|
|
154 |
!
|
|
155 |
|
|
156 |
setScaledRed:r scaledGreen:g scaledBlue:b alphaByte:a
|
|
157 |
"a must be 0..255;
|
|
158 |
r,g,b must be 0..MAXVALUE"
|
|
159 |
|
|
160 |
self setScaledRed:r scaledGreen:g scaledBlue:b .
|
|
161 |
self setAlphaByte:a.
|
|
162 |
|
|
163 |
"
|
|
164 |
self scaledRed:0 scaledGreen:0 scaledBlue:0 alpha:1
|
|
165 |
"
|
|
166 |
! !
|
|
167 |
|
|
168 |
!TranslucentColor methodsFor:'color operations'!
|
|
169 |
|
|
170 |
mixed:amount with:aColor
|
|
171 |
"create a new color from mixing amount of the receiver
|
|
172 |
with the argument, aColor.
|
|
173 |
Mixing is done by adding components (i.e. additive mixing)
|
|
174 |
(which is different from mixing colors on paper, which is subtractive).
|
|
175 |
With an amount of 1, this is the same as blendWith."
|
|
176 |
|
|
177 |
|newColor|
|
|
178 |
|
|
179 |
newColor := super mixed:amount with:aColor.
|
|
180 |
newColor setAlphaByte:(self alphaByte).
|
|
181 |
^ newColor
|
|
182 |
|
|
183 |
"
|
|
184 |
TranslucentColor red:50 green:50 blue:50 alpha:0.5
|
|
185 |
(TranslucentColor red:50 green:50 blue:50 alpha:0.5) lightened
|
|
186 |
(TranslucentColor red:50 green:50 blue:50 alpha:0.5) darkened
|
|
187 |
"
|
|
188 |
! !
|
|
189 |
|
|
190 |
!TranslucentColor methodsFor:'comparing'!
|
|
191 |
|
|
192 |
= aColor
|
8280
|
193 |
aColor species == self species ifFalse:[^ false].
|
|
194 |
|
8278
|
195 |
^ (self alpha = aColor alpha)
|
|
196 |
and:[ super = aColor ]
|
|
197 |
!
|
|
198 |
|
|
199 |
almostSameAs:aColor
|
|
200 |
^ (self alpha = aColor alpha)
|
|
201 |
and:[ super almostSameAs:aColor ]
|
2941
|
202 |
! !
|
|
203 |
|
8167
|
204 |
!TranslucentColor methodsFor:'inspecting'!
|
|
205 |
|
|
206 |
inspectorValueStringInListFor:anInspector
|
|
207 |
"returns a string to be shown in the inspector's list"
|
|
208 |
|
|
209 |
^ self htmlPrintString,'.',(self alphaByte hexPrintString:2)
|
|
210 |
|
|
211 |
"Created: / 05-09-2017 / 10:43:54 / cg"
|
|
212 |
! !
|
|
213 |
|
2941
|
214 |
!TranslucentColor methodsFor:'printing & storing'!
|
|
215 |
|
|
216 |
storeOn:aStream
|
|
217 |
"append a string representing an expression to reconstruct the receiver
|
|
218 |
to the argument, aStream"
|
|
219 |
|
|
220 |
|clsName|
|
|
221 |
|
|
222 |
clsName := self class name.
|
|
223 |
|
|
224 |
aStream nextPutAll:'(' , clsName , ' red:'.
|
|
225 |
(self red) storeOn:aStream.
|
|
226 |
aStream nextPutAll:' green:'.
|
|
227 |
(self green) storeOn:aStream.
|
|
228 |
aStream nextPutAll:' blue:'.
|
|
229 |
(self blue) storeOn:aStream.
|
|
230 |
aStream nextPutAll:' alpha:'.
|
|
231 |
(self alpha) storeOn:aStream.
|
|
232 |
aStream nextPut:$).
|
|
233 |
|
|
234 |
"
|
|
235 |
(self red:100 green:100 blue:0 alpha:1) storeOn:Transcript
|
|
236 |
"
|
|
237 |
! !
|
|
238 |
|
|
239 |
!TranslucentColor methodsFor:'queries'!
|
|
240 |
|
|
241 |
isOpaque
|
|
242 |
"return true, if I represent an opaque color"
|
|
243 |
|
|
244 |
^ alpha == 255
|
|
245 |
|
|
246 |
!
|
|
247 |
|
|
248 |
isTranslucent
|
|
249 |
"return true, if I represent a translucent color;
|
|
250 |
that is: not completely opaque"
|
|
251 |
|
|
252 |
^ alpha < 255
|
|
253 |
|
|
254 |
!
|
|
255 |
|
2946
|
256 |
isTranslucentColor
|
|
257 |
"return true, if I represent a translucent color;
|
|
258 |
This means: self isTranslucent, but isTransparent not"
|
|
259 |
|
|
260 |
^ alpha > 0
|
|
261 |
!
|
|
262 |
|
2941
|
263 |
isTransparent
|
|
264 |
"return true, if I represent a completely transparent color"
|
|
265 |
|
|
266 |
^ alpha == 0
|
|
267 |
! !
|
|
268 |
|
|
269 |
!TranslucentColor class methodsFor:'documentation'!
|
|
270 |
|
|
271 |
version
|
7784
|
272 |
^ '$Header$'
|
7797
|
273 |
!
|
|
274 |
|
|
275 |
version_CVS
|
|
276 |
^ '$Header$'
|
2941
|
277 |
! !
|
6279
|
278 |
|