author | Claus Gittinger <cg@exept.de> |
Wed, 22 Jan 1997 04:19:07 +0100 | |
changeset 378 | 3924b37b0ea4 |
parent 301 | 9d63572bb1e2 |
child 412 | 5fbd63617e33 |
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 |
" |
|
12 |
||
13 |
Color subclass:#ColorValue |
|
214 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Support' |
|
39 | 18 |
! |
19 |
||
20 |
!ColorValue class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
ColorValue is provided for ST-80 compatibility. |
|
39 |
read the section on compatibility issues in the Color class's documentation. |
|
220 | 40 |
|
41 |
[author:] |
|
42 |
Claus Gittinger |
|
39 | 43 |
" |
44 |
! ! |
|
45 |
||
46 |
!ColorValue class methodsFor:'instance creation'! |
|
47 |
||
214 | 48 |
brightness:grey |
49 |
"return a grey color. |
|
50 |
The grey value is given in 0..1 instead of percent" |
|
51 |
||
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
52 |
^ self scaledGray:(grey * MaxValue) rounded |
214 | 53 |
|
54 |
" |
|
55 |
ColorValue brightness:0.5 |
|
56 |
" |
|
277 | 57 |
|
58 |
"Modified: 28.5.1996 / 20:53:52 / cg" |
|
214 | 59 |
! |
60 |
||
100 | 61 |
doesNotUnderstand:aMessage |
62 |
"catch other instance creation messages" |
|
63 |
||
64 |
|clr| |
|
65 |
||
66 |
(clr := self name:aMessage selector asString) notNil ifTrue:[ |
|
67 |
^ clr |
|
68 |
]. |
|
69 |
^ super doesNotUnderstand:aMessage |
|
70 |
||
71 |
" |
|
72 |
ColorValue royalBlue |
|
73 |
ColorValue funnyGreen |
|
74 |
" |
|
47 | 75 |
! |
76 |
||
63 | 77 |
hue:hue saturation:sat brightness:light |
78 |
"return a color. |
|
79 |
The hue, saturation and brightness values are given in 0..1 instead of |
|
80 |
degrees / percent" |
|
81 |
||
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
82 |
^ self hue:hue*360 light:light*100 saturation:sat*100 |
63 | 83 |
|
84 |
" |
|
85 |
ColorValue hue:0 saturation:1 brightness:0.5 |
|
86 |
" |
|
87 |
! |
|
88 |
||
214 | 89 |
red:r green:g blue:b |
90 |
"return a color from red, green and blue values. |
|
91 |
The arguments, r, g and b must be in the range (0..1)" |
|
92 |
||
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
93 |
^ self |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
94 |
scaledRed:(r * MaxValue) rounded |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
95 |
scaledGreen:(g * MaxValue) rounded |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
96 |
scaledBlue:(b * MaxValue) rounded |
214 | 97 |
|
98 |
" |
|
99 |
ColorValue red:0 green:1 blue:0 |
|
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
100 |
ColorValue red:0 green:0.5 blue:0 |
214 | 101 |
" |
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
102 |
! ! |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
103 |
|
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
104 |
!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
|
105 |
|
301 | 106 |
blue |
107 |
"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
|
108 |
|
301 | 109 |
^ blue / MaxValue |
214 | 110 |
! |
111 |
||
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
112 |
green |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
113 |
"return the green component in 0..1" |
39 | 114 |
|
300
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
115 |
^ green / MaxValue |
97f6b30e8a50
Color changed to use integer r/g/b components internally (0..16rFFFF)
Claus Gittinger <cg@exept.de>
parents:
277
diff
changeset
|
116 |
! |
39 | 117 |
|
301 | 118 |
light |
119 |
"return the hue component in 0..1" |
|
120 |
||
121 |
^ super light / 100.0 |
|
122 |
||
123 |
" |
|
124 |
Color yellow light |
|
125 |
ColorValue yellow light |
|
126 |
" |
|
127 |
||
128 |
"Created: 11.6.1996 / 17:17:39 / cg" |
|
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 |
|
301 | 131 |
red |
132 |
"return the red component in 0..1" |
|
133 |
||
134 |
^ red / MaxValue |
|
135 |
! |
|
136 |
||
137 |
saturation |
|
138 |
"return the saturation component in 0..1" |
|
139 |
||
140 |
^ super saturation / 100.0 |
|
141 |
||
142 |
" |
|
143 |
Color yellow saturation |
|
144 |
ColorValue yellow saturation |
|
145 |
" |
|
146 |
||
147 |
"Created: 11.6.1996 / 17:17:57 / cg" |
|
39 | 148 |
! ! |
214 | 149 |
|
378 | 150 |
!ColorValue methodsFor:'converting'! |
151 |
||
152 |
fromLiteralArrayEncoding:encoding |
|
153 |
"read my values from an encoding. |
|
154 |
The encoding is supposed to be of the form: |
|
155 |
(#ColorValue scaledRed scaledGreen scaledBlue) |
|
156 |
This is the reverse operation to #literalArrayEncoding." |
|
157 |
||
158 |
red := (encoding at:2). |
|
159 |
green := (encoding at:3). |
|
160 |
blue := (encoding at:4). |
|
161 |
||
162 |
" |
|
163 |
ColorValue new fromLiteralArrayEncoding:#(#Color 7700 7700 7700) |
|
164 |
" |
|
165 |
||
166 |
"Created: 22.1.1997 / 04:18:50 / cg" |
|
167 |
! |
|
168 |
||
169 |
literalArrayEncoding |
|
170 |
"encode myself as an array, from which a copy of the receiver |
|
171 |
can be reconstructed with #decodeAsLiteralArray. |
|
172 |
The encoding is: |
|
173 |
(#ColorValue scaledRed scaledGreen scaledBlue) |
|
174 |
" |
|
175 |
||
176 |
^ Array |
|
177 |
with:self class name asSymbol |
|
178 |
with:(self scaledRed) |
|
179 |
with:(self scaledGreen) |
|
180 |
with:(self scaledBlue) |
|
181 |
||
182 |
" |
|
183 |
ColorValue new fromLiteralArrayEncoding:#(#Color 50 25 25) |
|
184 |
(ColorValue red:0.5 green:0.25 blue:1.0) literalArrayEncoding |
|
185 |
" |
|
186 |
||
187 |
"Modified: 22.1.1997 / 04:17:59 / cg" |
|
188 |
! ! |
|
189 |
||
214 | 190 |
!ColorValue class methodsFor:'documentation'! |
191 |
||
192 |
version |
|
378 | 193 |
^ '$Header: /cvs/stx/stx/libview2/ColorValue.st,v 1.13 1997-01-22 03:19:07 cg Exp $' |
214 | 194 |
! ! |