本文整理汇总了C++中SkRect::inset方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::inset方法的具体用法?C++ SkRect::inset怎么用?C++ SkRect::inset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::inset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convolve_gaussian
static void convolve_gaussian(GrDrawContext* drawContext,
GrRenderTarget* rt,
const GrClip& clip,
const SkRect& srcRect,
const SkRect& dstRect,
GrTexture* texture,
Gr1DKernelEffect::Direction direction,
int radius,
float sigma,
bool cropToSrcRect) {
float bounds[2] = { 0.0f, 1.0f };
if (!cropToSrcRect) {
convolve_gaussian_1d(drawContext, rt, clip, srcRect, dstRect, texture,
direction, radius, sigma, false, bounds);
return;
}
SkRect lowerSrcRect = srcRect, lowerDstRect = dstRect;
SkRect middleSrcRect = srcRect, middleDstRect = dstRect;
SkRect upperSrcRect = srcRect, upperDstRect = dstRect;
SkScalar size;
SkScalar rad = SkIntToScalar(radius);
if (direction == Gr1DKernelEffect::kX_Direction) {
bounds[0] = SkScalarToFloat(srcRect.left()) / texture->width();
bounds[1] = SkScalarToFloat(srcRect.right()) / texture->width();
size = srcRect.width();
lowerSrcRect.fRight = srcRect.left() + rad;
lowerDstRect.fRight = dstRect.left() + rad;
upperSrcRect.fLeft = srcRect.right() - rad;
upperDstRect.fLeft = dstRect.right() - rad;
middleSrcRect.inset(rad, 0);
middleDstRect.inset(rad, 0);
} else {
bounds[0] = SkScalarToFloat(srcRect.top()) / texture->height();
bounds[1] = SkScalarToFloat(srcRect.bottom()) / texture->height();
size = srcRect.height();
lowerSrcRect.fBottom = srcRect.top() + rad;
lowerDstRect.fBottom = dstRect.top() + rad;
upperSrcRect.fTop = srcRect.bottom() - rad;
upperDstRect.fTop = dstRect.bottom() - rad;
middleSrcRect.inset(0, rad);
middleDstRect.inset(0, rad);
}
if (radius >= size * SK_ScalarHalf) {
// Blur radius covers srcRect; use bounds over entire draw
convolve_gaussian_1d(drawContext, rt, clip, srcRect, dstRect, texture,
direction, radius, sigma, true, bounds);
} else {
// Draw upper and lower margins with bounds; middle without.
convolve_gaussian_1d(drawContext, rt, clip, lowerSrcRect, lowerDstRect, texture,
direction, radius, sigma, true, bounds);
convolve_gaussian_1d(drawContext, rt, clip, upperSrcRect, upperDstRect, texture,
direction, radius, sigma, true, bounds);
convolve_gaussian_1d(drawContext, rt, clip, middleSrcRect, middleDstRect, texture,
direction, radius, sigma, false, bounds);
}
}
示例2: calVideoRect
SkRect VideoLayerAndroid::calVideoRect(const SkRect& rect)
{
SkRect videoRect = rect;
VideoLayerManager* manager = TilesManager::instance()->videoLayerManager();
float aspectRatio = manager->getAspectRatio(uniqueId());
float deltaY = rect.height() - rect.width() / aspectRatio;
if (deltaY >= 0)
videoRect.inset(0, deltaY / 2);
else {
float deltaX = rect.width() - rect.height() * aspectRatio;
if (deltaX >= 0)
videoRect.inset(deltaX / 2, 0);
}
return videoRect;
}
示例3: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
canvas->drawColor(SK_ColorWHITE);
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
static const CanvasProc gProc[] = {
show_text, show_thick, show_hair, show_fill
};
SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) };
SkPath clipPath;
r.inset(SK_Scalar1 / 4, SK_Scalar1 / 4);
clipPath.addRoundRect(r, SkIntToScalar(20), SkIntToScalar(20));
// clipPath.toggleInverseFillType();
for (int aa = 0; aa <= 1; ++aa) {
canvas->save();
for (size_t i = 0; i < SK_ARRAY_COUNT(gProc); ++i) {
canvas->save();
canvas->clipPath(clipPath, SkRegion::kIntersect_Op, true);
// canvas->drawColor(SK_ColorWHITE);
gProc[i](canvas, SkToBool(aa));
canvas->restore();
canvas->translate(W * SK_Scalar1 * 8 / 7, 0);
}
canvas->restore();
canvas->translate(0, H * SK_Scalar1 * 8 / 7);
}
}
示例4: onDraw
virtual void onDraw(SkCanvas* canvas) {
switch (fStyle) {
case kRect_Style:
canvas->drawRect(fRect, fPaint);
break;
case kOval_Style:
canvas->drawOval(fRect, fPaint);
break;
case kRRect_Style: {
SkScalar rx = fRect.width() / 5;
SkScalar ry = fRect.height() / 5;
if (rx < ry) {
ry = rx;
} else {
rx = ry;
}
canvas->drawRoundRect(fRect, rx, ry, fPaint);
break;
}
case kFrame_Style: {
SkPath path;
path.addOval(fRect, SkPath::kCW_Direction);
SkRect r = fRect;
r.inset(fRect.width()/6, 0);
path.addOval(r, SkPath::kCCW_Direction);
canvas->drawPath(path, fPaint);
break;
}
}
}
示例5: onDraw
void onDraw(SkCanvas* canvas) override {
canvas->translate(20, 20);
SkRect r = SkRect::MakeWH(1000, 1000);
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(15);
const SkScalar inset = paint.getStrokeWidth() + 4;
const SkScalar sweepAngle = 345;
SkRandom rand;
SkScalar sign = 1;
while (r.width() > paint.getStrokeWidth() * 3) {
paint.setColor(sk_tool_utils::color_to_565(rand.nextU() | (0xFF << 24)));
SkScalar startAngle = rand.nextUScalar1() * 360;
SkScalar speed = SkScalarSqrt(16 / r.width()) * 0.5f;
startAngle += fRotate * 360 * speed * sign;
SkPath path;
path.addArc(r, startAngle, sweepAngle);
canvas->drawPath(path, paint);
r.inset(inset, inset);
sign = -sign;
}
}
示例6: acr
static void draw_2_bitmaps(SkCanvas* canvas, const SkBitmap& bm, bool doClip,
int dx, int dy, SkImageFilter* filter = NULL) {
SkAutoCanvasRestore acr(canvas, true);
SkPaint paint;
SkRect clipR = SkRect::MakeXYWH(SkIntToScalar(dx),
SkIntToScalar(dy),
SkIntToScalar(bm.width()),
SkIntToScalar(bm.height()));
paint.setImageFilter(filter);
clipR.inset(5, 5);
if (doClip) {
canvas->save();
canvas->clipRect(clipR);
}
canvas->drawSprite(bm, dx, dy, &paint);
if (doClip) {
canvas->restore();
}
canvas->translate(SkIntToScalar(bm.width() + 20), 0);
if (doClip) {
canvas->save();
canvas->clipRect(clipR);
}
canvas->drawBitmap(bm, SkIntToScalar(dx), SkIntToScalar(dy), &paint);
if (doClip) {
canvas->restore();
}
}
示例7: patheffect_slide
static void patheffect_slide(SkCanvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
SkPath path;
path.moveTo(20, 20);
path.lineTo(70, 120);
path.lineTo(120, 30);
path.lineTo(170, 80);
path.lineTo(240, 50);
size_t i;
canvas->save();
for (i = 0; i < SK_ARRAY_COUNT(gPE); i++) {
gPE[i](&paint);
canvas->drawPath(path, paint);
canvas->translate(0, 75);
}
canvas->restore();
path.reset();
SkRect r = { 0, 0, 250, 120 };
path.addOval(r, SkPath::kCW_Direction);
r.inset(50, 50);
path.addRect(r, SkPath::kCCW_Direction);
canvas->translate(320, 20);
for (i = 0; i < SK_ARRAY_COUNT(gPE2); i++) {
gPE2[i](&paint);
canvas->drawPath(path, paint);
canvas->translate(0, 160);
}
}
示例8: drawCell
static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode,
SkAlpha a0, SkAlpha a1) {
SkPaint paint;
paint.setAntiAlias(true);
SkRect r = SkRect::MakeWH(W, H);
r.inset(W/10, H/10);
paint.setColor(SK_ColorBLUE);
paint.setAlpha(a0);
canvas->drawOval(r, paint);
paint.setColor(SK_ColorRED);
paint.setAlpha(a1);
paint.setXfermode(mode);
SkScalar offset = SK_Scalar1 / 3;
SkRect rect = SkRect::MakeXYWH(W / 4 + offset,
H / 4 + offset,
W / 2, H / 2);
canvas->drawRect(rect, paint);
return H;
}
示例9: drawLine
void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) {
SkPaint paint;
fInverse.mapPoints(pts, 2);
if (fGrid) {
apply_grid(pts, 2);
}
erase(fMinSurface);
this->setupPaint(&paint);
paint.setColor(FAT_PIXEL_COLOR);
if (fUseClip) {
fMinSurface->getCanvas()->save();
SkRect r = fClipRect;
r.inset(SK_Scalar1/3, SK_Scalar1/3);
fMinSurface->getCanvas()->clipRect(r, SkRegion::kIntersect_Op, true);
}
fMinSurface->getCanvas()->drawLine(pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, paint);
if (fUseClip) {
fMinSurface->getCanvas()->restore();
}
this->copyMinToMax();
SkCanvas* max = fMaxSurface->getCanvas();
fMatrix.mapPoints(pts, 2);
this->drawLineSkeleton(max, pts);
fMaxSurface->draw(canvas, 0, 0, NULL);
}
示例10: draw_rect
static void draw_rect(SkCanvas* canvas, bool showGL, int flags) {
SkPaint paint;
paint.setAntiAlias(true);
SkRect r = SkRect::MakeLTRB(50, 70, 250, 370);
setFade(&paint, showGL);
canvas->drawRect(r, paint);
if (showGL) {
show_mesh(canvas, r);
}
canvas->translate(320, 0);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(25);
canvas->drawRect(r, paint);
if (showGL) {
SkScalar rad = paint.getStrokeWidth() / 2;
SkPoint pts[8];
r.outset(rad, rad);
r.toQuad(&pts[0]);
r.inset(rad*2, rad*2);
r.toQuad(&pts[4]);
const uint16_t indices[] = {
0, 4, 1, 5, 2, 6, 3, 7, 0, 4
};
show_mesh(canvas, pts, indices, SK_ARRAY_COUNT(indices));
}
}
示例11: drawCell
static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha a1)
{
SkPaint paint;
paint.setAntiAlias(true);
SkRect r = SkRect::MakeWH(W, H);
r.inset(W/10, H/10);
paint.setColor(SK_ColorBLUE);
paint.setAlpha(a0);
canvas->drawOval(r, paint);
paint.setColor(SK_ColorRED);
paint.setAlpha(a1);
paint.setXfermode(mode);
for (int angle = 0; angle < 24; ++angle)
{
SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth;
SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight;
paint.setStrokeWidth(SK_Scalar1 * angle * 2 / 24);
canvas->drawLine(W/2, H/2, W/2 + x, H/2 + y, paint);
}
return H;
}
示例12: SkMaxScalar
// found and fixed for webkit: mishandling when we hit recursion limit on
// mostly degenerate cubic flatness test
DEF_TEST(Paint_regression_cubic, reporter) {
SkPath path, stroke;
SkPaint paint;
path.moveTo(460.2881309415525f,
303.250847066498f);
path.cubicTo(463.36378422175284f,
302.1169735073363f,
456.32239330810046f,
304.720354932878f,
453.15255460013304f,
305.788586869862f);
SkRect fillR, strokeR;
fillR = path.getBounds();
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(2));
paint.getFillPath(path, &stroke);
strokeR = stroke.getBounds();
SkRect maxR = fillR;
SkScalar miter = SkMaxScalar(SK_Scalar1, paint.getStrokeMiter());
SkScalar inset = paint.getStrokeJoin() == SkPaint::kMiter_Join ?
SkScalarMul(paint.getStrokeWidth(), miter) :
paint.getStrokeWidth();
maxR.inset(-inset, -inset);
// test that our stroke didn't explode
REPORTER_ASSERT(reporter, maxR.contains(strokeR));
}
示例13: paint
static void lettersToBitmap2(SkBitmap* dst, const char chars[],
const SkPaint& original, SkBitmap::Config config) {
SkPath path;
SkScalar x = 0;
SkScalar width;
SkPath p;
for (size_t i = 0; i < strlen(chars); i++) {
original.getTextPath(&chars[i], 1, x, 0, &p);
path.addPath(p);
original.getTextWidths(&chars[i], 1, &width);
x += width;
}
SkRect bounds = path.getBounds();
SkScalar sw = -original.getStrokeWidth();
bounds.inset(sw, sw);
path.offset(-bounds.fLeft, -bounds.fTop);
bounds.offset(-bounds.fLeft, -bounds.fTop);
int w = SkScalarRound(bounds.width());
int h = SkScalarRound(bounds.height());
SkPaint paint(original);
paint.setAntiAlias(true);
paint.setXfermodeMode(SkXfermode::kDstATop_Mode);
paint.setColor(original.getColor());
paint.setStyle(SkPaint::kStroke_Style);
dst->setConfig(config, w, h);
dst->allocPixels();
dst->eraseColor(SK_ColorWHITE);
SkCanvas canvas(*dst);
canvas.drawPath(path, paint);
}
示例14: draw
void draw(SkCanvas* canvas,
const SkRect& rect,
const SkSize& deviceSize,
SkPaint::FilterLevel filterLevel,
SkImageFilter* input = NULL) {
SkRect dstRect;
canvas->getTotalMatrix().mapRect(&dstRect, rect);
canvas->save();
SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width());
SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height());
canvas->translate(rect.x(), rect.y());
canvas->scale(deviceScaleX, deviceScaleY);
canvas->translate(-rect.x(), -rect.y());
SkMatrix matrix;
matrix.setScale(SkScalarInvert(deviceScaleX),
SkScalarInvert(deviceScaleY));
SkAutoTUnref<SkImageFilter> imageFilter(
SkMatrixImageFilter::Create(matrix, filterLevel, input));
SkPaint filteredPaint;
filteredPaint.setImageFilter(imageFilter.get());
canvas->saveLayer(&rect, &filteredPaint);
SkPaint paint;
paint.setColor(0xFF00FF00);
SkRect ovalRect = rect;
ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
canvas->drawOval(ovalRect, paint);
canvas->restore(); // for saveLayer
canvas->restore();
}
示例15: make_bmp
static SkBitmap make_bmp(int w, int h) {
SkBitmap bmp;
bmp.allocN32Pixels(w, h, true);
SkCanvas canvas(bmp);
SkScalar wScalar = SkIntToScalar(w);
SkScalar hScalar = SkIntToScalar(h);
SkPoint pt = { wScalar / 2, hScalar / 2 };
SkScalar radius = 3 * SkMaxScalar(wScalar, hScalar);
SkColor colors[] = {SK_ColorDKGRAY,
ToolUtils::color_to_565(0xFF222255),
ToolUtils::color_to_565(0xFF331133),
ToolUtils::color_to_565(0xFF884422),
ToolUtils::color_to_565(0xFF000022),
SK_ColorWHITE,
ToolUtils::color_to_565(0xFFAABBCC)};
SkScalar pos[] = {0,
SK_Scalar1 / 6,
2 * SK_Scalar1 / 6,
3 * SK_Scalar1 / 6,
4 * SK_Scalar1 / 6,
5 * SK_Scalar1 / 6,
SK_Scalar1};
SkPaint paint;
SkRect rect = SkRect::MakeWH(wScalar, hScalar);
SkMatrix mat = SkMatrix::I();
for (int i = 0; i < 4; ++i) {
paint.setShader(SkGradientShader::MakeRadial(
pt, radius,
colors, pos,
SK_ARRAY_COUNT(colors),
SkTileMode::kRepeat,
0, &mat));
canvas.drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.preTranslate(6 * wScalar, 6 * hScalar);
mat.postScale(SK_Scalar1 / 3, SK_Scalar1 / 3);
}
SkFont font(ToolUtils::create_portable_typeface(), wScalar / 2.2f);
paint.setShader(nullptr);
paint.setColor(SK_ColorLTGRAY);
constexpr char kTxt[] = "Skia";
SkPoint texPos = { wScalar / 17, hScalar / 2 + font.getSize() / 2.5f };
canvas.drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8,
texPos.fX, texPos.fY, font, paint);
paint.setColor(SK_ColorBLACK);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SK_Scalar1);
canvas.drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8,
texPos.fX, texPos.fY, font, paint);
return bmp;
}