2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
14 // Test out various combinations of nested rects, ovals and rrects.
15 class NestedGM : public GM {
17 NestedGM(bool doAA) : fDoAA(doAA) {
18 this->setBGColor(0xFFDDDDDD);
23 SkString onShortName() SK_OVERRIDE {
24 SkString name("nested");
33 SkISize onISize() SK_OVERRIDE {
34 return SkISize::Make(kImageWidth, kImageHeight);
44 static void AddShape(SkPath* path, const SkRect& rect, Shapes shape, SkPath::Direction dir) {
47 path->addRect(rect, dir);
51 rr.setRectXY(rect, 5, 5);
52 path->addRRect(rr, dir);
56 path->addOval(rect, dir);
63 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
66 shapePaint.setColor(SK_ColorBLACK);
67 shapePaint.setAntiAlias(fDoAA);
69 SkRect outerRect = SkRect::MakeWH(40, 40);
71 SkRect innerRects[] = {
72 { 10, 10, 30, 30 }, // small
73 { .5f, 18, 4.5f, 22 } // smaller and offset to left
76 // draw a background pattern to make transparency errors more apparent
79 for (int y = 0; y < kImageHeight; y += 10) {
80 for (int x = 0; x < kImageWidth; x += 10) {
81 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x),
85 p.setColor(rand.nextU() | 0xFF000000);
86 canvas->drawRect(r, p);
90 canvas->translate(2, 2);
91 for (int outerShape = 0; outerShape < kShapeCount; ++outerShape) {
93 for (int innerShape = 0; innerShape < kShapeCount; ++innerShape) {
94 for (size_t innerRect = 0; innerRect < SK_ARRAY_COUNT(innerRects); ++innerRect) {
97 AddShape(&path, outerRect, (Shapes) outerShape, SkPath::kCW_Direction);
98 AddShape(&path, innerRects[innerRect], (Shapes) innerShape,
99 SkPath::kCCW_Direction);
101 canvas->drawPath(path, shapePaint);
102 canvas->translate(45, 0);
106 canvas->translate(0, 45);
112 static const int kImageWidth = 269;
113 static const int kImageHeight = 134;
117 typedef GM INHERITED;
120 ///////////////////////////////////////////////////////////////////////////////
122 DEF_GM( return new NestedGM(true); )
123 DEF_GM( return new NestedGM(false); )