Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Commit

Permalink
clip canvas draw bounds to the AE canvas
Browse files Browse the repository at this point in the history
Summary:
this adds clipping that will respect the bounds of the after effects
canvas, rather than drawing in all allotted space of the drawable
Closes #84

Differential Revision: D4439895

Pulled By: LazyChild

fbshipit-source-id: c9de07b227a3d382716b69a816eecaf796536ded
  • Loading branch information
lozzle authored and facebook-github-bot committed Jan 20, 2017
1 parent b286d6f commit d3a171f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class KeyframesDrawable extends Drawable
private float mScaleFromCenter;
private float mScaleFromEnd;
private final Map<String, FeatureConfig> mFeatureConfigs;

private boolean mClipToAECanvas;

private boolean mHasInitialized = false;

Expand Down Expand Up @@ -130,6 +130,7 @@ public class KeyframesDrawable extends Drawable
}

setMaxFrameRate(builder.getMaxFrameRate());
mClipToAECanvas = builder.getExperimentalFeatures().getClipToAECanvas();
}

/**
Expand Down Expand Up @@ -170,6 +171,13 @@ public void setDirectionalScale(
public void draw(Canvas canvas) {
Rect currBounds = getBounds();
canvas.translate(currBounds.left, currBounds.top);
if (mClipToAECanvas) {
canvas.clipRect(
0,
0,
mKFImage.getCanvasSize()[0] * mScale * mScaleFromEnd * mScaleFromCenter,
mKFImage.getCanvasSize()[1] * mScale * mScaleFromEnd * mScaleFromCenter);
}
KFPath pathToDraw;
FeatureState featureState;
for (int i = 0, len = mFeatureStateList.size(); i < len; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ ExperimentalFeatures getExperimentalFeatures() {
*/
public class ExperimentalFeatures {
private Map<String, KeyframesDrawable.FeatureConfig> mParticleFeatureConfigs;
private boolean mClipToAECanvas = false;

public KeyframesDrawable build() {
return KeyframesDrawableBuilder.this.build();
Expand All @@ -88,5 +89,14 @@ public ExperimentalFeatures withParticleFeatureConfigs(
Map<String, KeyframesDrawable.FeatureConfig> getParticleFeatureConfigs() {
return mParticleFeatureConfigs;
}

public ExperimentalFeatures clipToAECanvas() {
mClipToAECanvas = true;
return ExperimentalFeatures.this;
}

boolean getClipToAECanvas() {
return mClipToAECanvas;
}
}
}

0 comments on commit d3a171f

Please sign in to comment.