7784
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1999 by eXept Software AG
|
|
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 |
"
|
|
27 |
COPYRIGHT (c) 1999 by eXept Software AG
|
|
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 |
|
|
78 |
alpha := (alphaFraction * 255) rounded
|
|
79 |
!
|
|
80 |
|
6279
|
81 |
alphaByte
|
|
82 |
"return the alpha value as byte 0..255,
|
|
83 |
where 0 is completely transparent and 255 is completely opaque"
|
|
84 |
|
6354
|
85 |
^ alpha
|
6279
|
86 |
!
|
|
87 |
|
2946
|
88 |
privateAlpha
|
|
89 |
"return the internal alpha value (0..255),
|
|
90 |
where 0 is completely transparent and 255 is completely opaque"
|
|
91 |
|
6354
|
92 |
^ alpha
|
|
93 |
!
|
2946
|
94 |
|
6354
|
95 |
scaledAlpha
|
|
96 |
"return the alpha value (0..16rFFFF),
|
|
97 |
where 0 is completely transparent and 16rFFFF is completely opaque"
|
2946
|
98 |
|
6354
|
99 |
^ alpha * 16rFFFF // 255
|
2946
|
100 |
!
|
|
101 |
|
2941
|
102 |
setAlphaByte:aByteValuedInteger
|
|
103 |
"set the alpha value (0..255),
|
|
104 |
where 0 is completely transparent and 255 is completely opaque"
|
|
105 |
|
|
106 |
alpha := aByteValuedInteger
|
|
107 |
|
|
108 |
|
|
109 |
! !
|
|
110 |
|
|
111 |
!TranslucentColor methodsFor:'printing & storing'!
|
|
112 |
|
|
113 |
storeOn:aStream
|
|
114 |
"append a string representing an expression to reconstruct the receiver
|
|
115 |
to the argument, aStream"
|
|
116 |
|
|
117 |
|clsName|
|
|
118 |
|
|
119 |
clsName := self class name.
|
|
120 |
|
|
121 |
aStream nextPutAll:'(' , clsName , ' red:'.
|
|
122 |
(self red) storeOn:aStream.
|
|
123 |
aStream nextPutAll:' green:'.
|
|
124 |
(self green) storeOn:aStream.
|
|
125 |
aStream nextPutAll:' blue:'.
|
|
126 |
(self blue) storeOn:aStream.
|
|
127 |
aStream nextPutAll:' alpha:'.
|
|
128 |
(self alpha) storeOn:aStream.
|
|
129 |
aStream nextPut:$).
|
|
130 |
|
|
131 |
"
|
|
132 |
(self red:100 green:100 blue:0 alpha:1) storeOn:Transcript
|
|
133 |
"
|
|
134 |
! !
|
|
135 |
|
|
136 |
!TranslucentColor methodsFor:'queries'!
|
|
137 |
|
|
138 |
isOpaque
|
|
139 |
"return true, if I represent an opaque color"
|
|
140 |
|
|
141 |
^ alpha == 255
|
|
142 |
|
|
143 |
!
|
|
144 |
|
|
145 |
isTranslucent
|
|
146 |
"return true, if I represent a translucent color;
|
|
147 |
that is: not completely opaque"
|
|
148 |
|
|
149 |
^ alpha < 255
|
|
150 |
|
|
151 |
!
|
|
152 |
|
2946
|
153 |
isTranslucentColor
|
|
154 |
"return true, if I represent a translucent color;
|
|
155 |
This means: self isTranslucent, but isTransparent not"
|
|
156 |
|
|
157 |
^ alpha > 0
|
|
158 |
!
|
|
159 |
|
2941
|
160 |
isTransparent
|
|
161 |
"return true, if I represent a completely transparent color"
|
|
162 |
|
|
163 |
^ alpha == 0
|
|
164 |
! !
|
|
165 |
|
|
166 |
!TranslucentColor class methodsFor:'documentation'!
|
|
167 |
|
|
168 |
version
|
7784
|
169 |
^ '$Header$'
|
7797
|
170 |
!
|
|
171 |
|
|
172 |
version_CVS
|
|
173 |
^ '$Header$'
|
2941
|
174 |
! !
|
6279
|
175 |
|