Commit 4df24abb authored by Viktor Lidholt's avatar Viktor Lidholt

Merge pull request #3016 from vlidholt/linedrawing

Initial version of Fancy line drawer demo
parents 243960d7 a1212dbc
......@@ -24,3 +24,4 @@ assets:
- packages/flutter_gallery_assets/jumpingjack.json
- packages/flutter_gallery_assets/jumpingjack.png
- packages/flutter_gallery_assets/grain.png
- packages/flutter_gallery_assets/fancylines.png
// Copyright 2016 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:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_sprites/flutter_sprites.dart';
class DrawingDemo extends StatefulWidget {
@override
_DrawingDemoState createState() => new _DrawingDemoState();
}
class _DrawingDemoState extends State<DrawingDemo> {
_LineDrawingNode _rootNode;
ImageMap _images;
Future<Null> _loadAssets(AssetBundle bundle) async {
_images = new ImageMap(bundle);
await _images.load(<String>[
'packages/flutter_gallery_assets/fancylines.png'
]);
}
@override
void initState() {
super.initState();
_loadAssets(DefaultAssetBundle.of(context)).then((_) {
setState(() {
_rootNode = new _LineDrawingNode(_images);
});
});
}
@override
Widget build(BuildContext context) {
Widget body;
if (_rootNode == null) {
body = new Center(
child: new CircularProgressIndicator()
);
} else {
body = new SpriteWidget(_rootNode, SpriteBoxTransformMode.nativePoints);
}
return new Scaffold(
appBar: new AppBar(
title: new Text("Fancy Lines")
),
body: body
);
}
}
class _LineDrawingNode extends NodeWithSize {
_LineDrawingNode(this._images) : super(const Size(1024.0, 1024.0)) {
userInteractionEnabled = true;
}
final ImageMap _images;
EffectLine _currentLine;
@override
bool handleEvent(SpriteBoxEvent event) {
if (event.type == PointerDownEvent) {
_currentLine = new EffectLine(
texture: new Texture(_images['packages/flutter_gallery_assets/fancylines.png']),
colorSequence: new ColorSequence.fromStartAndEndColor(Colors.purple[500], Colors.purple[600]),
fadeAfterDelay: 3.0,
fadeDuration: 1.0
);
_currentLine.addPoint(event.boxPosition);
addChild(_currentLine);
} else if (event.type == PointerMoveEvent) {
_currentLine.addPoint(event.boxPosition);
}
return true;
}
}
......@@ -16,6 +16,7 @@ import '../demo/chip_demo.dart';
import '../demo/date_picker_demo.dart';
import '../demo/dialog_demo.dart';
import '../demo/drop_down_demo.dart';
import '../demo/drawing_demo.dart';
import '../demo/fitness_demo.dart';
import '../demo/flexible_space_demo.dart';
import '../demo/grid_list_demo.dart';
......@@ -80,6 +81,7 @@ class GalleryHomeState extends State<GalleryHome> {
children: <Widget>[
new GalleryItem(title: "Weather", builder: () => new WeatherDemo()),
new GalleryItem(title: "Fitness", builder: () => new FitnessDemo()),
new GalleryItem(title: "Fancy Lines", builder: () => new DrawingDemo()),
]
),
new TwoLevelSublist(
......
......@@ -7,4 +7,4 @@ dependencies:
path: ../../packages/flutter
flutter_sprites:
path: ../../packages/flutter_sprites
flutter_gallery_assets: '0.0.12'
flutter_gallery_assets: '0.0.13'
......@@ -228,7 +228,7 @@ class SpriteBox extends RenderBox {
// Check if this event should be dispatched
if (node.handleMultiplePointers || event.pointer == node._handlingPointer) {
// Dispatch event
bool consumedEvent = node.handleEvent(new SpriteBoxEvent(event.position, event.runtimeType, event.pointer));
bool consumedEvent = node.handleEvent(new SpriteBoxEvent(globalToLocal(event.position), event.runtimeType, event.pointer));
if (consumedEvent == null || consumedEvent)
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment