save correct color to db
use different pointer for highlighter
This commit is contained in:
@ -40,7 +40,8 @@ class MyPainter extends CustomPainter {
|
||||
void paint(Canvas canvas, Size size) {
|
||||
var paint = Paint()
|
||||
..color = Colors.blue
|
||||
..strokeCap = StrokeCap.square;
|
||||
..strokeCap = StrokeCap.square
|
||||
..isAntiAlias = true;
|
||||
|
||||
// clipping canvas to reqired size
|
||||
canvas.clipRect(Offset.zero & size);
|
||||
@ -59,8 +60,24 @@ class MyPainter extends CustomPainter {
|
||||
Offset pt2 = stroke.points[i + 1].point;
|
||||
pt2 = _translatept(pt2, size);
|
||||
|
||||
canvas.drawLine(
|
||||
pt1, pt2, paint..strokeWidth = stroke.points[i].thickness * zoom);
|
||||
final zoomedthickness = stroke.points[i].thickness * zoom;
|
||||
|
||||
// only temporary solution to differ from highlighter and pen
|
||||
if (stroke.color.opacity != 1.0) {
|
||||
final off = Offset(zoomedthickness / 2, zoomedthickness / 2);
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo((pt1 - off).dx, (pt1 - off).dy)
|
||||
..lineTo((pt1 + off).dx, (pt1 + off).dy)
|
||||
..lineTo((pt2 + off).dx, (pt2 + off).dy)
|
||||
..lineTo((pt2 - off).dx, (pt2 - off).dy)
|
||||
..lineTo((pt1 - off).dx, (pt1 - off).dy),
|
||||
paint
|
||||
..style = PaintingStyle.fill
|
||||
..strokeWidth = 0);
|
||||
} else {
|
||||
canvas.drawLine(pt1, pt2, paint..strokeWidth = zoomedthickness);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,19 +62,20 @@ class PaintController extends ChangeNotifier {
|
||||
if (activePen == Pen.eraser || activePen == Pen.selector) return;
|
||||
|
||||
int strokeid = strokes.isNotEmpty ? strokes.last.id + 1 : 0;
|
||||
final color = activePen == Pen.pen
|
||||
? const Color(0xFF444444)
|
||||
: Colors.yellow.withOpacity(.3);
|
||||
strokes.add(Stroke.fromPoints(
|
||||
[Point(offset, _calcTiltedWidth(3.0, e.tilt))],
|
||||
strokeid,
|
||||
activePen == Pen.pen
|
||||
? const Color(0xFF444444)
|
||||
: Colors.yellow.withOpacity(.5)));
|
||||
file.addStroke(strokeid);
|
||||
[Point(offset, _calcTiltedWidth(3.0, e.tilt))], strokeid, color));
|
||||
file.addStroke(strokeid, color);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void pointUpEvent(PointerUpEvent e) {
|
||||
if (activePen == Pen.eraser) return;
|
||||
|
||||
// pointerupevent doesn't deliver correct event button
|
||||
if (_allowedToDraw(e.kind, 1)) {
|
||||
final lastStroke = strokes.last;
|
||||
if (lastStroke.points.length <= 1) {
|
||||
@ -122,20 +123,24 @@ class PaintController extends ChangeNotifier {
|
||||
}
|
||||
break;
|
||||
case Pen.pen:
|
||||
case Pen.highlighter:
|
||||
final pts = strokes.last.points;
|
||||
// avoid duplicates
|
||||
if (pts.last.point == offset) return;
|
||||
|
||||
double newWidth = _calcTiltedWidth(5.0, event.tilt);
|
||||
double newWidth = _calcTiltedWidth(4.0, event.tilt);
|
||||
if (pts.length > 1) {
|
||||
newWidth = _calcAngleDependentWidth(pts.last,
|
||||
pts[pts.length - (pts.length > 5 ? 5 : pts.length)], newWidth);
|
||||
}
|
||||
|
||||
Point p = Point(offset, newWidth);
|
||||
strokes.last.addPoint(p);
|
||||
// // todo do a batch commit per stroke
|
||||
// file.addPoint(strokes.last.id, p);
|
||||
strokes.last.addPoint(Point(offset, newWidth));
|
||||
break;
|
||||
case Pen.highlighter:
|
||||
final pts = strokes.last.points;
|
||||
// avoid duplicates
|
||||
if (pts.last.point == offset) return;
|
||||
|
||||
strokes.last.addPoint(Point(offset, 15.0));
|
||||
break;
|
||||
case Pen.selector:
|
||||
// TODO: Handle this case.
|
||||
|
Reference in New Issue
Block a user