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