Options
These globals are now defined:
double duration; // The requested duration of the animation. double frame; // A value in [0, 1] of where we are in the animation.
This global is now defined:
GrBackendRenderTarget backEndRenderTarget;
GrBackendTexture backEndTextureRenderTarget;
Optional source image
These globals are now defined:
SkBitmap source; sk_sp<SkImage> image; GrBackendTexture backEndTexture; // GPU Only.
Note:
Adding comments with SK_FOLD_START and SK_FOLD_END creates foldable code
blocks.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
xxxxxxxxxx
74
sk_sp<SkImageFilter> GetShadowFilter(SkScalar dx, SkScalar dy,
SkScalar blurRadius = 0,
SkColor color = SK_ColorBLACK,
bool inset = false) {
blurRadius *= 0.5f;
if (!inset) {
return SkImageFilters::DropShadowOnly(dx, dy, blurRadius, blurRadius, color, nullptr);
}
sk_sp<SkImageFilter> colorFilter = SkImageFilters::ColorFilter(
SkColorFilters::Blend(color, SkBlendMode::kSrcOut), nullptr);
sk_sp<SkImageFilter> offsetFilter =
SkImageFilters::Offset(dx, dy, colorFilter);
sk_sp<SkImageFilter> blurFilter = SkImageFilters::Blur(
blurRadius, blurRadius, SkTileMode::kDecal, offsetFilter);
return blurFilter;
}
void draw(SkCanvas* canvas) {
SkSurface* surface = canvas->getSurface();
const SkScalar cx = 200;
const SkScalar cy = 125;
const SkScalar dx = 10;
const SkScalar dy = 10;
const SkScalar blurRadius = 10;
const SkScalar spreadRadius = 10;
const SkColor& color = SK_ColorBLACK;
bool inner = true;
sk_sp<SkImageFilter> filter = GetShadowFilter(dx, dy, blurRadius, color, inner);
const SkScalar width = 300;
const SkScalar height = 150;
const SkScalar x = cx - width * 0.5f;
const SkScalar y = cy - height * 0.5f;
SkRect rect = SkRect::MakeXYWH(x, y, width, height);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorRED);
SkPaint shadow;
shadow.setAntiAlias(true);
shadow.setImageFilter(filter);
SkMatrix matrix = canvas->getTotalMatrix();
SkScalar scaleFactor = (inner ? -1.0f : 1.0f) * (spreadRadius * 2);
SkScalar scaleX = 1.0f + scaleFactor / std::max(rect.width(), 1.0f);
SkScalar scaleY = 1.0f + scaleFactor / std::max(rect.height(), 1.0f);
matrix.preScale(scaleX, scaleY, rect.centerX(), rect.centerY());
if (!inner) {
canvas->save();
canvas->setMatrix(matrix);
canvas->drawRect(rect, shadow);
canvas->restore();
}
canvas->drawRect(rect, paint);
if (inner) {
canvas->save();
canvas->clipRect(rect, SkClipOp::kIntersect, true);
canvas->setMatrix(matrix);
canvas->drawRect(rect, shadow);
canvas->restore();
}
}