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 typedef void PickerListener(String selectedColor); | 5 typedef void PickerListener(String selectedColor); |
6 | 6 |
7 class ColorPicker { | 7 class ColorPicker { |
8 static const hexValues = const ['00', '33', '66', '99', 'CC', 'FF']; | 8 static const hexValues = const ['00', '33', '66', '99', 'CC', 'FF']; |
9 static const COLS = 18; | 9 static const COLS = 18; |
10 // Block height, width, padding | 10 // Block height, width, padding |
11 static const BH = 10; | 11 static const BH = 10; |
12 static const BW = 10; | 12 static const BW = 10; |
13 static const BP = 1; | 13 static const BP = 1; |
14 final List<PickerListener> _listeners; | 14 final List<PickerListener> _listeners; |
15 CanvasElement canvasElement; | 15 CanvasElement canvasElement; |
16 String _selectedColor = 'red'; | 16 String _selectedColor = 'red'; |
17 final height = 160; | 17 final height = 160; |
18 final width = 180; | 18 final width = 180; |
19 CanvasRenderingContext2D ctx; | 19 CanvasRenderingContext2D ctx; |
20 | 20 |
21 ColorPicker(this.canvasElement) : | 21 ColorPicker(this.canvasElement) : |
22 _listeners = [] | 22 _listeners = [] |
23 { | 23 { |
24 ctx = canvasElement.context2d; | 24 ctx = canvasElement.context2d; |
25 drawPalette(); | 25 drawPalette(); |
26 addHandlers(); | 26 addHandlers(); |
27 showSelected(); | 27 showSelected(); |
28 } | 28 } |
29 | 29 |
30 String get selectedColor() => _selectedColor; | 30 String get selectedColor => _selectedColor; |
31 | 31 |
32 void set selectedColor(String color) { | 32 void set selectedColor(String color) { |
33 _selectedColor = color; | 33 _selectedColor = color; |
34 | 34 |
35 showSelected(); | 35 showSelected(); |
36 fireSelected(); | 36 fireSelected(); |
37 } | 37 } |
38 | 38 |
39 void onMouseMove(MouseEvent event) { | 39 void onMouseMove(MouseEvent event) { |
40 int x = event.offsetX; | 40 int x = event.offsetX; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 int i = value.floor().toInt(); | 107 int i = value.floor().toInt(); |
108 | 108 |
109 int r = (i ~/ 36) % 6; | 109 int r = (i ~/ 36) % 6; |
110 int g = (i % 36) ~/ 6; | 110 int g = (i % 36) ~/ 6; |
111 int b = i % 6; | 111 int b = i % 6; |
112 | 112 |
113 return '#${hexValues[r]}${hexValues[g]}${hexValues[b]}'; | 113 return '#${hexValues[r]}${hexValues[g]}${hexValues[b]}'; |
114 } | 114 } |
115 | 115 |
116 } | 116 } |
OLD | NEW |