Skip to content

Commit

Permalink
fix: Draw outline independent of background (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Pepe authored Jun 7, 2024
1 parent 3752770 commit 36f6c41
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 8 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
? Text('Hide outline')
: Text('Show Outline'),
),
MaterialButton(
onPressed: () {
controller.setShowBackground(!controller.showBackground);
},
child: controller.showUserStroke
? Text('Hide background')
: Text('Show background'),
),
MaterialButton(
onPressed: () {
controller.setShowMedian(!controller.showMedian);
Expand Down
21 changes: 11 additions & 10 deletions lib/src/character_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CharacterPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
_paintBackground(canvas, size);
_paintBackgroundAndOutline(canvas, size);

for (var i = 0; i < controller.strokeOrder.strokeOutlines.length; i++) {
if (i == controller.currentStroke &&
Expand All @@ -62,17 +62,18 @@ class CharacterPainter extends CustomPainter {
}
}

void _paintBackground(Canvas canvas, Size size) {
void _paintBackgroundAndOutline(Canvas canvas, Size size) {
final outlines = controller.strokeOrder.strokeOutlines;
for (var i = 0; i < outlines.length; i++) {
// Paint the background only for those strokes that are not getting
// painted with the actual stroke color later
if (controller.showBackground && !shouldPaintStroke[i]) {
canvas.drawPath(
_scalePath(outlines[i], size),
backgroundPaint,
);

// Paint the background and outline only for those strokes that are not
// getting painted with the actual stroke color later
if (!shouldPaintStroke[i]) {
if (controller.showBackground) {
canvas.drawPath(
_scalePath(outlines[i], size),
backgroundPaint,
);
}
if (controller.showOutline) {
canvas.drawPath(
_scalePath(outlines[i], size),
Expand Down

0 comments on commit 36f6c41

Please sign in to comment.