author | mawalch |
Wed, 28 Sep 2016 13:20:15 +0200 | |
changeset 3750 | 73f907f202bc |
parent 3453 | 5591424bb4d2 |
child 3813 | d581c117b1db |
permissions | -rw-r--r-- |
3452 | 1 |
"{ Encoding: utf8 }" |
2 |
||
39 | 3 |
" |
4 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
" |
|
3452 | 14 |
"{ Package: 'stx:libview2' }" |
39 | 15 |
|
3452 | 16 |
"{ NameSpace: Smalltalk }" |
2135 | 17 |
|
39 | 18 |
Color subclass:#ColorValue |
214 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Graphics-Support' |
|
39 | 23 |
! |
24 |
||
25 |
!ColorValue class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
||
41 |
documentation |
|
42 |
" |
|
43 |
ColorValue is provided for ST-80 compatibility. |
|
44 |
read the section on compatibility issues in the Color class's documentation. |
|
220 | 45 |
|
46 |
[author:] |
|
47 |
Claus Gittinger |
|
39 | 48 |
" |
49 |
! ! |
|
50 |
||
51 |
!ColorValue class methodsFor:'instance creation'! |
|
52 |
||
214 | 53 |
brightness:grey |
54 |
"return a grey color. |
|
55 |
The grey value is given in 0..1 instead of percent" |
|
56 |
||
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
57 |
^ self scaledGray:(grey * MaxValue) rounded |
214 | 58 |
|
59 |
" |
|
60 |
ColorValue brightness:0.5 |
|
61 |
" |
|
277 | 62 |
|
63 |
"Modified: 28.5.1996 / 20:53:52 / cg" |
|
214 | 64 |
! |
65 |
||
100 | 66 |
doesNotUnderstand:aMessage |
67 |
"catch other instance creation messages" |
|
68 |
||
69 |
|clr| |
|
70 |
||
71 |
(clr := self name:aMessage selector asString) notNil ifTrue:[ |
|
72 |
^ clr |
|
73 |
]. |
|
74 |
^ super doesNotUnderstand:aMessage |
|
75 |
||
76 |
" |
|
77 |
ColorValue royalBlue |
|
78 |
ColorValue funnyGreen |
|
79 |
" |
|
47 | 80 |
! |
81 |
||
63 | 82 |
hue:hue saturation:sat brightness:light |
83 |
"return a color. |
|
84 |
The hue, saturation and brightness values are given in 0..1 instead of |
|
85 |
degrees / percent" |
|
86 |
||
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
87 |
^ self hue:hue*360 light:light*100 saturation:sat*100 |
63 | 88 |
|
89 |
" |
|
90 |
ColorValue hue:0 saturation:1 brightness:0.5 |
|
91 |
" |
|
92 |
! |
|
93 |
||
214 | 94 |
red:r green:g blue:b |
95 |
"return a color from red, green and blue values. |
|
96 |
The arguments, r, g and b must be in the range (0..1)" |
|
97 |
||
412 | 98 |
^ super |
99 |
scaledRed:(r * MaxValue) rounded |
|
100 |
scaledGreen:(g * MaxValue) rounded |
|
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
101 |
scaledBlue:(b * MaxValue) rounded |
214 | 102 |
|
103 |
" |
|
104 |
ColorValue red:0 green:1 blue:0 |
|
412 | 105 |
ColorValue red:0 green:0.5 blue:0 |
106 |
" |
|
107 |
! |
|
108 |
||
109 |
scaledRed:r scaledGreen:g scaledBlue:b |
|
110 |
"return a color from scaled red, green and blue values. |
|
111 |
This rescales from ST80 scale-values (0..1FFF) to whatever our |
|
112 |
internal scale value is." |
|
113 |
||
114 |
^ super |
|
115 |
scaledRed:(r * MaxValue / 16r1FFF) rounded |
|
116 |
scaledGreen:(g * MaxValue / 16r1FFF) rounded |
|
117 |
scaledBlue:(b * MaxValue / 16r1FFF) rounded |
|
118 |
||
119 |
" |
|
120 |
ColorValue scaledRed:0 scaledGreen:16r0FFF scaledBlue:0 |
|
214 | 121 |
" |
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
122 |
! ! |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
123 |
|
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
124 |
!ColorValue methodsFor:'accessing'! |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
125 |
|
301 | 126 |
blue |
127 |
"return the blue component in 0..1" |
|
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
128 |
|
301 | 129 |
^ blue / MaxValue |
214 | 130 |
! |
131 |
||
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
132 |
green |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
133 |
"return the green component in 0..1" |
39 | 134 |
|
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
135 |
^ green / MaxValue |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
136 |
! |
39 | 137 |
|
301 | 138 |
light |
139 |
"return the hue component in 0..1" |
|
140 |
||
141 |
^ super light / 100.0 |
|
142 |
||
143 |
" |
|
144 |
Color yellow light |
|
145 |
ColorValue yellow light |
|
146 |
" |
|
147 |
||
148 |
"Created: 11.6.1996 / 17:17:39 / cg" |
|
149 |
! |
|
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
150 |
|
301 | 151 |
red |
152 |
"return the red component in 0..1" |
|
153 |
||
154 |
^ red / MaxValue |
|
155 |
! |
|
156 |
||
157 |
saturation |
|
158 |
"return the saturation component in 0..1" |
|
159 |
||
160 |
^ super saturation / 100.0 |
|
161 |
||
162 |
" |
|
163 |
Color yellow saturation |
|
164 |
ColorValue yellow saturation |
|
165 |
" |
|
166 |
||
167 |
"Created: 11.6.1996 / 17:17:57 / cg" |
|
39 | 168 |
! ! |
214 | 169 |
|
378 | 170 |
!ColorValue methodsFor:'converting'! |
171 |
||
172 |
fromLiteralArrayEncoding:encoding |
|
173 |
"read my values from an encoding. |
|
174 |
The encoding is supposed to be of the form: |
|
175 |
(#ColorValue scaledRed scaledGreen scaledBlue) |
|
176 |
This is the reverse operation to #literalArrayEncoding." |
|
177 |
||
488 | 178 |
|clr| |
179 |
||
180 |
encoding size == 2 ifTrue:[ |
|
181 |
clr := ColorValue name:(encoding at:2). |
|
495 | 182 |
red := clr scaledRed. |
183 |
green := clr scaledGreen. |
|
184 |
blue := clr scaledBlue. |
|
488 | 185 |
] ifFalse:[ |
3453 | 186 |
"/ (encoding at:2) isSymbol ifTrue:[ |
187 |
"/ clr := ColorValue perform:(encoding at:2) withArguments:(encoding at:3). |
|
188 |
"/ red := clr scaledRed. |
|
189 |
"/ green := clr scaledGreen. |
|
190 |
"/ blue := clr scaledBlue. |
|
191 |
"/ ] ifFalse:[ |
|
3452 | 192 |
red := (encoding at:2). |
193 |
green := (encoding at:3). |
|
194 |
blue := (encoding at:4). |
|
3453 | 195 |
"/ ] |
488 | 196 |
] |
378 | 197 |
|
198 |
" |
|
199 |
ColorValue new fromLiteralArrayEncoding:#(#Color 7700 7700 7700) |
|
200 |
" |
|
201 |
||
202 |
"Created: 22.1.1997 / 04:18:50 / cg" |
|
495 | 203 |
"Modified: 6.3.1997 / 15:45:01 / cg" |
378 | 204 |
! |
205 |
||
206 |
literalArrayEncoding |
|
207 |
"encode myself as an array, from which a copy of the receiver |
|
208 |
can be reconstructed with #decodeAsLiteralArray. |
|
209 |
The encoding is: |
|
210 |
(#ColorValue scaledRed scaledGreen scaledBlue) |
|
211 |
" |
|
212 |
||
213 |
^ Array |
|
2135 | 214 |
with:self class name |
378 | 215 |
with:(self scaledRed) |
216 |
with:(self scaledGreen) |
|
217 |
with:(self scaledBlue) |
|
218 |
||
219 |
" |
|
220 |
ColorValue new fromLiteralArrayEncoding:#(#Color 50 25 25) |
|
221 |
(ColorValue red:0.5 green:0.25 blue:1.0) literalArrayEncoding |
|
222 |
" |
|
223 |
||
224 |
"Modified: 22.1.1997 / 04:17:59 / cg" |
|
225 |
! ! |
|
226 |
||
3452 | 227 |
|
228 |
||
214 | 229 |
!ColorValue class methodsFor:'documentation'! |
230 |
||
231 |
version |
|
3453 | 232 |
^ '$Header: /cvs/stx/stx/libview2/ColorValue.st,v 1.19 2015-03-24 15:15:07 cg Exp $' |
233 |
! |
|
234 |
||
235 |
version_CVS |
|
236 |
^ '$Header: /cvs/stx/stx/libview2/ColorValue.st,v 1.19 2015-03-24 15:15:07 cg Exp $' |
|
214 | 237 |
! ! |
3452 | 238 |