本文整理汇总了C++中SkRect::left方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::left方法的具体用法?C++ SkRect::left怎么用?C++ SkRect::left使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::left方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convolve_gaussian
static void convolve_gaussian(GrContext* context,
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_pass(context, 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_pass(context, srcRect, dstRect, texture,
direction, radius, sigma, true, bounds);
} else {
// Draw upper and lower margins with bounds; middle without.
convolve_gaussian_pass(context, lowerSrcRect, lowerDstRect, texture,
direction, radius, sigma, true, bounds);
convolve_gaussian_pass(context, upperSrcRect, upperDstRect, texture,
direction, radius, sigma, true, bounds);
convolve_gaussian_pass(context, middleSrcRect, middleDstRect, texture,
direction, radius, sigma, false, bounds);
}
}
示例2: onDraw
void onDraw(SkCanvas* canvas) override {
SkPaint blurPaint;
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(5.0f, 5.0f));
blurPaint.setImageFilter(blur);
const SkScalar tile_size = SkIntToScalar(128);
SkRect bounds;
if (!canvas->getClipBounds(&bounds)) {
bounds.setEmpty();
}
int ts = SkScalarCeilToInt(tile_size);
SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
SkAutoTUnref<SkSurface> tileSurface(canvas->newSurface(info));
if (!tileSurface.get()) {
tileSurface.reset(SkSurface::NewRaster(info));
}
SkCanvas* tileCanvas = tileSurface->getCanvas();
for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) {
for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size) {
tileCanvas->save();
tileCanvas->clear(0);
tileCanvas->translate(-x, -y);
SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT);
tileCanvas->saveLayer(&rect, &blurPaint);
SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25);
tileCanvas->clipRRect(rrect, SkRegion::kDifference_Op, true);
SkPaint paint;
tileCanvas->drawRect(rect, paint);
tileCanvas->restore();
tileCanvas->restore();
canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
}
}
}
示例3: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkPaint paint;
paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref();
const SkScalar tile_size = SkIntToScalar(128);
SkRect bounds;
if (!canvas->getClipBounds(&bounds)) {
bounds.setEmpty();
}
for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) {
for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size));
canvas->saveLayer(NULL, &paint);
const char* str[] = {
"The quick",
"brown fox",
"jumped over",
"the lazy dog.",
};
SkPaint textPaint;
textPaint.setAntiAlias(true);
textPaint.setTextSize(SkIntToScalar(100));
int posY = 0;
for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
posY += 100;
canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0),
SkIntToScalar(posY), textPaint);
}
canvas->restore();
canvas->restore();
}
}
}
示例4: onDraw
void onDraw(const int loops, SkCanvas* canvas) override {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2);
if (fRound) {
paint.setStrokeJoin(SkPaint::kRound_Join);
}
this->setupPaint(&paint);
const SkRect r = fPath.getBounds();
switch (fAlign) {
case kLeft_Align:
canvas->translate(-r.left(), 0);
break;
case kMiddle_Align:
break;
case kRight_Align:
canvas->translate(640 - r.right(), 0);
break;
}
for (int i = 0; i < loops; i++) {
canvas->drawPath(fPath, paint);
}
}
示例5: test_big_aa_rect
// test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint)
static void test_big_aa_rect(skiatest::Reporter* reporter) {
SkBitmap output;
SkPMColor pixel[1];
output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4);
auto surf = SkSurface::MakeRasterN32Premul(300, 33300);
SkCanvas* canvas = surf->getCanvas();
SkRect r = { 0, 33000, 300, 33300 };
int x = SkScalarRoundToInt(r.left());
int y = SkScalarRoundToInt(r.top());
// check that the pixel in question starts as transparent (by the surface)
if (surf->readPixels(output, x, y)) {
REPORTER_ASSERT(reporter, 0 == pixel[0]);
} else {
REPORTER_ASSERT(reporter, false, "readPixels failed");
}
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorWHITE);
canvas->drawRect(r, paint);
// Now check that it is BLACK
if (surf->readPixels(output, x, y)) {
// don't know what swizzling PMColor did, but white should always
// appear the same.
REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
} else {
REPORTER_ASSERT(reporter, false, "readPixels failed");
}
}
示例6: draw_gradients
static void draw_gradients(SkCanvas* canvas,
sk_sp<SkShader> (*makeShader)(const SkPoint[2], const SkMatrix&),
const SkPoint ptsArray[][2], int numImages) {
// Use some nice prime numbers for the rectangle and matrix with
// different scaling along the x and y axes (which is the bug this
// test addresses, where incorrect order of operations mixed up the axes)
SkRect rectGrad = {
SkIntToScalar(43), SkIntToScalar(61),
SkIntToScalar(181), SkIntToScalar(167) };
SkMatrix shaderMat;
shaderMat.setScale(rectGrad.width(), rectGrad.height());
shaderMat.postTranslate(rectGrad.left(), rectGrad.top());
canvas->save();
for (int i = 0; i < numImages; i++) {
// Advance line downwards if necessary.
if (i % IMAGES_X == 0 && i != 0) {
canvas->restore();
canvas->translate(0, TESTGRID_Y);
canvas->save();
}
SkPaint paint;
paint.setShader(makeShader(*ptsArray, shaderMat));
canvas->drawRect(rectGrad, paint);
// Advance to next position.
canvas->translate(TESTGRID_X, 0);
ptsArray++;
}
canvas->restore();
}
示例7: draw_bbox
static void draw_bbox(SkCanvas* canvas, const SkRect& r) {
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(0xFFFF7088);
canvas->drawRect(r, paint);
canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint);
canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint);
}
示例8: makeRect
Json::Value SkJSONCanvas::makeRect(const SkRect& rect) {
Json::Value result(Json::arrayValue);
result.append(Json::Value(rect.left()));
result.append(Json::Value(rect.top()));
result.append(Json::Value(rect.right()));
result.append(Json::Value(rect.bottom()));
return result;
}
示例9:
PassRefPtr<JSONObject> LoggingCanvas::objectForSkRect(const SkRect& rect)
{
RefPtr<JSONObject> rectItem = JSONObject::create();
rectItem->setNumber("left", rect.left());
rectItem->setNumber("top", rect.top());
rectItem->setNumber("right", rect.right());
rectItem->setNumber("bottom", rect.bottom());
return rectItem.release();
}
示例10: onDraw
virtual void onDraw(SkCanvas* canvas) {
canvas->drawColor(SK_ColorGRAY);
SkPaint paint;
paint.setTypeface(fTypeface);
const char* text = "hamburgerfons";
// draw text at different point sizes
const int textSize[] = { 10, 30, 50 };
const int textYOffset[] = { 10, 40, 100};
SkASSERT(sizeof(textSize) == sizeof(textYOffset));
for (size_t y = 0; y < sizeof(textSize) / sizeof(int); ++y) {
paint.setTextSize(SkIntToScalar(textSize[y]));
canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y]), paint);
}
// setup work needed to draw text with different clips
canvas->translate(10, 160);
paint.setTextSize(40);
// compute the bounds of the text
SkRect bounds;
paint.measureText(text, strlen(text), &bounds);
const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf;
SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
boundsHalfWidth, boundsHalfHeight);
SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.centerY(),
boundsHalfWidth, boundsHalfHeight);
SkRect interiorClip = bounds;
interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip };
SkPaint clipHairline;
clipHairline.setColor(SK_ColorWHITE);
clipHairline.setStyle(SkPaint::kStroke_Style);
for (size_t x = 0; x < sizeof(clipRects) / sizeof(SkRect); ++x) {
canvas->save();
canvas->drawRect(clipRects[x], clipHairline);
paint.setAlpha(0x20);
canvas->drawText(text, strlen(text), 0, 0, paint);
canvas->clipRect(clipRects[x]);
paint.setAlpha(0xFF);
canvas->drawText(text, strlen(text), 0, 0, paint);
canvas->restore();
canvas->translate(0, bounds.height() + SkIntToScalar(25));
}
}
示例11: draw_box_frame
static void draw_box_frame(SkCanvas* canvas, int width, int height) {
SkPaint p;
p.setStyle(SkPaint::kStroke_Style);
p.setColor(SK_ColorRED);
SkRect r = SkRect::MakeIWH(width, height);
r.inset(0.5f, 0.5f);
canvas->drawRect(r, p);
canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), p);
canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), p);
}
示例12: drawBorders
void drawBorders(SkCanvas* canvas) {
SkPaint p;
p.setStyle(SkPaint::kStroke_Style);
p.setColor(SK_ColorBLUE);
SkRect r = SkRect::MakeWH(fCell.width() * 2, fCell.height() * 2);
r.inset(SK_ScalarHalf, SK_ScalarHalf);
canvas->drawRect(r, p);
canvas->drawLine(r.left(), r.centerY(), r.right(), r.centerY(), p);
canvas->drawLine(r.centerX(), r.top(), r.centerX(), r.bottom(), p);
}
示例13: MakeLinear
static sk_sp<SkShader> make_shader(const SkRect& bounds) {
const SkPoint pts[] = {
{ bounds.left(), bounds.top() },
{ bounds.right(), bounds.bottom() },
};
const SkColor colors[] = {
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK,
SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
};
return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
SkShader::kClamp_TileMode);
}
示例14: writePathVertices
void writePathVertices(GrDrawBatch::Target* target,
GrBatchAtlas* atlas,
intptr_t offset,
GrColor color,
size_t vertexStride,
const SkMatrix& viewMatrix,
const ShapeData* shapeData) const {
GrTexture* texture = atlas->getTexture();
SkScalar dx = shapeData->fBounds.fLeft;
SkScalar dy = shapeData->fBounds.fTop;
SkScalar width = shapeData->fBounds.width();
SkScalar height = shapeData->fBounds.height();
SkScalar invScale = 1.0f / shapeData->fScale;
dx *= invScale;
dy *= invScale;
width *= invScale;
height *= invScale;
SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
// vertex positions
// TODO make the vertex attributes a struct
SkRect r = SkRect::MakeXYWH(dx, dy, width, height);
positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertexStride);
// colors
for (int i = 0; i < kVerticesPerQuad; i++) {
GrColor* colorPtr = (GrColor*)(offset + sizeof(SkPoint) + i * vertexStride);
*colorPtr = color;
}
const SkScalar tx = SkIntToScalar(shapeData->fAtlasLocation.fX);
const SkScalar ty = SkIntToScalar(shapeData->fAtlasLocation.fY);
// vertex texture coords
SkPoint* textureCoords = (SkPoint*)(offset + sizeof(SkPoint) + sizeof(GrColor));
textureCoords->setRectFan(tx / texture->width(),
ty / texture->height(),
(tx + shapeData->fBounds.width()) / texture->width(),
(ty + shapeData->fBounds.height()) / texture->height(),
vertexStride);
}
示例15: draw_rect
static void draw_rect(SkCanvas* canvas, const SkRect& r, SkColor c, SkColorProfileType profile,
const SkAlpha aa[]) {
const SkIRect ir = r.round();
SkBitmap bm;
bm.allocN32Pixels(ir.width(), ir.height());
bm.eraseColor(0xFFFFFFFF);
SkPixmap pm;
bm.peekPixels(&pm);
uint32_t flags = 0;
if (SkColorGetA(c) == 0xFF) {
flags |= SkXfermode::kSrcIsOpaque_PM4fFlag;
}
if (kSRGB_SkColorProfileType == profile) {
flags |= SkXfermode::kDstIsSRGB_PM4fFlag;
}
const SkXfermode::PM4fState state { nullptr, flags };
const SkPM4f src = SkColor4f::FromColor(c).premul();
auto proc1 = SkXfermode::GetPM4fProc1(SkXfermode::kSrcOver_Mode, flags);
for (int y = 0; y < ir.height()/2; ++y) {
proc1(state, pm.writable_addr32(0, y), src, ir.width(), aa);
}
SkPM4f srcRow[1000];
for (int i = 0; i < ir.width(); ++i) {
srcRow[i] = src;
}
auto procN = SkXfermode::GetPM4fProcN(SkXfermode::kSrcOver_Mode, flags);
// +1 to skip a row, so we can see the boundary between proc1 and procN
for (int y = ir.height()/2 + 1; y < ir.height(); ++y) {
procN(state, pm.writable_addr32(0, y), srcRow, ir.width(), aa);
}
canvas->drawBitmap(bm, r.left(), r.top(), nullptr);
}