本文整理汇总了C++中SkRect::setXYWH方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::setXYWH方法的具体用法?C++ SkRect::setXYWH怎么用?C++ SkRect::setXYWH使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::setXYWH方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: surface
static sk_sp<SkImage> make_image(SkCanvas* root, SkIRect* center) {
const int kFixed = 28;
const int kStretchy = 8;
const int kSize = 2*kFixed + kStretchy;
SkAutoTUnref<SkSurface> surface(make_surface(root, kSize));
SkCanvas* canvas = surface->getCanvas();
SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize));
const SkScalar strokeWidth = SkIntToScalar(6);
const SkScalar radius = SkIntToScalar(kFixed) - strokeWidth/2;
center->setXYWH(kFixed, kFixed, kStretchy, kStretchy);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(0xFFFF0000);
canvas->drawRoundRect(r, radius, radius, paint);
r.setXYWH(SkIntToScalar(kFixed), 0, SkIntToScalar(kStretchy), SkIntToScalar(kSize));
paint.setColor(0x8800FF00);
canvas->drawRect(r, paint);
r.setXYWH(0, SkIntToScalar(kFixed), SkIntToScalar(kSize), SkIntToScalar(kStretchy));
paint.setColor(0x880000FF);
canvas->drawRect(r, paint);
return surface->makeImageSnapshot();
}
示例2: make_bitmap
static void make_bitmap(SkBitmap* bitmap, SkIRect* center) {
const int kFixed = 28;
const int kStretchy = 8;
const int kSize = 2*kFixed + kStretchy;
bitmap->allocN32Pixels(kSize, kSize);
SkCanvas canvas(*bitmap);
canvas.clear(SK_ColorTRANSPARENT);
SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize));
const SkScalar strokeWidth = SkIntToScalar(6);
const SkScalar radius = SkIntToScalar(kFixed) - strokeWidth/2;
center->setXYWH(kFixed, kFixed, kStretchy, kStretchy);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(0xFFFF0000);
canvas.drawRoundRect(r, radius, radius, paint);
r.setXYWH(SkIntToScalar(kFixed), 0, SkIntToScalar(kStretchy), SkIntToScalar(kSize));
paint.setColor(0x8800FF00);
canvas.drawRect(r, paint);
r.setXYWH(0, SkIntToScalar(kFixed), SkIntToScalar(kSize), SkIntToScalar(kStretchy));
paint.setColor(0x880000FF);
canvas.drawRect(r, paint);
}
示例3: show_stroke
static void show_stroke(SkCanvas* canvas, bool doAA, SkScalar strokeWidth, int n) {
SkRandom rand;
SkPaint paint;
paint.setAntiAlias(doAA);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(strokeWidth);
for (int i = 0; i < n; ++i) {
SkRect r;
SkPath p;
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
paint.setColor(rand.nextU());
canvas->drawRect(r, paint);
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
paint.setColor(rand.nextU());
p.addOval(r);
canvas->drawPath(p, paint);
const SkScalar minx = -SkIntToScalar(W)/4;
const SkScalar maxx = 5*SkIntToScalar(W)/4;
const SkScalar miny = -SkIntToScalar(H)/4;
const SkScalar maxy = 5*SkIntToScalar(H)/4;
paint.setColor(rand.nextU());
canvas->drawLine(randRange(rand, minx, maxx), randRange(rand, miny, maxy),
randRange(rand, minx, maxx), randRange(rand, miny, maxy),
paint);
}
}
示例4: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
SkIRect srcRect;
SkRect dstRect;
SkPaint paint;
paint.setFilterBitmap(true);
// Test that bitmap draws from malloc-backed bitmaps respect
// the constrained texture domain.
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(5.0f, 5.0f, 305.0f, 305.0f);
canvas->drawBitmapRect(fBM, &srcRect, dstRect, &paint);
// Test that bitmap draws across separate devices also respect
// the constrainted texture domain.
// Note: GPU-backed bitmaps follow a different rendering path
// when copying from one GPU device to another.
SkAutoTUnref<SkDevice> secondDevice(canvas->createCompatibleDevice(
SkBitmap::kARGB_8888_Config, 5, 5, true));
SkCanvas secondCanvas(secondDevice.get());
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(1.0f, 1.0f, 3.0f, 3.0f);
secondCanvas.drawBitmapRect(fBM, &srcRect, dstRect, &paint);
SkBitmap deviceBitmap = secondDevice->accessBitmap(false);
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(405.0f, 5.0f, 305.0f, 305.0f);
canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
// Test that bitmap blurring using a subrect
// renders correctly
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(5.0f, 405.0f, 305.0f, 305.0f);
SkMaskFilter* mf = SkBlurMaskFilter::Create(
5,
SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMaskFilter::kHighQuality_BlurFlag |
SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
paint.setMaskFilter(mf)->unref();
canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
// Blur and a rotation + NULL src rect
// This should not trigger the texture domain code
// but it will test a code path in SkGpuDevice::drawBitmap
// that handles blurs with rects transformed to non-
// orthogonal rects. It also tests the NULL src rect handling
mf = SkBlurMaskFilter::Create(
5,
SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMaskFilter::kHighQuality_BlurFlag);
paint.setMaskFilter(mf)->unref();
dstRect.setXYWH(-150.0f, -150.0f, 300.0f, 300.0f);
canvas->translate(550, 550);
canvas->rotate(45);
canvas->drawBitmapRect(fBM, NULL, dstRect, &paint);
}
示例5: onSizeChange
void onSizeChange() override {
fWeightControl.setXYWH(this->width() - 150, 30, 30, 400);
fErrorControl.setXYWH(this->width() - 100, 30, 30, 400);
fWidthControl.setXYWH(this->width() - 50, 30, 30, 400);
int buttonOffset = 450;
fCubicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
buttonOffset += 50;
fConicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
buttonOffset += 50;
fQuadButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
buttonOffset += 50;
fRRectButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
buttonOffset += 50;
fCircleButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
buttonOffset += 50;
fTextButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
this->INHERITED::onSizeChange();
}
示例6: onDraw
virtual void onDraw(SkCanvas* canvas) {
drawBG(canvas);
SkBitmap sprite;
sprite.setConfig(SkBitmap::kARGB_8888_Config, 4, 4, 4*sizeof(SkColor));
const SkColor spriteData[16] = {
SK_ColorBLACK, SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorRED,
SK_ColorGREEN, SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLUE,
SK_ColorYELLOW, SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorBLACK
};
sprite.allocPixels();
sprite.lockPixels();
SkPMColor* addr = sprite.getAddr32(0, 0);
for (size_t i = 0; i < SK_ARRAY_COUNT(spriteData); ++i) {
addr[i] = SkPreMultiplyColor(spriteData[i]);
}
sprite.unlockPixels();
// We draw a magnified subrect of the sprite
// sample interpolation may cause color bleeding around edges
// the subrect is a pure white area
SkIRect srcRect;
SkRect dstRect;
SkPaint paint;
paint.setFilterBitmap(true);
//First row : full texture with and without filtering
srcRect.setXYWH(0, 0, 4, 4);
dstRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0)
, SkIntToScalar(100), SkIntToScalar(100));
canvas->drawBitmapRect(sprite, &srcRect, dstRect, &paint);
dstRect.setXYWH(SkIntToScalar(100), SkIntToScalar(0)
, SkIntToScalar(100), SkIntToScalar(100));
canvas->drawBitmapRect(sprite, &srcRect, dstRect);
//Second row : sub rect of texture with and without filtering
srcRect.setXYWH(1, 1, 2, 2);
dstRect.setXYWH(SkIntToScalar(25), SkIntToScalar(125)
, SkIntToScalar(50), SkIntToScalar(50));
canvas->drawBitmapRect(sprite, &srcRect, dstRect, &paint);
dstRect.setXYWH(SkIntToScalar(125), SkIntToScalar(125)
, SkIntToScalar(50), SkIntToScalar(50));
canvas->drawBitmapRect(sprite, &srcRect, dstRect);
}
示例7: make_bitmap
static void make_bitmap(SkBitmap* bitmap, GrContext* ctx, SkIRect* center) {
SkDevice* dev;
SkCanvas canvas;
const int kFixed = 28;
const int kStretchy = 8;
const int kSize = 2*kFixed + kStretchy;
#if SK_SUPPORT_GPU
if (ctx) {
dev = new SkGpuDevice(ctx, SkBitmap::kARGB_8888_Config, kSize, kSize);
*bitmap = dev->accessBitmap(false);
} else
#endif
{
bitmap->setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize);
bitmap->allocPixels();
dev = new SkDevice(*bitmap);
}
canvas.setDevice(dev)->unref();
canvas.clear(0);
SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize));
const SkScalar strokeWidth = SkIntToScalar(6);
const SkScalar radius = SkIntToScalar(kFixed) - strokeWidth/2;
center->setXYWH(kFixed, kFixed, kStretchy, kStretchy);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(0xFFFF0000);
canvas.drawRoundRect(r, radius, radius, paint);
r.setXYWH(SkIntToScalar(kFixed), 0, SkIntToScalar(kStretchy), SkIntToScalar(kSize));
paint.setColor(0x8800FF00);
canvas.drawRect(r, paint);
r.setXYWH(0, SkIntToScalar(kFixed), SkIntToScalar(kSize), SkIntToScalar(kStretchy));
paint.setColor(0x880000FF);
canvas.drawRect(r, paint);
}
示例8: show_fill
static void show_fill(SkCanvas* canvas, bool doAA) {
SkRandom rand;
SkPaint paint;
paint.setAntiAlias(doAA);
for (int i = 0; i < 50; ++i) {
SkRect r;
SkPath p;
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
paint.setColor(rand.nextU());
canvas->drawRect(r, paint);
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
paint.setColor(rand.nextU());
p.addOval(r);
canvas->drawPath(p, paint);
}
}
示例9: TestDeferredCanvasFreshFrame
static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) {
SkBitmap store;
SkRect fullRect;
fullRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth),
SkIntToScalar(gHeight));
SkRect partialRect;
partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0),
SkIntToScalar(1), SkIntToScalar(1));
create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
SkDevice device(store);
SkDeferredCanvas canvas(&device);
// verify that frame is intially fresh
REPORTER_ASSERT(reporter, canvas.getDeferredDevice()->isFreshFrame());
// no clearing op since last call to isFreshFrame -> not fresh
REPORTER_ASSERT(reporter, !canvas.getDeferredDevice()->isFreshFrame());
// Verify that clear triggers a fresh frame
canvas.clear(0x00000000);
REPORTER_ASSERT(reporter, canvas.getDeferredDevice()->isFreshFrame());
// Verify that clear with saved state triggers a fresh frame
canvas.save(SkCanvas::kMatrixClip_SaveFlag);
canvas.clear(0x00000000);
canvas.restore();
REPORTER_ASSERT(reporter, canvas.getDeferredDevice()->isFreshFrame());
// Verify that clear within a layer does NOT trigger a fresh frame
canvas.saveLayer(NULL, NULL, SkCanvas::kARGB_ClipLayer_SaveFlag);
canvas.clear(0x00000000);
canvas.restore();
REPORTER_ASSERT(reporter, !canvas.getDeferredDevice()->isFreshFrame());
// Verify that a clear with clipping triggers a fresh frame
// (clear is not affected by clipping)
canvas.save(SkCanvas::kMatrixClip_SaveFlag);
canvas.clipRect(partialRect, SkRegion::kIntersect_Op, false);
canvas.clear(0x00000000);
canvas.restore();
REPORTER_ASSERT(reporter, canvas.getDeferredDevice()->isFreshFrame());
// Verify that full frame rects with different forms of opaque paint
// trigger frames to be marked as fresh
{
SkPaint paint;
paint.setStyle( SkPaint::kFill_Style );
paint.setAlpha( 255 );
canvas.drawRect(fullRect, paint);
REPORTER_ASSERT(reporter, canvas.getDeferredDevice()->isFreshFrame());
}
{
SkPaint paint;
paint.setStyle( SkPaint::kFill_Style );
SkBitmap bmp;
create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
bmp.setIsOpaque(true);
SkShader* shader = SkShader::CreateBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
paint.setShader(shader)->unref();
canvas.drawRect(fullRect, paint);
REPORTER_ASSERT(reporter, canvas.getDeferredDevice()->isFreshFrame());
}
// Verify that full frame rects with different forms of non-opaque paint
// do not trigger frames to be marked as fresh
{
SkPaint paint;
paint.setStyle( SkPaint::kFill_Style );
paint.setAlpha( 254 );
canvas.drawRect(fullRect, paint);
REPORTER_ASSERT(reporter, !canvas.getDeferredDevice()->isFreshFrame());
}
{
SkPaint paint;
paint.setStyle( SkPaint::kFill_Style );
SkBitmap bmp;
create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
bmp.setIsOpaque(false);
SkShader* shader = SkShader::CreateBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
paint.setShader(shader)->unref();
canvas.drawRect(fullRect, paint);
REPORTER_ASSERT(reporter, !canvas.getDeferredDevice()->isFreshFrame());
}
// Verify that incomplete coverage does not trigger a fresh frame
{
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setAlpha(255);
canvas.drawRect(partialRect, paint);
REPORTER_ASSERT(reporter, !canvas.getDeferredDevice()->isFreshFrame());
}
// Verify that incomplete coverage due to clipping does not trigger a fresh
// frame
{
canvas.save(SkCanvas::kMatrixClip_SaveFlag);
canvas.clipRect(partialRect, SkRegion::kIntersect_Op, false);
SkPaint paint;
//.........这里部分代码省略.........
示例10: drawInBitmap
static void drawInBitmap(SkBitmap &bitmap)
{
SkCanvas canvas(bitmap);
canvas.clear(SK_ColorWHITE);
SkPaint myPaint;
myPaint.setAntiAlias(true);
myPaint.setColor(SK_ColorBLACK);
myPaint.setStrokeWidth(SkIntToScalar(1));
canvas.translate(SkIntToScalar(36), SkIntToScalar(36));
canvas.scale(SkIntToScalar(1), SkIntToScalar(-1));
canvas.scale(SkDoubleToScalar(0.17), SkDoubleToScalar(0.17));
{
SkPoint linearPoints[] = {
{SkIntToScalar(-58), SkIntToScalar(13)},
{SkIntToScalar(-58+(116/2)), SkIntToScalar(13)}
};
SkColor linearColors[] = {SK_ColorBLACK, SK_ColorLTGRAY};
SkShader* shader = SkGradientShader::CreateLinear(
linearPoints, linearColors, NULL, 2,
SkShader::kMirror_TileMode);
SkAutoUnref shader_deleter(shader);
myPaint.setShader(shader);
myPaint.setFlags(SkPaint::kAntiAlias_Flag);
SkRect rect0;
rect0.setXYWH(SkIntToScalar(-58), SkIntToScalar(13), SkIntToScalar(116), SkIntToScalar(76));
canvas.drawRect(rect0,myPaint);
// Detach shader
myPaint.setShader(NULL);
}
myPaint.setColor(SK_ColorBLACK);
myPaint.setStyle(SkPaint::kStrokeAndFill_Style);
SkRect rect;
rect.setXYWH(SkIntToScalar(-60), SkIntToScalar(75), SkIntToScalar(120), SkIntToScalar(6));
canvas.drawRect(rect, myPaint);
SkRect rect1;
rect1.setXYWH(SkIntToScalar(-60), SkIntToScalar(61), SkIntToScalar(120), SkIntToScalar(6));
canvas.drawRect(rect1, myPaint);
SkRect rect2;
rect2.setXYWH(SkIntToScalar(-60), SkIntToScalar(49), SkIntToScalar(120), SkIntToScalar(6));
canvas.drawRect(rect2, myPaint);
SkPoint pts0[] = {
{-60,11},
{-42,23},
{38,23},
{56,11},
{-60,11}
};
myPaint.setColor(SK_ColorBLUE);
myPaint.setStyle(SkPaint::kStroke_Style);
SkPath path0;
path0.addPoly(pts0, 5, true);
canvas.drawPath(path0, myPaint);
path0.addPoly(pts0, 5, true);
myPaint.setColor(SK_ColorWHITE);
myPaint.setStyle(SkPaint::kFill_Style);
canvas.drawPath(path0, myPaint);
myPaint.setColor(SK_ColorBLACK);
myPaint.setStyle(SkPaint::kStroke_Style);
canvas.drawLine(SkIntToScalar(-100), SkIntToScalar(-90), SkIntToScalar(100), SkIntToScalar(-91), myPaint);
canvas.drawLine(SkIntToScalar(0), SkIntToScalar(-90), SkIntToScalar(26), SkIntToScalar(-58), myPaint);
canvas.drawLine(SkIntToScalar(26), SkIntToScalar(-58), SkIntToScalar(-2), SkIntToScalar(37), myPaint);
myPaint.setStyle(SkPaint::kStrokeAndFill_Style);
canvas.drawCircle(SkIntToScalar(0), SkIntToScalar(33), SkIntToScalar(4), myPaint);
myPaint.setStyle(SkPaint::kStroke_Style);
canvas.drawCircle(SkDoubleToScalar(0), SkDoubleToScalar(-(129+49)/2), SkIntToScalar(40), myPaint);
myPaint.setColor(SK_ColorLTGRAY);
myPaint.setStyle(SkPaint::kStrokeAndFill_Style);
SkPoint pts[9];
pts[0].set(-60, -50);
pts[1].set(-60, 100);
pts[2].set( 60, 100);
pts[3].set(60, -52);
pts[4].set(100, -52);
//.........这里部分代码省略.........