add scrollable page with normed shape

This commit is contained in:
lukas-heiligenbrunner 2022-10-24 12:27:38 +02:00
parent 7eead41703
commit d24f0407b8
3 changed files with 27 additions and 12 deletions

View File

@ -7,17 +7,20 @@ import 'package:notes/canvas/my_painter.dart';
import 'document_types.dart'; import 'document_types.dart';
class DrawingCanvas extends StatefulWidget { class DrawingPage extends StatefulWidget {
const DrawingCanvas({Key? key}) : super(key: key); const DrawingPage({Key? key}) : super(key: key);
@override @override
State<DrawingCanvas> createState() => _DrawingCanvasState(); State<DrawingPage> createState() => _DrawingPageState();
} }
class _DrawingCanvasState extends State<DrawingCanvas> { class _DrawingPageState extends State<DrawingPage> {
List<Stroke> _strokes = []; List<Stroke> _strokes = [];
bool allowDrawWithFinger = false; bool allowDrawWithFinger = false;
double zoom = 0.6;
Offset scrollPos = const Offset(.0, .0);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -31,6 +34,8 @@ class _DrawingCanvasState extends State<DrawingCanvas> {
} }
double _calcAngleDependentWidth(List<Point> pts, double basetickness){ double _calcAngleDependentWidth(List<Point> pts, double 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);
@ -45,6 +50,10 @@ class _DrawingCanvasState extends State<DrawingCanvas> {
} }
Widget _buildCanvas() { Widget _buildCanvas() {
final width = MediaQuery.of(context).size.width;
final zoomedwidth = width * zoom;
return Scaffold( return Scaffold(
body: Listener( body: Listener(
onPointerMove: (event) { onPointerMove: (event) {
@ -75,6 +84,7 @@ class _DrawingCanvasState extends State<DrawingCanvas> {
}); });
} }
}, },
onPointerUp: (event) { onPointerUp: (event) {
if (allowDrawWithFinger || event.kind != PointerDeviceKind.touch) { if (allowDrawWithFinger || event.kind != PointerDeviceKind.touch) {
if (_strokes.last.points.length <= 1) { if (_strokes.last.points.length <= 1) {
@ -118,12 +128,17 @@ class _DrawingCanvasState extends State<DrawingCanvas> {
// _strokes = List.from(_strokes)..add(Stroke.fromPoints([details.localPosition])); // _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),
size: Size.infinite, // todo not working
size: Size(zoomedwidth, zoomedwidth * sqrt2), // todo add different paper dimensions
// ), // ),
), ),
), ),
),
),
); );
} }
} }

View File

@ -1,5 +1,3 @@
import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'document_types.dart'; import 'document_types.dart';
@ -16,6 +14,8 @@ class MyPainter extends CustomPainter {
..strokeCap = StrokeCap.square; ..strokeCap = StrokeCap.square;
// ..strokeWidth = 3.0; // ..strokeWidth = 3.0;
canvas.drawColor(Color.fromRGBO(255, 255, 255, .1), BlendMode.src);
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;

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:notes/CollapseDrawer.dart'; import 'package:notes/CollapseDrawer.dart';
import 'package:notes/all_notes_page.dart'; import 'package:notes/all_notes_page.dart';
import 'package:notes/canvas/drawing_canvas.dart'; import 'package:notes/canvas/drawing_page.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@ -66,7 +66,7 @@ class _MyHomePageState extends State<MyHomePage> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => const DrawingCanvas(), builder: (context) => const DrawingPage(),
), ),
); );
}, },