Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erase support (transparent background only) #18

Merged
merged 4 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2018 Eric Prokop und Nils Wieler Hard- und Softwareentwicklung GbR
Copyright 2018 Eric Prokop und Nils Wieler Hard- und Softwareentwicklung GbR und Tomasz Marzeion

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
18 changes: 17 additions & 1 deletion lib/painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ class _PathHistory{
}

void draw(Canvas canvas,Size size){
canvas.saveLayer(Offset.zero & size, Paint());
canvas.drawRect(new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _backgroundPaint);
for(MapEntry<Path,Paint> path in _paths){
canvas.drawPath(path.key,path.value);
}
canvas.restore();
}
}

Expand All @@ -176,6 +178,7 @@ class PictureDetails{
class PainterController extends ChangeNotifier{
Color _drawColor=new Color.fromARGB(255, 0, 0, 0);
Color _backgroundColor=new Color.fromARGB(255, 255, 255, 255);
bool _eraseMode=false;

double _thickness=1.0;
PictureDetails _cached;
Expand All @@ -186,6 +189,14 @@ class PainterController extends ChangeNotifier{
_pathHistory=new _PathHistory();
}

// setter for erase mode.
// Note: Works only for transparent background
bool get eraseMode => _eraseMode;
set eraseMode(bool enabled) {
_eraseMode = enabled;
_updatePaint();
}

Color get drawColor => _drawColor;
set drawColor(Color color){
_drawColor=color;
Expand All @@ -206,7 +217,12 @@ class PainterController extends ChangeNotifier{

void _updatePaint(){
Paint paint=new Paint();
paint.color=drawColor;
if (_eraseMode) {
paint.color=Color.fromARGB(0, 255, 0, 0);
paint.blendMode = BlendMode.clear;
} else {
paint.color=drawColor;
}
paint.style=PaintingStyle.stroke;
paint.strokeWidth=thickness;
_pathHistory.currentPaint=paint;
Expand Down