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

Fixing rounded rectangle and clips. #109

Merged
merged 14 commits into from
Jun 20, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 4 additions & 1 deletion flare_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ dependencies:
flutter:
sdk: flutter
flare_dart:
path: ../flare_dart
git:
url: git://github.com/2d-inc/Flare-Flutter.git
ref: dev
path: flare_dart
dev_dependencies:
flutter_test:
sdk: flutter