Skip to content

Commit

Permalink
Fixing issue with image clipping.
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-rosso committed Oct 9, 2019
1 parent ae1c901 commit 373c14a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 54 deletions.
4 changes: 4 additions & 0 deletions flare_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.6.1] - 2019-10-09 14:20:54

- Image and Shapes share clipping logic. Fixes issue with image clipping.

## [1.6.0] - 2019-10-09 11:08:52

- Using latest flare_dart with support for difference clipping.
Expand Down
101 changes: 48 additions & 53 deletions flare_flutter/lib/flare.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,51 @@ abstract class FlutterActorDrawable {
void onBlendModeChanged(ui.BlendMode blendMode);

void draw(ui.Canvas canvas);

List<List<ClipShape>> get clipShapes;
ActorArtboard get artboard;

void clip(ui.Canvas canvas) {
for (final List<ClipShape> clips in clipShapes) {
for (final ClipShape clipShape in clips) {
var shape = clipShape.shape;
if (shape.renderCollapsed) {
continue;
}
if (clipShape.intersect) {
canvas.clipPath((shape as FlutterActorShape).path);
} else {
var artboardRect = Rect.fromLTWH(
artboard.origin[0] * artboard.width,
artboard.origin[1] * artboard.height,
artboard.width,
artboard.height);

if (shape.fill != null && shape.fill.fillRule == FillRule.evenOdd) {
// One single clip path with subtraction rect and all sub paths.
var clipPath = ui.Path();
clipPath.addRect(artboardRect);
for (final path in shape.paths) {
clipPath.addPath((path as FlutterPath).path, ui.Offset.zero,
matrix4: path.pathTransform?.mat4);
}
clipPath.fillType = PathFillType.evenOdd;
canvas.clipPath(clipPath);
} else {
// One clip path with rect per shape path.
for (final path in shape.paths) {
var clipPath = ui.Path();
clipPath.addRect(artboardRect);
clipPath.addPath((path as FlutterPath).path, ui.Offset.zero,
matrix4: path.pathTransform?.mat4);
clipPath.fillType = PathFillType.evenOdd;
canvas.clipPath(clipPath);
}
}
}
}
}
}
}

abstract class FlutterFill {
Expand Down Expand Up @@ -231,46 +276,7 @@ class FlutterActorShape extends ActorShape with FlutterActorDrawable {

canvas.save();

// Get Clips
for (final List<ClipShape> clips in clipShapes) {
for (final ClipShape clipShape in clips) {
var shape = clipShape.shape;
if (shape.renderCollapsed) {
continue;
}
if (clipShape.intersect) {
canvas.clipPath((shape as FlutterActorShape).path);
} else {
var artboardRect = Rect.fromLTWH(
artboard.origin[0] * artboard.width,
artboard.origin[1] * artboard.height,
artboard.width,
artboard.height);

if (shape.fill != null && shape.fill.fillRule == FillRule.evenOdd) {
// One single clip path with subtraction rect and all sub paths.
var clipPath = ui.Path();
clipPath.addRect(artboardRect);
for (final path in shape.paths) {
clipPath.addPath((path as FlutterPath).path, ui.Offset.zero,
matrix4: path.pathTransform?.mat4);
}
clipPath.fillType = PathFillType.evenOdd;
canvas.clipPath(clipPath);
} else {
// One clip path with rect per shape path.
for (final path in shape.paths) {
var clipPath = ui.Path();
clipPath.addRect(artboardRect);
clipPath.addPath((path as FlutterPath).path, ui.Offset.zero,
matrix4: path.pathTransform?.mat4);
clipPath.fillType = PathFillType.evenOdd;
canvas.clipPath(clipPath);
}
}
}
}
}
clip(canvas);

ui.Path renderPath = getRenderPath(canvas);

Expand Down Expand Up @@ -1129,19 +1135,8 @@ class FlutterActorImage extends ActorImage with FlutterActorDrawable {
return;
}
canvas.save();
// Get Clips
for (final List<ClipShape> clips in clipShapes) {
if (clips.length == 1) {
canvas.clipPath((clips[0] as FlutterActorShape).path);
} else {
ui.Path clippingPath = ui.Path();
for (final ClipShape clipShape in clips) {
clippingPath.addPath(
(clipShape.shape as FlutterActorShape).path, ui.Offset.zero);
}
canvas.clipPath(clippingPath);
}
}

clip(canvas);

_paint.color =
_paint.color.withOpacity(renderOpacity.clamp(0.0, 1.0).toDouble());
Expand Down
2 changes: 1 addition & 1 deletion flare_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flare_flutter
description: Vector design and runtime animation for Flutter.
version: 1.6.0
version: 1.6.1
author: "2Dimensions Team <info@2dimensions.com>"
homepage: https://github.com/2d-inc/Flare-Flutter
environment:
Expand Down

0 comments on commit 373c14a

Please sign in to comment.