| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 paint->setColor(color); | 91 paint->setColor(color); |
| 92 if (40 == paint->getStrokeWidth()) { | 92 if (40 == paint->getStrokeWidth()) { |
| 93 paint->setAlpha(0xA0); | 93 paint->setAlpha(0xA0); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 void onDraw(SkCanvas* canvas) override { | 97 void onDraw(SkCanvas* canvas) override { |
| 98 // Stroke widths are: | 98 // Stroke widths are: |
| 99 // 0(may use hairline rendering), 10(common case for stroke-style) | 99 // 0(may use hairline rendering), 10(common case for stroke-style) |
| 100 // 40(>= geometry width/height, make the contour filled in fact) | 100 // 40(>= geometry width/height, make the contour filled in fact) |
| 101 static const int kStrokeWidths[] = {0, 10, 40}; | 101 constexpr int kStrokeWidths[] = {0, 10, 40}; |
| 102 SkASSERT(kNumStrokeWidths == SK_ARRAY_COUNT(kStrokeWidths)); | 102 SkASSERT(kNumStrokeWidths == SK_ARRAY_COUNT(kStrokeWidths)); |
| 103 | 103 |
| 104 static const SkPaint::Join kJoins[] = { | 104 constexpr SkPaint::Join kJoins[] = { |
| 105 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join | 105 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join |
| 106 }; | 106 }; |
| 107 SkASSERT(kNumJoins == SK_ARRAY_COUNT(kJoins)); | 107 SkASSERT(kNumJoins == SK_ARRAY_COUNT(kJoins)); |
| 108 | 108 |
| 109 int counter = 0; | 109 int counter = 0; |
| 110 SkPaint paint; | 110 SkPaint paint; |
| 111 paint.setAntiAlias(true); | 111 paint.setAntiAlias(true); |
| 112 | 112 |
| 113 SkRandom rand; | 113 SkRandom rand; |
| 114 // For stroke style painter | 114 // For stroke style painter |
| 115 paint.setStyle(SkPaint::kStroke_Style); | 115 paint.setStyle(SkPaint::kStroke_Style); |
| 116 for (int join = 0; join < kNumJoins; ++join) { | 116 for (int join = 0; join < kNumJoins; ++join) { |
| 117 for (int width = 0; width < kNumStrokeWidths; ++width) { | 117 for (int width = 0; width < kNumStrokeWidths; ++width) { |
| 118 for (int i = 0; i < fPolygons.count(); ++i) { | 118 for (int i = 0; i < fPolygons.count(); ++i) { |
| 119 canvas->save(); | 119 canvas->save(); |
| 120 SetLocation(canvas, counter, fPolygons.count()); | 120 SetLocation(canvas, counter, fPolygons.count()); |
| 121 | 121 |
| 122 SetColorAndAlpha(&paint, &rand); | 122 SetColorAndAlpha(&paint, &rand); |
| 123 paint.setStrokeJoin(kJoins[join]); | 123 paint.setStrokeJoin(kJoins[join]); |
| 124 paint.setStrokeWidth(SkIntToScalar(kStrokeWidths[width])); | 124 paint.setStrokeWidth(SkIntToScalar(kStrokeWidths[width])); |
| 125 | 125 |
| 126 canvas->drawPath(fPolygons[i], paint); | 126 canvas->drawPath(fPolygons[i], paint); |
| 127 canvas->restore(); | 127 canvas->restore(); |
| 128 ++counter; | 128 ++counter; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 // For stroke-and-fill style painter and fill style painter | 133 // For stroke-and-fill style painter and fill style painter |
| 134 static const SkPaint::Style kStyles[] = { | 134 constexpr SkPaint::Style kStyles[] = { |
| 135 SkPaint::kStrokeAndFill_Style, SkPaint::kFill_Style | 135 SkPaint::kStrokeAndFill_Style, SkPaint::kFill_Style |
| 136 }; | 136 }; |
| 137 SkASSERT(kNumExtraStyles == SK_ARRAY_COUNT(kStyles)); | 137 SkASSERT(kNumExtraStyles == SK_ARRAY_COUNT(kStyles)); |
| 138 | 138 |
| 139 paint.setStrokeJoin(SkPaint::kMiter_Join); | 139 paint.setStrokeJoin(SkPaint::kMiter_Join); |
| 140 paint.setStrokeWidth(SkIntToScalar(20)); | 140 paint.setStrokeWidth(SkIntToScalar(20)); |
| 141 for (int style = 0; style < kNumExtraStyles; ++style) { | 141 for (int style = 0; style < kNumExtraStyles; ++style) { |
| 142 paint.setStyle(kStyles[style]); | 142 paint.setStyle(kStyles[style]); |
| 143 for (int i = 0; i < fPolygons.count(); ++i) { | 143 for (int i = 0; i < fPolygons.count(); ++i) { |
| 144 canvas->save(); | 144 canvas->save(); |
| 145 SetLocation(canvas, counter, fPolygons.count()); | 145 SetLocation(canvas, counter, fPolygons.count()); |
| 146 SetColorAndAlpha(&paint, &rand); | 146 SetColorAndAlpha(&paint, &rand); |
| 147 canvas->drawPath(fPolygons[i], paint); | 147 canvas->drawPath(fPolygons[i], paint); |
| 148 canvas->restore(); | 148 canvas->restore(); |
| 149 ++counter; | 149 ++counter; |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 static const int kNumPolygons = 8; | 155 static constexpr int kNumPolygons = 8; |
| 156 static const int kCellSize = 100; | 156 static constexpr int kCellSize = 100; |
| 157 static const int kNumExtraStyles = 2; | 157 static constexpr int kNumExtraStyles = 2; |
| 158 static const int kNumStrokeWidths = 3; | 158 static constexpr int kNumStrokeWidths = 3; |
| 159 static const int kNumJoins = 3; | 159 static constexpr int kNumJoins = 3; |
| 160 | 160 |
| 161 SkTArray<SkPath> fPolygons; | 161 SkTArray<SkPath> fPolygons; |
| 162 typedef GM INHERITED; | 162 typedef GM INHERITED; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 ////////////////////////////////////////////////////////////////////////////// | 165 ////////////////////////////////////////////////////////////////////////////// |
| 166 | 166 |
| 167 DEF_GM(return new PolygonsGM;) | 167 DEF_GM(return new PolygonsGM;) |
| 168 | 168 |
| 169 } | 169 } |
| OLD | NEW |