Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: sky/sdk/lib/framework/widgets/ink_well.dart

Issue 1177383006: Rename all the things (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix imports Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 import 'dart:math' as math;
6 import 'dart:sky' as sky;
7
8 import '../animation/animated_value.dart';
9 import '../animation/curves.dart';
10 import '../rendering/box.dart';
11 import '../rendering/object.dart';
12 import 'ui_node.dart';
13 import 'basic.dart';
14
15 const int _kSplashInitialOpacity = 0x80;
16 const double _kSplashInitialDelay = 0.0; // we could delay initially in case the user scrolls
17 const double _kSplashInitialSize = 0.0;
18 const double _kSplashConfirmedVelocity = 0.3;
19 const double _kSplashUnconfirmedVelocity = 0.1;
20
21 double _getSplashTargetSize(Size bounds, Point position) {
22 return math.max(math.max(position.x, bounds.width - position.x),
23 math.max(position.y, bounds.height - position.y));
24 }
25
26 class InkSplash {
27 InkSplash(this.pointer, this.position, this.well) {
28 _targetRadius = _getSplashTargetSize(well.size, position);
29 double duration = _targetRadius / _kSplashUnconfirmedVelocity;
30 _radius = new AnimatedValue(_kSplashInitialSize, onChange: _handleRadiusChan ge);
31 _radius.animateTo(_targetRadius, duration, curve: easeOut,
32 initialDelay: _kSplashInitialDelay);
33 }
34
35 final int pointer;
36 final Point position;
37 final RenderInkWell well;
38
39 double _targetRadius;
40 AnimatedValue _radius;
41
42 void confirm() {
43 double duration = (_targetRadius - _radius.value) / _kSplashConfirmedVelocit y;
44 if (duration <= 0.0)
45 return;
46 _radius.animateTo(_targetRadius, duration, curve: easeOut);
47 }
48
49 void _handleRadiusChange() {
50 if (_radius.value == _targetRadius)
51 well._splashes.remove(this);
52 well.markNeedsPaint();
53 }
54
55 void paint(RenderObjectDisplayList canvas) {
56 int opacity = (_kSplashInitialOpacity * (1.0 - (_radius.value / _targetRadiu s))).floor();
57 sky.Paint paint = new sky.Paint()..color = new sky.Color(opacity << 24);
58 canvas.drawCircle(position.x, position.y, _radius.value, paint);
59 }
60 }
61
62 class RenderInkWell extends RenderProxyBox {
63 RenderInkWell({ RenderBox child }) : super(child);
64
65 final List<InkSplash> _splashes = new List<InkSplash>();
66
67 void handleEvent(sky.Event event, BoxHitTestEntry entry) {
68 switch (event.type) {
69 case 'gesturetapdown':
70 // TODO(abarth): We should position the splash at the location of the ta p.
71 _startSplash(event.primaryPointer, entry.localPosition);
72 break;
73 case 'gesturetap':
74 _confirmSplash(event.primaryPointer);
75 break;
76 }
77 }
78
79 void _startSplash(int pointer, Point position) {
80 _splashes.add(new InkSplash(pointer, position, this));
81 markNeedsPaint();
82 }
83
84 void _confirmSplash(int pointer) {
85 _splashes.where((splash) => splash.pointer == pointer)
86 .forEach((splash) { splash.confirm(); });
87 markNeedsPaint();
88 }
89
90 void paint(RenderObjectDisplayList canvas) {
91 if (!_splashes.isEmpty) {
92 canvas.save();
93 canvas.clipRect(new Rect.fromSize(size));
94 for (InkSplash splash in _splashes)
95 splash.paint(canvas);
96 canvas.restore();
97 }
98 super.paint(canvas);
99 }
100 }
101
102 class InkWell extends OneChildRenderObjectWrapper {
103 InkWell({ UINode child, Object key })
104 : super(child: child, key: key);
105
106 RenderInkWell get root { RenderInkWell result = super.root; return result; }
107
108 RenderInkWell createNode() => new RenderInkWell();
109 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/widgets/icon_button.dart ('k') | sky/sdk/lib/framework/widgets/material.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698