4791
|
1 |
"{ Package: 'stx:libview' }"
|
|
2 |
|
2941
|
3 |
Color subclass:#TranslucentColor
|
|
4 |
instanceVariableNames:'alpha'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Graphics-Support'
|
|
8 |
!
|
|
9 |
|
|
10 |
!TranslucentColor class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
TranslucentColor represents colors with an alpha (transparency)
|
|
15 |
channel.
|
|
16 |
This is experimental and not yet used by the system.
|
|
17 |
|
|
18 |
[Instance variables:]
|
|
19 |
|
4791
|
20 |
alpha <Integer> the internal alpha value (0..255)
|
2941
|
21 |
"
|
|
22 |
! !
|
|
23 |
|
|
24 |
!TranslucentColor class methodsFor:'instance creation'!
|
|
25 |
|
|
26 |
red:r green:g blue:b alpha:alpha
|
|
27 |
alpha = 1 ifTrue:[
|
6354
|
28 |
^ super red:r green:g blue:b
|
2941
|
29 |
].
|
6354
|
30 |
^ (super
|
|
31 |
scaledRed:(r * MaxValue // 100)
|
|
32 |
scaledGreen:(g * MaxValue // 100)
|
|
33 |
scaledBlue:(b * MaxValue // 100)) alpha:alpha
|
2941
|
34 |
|
|
35 |
! !
|
|
36 |
|
|
37 |
!TranslucentColor methodsFor:'accessing'!
|
|
38 |
|
|
39 |
alpha
|
|
40 |
"return the alpha value (0..1),
|
|
41 |
where 0 is completely transparent and 1 is completely opaque"
|
|
42 |
|
|
43 |
^ alpha asFloat / 255.0
|
|
44 |
|
|
45 |
|
|
46 |
!
|
|
47 |
|
|
48 |
alpha:alphaFraction
|
|
49 |
"set the alpha value (0..1),
|
|
50 |
where 0 is completely transparent and 1 is completely opaque"
|
|
51 |
|
|
52 |
alpha := (alphaFraction * 255) rounded
|
|
53 |
!
|
|
54 |
|
6279
|
55 |
alphaByte
|
|
56 |
"return the alpha value as byte 0..255,
|
|
57 |
where 0 is completely transparent and 255 is completely opaque"
|
|
58 |
|
6354
|
59 |
^ alpha
|
6279
|
60 |
!
|
|
61 |
|
2946
|
62 |
privateAlpha
|
|
63 |
"return the internal alpha value (0..255),
|
|
64 |
where 0 is completely transparent and 255 is completely opaque"
|
|
65 |
|
6354
|
66 |
^ alpha
|
|
67 |
!
|
2946
|
68 |
|
6354
|
69 |
scaledAlpha
|
|
70 |
"return the alpha value (0..16rFFFF),
|
|
71 |
where 0 is completely transparent and 16rFFFF is completely opaque"
|
2946
|
72 |
|
6354
|
73 |
^ alpha * 16rFFFF // 255
|
2946
|
74 |
!
|
|
75 |
|
6354
|
76 |
|
2941
|
77 |
setAlphaByte:aByteValuedInteger
|
|
78 |
"set the alpha value (0..255),
|
|
79 |
where 0 is completely transparent and 255 is completely opaque"
|
|
80 |
|
|
81 |
alpha := aByteValuedInteger
|
|
82 |
|
|
83 |
|
|
84 |
! !
|
|
85 |
|
|
86 |
!TranslucentColor methodsFor:'printing & storing'!
|
|
87 |
|
|
88 |
storeOn:aStream
|
|
89 |
"append a string representing an expression to reconstruct the receiver
|
|
90 |
to the argument, aStream"
|
|
91 |
|
|
92 |
|clsName|
|
|
93 |
|
|
94 |
clsName := self class name.
|
|
95 |
|
|
96 |
aStream nextPutAll:'(' , clsName , ' red:'.
|
|
97 |
(self red) storeOn:aStream.
|
|
98 |
aStream nextPutAll:' green:'.
|
|
99 |
(self green) storeOn:aStream.
|
|
100 |
aStream nextPutAll:' blue:'.
|
|
101 |
(self blue) storeOn:aStream.
|
|
102 |
aStream nextPutAll:' alpha:'.
|
|
103 |
(self alpha) storeOn:aStream.
|
|
104 |
aStream nextPut:$).
|
|
105 |
|
|
106 |
"
|
|
107 |
(self red:100 green:100 blue:0 alpha:1) storeOn:Transcript
|
|
108 |
"
|
|
109 |
! !
|
|
110 |
|
|
111 |
!TranslucentColor methodsFor:'queries'!
|
|
112 |
|
|
113 |
isOpaque
|
|
114 |
"return true, if I represent an opaque color"
|
|
115 |
|
|
116 |
^ alpha == 255
|
|
117 |
|
|
118 |
!
|
|
119 |
|
|
120 |
isTranslucent
|
|
121 |
"return true, if I represent a translucent color;
|
|
122 |
that is: not completely opaque"
|
|
123 |
|
|
124 |
^ alpha < 255
|
|
125 |
|
|
126 |
!
|
|
127 |
|
2946
|
128 |
isTranslucentColor
|
|
129 |
"return true, if I represent a translucent color;
|
|
130 |
This means: self isTranslucent, but isTransparent not"
|
|
131 |
|
|
132 |
^ alpha > 0
|
|
133 |
!
|
|
134 |
|
2941
|
135 |
isTransparent
|
|
136 |
"return true, if I represent a completely transparent color"
|
|
137 |
|
|
138 |
^ alpha == 0
|
|
139 |
! !
|
|
140 |
|
|
141 |
!TranslucentColor class methodsFor:'documentation'!
|
|
142 |
|
|
143 |
version
|
6354
|
144 |
^ '$Header: /cvs/stx/stx/libview/TranslucentColor.st,v 1.5 2014-03-22 09:26:53 cg Exp $'
|
2941
|
145 |
! !
|
6279
|
146 |
|