Example #1
0
static void draw_rect(SkCanvas* canvas, bool showGL, int flags) {
    SkPaint paint;
    paint.setAntiAlias(true);

    SkRect r = SkRect::MakeLTRB(50, 70, 250, 370);

    setFade(&paint, showGL);
    canvas->drawRect(r, paint);
    if (showGL) {
        show_mesh(canvas, r);
    }

    canvas->translate(320, 0);

    paint.setStyle(SkPaint::kStroke_Style);
    paint.setStrokeWidth(25);
    canvas->drawRect(r, paint);
    if (showGL) {
        SkScalar rad = paint.getStrokeWidth() / 2;
        SkPoint pts[8];
        r.outset(rad, rad);
        r.toQuad(&pts[0]);
        r.inset(rad*2, rad*2);
        r.toQuad(&pts[4]);

        const uint16_t indices[] = {
            0, 4, 1, 5, 2, 6, 3, 7, 0, 4
        };
        show_mesh(canvas, pts, indices, SK_ARRAY_COUNT(indices));
    }
}
Example #2
0
 virtual void onDrawSelection(SkCanvas* canvas) {
     SkRect r;
     this->getBounds(&r);
     SkPaint paint;
     SkPoint pts[4];
     r.toQuad(pts);
     paint.setStrokeWidth(SkIntToScalar(10));
     paint.setColor(0x80FF8844);
     paint.setStrokeCap(SkPaint::kRound_Cap);
     canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, pts, paint);
 }
Example #3
0
 void drawShape(SkCanvas* canvas,
                SkPaint* paint,
                ShapeType type) {
     static const SkRect kRect = SkRect::MakeXYWH(SkIntToScalar(-50), SkIntToScalar(-50),
                                                  SkIntToScalar(75), SkIntToScalar(105));
     switch (type) {
         case kCircle_ShapeType:
             canvas->drawCircle(0, 0, 50, *paint);
             break;
         case kRoundRect_ShapeType:
             canvas->drawRoundRect(kRect, SkIntToScalar(10), SkIntToScalar(20), *paint);
             break;
         case kRect_ShapeType:
             canvas->drawRect(kRect, *paint);
             break;
         case kConvexPath_ShapeType:
             if (fConvexPath.isEmpty()) {
                 SkPoint points[4];
                 kRect.toQuad(points);
                 fConvexPath.moveTo(points[0]);
                 fConvexPath.quadTo(points[1], points[2]);
                 fConvexPath.quadTo(points[3], points[0]);
                 SkASSERT(fConvexPath.isConvex());
             }
             canvas->drawPath(fConvexPath, *paint);
             break;
         case kConcavePath_ShapeType:
             if (fConcavePath.isEmpty()) {
                 SkPoint points[5] = {{0, SkIntToScalar(-50)} };
                 SkMatrix rot;
                 rot.setRotate(SkIntToScalar(360) / 5);
                 for (int i = 1; i < 5; ++i) {
                     rot.mapPoints(points + i, points + i - 1, 1);
                 }
                 fConcavePath.moveTo(points[0]);
                 for (int i = 0; i < 5; ++i) {
                     fConcavePath.lineTo(points[(2 * i) % 5]);
                 }
                 fConcavePath.setFillType(SkPath::kEvenOdd_FillType);
                 SkASSERT(!fConcavePath.isConvex());
             }
             canvas->drawPath(fConcavePath, *paint);
             break;
         case kText_ShapeType: {
             const char* text = "Hello!";
             paint->setTextSize(30);
             sk_tool_utils::set_portable_typeface(paint);
             canvas->drawText(text, strlen(text), 0, 0, *paint);
         }
         default:
             break;
     }
 }
Example #4
0
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());
}