show lines for zooming

This commit is contained in:
lukas-heiligenbrunner 2022-10-24 16:28:56 +02:00
parent d24f0407b8
commit 693d0538ef
2 changed files with 34 additions and 41 deletions

View File

@ -18,7 +18,7 @@ class _DrawingPageState extends State<DrawingPage> {
List<Stroke> _strokes = [];
bool allowDrawWithFinger = false;
double zoom = 0.6;
double zoom = .5;
Offset scrollPos = const Offset(.0, .0);
@override
@ -37,7 +37,10 @@ class _DrawingPageState extends State<DrawingPage> {
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<DrawingPage> {
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: GestureDetector(
onScaleUpdate: (details) {
setState(() {
zoom = details.scale;
});
},
child: CustomPaint(
painter: MyPainter(strokes: _strokes),
painter: MyPainter(strokes: _strokes,offset: scrollPos, zoom: zoom),
// todo not working
size: Size(zoomedwidth, zoomedwidth * sqrt2), // todo add different paper dimensions
// ),
),
size: Size.infinite, // todo add different paper dimensions
),
),
),

View File

@ -3,19 +3,31 @@ import 'package:flutter/material.dart';
import 'document_types.dart';
class MyPainter extends CustomPainter {
List<Stroke> strokes = <Stroke>[];
List<Stroke> 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