Skip to content

Commit

Permalink
Merge pull request #108 from 2d-inc/master
Browse files Browse the repository at this point in the history
Fixing rectangle and clips.
  • Loading branch information
luigi-rosso authored Jun 20, 2019
2 parents 8f04aa6 + 0230aab commit 0ee2efe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
24 changes: 13 additions & 11 deletions flare_dart/lib/actor_rectangle.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import 'dart:math';

import "actor_artboard.dart";
import "actor_component.dart";
import "actor_node.dart";
import "math/vec2d.dart";
import "stream_reader.dart";
import "actor_path.dart";
import "math/vec2d.dart";
import "path_point.dart";
import "actor_component.dart";

const double CircleConstant = 0.55;
import "stream_reader.dart";

class ActorRectangle extends ActorProceduralPath {
double _radius = 0.0;

@override
void invalidatePath() {}

@override
ActorComponent makeInstance(ActorArtboard resetArtboard) {
ActorRectangle instance = ActorRectangle();
instance.copyRectangle(this, resetArtboard);
Expand Down Expand Up @@ -41,17 +42,18 @@ class ActorRectangle extends ActorProceduralPath {

@override
List<PathPoint> get points {
double halfWidth = width / 2.0;
double halfHeight = height / 2.0;
double halfWidth = width / 2;
double halfHeight = height / 2;
double renderRadius = min(_radius, min(halfWidth, halfHeight));
List<PathPoint> _rectanglePathPoints = <PathPoint>[];
_rectanglePathPoints.add(StraightPathPoint.fromValues(
Vec2D.fromValues(-halfWidth, -halfHeight), _radius));
Vec2D.fromValues(-halfWidth, -halfHeight), renderRadius));
_rectanglePathPoints.add(StraightPathPoint.fromValues(
Vec2D.fromValues(halfWidth, -halfHeight), _radius));
Vec2D.fromValues(halfWidth, -halfHeight), renderRadius));
_rectanglePathPoints.add(StraightPathPoint.fromValues(
Vec2D.fromValues(halfWidth, halfHeight), _radius));
Vec2D.fromValues(halfWidth, halfHeight), renderRadius));
_rectanglePathPoints.add(StraightPathPoint.fromValues(
Vec2D.fromValues(-halfWidth, halfHeight), _radius));
Vec2D.fromValues(-halfWidth, halfHeight), renderRadius));

return _rectanglePathPoints;
}
Expand Down
15 changes: 13 additions & 2 deletions flare_flutter/lib/flare.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,25 @@ class FlutterActorShape extends ActorShape with FlutterActorDrawable {
// Get Clips
for (final List<ActorShape> clips in clipShapes) {
if (clips.length == 1) {
canvas.clipPath((clips[0] as FlutterActorShape).path);
if (clips.first.renderCollapsed) {
continue;
}
canvas.clipPath((clips.first as FlutterActorShape).path);
} else {
ui.Path clippingPath = ui.Path();
bool empty = true;
for (final ActorShape clipShape in clips) {
if (clipShape.renderCollapsed) {
continue;
}
clippingPath.addPath(
(clipShape as FlutterActorShape).path, ui.Offset.zero);
empty = false;
}

if (!empty) {
canvas.clipPath(clippingPath);
}
canvas.clipPath(clippingPath);
}
}
if (fills != null) {
Expand Down

0 comments on commit 0ee2efe

Please sign in to comment.