7784
|
1 |
"
|
7942
|
2 |
COPYRIGHT (c) 1999 by Claus Gittinger / eXept Software AG
|
7784
|
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 |
"
|
4791
|
12 |
"{ Package: 'stx:libview' }"
|
|
13 |
|
7784
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
2941
|
16 |
Color subclass:#TranslucentColor
|
|
17 |
instanceVariableNames:'alpha'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Graphics-Support'
|
|
21 |
!
|
|
22 |
|
|
23 |
!TranslucentColor class methodsFor:'documentation'!
|
|
24 |
|
7784
|
25 |
copyright
|
|
26 |
"
|
7942
|
27 |
COPYRIGHT (c) 1999 by Claus Gittinger / eXept Software AG
|
7784
|
28 |
All Rights Reserved
|
|
29 |
|
|
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 |
!
|
|
38 |
|
2941
|
39 |
documentation
|
|
40 |
"
|
7797
|
41 |
TranslucentColor represents colors with an alpha (transparency) channel.
|
2941
|
42 |
This is experimental and not yet used by the system.
|
|
43 |
|
|
44 |
[Instance variables:]
|
|
45 |
|
4791
|
46 |
alpha <Integer> the internal alpha value (0..255)
|
2941
|
47 |
"
|
|
48 |
! !
|
|
49 |
|
|
50 |
!TranslucentColor class methodsFor:'instance creation'!
|
|
51 |
|
|
52 |
red:r green:g blue:b alpha:alpha
|
|
53 |
alpha = 1 ifTrue:[
|
6354
|
54 |
^ super red:r green:g blue:b
|
2941
|
55 |
].
|
6354
|
56 |
^ (super
|
|
57 |
scaledRed:(r * MaxValue // 100)
|
|
58 |
scaledGreen:(g * MaxValue // 100)
|
|
59 |
scaledBlue:(b * MaxValue // 100)) alpha:alpha
|
2941
|
60 |
|
|
61 |
! !
|
|
62 |
|
|
63 |
!TranslucentColor methodsFor:'accessing'!
|
|
64 |
|
|
65 |
alpha
|
|
66 |
"return the alpha value (0..1),
|
|
67 |
where 0 is completely transparent and 1 is completely opaque"
|
|
68 |
|
|
69 |
^ alpha asFloat / 255.0
|
|
70 |
|
|
71 |
|
|
72 |
!
|
|
73 |
|
|
74 |
alpha:alphaFraction
|
|
75 |
"set the alpha value (0..1),
|
|
76 |
where 0 is completely transparent and 1 is completely opaque"
|
|
77 |
|
8167
|
78 |
"/ self assert:(alphaFraction between:0 and:1).
|
2941
|
79 |
alpha := (alphaFraction * 255) rounded
|
8167
|
80 |
|
|
81 |
"Modified: / 05-09-2017 / 16:46:11 / cg"
|
2941
|
82 |
!
|
|
83 |
|
6279
|
84 |
alphaByte
|
|
85 |
"return the alpha value as byte 0..255,
|
|
86 |
where 0 is completely transparent and 255 is completely opaque"
|
|
87 |
|
6354
|
88 |
^ alpha
|
6279
|
89 |
!
|
|
90 |
|
2946
|
91 |
privateAlpha
|
|
92 |
"return the internal alpha value (0..255),
|
|
93 |
where 0 is completely transparent and 255 is completely opaque"
|
|
94 |
|
6354
|
95 |
^ alpha
|
|
96 |
!
|
2946
|
97 |
|
6354
|
98 |
scaledAlpha
|
|
99 |
"return the alpha value (0..16rFFFF),
|
|
100 |
where 0 is completely transparent and 16rFFFF is completely opaque"
|
2946
|
101 |
|
6354
|
102 |
^ alpha * 16rFFFF // 255
|
2946
|
103 |
!
|
|
104 |
|
2941
|
105 |
setAlphaByte:aByteValuedInteger
|
|
106 |
"set the alpha value (0..255),
|
|
107 |
where 0 is completely transparent and 255 is completely opaque"
|
|
108 |
|
|
109 |
alpha := aByteValuedInteger
|
|
110 |
|
|
111 |
|
|
112 |
! !
|
|
113 |
|
8167
|
114 |
!TranslucentColor methodsFor:'inspecting'!
|
|
115 |
|
|
116 |
inspectorValueStringInListFor:anInspector
|
|
117 |
"returns a string to be shown in the inspector's list"
|
|
118 |
|
|
119 |
^ self htmlPrintString,'.',(self alphaByte hexPrintString:2)
|
|
120 |
|
|
121 |
"Created: / 05-09-2017 / 10:43:54 / cg"
|
|
122 |
! !
|
|
123 |
|
2941
|
124 |
!TranslucentColor methodsFor:'printing & storing'!
|
|
125 |
|
|
126 |
storeOn:aStream
|
|
127 |
"append a string representing an expression to reconstruct the receiver
|
|
128 |
to the argument, aStream"
|
|
129 |
|
|
130 |
|clsName|
|
|
131 |
|
|
132 |
clsName := self class name.
|
|
133 |
|
|
134 |
aStream nextPutAll:'(' , clsName , ' red:'.
|
|
135 |
(self red) storeOn:aStream.
|
|
136 |
aStream nextPutAll:' green:'.
|
|
137 |
(self green) storeOn:aStream.
|
|
138 |
aStream nextPutAll:' blue:'.
|
|
139 |
(self blue) storeOn:aStream.
|
|
140 |
aStream nextPutAll:' alpha:'.
|
|
141 |
(self alpha) storeOn:aStream.
|
|
142 |
aStream nextPut:$).
|
|
143 |
|
|
144 |
"
|
|
145 |
(self red:100 green:100 blue:0 alpha:1) storeOn:Transcript
|
|
146 |
"
|
|
147 |
! !
|
|
148 |
|
|
149 |
!TranslucentColor methodsFor:'queries'!
|
|
150 |
|
|
151 |
isOpaque
|
|
152 |
"return true, if I represent an opaque color"
|
|
153 |
|
|
154 |
^ alpha == 255
|
|
155 |
|
|
156 |
!
|
|
157 |
|
|
158 |
isTranslucent
|
|
159 |
"return true, if I represent a translucent color;
|
|
160 |
that is: not completely opaque"
|
|
161 |
|
|
162 |
^ alpha < 255
|
|
163 |
|
|
164 |
!
|
|
165 |
|
2946
|
166 |
isTranslucentColor
|
|
167 |
"return true, if I represent a translucent color;
|
|
168 |
This means: self isTranslucent, but isTransparent not"
|
|
169 |
|
|
170 |
^ alpha > 0
|
|
171 |
!
|
|
172 |
|
2941
|
173 |
isTransparent
|
|
174 |
"return true, if I represent a completely transparent color"
|
|
175 |
|
|
176 |
^ alpha == 0
|
|
177 |
! !
|
|
178 |
|
|
179 |
!TranslucentColor class methodsFor:'documentation'!
|
|
180 |
|
|
181 |
version
|
7784
|
182 |
^ '$Header$'
|
7797
|
183 |
!
|
|
184 |
|
|
185 |
version_CVS
|
|
186 |
^ '$Header$'
|
2941
|
187 |
! !
|
6279
|
188 |
|