| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:sky' as sky; | 5 import 'dart:sky' as sky; |
| 6 | 6 |
| 7 import 'package:sky/widgets/theme.dart'; | 7 import 'package:sky/widgets/theme.dart'; |
| 8 | 8 |
| 9 import 'basic.dart'; | 9 import 'basic.dart'; |
| 10 import 'toggleable.dart'; | 10 import 'toggleable.dart'; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 void customPaintCallback(sky.Canvas canvas, Size size) { | 42 void customPaintCallback(sky.Canvas canvas, Size size) { |
| 43 ThemeData themeData = Theme.of(this); | 43 ThemeData themeData = Theme.of(this); |
| 44 Color uncheckedColor = themeData.brightness == ThemeBrightness.light ? _kLig
htUncheckedColor : _kDarkUncheckedColor; | 44 Color uncheckedColor = themeData.brightness == ThemeBrightness.light ? _kLig
htUncheckedColor : _kDarkUncheckedColor; |
| 45 | 45 |
| 46 // Choose a color between grey and the theme color | 46 // Choose a color between grey and the theme color |
| 47 sky.Paint paint = new sky.Paint()..strokeWidth = 2.0 | 47 sky.Paint paint = new sky.Paint()..strokeWidth = 2.0 |
| 48 ..color = uncheckedColor; | 48 ..color = uncheckedColor; |
| 49 | 49 |
| 50 // The rrect contracts slightly during the animation | 50 // The rrect contracts slightly during the animation |
| 51 double inset = 2.0 - (toggleAnimation.value - _kMidpoint).abs() * 2.0; | 51 double inset = 2.0 - (position.value - _kMidpoint).abs() * 2.0; |
| 52 sky.Rect rect = new sky.Rect.fromLTRB(inset, inset, _kEdgeSize - inset, _kEd
geSize - inset); | 52 sky.Rect rect = new sky.Rect.fromLTRB(inset, inset, _kEdgeSize - inset, _kEd
geSize - inset); |
| 53 sky.RRect rrect = new sky.RRect()..setRectXY(rect, _kEdgeRadius, _kEdgeRadiu
s); | 53 sky.RRect rrect = new sky.RRect()..setRectXY(rect, _kEdgeRadius, _kEdgeRadiu
s); |
| 54 | 54 |
| 55 // Outline of the empty rrect | 55 // Outline of the empty rrect |
| 56 paint.setStyle(sky.PaintingStyle.stroke); | 56 paint.setStyle(sky.PaintingStyle.stroke); |
| 57 canvas.drawRRect(rrect, paint); | 57 canvas.drawRRect(rrect, paint); |
| 58 | 58 |
| 59 // Radial gradient that changes size | 59 // Radial gradient that changes size |
| 60 if (toggleAnimation.value > 0) { | 60 if (position.value > 0) { |
| 61 paint.setStyle(sky.PaintingStyle.fill); | 61 paint.setStyle(sky.PaintingStyle.fill); |
| 62 paint.setShader( | 62 paint.setShader( |
| 63 new sky.Gradient.radial( | 63 new sky.Gradient.radial( |
| 64 new Point(_kEdgeSize / 2.0, _kEdgeSize / 2.0), | 64 new Point(_kEdgeSize / 2.0, _kEdgeSize / 2.0), |
| 65 _kEdgeSize * (_kMidpoint - toggleAnimation.value) * 8.0, | 65 _kEdgeSize * (_kMidpoint - position.value) * 8.0, |
| 66 [const sky.Color(0x00000000), uncheckedColor] | 66 [const sky.Color(0x00000000), uncheckedColor] |
| 67 ) | 67 ) |
| 68 ); | 68 ); |
| 69 canvas.drawRRect(rrect, paint); | 69 canvas.drawRRect(rrect, paint); |
| 70 } | 70 } |
| 71 | 71 |
| 72 if (toggleAnimation.value > _kMidpoint) { | 72 if (position.value > _kMidpoint) { |
| 73 double t = (toggleAnimation.value - _kMidpoint) / (1.0 - _kMidpoint); | 73 double t = (position.value - _kMidpoint) / (1.0 - _kMidpoint); |
| 74 | 74 |
| 75 // Solid filled rrect | 75 // Solid filled rrect |
| 76 paint.setStyle(sky.PaintingStyle.strokeAndFill); | 76 paint.setStyle(sky.PaintingStyle.strokeAndFill); |
| 77 paint.color = new Color.fromARGB((t * 255).floor(), | 77 paint.color = new Color.fromARGB((t * 255).floor(), |
| 78 themeData.accentColor.red, | 78 themeData.accentColor.red, |
| 79 themeData.accentColor.green, | 79 themeData.accentColor.green, |
| 80 themeData.accentColor.blue); | 80 themeData.accentColor.blue); |
| 81 canvas.drawRRect(rrect, paint); | 81 canvas.drawRRect(rrect, paint); |
| 82 | 82 |
| 83 // White inner check | 83 // White inner check |
| 84 paint.color = const sky.Color(0xFFFFFFFF); | 84 paint.color = const sky.Color(0xFFFFFFFF); |
| 85 paint.setStyle(sky.PaintingStyle.stroke); | 85 paint.setStyle(sky.PaintingStyle.stroke); |
| 86 sky.Path path = new sky.Path(); | 86 sky.Path path = new sky.Path(); |
| 87 sky.Point start = new sky.Point(_kEdgeSize * 0.2, _kEdgeSize * 0.5); | 87 sky.Point start = new sky.Point(_kEdgeSize * 0.2, _kEdgeSize * 0.5); |
| 88 sky.Point mid = new sky.Point(_kEdgeSize * 0.4, _kEdgeSize * 0.7); | 88 sky.Point mid = new sky.Point(_kEdgeSize * 0.4, _kEdgeSize * 0.7); |
| 89 sky.Point end = new sky.Point(_kEdgeSize * 0.8, _kEdgeSize * 0.3); | 89 sky.Point end = new sky.Point(_kEdgeSize * 0.8, _kEdgeSize * 0.3); |
| 90 Point lerp(Point p1, Point p2, double t) | 90 Point lerp(Point p1, Point p2, double t) |
| 91 => new Point(p1.x * (1.0 - t) + p2.x * t, p1.y * (1.0 - t) + p2.y * t); | 91 => new Point(p1.x * (1.0 - t) + p2.x * t, p1.y * (1.0 - t) + p2.y * t); |
| 92 sky.Point drawStart = lerp(start, mid, 1.0 - t); | 92 sky.Point drawStart = lerp(start, mid, 1.0 - t); |
| 93 sky.Point drawEnd = lerp(mid, end, t); | 93 sky.Point drawEnd = lerp(mid, end, t); |
| 94 path.moveTo(drawStart.x, drawStart.y); | 94 path.moveTo(drawStart.x, drawStart.y); |
| 95 path.lineTo(mid.x, mid.y); | 95 path.lineTo(mid.x, mid.y); |
| 96 path.lineTo(drawEnd.x, drawEnd.y); | 96 path.lineTo(drawEnd.x, drawEnd.y); |
| 97 canvas.drawPath(path, paint); | 97 canvas.drawPath(path, paint); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 } | 100 } |
| OLD | NEW |