diff --git a/lib/canvas/drawing_page.dart b/lib/canvas/drawing_page.dart index 811f20a..638754b 100644 --- a/lib/canvas/drawing_page.dart +++ b/lib/canvas/drawing_page.dart @@ -18,7 +18,7 @@ class _DrawingPageState extends State { List _strokes = []; bool allowDrawWithFinger = false; - double zoom = 0.6; + double zoom = .5; Offset scrollPos = const Offset(.0, .0); @override @@ -29,15 +29,18 @@ class _DrawingPageState extends State { ); } - double _calcTiltedWidth(double baseWidth, double tilt){ + double _calcTiltedWidth(double baseWidth, double tilt) { return baseWidth * tilt; } - double _calcAngleDependentWidth(List pts, double basetickness){ + double _calcAngleDependentWidth(List pts, double basetickness) { return basetickness; // todo do correct linear interpolation and extimate angle - final lininterpol = PolynomialInterpolation(nodes: pts.map((e) => InterpolationNode(x: e.point.dx, y: e.point.dy)).toList(growable: false)); + final lininterpol = PolynomialInterpolation( + nodes: pts + .map((e) => InterpolationNode(x: e.point.dx, y: e.point.dy)) + .toList(growable: false)); lininterpol.compute(1.0); print(lininterpol.buildPolynomial().toString()); @@ -102,40 +105,16 @@ class _DrawingPageState extends State { print(_strokes.last.points.length); } }, - // child: GestureDetector( - // onPanUpdate: (DragUpdateDetails details) { - // setState(() { - // _strokes = List.from(_strokes,growable: false)..last.points.add(details.localPosition); - // }); - // }, - // onPanEnd: (DragEndDetails details) { - // if(_strokes.last.points.length <= 1){ - // // if the line consists only of one point (point) add endpoint as the same to allow drawing a line - // // todo maybe solve this in custompainter in future - // setState(() { - // _strokes = List.from(_strokes,growable: false)..last.points.add(_strokes.last.points.last); - // }); - // }else{ - // setState(() {}); - // } - // - // - // print(_strokes.length); - // print(_strokes.last.points.length); - // }, - // onPanStart: (details) { - // setState(() { - // _strokes = List.from(_strokes)..add(Stroke.fromPoints([details.localPosition])); - // }); - // }, - child: SingleChildScrollView( - child: Center( - child: CustomPaint( - painter: MyPainter(strokes: _strokes), - // todo not working - size: Size(zoomedwidth, zoomedwidth * sqrt2), // todo add different paper dimensions - // ), - ), + child: GestureDetector( + onScaleUpdate: (details) { + setState(() { + zoom = details.scale; + }); + }, + child: CustomPaint( + painter: MyPainter(strokes: _strokes,offset: scrollPos, zoom: zoom), + // todo not working + size: Size.infinite, // todo add different paper dimensions ), ), ), diff --git a/lib/canvas/my_painter.dart b/lib/canvas/my_painter.dart index 62c29ec..c2d2abf 100644 --- a/lib/canvas/my_painter.dart +++ b/lib/canvas/my_painter.dart @@ -3,19 +3,31 @@ import 'package:flutter/material.dart'; import 'document_types.dart'; class MyPainter extends CustomPainter { - List strokes = []; + List strokes; + double zoom; + Offset offset; - MyPainter({required this.strokes}); + MyPainter({required this.strokes, required this.zoom, required this.offset}); @override void paint(Canvas canvas, Size size) { var paint = Paint() ..color = Colors.blue ..strokeCap = StrokeCap.square; - // ..strokeWidth = 3.0; + + + // ..strokeWidth = 3.0; + // canvas.scale(zoom); + print("zoom: ${zoom}"); canvas.drawColor(Color.fromRGBO(255, 255, 255, .1), BlendMode.src); + final pagewidth = size.width * zoom; + + final sidewidth = (size.width - pagewidth) / 2; + canvas.drawLine(Offset(sidewidth, .0), Offset(sidewidth, size.height), paint); + canvas.drawLine(Offset(sidewidth + pagewidth, .0), Offset(sidewidth + pagewidth, size.height), paint); + for(final stroke in strokes){ for(int i = 0; i < stroke.points.length -1; i++){ final pt1 = stroke.points[i].point; @@ -25,6 +37,8 @@ class MyPainter extends CustomPainter { canvas.drawLine(pt1, pt2, paint..strokeWidth = stroke.points[i].thickness); } } + + } @override