本文整理汇总了C++中SkRRect::setNinePatch方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRRect::setNinePatch方法的具体用法?C++ SkRRect::setNinePatch怎么用?C++ SkRRect::setNinePatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRRect
的用法示例。
在下文中一共展示了SkRRect::setNinePatch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_empty
// Test that all the SkRRect entry points correctly handle un-sorted and
// zero-sized input rects
static void test_empty(skiatest::Reporter* reporter) {
static const SkRect oooRects[] = { // out of order
{ 100, 0, 0, 100 }, // ooo horizontal
{ 0, 100, 100, 0 }, // ooo vertical
{ 100, 100, 0, 0 }, // ooo both
};
static const SkRect emptyRects[] = {
{ 100, 100, 100, 200 }, // empty horizontal
{ 100, 100, 200, 100 }, // empty vertical
{ 100, 100, 100, 100 }, // empty both
{ 0, 0, 0, 0 } // setEmpty-empty
};
static const SkVector radii[4] = { { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 } };
SkRRect r;
for (size_t i = 0; i < SK_ARRAY_COUNT(oooRects); ++i) {
r.setRect(oooRects[i]);
REPORTER_ASSERT(reporter, !r.isEmpty());
r.setOval(oooRects[i]);
REPORTER_ASSERT(reporter, !r.isEmpty());
r.setRectXY(oooRects[i], 1, 2);
REPORTER_ASSERT(reporter, !r.isEmpty());
r.setNinePatch(oooRects[i], 0, 1, 2, 3);
REPORTER_ASSERT(reporter, !r.isEmpty());
r.setRectRadii(oooRects[i], radii);
REPORTER_ASSERT(reporter, !r.isEmpty());
}
for (size_t i = 0; i < SK_ARRAY_COUNT(emptyRects); ++i) {
r.setRect(emptyRects[i]);
REPORTER_ASSERT(reporter, r.isEmpty());
r.setOval(emptyRects[i]);
REPORTER_ASSERT(reporter, r.isEmpty());
r.setRectXY(emptyRects[i], 1, 2);
REPORTER_ASSERT(reporter, r.isEmpty());
r.setNinePatch(emptyRects[i], 0, 1, 2, 3);
REPORTER_ASSERT(reporter, r.isEmpty());
r.setRectRadii(emptyRects[i], radii);
REPORTER_ASSERT(reporter, r.isEmpty());
}
}
示例2: makeRRect
SkRRect makeRRect() {
SkRRect rrect;
RandomSetRRect rrectType = makeSetRRectType();
if (fPrintName) {
SkDebugf("%.*s%s\n", fPathDepth * 3, fTab, gRandomSetRRectNames[rrectType]);
}
switch (rrectType) {
case kSetEmpty:
rrect.setEmpty();
break;
case kSetRect: {
SkRect rect = makeRect();
rrect.setRect(rect);
}
break;
case kSetOval: {
SkRect oval = makeRect();
rrect.setOval(oval);
}
break;
case kSetRectXY: {
SkRect rect = makeRect();
SkScalar xRad = makeScalar();
SkScalar yRad = makeScalar();
rrect.setRectXY(rect, xRad, yRad);
}
break;
case kSetNinePatch: {
SkRect rect = makeRect();
SkScalar leftRad = makeScalar();
SkScalar topRad = makeScalar();
SkScalar rightRad = makeScalar();
SkScalar bottomRad = makeScalar();
rrect.setNinePatch(rect, leftRad, topRad, rightRad, bottomRad);
SkDebugf(""); // keep locals in scope
}
break;
case kSetRectRadii: {
SkRect rect = makeRect();
SkVector radii[4];
makeVectorArray(SK_ARRAY_COUNT(radii), radii);
rrect.setRectRadii(rect, radii);
}
break;
}
return rrect;
}
示例3:
static void test_9patch_rrect(skiatest::Reporter* reporter,
const SkRect& rect,
SkScalar l, SkScalar t, SkScalar r, SkScalar b,
bool checkRadii) {
SkRRect rr;
rr.setNinePatch(rect, l, t, r, b);
if (checkRadii) {
path_contains_rrect_check(reporter, rr);
} else {
path_contains_rrect_nocheck(reporter, rr);
}
SkRRect rr2; // construct the same RR using the most general set function
SkVector radii[4] = { { l, t }, { r, t }, { r, b }, { l, b } };
rr2.setRectRadii(rect, radii);
if (checkRadii) {
path_contains_rrect_check(reporter, rr);
} else {
path_contains_rrect_nocheck(reporter, rr);
}
}
示例4:
static void test_9patch_rrect(skiatest::Reporter* reporter,
const SkRect& rect,
SkScalar l, SkScalar t, SkScalar r, SkScalar b,
bool checkRadii) {
SkRRect rr;
rr.setNinePatch(rect, l, t, r, b);
REPORTER_ASSERT(reporter, SkRRect::kNinePatch_Type == rr.type());
REPORTER_ASSERT(reporter, rr.rect() == rect);
if (checkRadii) {
// This test doesn't hold if the radii will be rescaled by SkRRect
SkRect ninePatchRadii = { l, t, r, b };
SkPoint rquad[4];
ninePatchRadii.toQuad(rquad);
for (int i = 0; i < 4; ++i) {
REPORTER_ASSERT(reporter, rquad[i] == rr.radii((SkRRect::Corner) i));
}
}
SkRRect rr2; // construct the same RR using the most general set function
SkVector radii[4] = { { l, t }, { r, t }, { r, b }, { l, b } };
rr2.setRectRadii(rect, radii);
REPORTER_ASSERT(reporter, rr2 == rr && rr2.getType() == rr.getType());
}
示例5: draw_paths
void draw_paths(SkCanvas* canvas, ShadowMode mode) {
SkTArray<SkPath> paths;
paths.push_back().addRoundRect(SkRect::MakeWH(50, 50), 10, 10);
SkRRect oddRRect;
oddRRect.setNinePatch(SkRect::MakeWH(50, 50), 9, 13, 6, 16);
paths.push_back().addRRect(oddRRect);
paths.push_back().addRect(SkRect::MakeWH(50, 50));
paths.push_back().addCircle(25, 25, 25);
paths.push_back().cubicTo(100, 50, 20, 100, 0, 0);
paths.push_back().addOval(SkRect::MakeWH(20, 60));
// star
SkTArray<SkPath> concavePaths;
concavePaths.push_back().moveTo(0.0f, -33.3333f);
concavePaths.back().lineTo(9.62f, -16.6667f);
concavePaths.back().lineTo(28.867f, -16.6667f);
concavePaths.back().lineTo(19.24f, 0.0f);
concavePaths.back().lineTo(28.867f, 16.6667f);
concavePaths.back().lineTo(9.62f, 16.6667f);
concavePaths.back().lineTo(0.0f, 33.3333f);
concavePaths.back().lineTo(-9.62f, 16.6667f);
concavePaths.back().lineTo(-28.867f, 16.6667f);
concavePaths.back().lineTo(-19.24f, 0.0f);
concavePaths.back().lineTo(-28.867f, -16.6667f);
concavePaths.back().lineTo(-9.62f, -16.6667f);
concavePaths.back().close();
// dumbbell
concavePaths.push_back().moveTo(50, 0);
concavePaths.back().cubicTo(100, 25, 60, 50, 50, 0);
concavePaths.back().cubicTo(0, -25, 40, -50, 50, 0);
static constexpr SkScalar kPad = 15.f;
static constexpr SkScalar kLightR = 100.f;
static constexpr SkScalar kHeight = 50.f;
// transform light position relative to canvas to handle tiling
SkPoint lightXY = canvas->getTotalMatrix().mapXY(250, 400);
SkPoint3 lightPos = { lightXY.fX, lightXY.fY, 500 };
canvas->translate(3 * kPad, 3 * kPad);
canvas->save();
SkScalar x = 0;
SkScalar dy = 0;
SkTDArray<SkMatrix> matrices;
matrices.push()->reset();
SkMatrix* m = matrices.push();
m->setRotate(33.f, 25.f, 25.f);
m->postScale(1.2f, 0.8f, 25.f, 25.f);
for (auto& m : matrices) {
for (int flags : { kNone_ShadowFlag, kTransparentOccluder_ShadowFlag }) {
for (const auto& path : paths) {
SkRect postMBounds = path.getBounds();
m.mapRect(&postMBounds);
SkScalar w = postMBounds.width() + kHeight;
SkScalar dx = w + kPad;
if (x + dx > kW - 3 * kPad) {
canvas->restore();
canvas->translate(0, dy);
canvas->save();
x = 0;
dy = 0;
}
canvas->save();
canvas->concat(m);
if (kDebugColorNoOccluders == mode || kDebugColorOccluders == mode) {
draw_shadow(canvas, path, kHeight, SK_ColorRED, lightPos, kLightR,
true, flags);
draw_shadow(canvas, path, kHeight, SK_ColorBLUE, lightPos, kLightR,
false, flags);
} else if (kGrayscale == mode) {
SkColor ambientColor = SkColorSetARGB(0.1f * 255, 0, 0, 0);
SkColor spotColor = SkColorSetARGB(0.25f * 255, 0, 0, 0);
SkShadowUtils::DrawShadow(canvas, path, SkPoint3{0, 0, kHeight}, lightPos,
kLightR, ambientColor, spotColor, flags);
}
SkPaint paint;
paint.setAntiAlias(true);
if (kDebugColorNoOccluders == mode) {
// Draw the path outline in green on top of the ambient and spot shadows.
if (SkToBool(flags & kTransparentOccluder_ShadowFlag)) {
paint.setColor(SK_ColorCYAN);
} else {
paint.setColor(SK_ColorGREEN);
}
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(0);
} else {
paint.setColor(kDebugColorOccluders == mode ? SK_ColorLTGRAY : SK_ColorWHITE);
if (SkToBool(flags & kTransparentOccluder_ShadowFlag)) {
paint.setAlpha(128);
}
paint.setStyle(SkPaint::kFill_Style);
}
canvas->drawPath(path, paint);
canvas->restore();
//.........这里部分代码省略.........