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 static SkPath generate_square(SkScalar cx, SkScalar cy, SkScalar w) {
15 SkRect rect = SkRect::MakeXYWH(cx - w / 2, cy - w / 2, w, w);
21 static SkPath generate_rect_line(SkScalar cx, SkScalar cy, SkScalar l) {
22 SkRect rect = SkRect::MakeXYWH(cx - l / 2, cy, l, 0);
28 static SkPath generate_circle(SkScalar cx, SkScalar cy, SkScalar d) {
30 path.addCircle(cx, cy, d/2, SkPath::kCW_Direction);
34 static SkPath generate_line(SkScalar cx, SkScalar cy, SkScalar l) {
36 path.moveTo(cx - l / 2, cy);
37 path.lineTo(cx + l / 2, cy);
41 SkPaint::Style styles[] = {
42 SkPaint::kStroke_Style,
43 SkPaint::kStrokeAndFill_Style,
46 SkScalar pathSizes[] = {
51 SkScalar strokeWidths[] = {
55 SkPath ((*paths[])(SkScalar, SkScalar, SkScalar)) = {
62 const SkScalar slideWidth = 90, slideHeight = 90;
63 const SkScalar slideBoundary = 5;
66 class InversePathsGM : public GM {
74 SkString onShortName() SK_OVERRIDE {
75 return SkString("inverse_paths");
78 SkISize onISize() SK_OVERRIDE {
79 return SkISize::Make(800, 900);
82 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
83 SkScalar cx = slideWidth / 2 + slideBoundary;
84 SkScalar cy = slideHeight / 2 + slideBoundary;
85 SkScalar dx = slideWidth + 2 * slideBoundary;
86 SkScalar dy = slideHeight + 2 * slideBoundary;
88 SkRect clipRect = SkRect::MakeLTRB(slideBoundary, slideBoundary,
89 slideBoundary + slideWidth,
90 slideBoundary + slideHeight);
92 clipPaint.setStyle(SkPaint::kStroke_Style);
93 clipPaint.setStrokeWidth(SkIntToScalar(2));
96 outlinePaint.setColor(0x40000000);
97 outlinePaint.setStyle(SkPaint::kStroke_Style);
98 outlinePaint.setStrokeWidth(SkIntToScalar(0));
100 for (size_t styleIndex = 0; styleIndex < SK_ARRAY_COUNT(styles);
102 for (size_t sizeIndex = 0; sizeIndex < SK_ARRAY_COUNT(pathSizes);
104 SkScalar size = pathSizes[sizeIndex];
108 for (size_t widthIndex = 0;
109 widthIndex < SK_ARRAY_COUNT(strokeWidths);
112 paint.setColor(0xff007000);
113 paint.setStrokeWidth(strokeWidths[widthIndex]);
114 paint.setStyle(styles[styleIndex]);
116 for (size_t pathIndex = 0;
117 pathIndex < SK_ARRAY_COUNT(paths);
119 canvas->drawRect(clipRect, clipPaint);
122 canvas->clipRect(clipRect);
124 SkPath path = paths[pathIndex](cx, cy, size);
125 path.setFillType(SkPath::kInverseWinding_FillType);
126 canvas->drawPath(path, paint);
128 path.setFillType(SkPath::kWinding_FillType);
129 canvas->drawPath(path, outlinePaint);
132 canvas->translate(dx, 0);
137 canvas->translate(0, dy);
143 typedef GM INHERITED;
146 DEF_GM( return new InversePathsGM; )