ColorValue.st
changeset 4041 7c8b99928ec1
parent 3813 d581c117b1db
equal deleted inserted replaced
4040:1d540ba7a1d1 4041:7c8b99928ec1
   168 !ColorValue methodsFor:'converting'!
   168 !ColorValue methodsFor:'converting'!
   169 
   169 
   170 fromLiteralArrayEncoding:encoding
   170 fromLiteralArrayEncoding:encoding
   171     "read my values from an encoding.
   171     "read my values from an encoding.
   172      The encoding is supposed to be of the form: 
   172      The encoding is supposed to be of the form: 
   173         (#ColorValue scaledRed scaledGreen scaledBlue)
   173         #(ColorValue scaledRed scaledGreen scaledBlue)
   174      This is the reverse operation to #literalArrayEncoding."
   174      This is the reverse operation to #literalArrayEncoding."
   175 
   175 
   176     |clr|
   176     |clr|
       
   177 
       
   178     red notNil ifTrue:[
       
   179         "oops cannot change an existing color (you want to make red be green - or what)"
       
   180         self error:'Colors cannot change their components'.
       
   181         ^ self
       
   182     ].
   177 
   183 
   178     encoding size == 2 ifTrue:[
   184     encoding size == 2 ifTrue:[
   179         clr := self class name:(encoding at:2).
   185         clr := self class name:(encoding at:2).
   180         red := clr scaledRed.
   186         red := clr scaledRed.
   181         green := clr scaledGreen.
   187         green := clr scaledGreen.
   182         blue := clr scaledBlue.
   188         blue := clr scaledBlue.
   183     ] ifFalse:[
   189     ] ifFalse:[
   184 "/        (encoding at:2) isSymbol ifTrue:[
   190         red := encoding at:2.
   185 "/            clr := ColorValue perform:(encoding at:2) withArguments:(encoding at:3).
   191         green := encoding at:3.
   186 "/            red := clr scaledRed.
   192         blue := encoding at:4.
   187 "/            green := clr scaledGreen.
   193     ].
   188 "/            blue := clr scaledBlue.
       
   189 "/        ] ifFalse:[
       
   190             red := (encoding at:2).
       
   191             green := (encoding at:3).
       
   192             blue := (encoding at:4).
       
   193 "/        ]
       
   194     ]
       
   195 
   194 
   196     "
   195     "
   197       ColorValue new fromLiteralArrayEncoding:#(#Color 7700 7700 7700)
   196       ColorValue new fromLiteralArrayEncoding:#(#Color 7700 7700 7700)
   198     "
   197       ColorValue new fromLiteralArrayEncoding:#(ColorValue red)
   199 
   198     "
   200     "Created: 22.1.1997 / 04:18:50 / cg"
   199 
   201     "Modified: 6.3.1997 / 15:45:01 / cg"
   200     "Created: / 22-01-1997 / 04:18:50 / cg"
       
   201     "Modified: / 06-03-1997 / 15:45:01 / cg"
       
   202     "Modified (comment): / 11-01-2018 / 12:32:05 / stefan"
   202 !
   203 !
   203 
   204 
   204 literalArrayEncoding
   205 literalArrayEncoding
   205     "encode myself as an array, from which a copy of the receiver
   206     "encode myself as an array, from which a copy of the receiver
   206      can be reconstructed with #decodeAsLiteralArray.
   207      can be reconstructed with #decodeAsLiteralArray.