| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 8 |
| 9 static final hexValues = const ['00', '33', '66', '99', 'CC', 'FF']; | 9 static final hexValues = const ['00', '33', '66', '99', 'CC', 'FF']; |
| 10 static final COLS = 18; | 10 static final COLS = 18; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Adds a [PickerListener] to receive updates. | 60 * Adds a [PickerListener] to receive updates. |
| 61 */ | 61 */ |
| 62 void addListener(PickerListener listener) { | 62 void addListener(PickerListener listener) { |
| 63 _listeners.add(listener); | 63 _listeners.add(listener); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void addHandlers() { | 66 void addHandlers() { |
| 67 canvasElement.onmousemove = (e) { onMouseMove(e); }; | 67 canvasElement.addEventListener('mousemove', (e) => onMouseMove(e), true); |
| 68 canvasElement.onmousedown = (e) { onMouseDown(e); }; | 68 canvasElement.addEventListener('mousedown', (e) => onMouseDown(e), true); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void drawPalette() { | 71 void drawPalette() { |
| 72 int i=0; | 72 int i=0; |
| 73 for (int r=0; r < 256; r+=51) { | 73 for (int r=0; r < 256; r+=51) { |
| 74 for (int g=0; g < 256; g+=51) { | 74 for (int g=0; g < 256; g+=51) { |
| 75 for (int b=0; b < 256; b+=51) { | 75 for (int b=0; b < 256; b+=51) { |
| 76 String color = getHexString(i); | 76 String color = getHexString(i); |
| 77 ctx.fillStyle = color; | 77 ctx.fillStyle = color; |
| 78 int x = BW * (i % COLS); | 78 int x = BW * (i % COLS); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 104 } | 104 } |
| 105 | 105 |
| 106 String getHexString(int i) { | 106 String getHexString(int i) { |
| 107 int r = i ~/ 36; | 107 int r = i ~/ 36; |
| 108 int g = (i % 36) ~/ 6; | 108 int g = (i % 36) ~/ 6; |
| 109 int b = i % 6; | 109 int b = i % 6; |
| 110 return '#${hexValues[r]}${hexValues[g]}${hexValues[b]}'; | 110 return '#${hexValues[r]}${hexValues[g]}${hexValues[b]}'; |
| 111 } | 111 } |
| 112 | 112 |
| 113 } | 113 } |
| OLD | NEW |