The Trunk: Graphics-tpr.354.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Graphics-tpr.354.mcz

commits-2
tim Rowledge uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-tpr.354.mcz

==================== Summary ====================

Name: Graphics-tpr.354
Author: tpr
Time: 21 July 2016, 6:14:06.280273 pm
UUID: 31f2b403-7687-49a8-944b-b067f32fb482
Ancestors: Graphics-mt.353

Extend Color class>>fromString parsing to allow also a string of the forrm 'r,g,b' where each item can be the string representation of an integer between 0 and 255

=============== Diff against Graphics-mt.353 ===============

Item was changed:
  ----- Method: Color class>>fromString: (in category 'instance creation') -----
  fromString: aString
+ "for HTML color spec: #FFCCAA or white/black/red/other name, or an r,g,b triplet string"
- "for HTML color spec: #FFCCAA or white/black"
  "Color fromString: '#FFCCAA'.
  Color fromString: 'white'.
+ Color fromString: 'orange'
+ Color fromString: '126,42,33' "
- Color fromString: 'orange'"
 
+ | aColorHex rgb|
- | aColorHex |
  aString isEmptyOrNil ifTrue: [ ^self white ].
  aString first = $#
  ifTrue: [ aColorHex := aString allButFirst ]
  ifFalse: [ aColorHex := aString ].
+ "is the string a 6 digit hex number?"
  (aColorHex size = 6 and: [
  aColorHex allSatisfy: [ :each | '0123456789ABCDEFabcdef' includes: each ] ])
  ifTrue: [
  | green red blue |
+ red := (Integer readFrom: (aColorHex first: 2) base: 16).
+ green := (Integer readFrom: (aColorHex copyFrom: 3 to: 4) base: 16).
+ blue := (Integer readFrom: (aColorHex last: 2) base: 16).
+ ^self r: red g: green b: blue range: 255].
+ "is the string in the form a,b,c ?"
+ rgb := aColorHex findTokens: $, .
+ rgb size = 3 ifTrue: [
+ | green red blue |
+ red := (Integer readFrom:(rgb at: 1)) min: 255 max: 0.
+ green := (Integer readFrom:(rgb at: 2)) min: 255 max: 0.
+ blue := (Integer readFrom:(rgb at: 3)) min: 255 max: 0.
+ ^self r: red g: green b: blue range: 255].
- red := (Integer readFrom: (aColorHex first: 2) base: 16) / 255.
- green := (Integer readFrom: (aColorHex copyFrom: 3 to: 4) base: 16) / 255.
- blue := (Integer readFrom: (aColorHex last: 2) base: 16) / 255.
- ^self r: red g: green b: blue ].
  "try to match aColorHex with known named colors, case insensitive"
  ^self perform: (ColorNames detect: [:colorSymbol | aColorHex sameAs: colorSymbol] ifNone: [ #white ])!