本文整理汇总了C++中SkRect::offset方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::offset方法的具体用法?C++ SkRect::offset怎么用?C++ SkRect::offset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::offset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Just draw a blurred rect at each of the four corners of a square (centered at x,y).
// Use two clips to define a rectori where we want pixels to appear.
void draw0x0(SkCanvas* canvas, SkScalar x, SkScalar y) {
SkRect innerClip = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHalfSquareSize };
innerClip.offset(x, y);
SkRect outerClip = {
-kHalfOuterClipSize-kHalfSquareSize, -kHalfOuterClipSize-kHalfSquareSize,
kHalfOuterClipSize+kHalfSquareSize, kHalfOuterClipSize+kHalfSquareSize
};
outerClip.offset(x, y);
canvas->save();
canvas->clipRect(outerClip, SkCanvas::kIntersect_Op);
canvas->clipRect(innerClip, SkCanvas::kDifference_Op);
SkPaint paint;
paint.setAntiAlias(true);
paint.setMaskFilter(MakeBlur());
for (int i = 0; i < 4; ++i) {
paint.setColor(gColors[i]);
SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHalfSquareSize };
rect.offset(gBlurOffsets[i]);
rect.offset(x, y);
canvas->drawRect(rect, paint);
}
canvas->restore();
}
示例2: test_strokerect
static void test_strokerect(SkCanvas* canvas)
{
canvas->drawColor(SK_ColorWHITE);
SkRect r;
r.set(10, 10, 14, 14);
r.offset(0.25f, 0.3333f);
test_strokerect(canvas, r);
canvas->translate(0, 20);
r.set(10, 10, 14.5f, 14.5f);
r.offset(0.25f, 0.3333f);
test_strokerect(canvas, r);
canvas->translate(0, 20);
r.set(10, 10, 14.5f, 20);
r.offset(0.25f, 0.3333f);
test_strokerect(canvas, r);
canvas->translate(0, 20);
r.set(10, 10, 20, 14.5f);
r.offset(0.25f, 0.3333f);
test_strokerect(canvas, r);
canvas->translate(0, 20);
r.set(10, 10, 20, 20);
r.offset(0.25f, 0.3333f);
test_strokerect(canvas, r);
canvas->translate(0, 20);
}
示例3: draw_mode
void draw_mode(SkCanvas* canvas, SkXfermode* mode, int alpha,
SkScalar x, SkScalar y) {
SkPaint p;
SkMaskFilter* mf = SkBlurMaskFilter::Create(5, SkBlurMaskFilter::kNormal_BlurStyle, 0);
p.setMaskFilter(mf)->unref();
SkScalar ww = SkIntToScalar(W);
SkScalar hh = SkIntToScalar(H);
// draw a circle covering the upper
// left three quarters of the canvas
p.setColor(0xFFCC44FF);
SkRect r;
r.set(0, 0, ww*3/4, hh*3/4);
r.offset(x, y);
canvas->drawOval(r, p);
p.setXfermode(mode);
// draw a square overlapping the circle
// in the lower right of the canvas
p.setColor(0x00AA6633 | alpha << 24);
r.set(ww/3, hh/3, ww*19/20, hh*19/20);
r.offset(x, y);
canvas->drawRect(r, p);
}
示例4: show_bm
static void show_bm(SkCanvas* canvas, int width, int height, SkColor color) {
SkBitmap bm;
make_bm(&bm, width, height, color);
SkPaint paint;
SkRect r;
SkIRect ir;
paint.setStyle(SkPaint::kStroke_Style);
ir.set(0, 0, 128, 128);
r.set(ir);
canvas->save();
canvas->clipRect(r);
canvas->drawBitmap(bm, 0, 0, NULL);
canvas->restore();
canvas->drawRect(r, paint);
r.offset(SkIntToScalar(150), 0);
// exercises extract bitmap, but not shader
canvas->drawBitmapRect(bm, &ir, r, NULL);
canvas->drawRect(r, paint);
r.offset(SkIntToScalar(150), 0);
// exercises bitmapshader
canvas->drawBitmapRect(bm, NULL, r, NULL);
canvas->drawRect(r, paint);
}
示例5: draw_mode
void draw_mode(SkCanvas* canvas, SkBlendMode mode, int alpha, SkScalar x, SkScalar y) {
SkPaint p;
p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(5),
SkBlurMaskFilter::kNone_BlurFlag));
SkScalar ww = SkIntToScalar(W);
SkScalar hh = SkIntToScalar(H);
// draw a circle covering the upper
// left three quarters of the canvas
p.setColor(0xFFCC44FF);
SkRect r;
r.set(0, 0, ww*3/4, hh*3/4);
r.offset(x, y);
canvas->drawOval(r, p);
p.setBlendMode(mode);
// draw a square overlapping the circle
// in the lower right of the canvas
p.setColor(0x00AA6633 | alpha << 24);
r.set(ww/3, hh/3, ww*19/20, hh*19/20);
r.offset(x, y);
canvas->drawRect(r, p);
}
示例6: drawClippedGeom
void drawClippedGeom(SkCanvas* canvas, const SkPoint& offset, bool useAA) {
int count = canvas->save();
switch (fGeom) {
case kRect_Geometry:
canvas->clipRect(create_rect(offset), SkRegion::kReplace_Op, useAA);
break;
case kRRect_Geometry:
canvas->clipRRect(create_rrect(offset), SkRegion::kReplace_Op, useAA);
break;
case kCircle_Geometry:
canvas->clipRRect(create_circle(offset), SkRegion::kReplace_Op, useAA);
break;
case kConvexPath_Geometry:
canvas->clipPath(create_convex_path(offset), SkRegion::kReplace_Op, useAA);
break;
case kConcavePath_Geometry:
canvas->clipPath(create_concave_path(offset), SkRegion::kReplace_Op, useAA);
break;
case kRectAndRect_Geometry: {
SkRect r = create_rect(offset);
r.offset(fSign * kXlate, fSign * kXlate);
canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips
canvas->clipRect(create_rect(offset), SkRegion::kIntersect_Op, useAA);
} break;
case kRectAndRRect_Geometry: {
SkRect r = create_rect(offset);
r.offset(fSign * kXlate, fSign * kXlate);
canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips
canvas->clipRRect(create_rrect(offset), SkRegion::kIntersect_Op, useAA);
} break;
case kRectAndConvex_Geometry: {
SkRect r = create_rect(offset);
r.offset(fSign * kXlate, fSign * kXlate);
canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips
canvas->clipPath(create_convex_path(offset), SkRegion::kIntersect_Op, useAA);
} break;
case kRectAndConcave_Geometry: {
SkRect r = create_rect(offset);
r.offset(fSign * kXlate, fSign * kXlate);
canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips
canvas->clipPath(create_concave_path(offset), SkRegion::kIntersect_Op, useAA);
} break;
}
SkISize size = canvas->getDeviceSize();
SkRect bigR = SkRect::MakeWH(SkIntToScalar(size.width()), SkIntToScalar(size.height()));
SkPaint p;
p.setColor(SK_ColorRED);
canvas->drawRect(bigR, p);
canvas->restoreToCount(count);
}
示例7: drawMask
void drawMask(SkCanvas* canvas, const SkRect& r) {
SkPaint paint;
paint.setAntiAlias(true);
if (true) {
SkBitmap mask;
int w = SkScalarRound(r.width());
int h = SkScalarRound(r.height());
mask.setConfig(SkBitmap::kARGB_8888_Config, w, h);
mask.allocPixels();
mask.eraseColor(0);
SkCanvas c(mask);
SkRect bounds = r;
bounds.offset(-bounds.fLeft, -bounds.fTop);
c.drawOval(bounds, paint);
paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint);
} else {
SkPath p;
p.addOval(r);
p.setFillType(SkPath::kInverseWinding_FillType);
paint.setXfermodeMode(SkXfermode::kDstOut_Mode);
canvas->drawPath(p, paint);
}
}
示例8: Make
static std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, const SkMatrix& viewMatrix,
const SkRect& rect, const SkStrokeRec& stroke,
bool snapToPixelCenters) {
if (!allowed_stroke(stroke)) {
return nullptr;
}
NonAAStrokeRectOp* op = new NonAAStrokeRectOp();
op->fColor = color;
op->fViewMatrix = viewMatrix;
op->fRect = rect;
// Sort the rect for hairlines
op->fRect.sort();
op->fStrokeWidth = stroke.getWidth();
SkScalar rad = SkScalarHalf(op->fStrokeWidth);
SkRect bounds = rect;
bounds.outset(rad, rad);
// If our caller snaps to pixel centers then we have to round out the bounds
if (snapToPixelCenters) {
viewMatrix.mapRect(&bounds);
// We want to be consistent with how we snap non-aa lines. To match what we do in
// GrGLSLVertexShaderBuilder, we first floor all the vertex values and then add half a
// pixel to force us to pixel centers.
bounds.set(SkScalarFloorToScalar(bounds.fLeft),
SkScalarFloorToScalar(bounds.fTop),
SkScalarFloorToScalar(bounds.fRight),
SkScalarFloorToScalar(bounds.fBottom));
bounds.offset(0.5f, 0.5f);
op->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo);
} else {
op->setTransformedBounds(bounds, op->fViewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
}
return std::unique_ptr<GrLegacyMeshDrawOp>(op);
}
示例9: subtractLayers
SkRect LayerAndroid::subtractLayers(const SkRect& visibleRect) const
{
SkRect result;
if (m_recordingPicture) {
SkRect globalRect = bounds();
globalRect.offset(-getPosition()); // localToGlobal adds in position
SkMatrix globalMatrix;
localToGlobal(&globalMatrix);
globalMatrix.mapRect(&globalRect);
SkIRect roundedGlobal;
globalRect.round(&roundedGlobal);
SkIRect iVisibleRect;
visibleRect.round(&iVisibleRect);
SkRegion visRegion(iVisibleRect);
visRegion.op(roundedGlobal, SkRegion::kDifference_Op);
result.set(visRegion.getBounds());
#if DEBUG_NAV_UI
SkDebugf("%s visibleRect=(%g,%g,r=%g,b=%g) globalRect=(%g,%g,r=%g,b=%g)"
"result=(%g,%g,r=%g,b=%g)", __FUNCTION__,
visibleRect.fLeft, visibleRect.fTop,
visibleRect.fRight, visibleRect.fBottom,
globalRect.fLeft, globalRect.fTop,
globalRect.fRight, globalRect.fBottom,
result.fLeft, result.fTop, result.fRight, result.fBottom);
#endif
} else
result = visibleRect;
for (int i = 0; i < countChildren(); i++)
result = getChild(i)->subtractLayers(result);
return result;
}
示例10: onOnceBeforeDraw
void onOnceBeforeDraw() override {
SkRandom rand;
int steps = 20;
SkScalar dist = SkIntToScalar(400);
SkScalar x = SkIntToScalar(20);
SkScalar y = SkIntToScalar(50);
fPath.moveTo(x, y);
for (int i = 0; i < steps; i++) {
x += dist/steps;
SkScalar tmpY = y + SkIntToScalar(rand.nextS() % 25);
if (i == steps/2) {
fPath.moveTo(x, tmpY);
} else {
fPath.lineTo(x, tmpY);
}
}
{
SkRect oval;
oval.set(SkIntToScalar(20), SkIntToScalar(30),
SkIntToScalar(100), SkIntToScalar(60));
oval.offset(x, 0);
fPath.addRoundRect(oval, SkIntToScalar(8), SkIntToScalar(8));
}
fClickPt.set(SkIntToScalar(200), SkIntToScalar(200));
this->setBGColor(0xFFDDDDDD);
}
示例11: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
this->setupPaint(&paint);
paint.setAntiAlias(true);
SkRandom rand;
for (int i = 0; i < loops; i++) {
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
rand.nextUScalar1() * 400);
r.offset(fRadius, fRadius);
if (fRadius > 0) {
sk_sp<SkImageFilter> mf;
switch (fStyle) {
case kDilate_MT:
mf = SkDilateImageFilter::Make(SkScalarFloorToInt(fRadius),
SkScalarFloorToInt(fRadius),
nullptr);
break;
case kErode_MT:
mf = SkErodeImageFilter::Make(SkScalarFloorToInt(fRadius),
SkScalarFloorToInt(fRadius),
nullptr);
break;
}
paint.setImageFilter(std::move(mf));
}
canvas->drawOval(r, paint);
}
}
示例12: onSizeChange
void SampleWindow::onSizeChange() {
this->INHERITED::onSizeChange();
SkView::F2BIter iter(this);
SkView* view = iter.next();
view->setSize(this->width(), this->height());
// rebuild our clippath
{
const SkScalar W = this->width();
const SkScalar H = this->height();
fClipPath.reset();
#if 0
for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) {
SkRect r;
r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30));
for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0))
fClipPath.addRect(r);
}
#else
SkRect r;
r.set(0, 0, W, H);
fClipPath.addRect(r, SkPath::kCCW_Direction);
r.set(W/4, H/4, W*3/4, H*3/4);
fClipPath.addRect(r, SkPath::kCW_Direction);
#endif
}
this->updateTitle(); // to refresh our config
}
示例13: onPerCanvasPreDraw
void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) {
if (!fUseMultiPictureDraw) {
return;
}
SkIRect bounds;
SkAssertResult(canvas->getClipDeviceBounds(&bounds));
int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(FLAGS_benchTile));
int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(FLAGS_benchTile));
fSurfaces.setReserve(xTiles * yTiles);
fTileRects.setReserve(xTiles * yTiles);
SkImageInfo ii = canvas->imageInfo().makeWH(FLAGS_benchTile, FLAGS_benchTile);
for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile) {
for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTile) {
const SkIRect tileRect = SkIRect::MakeXYWH(x, y, FLAGS_benchTile, FLAGS_benchTile);
*fTileRects.append() = tileRect;
*fSurfaces.push() = canvas->newSurface(ii);
// Never want the contents of a tile to include stuff the parent
// canvas clips out
SkRect clip = SkRect::Make(bounds);
clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.fTop));
fSurfaces.top()->getCanvas()->clipRect(clip);
fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix());
fSurfaces.top()->getCanvas()->scale(fScale, fScale);
}
}
}
示例14: drawMask
void drawMask(SkCanvas* canvas, const SkRect& r) {
SkPaint paint;
paint.setAntiAlias(true);
if (true) {
SkBitmap mask;
int w = SkScalarRoundToInt(r.width());
int h = SkScalarRoundToInt(r.height());
mask.allocN32Pixels(w, h);
mask.eraseColor(SK_ColorTRANSPARENT);
SkCanvas c(mask);
SkRect bounds = r;
bounds.offset(-bounds.fLeft, -bounds.fTop);
c.drawOval(bounds, paint);
paint.setBlendMode(SkBlendMode::kDstIn);
canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint);
} else {
SkPath p;
p.addOval(r);
p.setFillType(SkPath::kInverseWinding_FillType);
paint.setBlendMode(SkBlendMode::kDstOut);
canvas->drawPath(p, paint);
}
}
示例15: add_rect_to_clip
static void add_rect_to_clip(const GrClip& clip, const SkRect& devRect, GrClip* out) {
switch (clip.clipType()) {
case GrClip::kClipStack_ClipType: {
SkClipStack* stack = new SkClipStack;
*stack = *clip.clipStack();
// The stack is actually in clip space not device space.
SkRect clipRect = devRect;
SkPoint origin = { SkIntToScalar(clip.origin().fX), SkIntToScalar(clip.origin().fY) };
clipRect.offset(origin);
SkIRect iclipRect;
clipRect.roundOut(&iclipRect);
clipRect = SkRect::Make(iclipRect);
stack->clipDevRect(clipRect, SkRegion::kIntersect_Op, false);
out->setClipStack(stack, &clip.origin());
break;
}
case GrClip::kWideOpen_ClipType:
*out = GrClip(devRect);
break;
case GrClip::kIRect_ClipType: {
SkIRect intersect;
devRect.roundOut(&intersect);
if (intersect.intersect(clip.irect())) {
*out = GrClip(intersect);
} else {
*out = clip;
}
break;
}
}
}