show lines for zooming
This commit is contained in:
parent
d24f0407b8
commit
693d0538ef
@ -18,7 +18,7 @@ class _DrawingPageState extends State<DrawingPage> {
|
|||||||
List<Stroke> _strokes = [];
|
List<Stroke> _strokes = [];
|
||||||
bool allowDrawWithFinger = false;
|
bool allowDrawWithFinger = false;
|
||||||
|
|
||||||
double zoom = 0.6;
|
double zoom = .5;
|
||||||
Offset scrollPos = const Offset(.0, .0);
|
Offset scrollPos = const Offset(.0, .0);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -29,15 +29,18 @@ class _DrawingPageState extends State<DrawingPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
double _calcTiltedWidth(double baseWidth, double tilt){
|
double _calcTiltedWidth(double baseWidth, double tilt) {
|
||||||
return baseWidth * tilt;
|
return baseWidth * tilt;
|
||||||
}
|
}
|
||||||
|
|
||||||
double _calcAngleDependentWidth(List<Point> pts, double basetickness){
|
double _calcAngleDependentWidth(List<Point> pts, double basetickness) {
|
||||||
return basetickness;
|
return basetickness;
|
||||||
|
|
||||||
// todo do correct linear interpolation and extimate angle
|
// 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);
|
lininterpol.compute(1.0);
|
||||||
print(lininterpol.buildPolynomial().toString());
|
print(lininterpol.buildPolynomial().toString());
|
||||||
|
|
||||||
@ -102,40 +105,16 @@ class _DrawingPageState extends State<DrawingPage> {
|
|||||||
print(_strokes.last.points.length);
|
print(_strokes.last.points.length);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// child: GestureDetector(
|
child: GestureDetector(
|
||||||
// onPanUpdate: (DragUpdateDetails details) {
|
onScaleUpdate: (details) {
|
||||||
// setState(() {
|
setState(() {
|
||||||
// _strokes = List.from(_strokes,growable: false)..last.points.add(details.localPosition);
|
zoom = details.scale;
|
||||||
// });
|
});
|
||||||
// },
|
},
|
||||||
// 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(
|
child: CustomPaint(
|
||||||
painter: MyPainter(strokes: _strokes),
|
painter: MyPainter(strokes: _strokes,offset: scrollPos, zoom: zoom),
|
||||||
// todo not working
|
// todo not working
|
||||||
size: Size(zoomedwidth, zoomedwidth * sqrt2), // todo add different paper dimensions
|
size: Size.infinite, // todo add different paper dimensions
|
||||||
// ),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -3,19 +3,31 @@ import 'package:flutter/material.dart';
|
|||||||
import 'document_types.dart';
|
import 'document_types.dart';
|
||||||
|
|
||||||
class MyPainter extends CustomPainter {
|
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
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
var paint = Paint()
|
var paint = Paint()
|
||||||
..color = Colors.blue
|
..color = Colors.blue
|
||||||
..strokeCap = StrokeCap.square;
|
..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);
|
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(final stroke in strokes){
|
||||||
for(int i = 0; i < stroke.points.length -1; i++){
|
for(int i = 0; i < stroke.points.length -1; i++){
|
||||||
final pt1 = stroke.points[i].point;
|
final pt1 = stroke.points[i].point;
|
||||||
@ -25,6 +37,8 @@ class MyPainter extends CustomPainter {
|
|||||||
canvas.drawLine(pt1, pt2, paint..strokeWidth = stroke.points[i].thickness);
|
canvas.drawLine(pt1, pt2, paint..strokeWidth = stroke.points[i].thickness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
Reference in New Issue
Block a user