| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of spirodraw; | 5 part of spirodraw; |
| 6 | 6 |
| 7 typedef void PickerListener(String selectedColor); | 7 typedef void PickerListener(String selectedColor); |
| 8 | 8 |
| 9 class ColorPicker { | 9 class ColorPicker { |
| 10 static const hexValues = const ['00', '33', '66', '99', 'CC', 'FF']; | 10 static const hexValues = const ['00', '33', '66', '99', 'CC', 'FF']; |
| 11 static const COLS = 18; | 11 static const COLS = 18; |
| 12 // Block height, width, padding | 12 // Block height, width, padding |
| 13 static const BH = 10; | 13 static const BH = 10; |
| 14 static const BW = 10; | 14 static const BW = 10; |
| 15 static const BP = 1; | 15 static const BP = 1; |
| 16 final List<PickerListener> _listeners; | 16 final List<PickerListener> _listeners; |
| 17 CanvasElement canvasElement; | 17 CanvasElement canvasElement; |
| 18 String _selectedColor = 'red'; | 18 String _selectedColor = 'red'; |
| 19 final height = 160; | 19 final height = 160; |
| 20 final width = 180; | 20 final width = 180; |
| 21 CanvasRenderingContext2D ctx; | 21 CanvasRenderingContext2D ctx; |
| 22 | 22 |
| 23 ColorPicker(this.canvasElement) : | 23 ColorPicker(this.canvasElement) : |
| 24 _listeners = [] | 24 _listeners = [] |
| 25 { | 25 { |
| 26 ctx = canvasElement.context2d; | 26 ctx = canvasElement.context2D; |
| 27 drawPalette(); | 27 drawPalette(); |
| 28 addHandlers(); | 28 addHandlers(); |
| 29 showSelected(); | 29 showSelected(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 String get selectedColor => _selectedColor; | 32 String get selectedColor => _selectedColor; |
| 33 | 33 |
| 34 void set selectedColor(String color) { | 34 void set selectedColor(String color) { |
| 35 _selectedColor = color; | 35 _selectedColor = color; |
| 36 | 36 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 int i = value.floor().toInt(); | 110 int i = value.floor().toInt(); |
| 111 | 111 |
| 112 int r = (i ~/ 36) % 6; | 112 int r = (i ~/ 36) % 6; |
| 113 int g = (i % 36) ~/ 6; | 113 int g = (i % 36) ~/ 6; |
| 114 int b = i % 6; | 114 int b = i % 6; |
| 115 | 115 |
| 116 return '#${hexValues[r]}${hexValues[g]}${hexValues[b]}'; | 116 return '#${hexValues[r]}${hexValues[g]}${hexValues[b]}'; |
| 117 } | 117 } |
| 118 | 118 |
| 119 } | 119 } |
| OLD | NEW |