本文整理汇总了C++中SkRect::top方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRect::top方法的具体用法?C++ SkRect::top怎么用?C++ SkRect::top使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRect
的用法示例。
在下文中一共展示了SkRect::top方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: draw
void draw(SkCanvas* canvas) {
SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
rect.bottom(), rect.isEmpty() ? "true" : "false");
rect.sort();
SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
rect.bottom(), rect.isEmpty() ? "true" : "false");
}
示例3: 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);
}
}
示例4: has_aligned_samples
static bool has_aligned_samples(const SkRect& srcRect, const SkRect& transformedRect) {
// detect pixel disalignment
if (SkScalarAbs(SkScalarRoundToScalar(transformedRect.left()) - transformedRect.left()) < kColorBleedTolerance &&
SkScalarAbs(SkScalarRoundToScalar(transformedRect.top()) - transformedRect.top()) < kColorBleedTolerance &&
SkScalarAbs(transformedRect.width() - srcRect.width()) < kColorBleedTolerance &&
SkScalarAbs(transformedRect.height() - srcRect.height()) < kColorBleedTolerance) {
return true;
}
return false;
}
示例5: 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);
}
示例6: 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();
}
}
}
示例7: quick_reject_in_y
static bool quick_reject_in_y(const SkPoint pts[4], const SkRect& clip) {
Sk4s ys(pts[0].fY, pts[1].fY, pts[2].fY, pts[3].fY);
Sk4s t(clip.top());
Sk4s b(clip.bottom());
return (ys < t).allTrue() || (ys > b).allTrue();
}
示例8: 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();
}
示例9: 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);
}
}
}
示例10: 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");
}
}
示例11: 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;
}
示例12:
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();
}
示例13: 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));
}
}
示例14: 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);
}
示例15: 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);
}