Skip to content

Commit

Permalink
Merge pull request #18 from tmarzeion/erase-support
Browse files Browse the repository at this point in the history
Erase support (transparent background only)
  • Loading branch information
EPNW-Eric committed Apr 20, 2020
2 parents 4845503 + 2f637b6 commit 5b8ef19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit 5b8ef19

Please sign in to comment.