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

Unified Diff: sky/examples/raw/touch_demo.dart

Issue 1151613005: Port touch-demo.sky to SkyView universe (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/raw/touch_demo.dart
diff --git a/sky/examples/raw/touch_demo.dart b/sky/examples/raw/touch_demo.dart
new file mode 100644
index 0000000000000000000000000000000000000000..295f83de40f7a104fd380afade833edeb54d5827
--- /dev/null
+++ b/sky/examples/raw/touch_demo.dart
@@ -0,0 +1,100 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:math';
+import 'dart:sky';
+import 'package:sky/framework/layout2.dart';
+
+// Material design colors. :p
+List<int> colors = [
+ 0xFF009688,
+ 0xFFFFC107,
+ 0xFF9C27B0,
+ 0xFF03A9F4,
+ 0xFF673AB7,
+ 0xFFCDDC39,
+];
+
+class Dot {
+ final Paint _paint;
+ double x = 0.0;
+ double y = 0.0;
+ double radius = 0.0;
+
+ Dot({int color}) : _paint = new Paint()..color = color;
+
+ void update(PointerEvent event) {
+ x = event.x;
+ y = event.y;
+ radius = 5 + (95 * event.pressure);
+ }
+
+ void paint(RenderNodeDisplayList canvas) {
+ canvas.drawCircle(x, y, radius, _paint);
+ }
+}
+
+class RenderTouchDemo extends RenderBox {
+ Map<int, Dot> dots = new Map();
+
+ RenderTouchDemo();
+
+ bool handlePointer(PointerEvent event, { double x: 0.0, double y: 0.0 }) {
+ if (event.type == 'pointerdown') {
eseidel 2015/05/21 17:54:45 Would be nice to be able to handle these as an enu
abarth-chromium 2015/05/21 19:26:49 Done.
Hixie 2015/05/21 19:47:06 eventually these will be class "is" expressions, w
+ int color = colors[event.pointer.remainder(colors.length)];
+ dots[event.pointer] = new Dot(color: color)..update(event);
+ markNeedsPaint();
+ return true;
+ }
+
+ if (event.type == 'pointerup') {
+ dots.remove(event.pointer);
+ markNeedsPaint();
eseidel 2015/05/21 17:54:45 You might actually want a dots model, which has ch
+ return true;
+ }
+
+ if (event.type == 'pointercancel') {
+ dots = new Map();
+ markNeedsPaint();
+ return true;
+ }
+
+ if (event.type == 'pointermove') {
+ dots[event.pointer].update(event);
+ markNeedsPaint();
+ return true;
+ }
+
+ return false;
+ }
+
+ void paint(RenderNodeDisplayList canvas) {
+ dots.forEach((_, Dot dot) {
+ dot.paint(canvas);
+ });
+ }
+}
+
+RenderView renderView;
+
+void beginFrame(double timeStamp) {
+ RenderNode.flushLayout();
+ renderView.paintFrame();
+}
+
+bool handleEvent(Event event) {
+ if (event is! PointerEvent)
+ return false;
+ return renderView.handlePointer(event, x: event.x, y: event.y);
+}
+
+void main() {
+ view.setEventCallback(handleEvent);
+ view.setBeginFrameCallback(beginFrame);
+
+ renderView = new RenderView(root: new RenderTouchDemo());
+ renderView.layout(newWidth: view.width, newHeight: view.height);
+
+ view.scheduleFrame();
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698