OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 <functional> | 8 #include <functional> |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkDashPathEffect.h" |
10 #include "gm.h" | 11 #include "gm.h" |
11 | 12 |
12 static constexpr SkScalar kStarts[] = {0.f, 10.f, 30.f, 45.f, 90.f, 165.f, 180.f
, 270.f}; | 13 static constexpr SkScalar kStarts[] = {0.f, 10.f, 30.f, 45.f, 90.f, 165.f, 180.f
, 270.f}; |
13 static constexpr SkScalar kSweeps[] = {1.f, 45.f, 90.f, 130.f, 180.f, 184.f, 300
.f, 355.f}; | 14 static constexpr SkScalar kSweeps[] = {1.f, 45.f, 90.f, 130.f, 180.f, 184.f, 300
.f, 355.f}; |
14 static constexpr SkScalar kDiameter = 40.f; | 15 static constexpr SkScalar kDiameter = 40.f; |
15 static constexpr SkRect kRect = {0.f, 0.f, kDiameter, kDiameter}; | 16 static constexpr SkRect kRect = {0.f, 0.f, kDiameter, kDiameter}; |
16 static constexpr int kW = 1000; | 17 static constexpr int kW = 1000; |
17 static constexpr int kH = 1000; | 18 static constexpr int kH = 1000; |
18 static constexpr SkScalar kPad = 20.f; | 19 static constexpr SkScalar kPad = 20.f; |
19 | 20 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 draw_arcs(canvas, setStroke); | 119 draw_arcs(canvas, setStroke); |
119 } | 120 } |
120 | 121 |
121 DEF_ARC_GM(stroke_and_fill_round) { | 122 DEF_ARC_GM(stroke_and_fill_round) { |
122 auto setStroke = [] (SkPaint* p) { | 123 auto setStroke = [] (SkPaint* p) { |
123 p->setStyle(SkPaint::kStrokeAndFill_Style); | 124 p->setStyle(SkPaint::kStrokeAndFill_Style); |
124 p->setStrokeCap(SkPaint::kRound_Cap); | 125 p->setStrokeCap(SkPaint::kRound_Cap); |
125 }; | 126 }; |
126 draw_arcs(canvas, setStroke); | 127 draw_arcs(canvas, setStroke); |
127 } | 128 } |
| 129 |
| 130 DEF_SIMPLE_GM(circular_arcs_weird, canvas, 1000, 400) { |
| 131 static constexpr SkScalar kS = 50; |
| 132 struct Arc { |
| 133 SkRect fOval; |
| 134 SkScalar fStart; |
| 135 SkScalar fSweep; |
| 136 }; |
| 137 static const Arc noDrawArcs[] = { |
| 138 // no sweep |
| 139 {SkRect::MakeWH(kS, kS), 0, 0}, |
| 140 // empty rect in x |
| 141 {SkRect::MakeWH(-kS, kS), 0, 90}, |
| 142 // empty rect in y |
| 143 {SkRect::MakeWH(kS, -kS), 0, 90}, |
| 144 // empty rect in x and y |
| 145 {SkRect::MakeWH( 0, 0), 0, 90}, |
| 146 }; |
| 147 static const Arc arcs[] = { |
| 148 // large start |
| 149 {SkRect::MakeWH(kS, kS), 810.f, 90.f}, |
| 150 // large negative start |
| 151 {SkRect::MakeWH(kS, kS), -810.f, 90.f}, |
| 152 // exactly 360 sweep |
| 153 {SkRect::MakeWH(kS, kS), 0.f, 360.f}, |
| 154 // exactly -360 sweep |
| 155 {SkRect::MakeWH(kS, kS), 0.f, -360.f}, |
| 156 // exactly 540 sweep |
| 157 {SkRect::MakeWH(kS, kS), 0.f, 540.f}, |
| 158 // exactly -540 sweep |
| 159 {SkRect::MakeWH(kS, kS), 0.f, -540.f}, |
| 160 // generic large sweep and large start |
| 161 {SkRect::MakeWH(kS, kS), 1125.f, 990.f}, |
| 162 }; |
| 163 SkTArray<SkPaint> paints; |
| 164 // fill |
| 165 paints.push_back(); |
| 166 // stroke |
| 167 paints.push_back().setStyle(SkPaint::kStroke_Style); |
| 168 paints.back().setStrokeWidth(kS / 6.f); |
| 169 // hairline |
| 170 paints.push_back().setStyle(SkPaint::kStroke_Style); |
| 171 paints.back().setStrokeWidth(0.f); |
| 172 // stroke and fill |
| 173 paints.push_back().setStyle(SkPaint::kStrokeAndFill_Style); |
| 174 paints.back().setStrokeWidth(kS / 6.f); |
| 175 // dash effect |
| 176 paints.push_back().setStyle(SkPaint::kStroke_Style); |
| 177 paints.back().setStrokeWidth(kS / 6.f); |
| 178 static constexpr SkScalar kDashIntervals[] = {kS / 15, 2 * kS / 15}; |
| 179 paints.back().setPathEffect(SkDashPathEffect::Make(kDashIntervals, 2, 0.f)); |
| 180 |
| 181 canvas->translate(kPad, kPad); |
| 182 // This loop should draw nothing. |
| 183 for (auto arc : noDrawArcs) { |
| 184 for (auto paint : paints) { |
| 185 paint.setAntiAlias(true); |
| 186 canvas->drawArc(arc.fOval, arc.fStart, arc.fSweep, false, paint); |
| 187 canvas->drawArc(arc.fOval, arc.fStart, arc.fSweep, true, paint); |
| 188 } |
| 189 } |
| 190 |
| 191 SkPaint linePaint; |
| 192 linePaint.setAntiAlias(true); |
| 193 linePaint.setColor(SK_ColorRED); |
| 194 SkScalar midX = SK_ARRAY_COUNT(arcs) * (kS + kPad) - kPad/2.f; |
| 195 SkScalar height = paints.count() * (kS + kPad); |
| 196 canvas->drawLine(midX, -kPad, midX, height, linePaint); |
| 197 |
| 198 for (auto paint : paints) { |
| 199 paint.setAntiAlias(true); |
| 200 canvas->save(); |
| 201 for (auto arc : arcs) { |
| 202 canvas->drawArc(arc.fOval, arc.fStart, arc.fSweep, false, paint); |
| 203 canvas->translate(kS + kPad, 0.f); |
| 204 } |
| 205 for (auto arc : arcs) { |
| 206 canvas->drawArc(arc.fOval, arc.fStart, arc.fSweep, true, paint); |
| 207 canvas->translate(kS + kPad, 0.f); |
| 208 } |
| 209 canvas->restore(); |
| 210 canvas->translate(0, kS + kPad); |
| 211 } |
| 212 } |
OLD | NEW |