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