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
75
struct Borders {
SkScalar left, top, right, bottom;
};
SkVector MakeInnerRadius(
SkScalar outerRadius,
SkScalar bx,
SkScalar by)
{
return {
fmaxf(outerRadius - bx, 0),
fmaxf(outerRadius - by, 0),
};
}
void draw(SkCanvas* canvas) {
// Surface size
SkScalar width = 300;
SkScalar height = 100;
// Configurable parameters
SkScalar radii[4] { 64, 16, 48, 8 };
Borders borders { 4, 16, 4, 16 };
SkColor fillColor = 0xFF'46278E;
SkColor borderColor = 0xFF'0FDEBD;
// Convert scalar radii to vectors
SkVector outerRadii[4];
SkScalar const* in_begin = &radii[0];
SkScalar const* in_end = &radii[4];
SkVector* out_begin = &outerRadii[0];
std::transform(in_begin, in_end, out_begin,
[](SkScalar r) -> SkVector {
return { r, r };
});
// Compute inner radii
SkVector innerRadii[4] {
MakeInnerRadius(radii[0], borders.left, borders.top),
MakeInnerRadius(radii[1], borders.right, borders.top),
MakeInnerRadius(radii[2], borders.right, borders.bottom),
MakeInnerRadius(radii[3], borders.left, borders.bottom),
};
// Prepare our paint and canvas
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kFill_Style);
canvas->clear(SK_ColorTRANSPARENT);
// Draw outer RRect
SkRRect outer;
outer.setRectRadii(SkRect::MakeWH(width, height), outerRadii);
paint.setColor(borderColor);
canvas->drawRRect(outer, paint);
// Draw inner RRect
auto innerBounds = SkRect::MakeXYWH(
borders.left,
borders.top,
width - (borders.left + borders.right),
height - (borders.top + borders.bottom));
SkRRect inner;
inner.setRectRadii(innerBounds, innerRadii);
paint.setColor(fillColor);
canvas->drawRRect(inner, paint);
}