OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 labelPaint); | 119 labelPaint); |
120 } | 120 } |
121 } | 121 } |
122 canvas->restore(); | 122 canvas->restore(); |
123 canvas->restore(); | 123 canvas->restore(); |
124 } | 124 } |
125 | 125 |
126 private: | 126 private: |
127 typedef GM INHERITED; | 127 typedef GM INHERITED; |
128 }; | 128 }; |
| 129 DEF_GM( return new EmptyPathGM; ) |
129 | 130 |
130 ////////////////////////////////////////////////////////////////////////////// | 131 ////////////////////////////////////////////////////////////////////////////// |
131 | 132 |
132 static GM* MyFactory(void*) { return new EmptyPathGM; } | 133 static void make_path_move(SkPath* path, const SkPoint pts[3]) { |
133 static GMRegistry reg(MyFactory); | 134 for (int i = 0; i < 3; ++i) { |
| 135 path->moveTo(pts[i]); |
| 136 } |
| 137 } |
| 138 |
| 139 static void make_path_move_close(SkPath* path, const SkPoint pts[3]) { |
| 140 for (int i = 0; i < 3; ++i) { |
| 141 path->moveTo(pts[i]); |
| 142 path->close(); |
| 143 } |
| 144 } |
| 145 |
| 146 static void make_path_move_line(SkPath* path, const SkPoint pts[3]) { |
| 147 for (int i = 0; i < 3; ++i) { |
| 148 path->moveTo(pts[i]); |
| 149 path->lineTo(pts[i]); |
| 150 } |
| 151 } |
| 152 |
| 153 typedef void (*MakePathProc)(SkPath*, const SkPoint pts[3]); |
| 154 |
| 155 static void make_path_move_mix(SkPath* path, const SkPoint pts[3]) { |
| 156 path->moveTo(pts[0]); |
| 157 path->moveTo(pts[1]); path->close(); |
| 158 path->moveTo(pts[2]); path->lineTo(pts[2]); |
| 159 } |
| 160 |
| 161 class EmptyStrokeGM : public GM { |
| 162 SkPoint fPts[3]; |
| 163 |
| 164 public: |
| 165 EmptyStrokeGM() { |
| 166 fPts[0].set(40, 40); |
| 167 fPts[1].set(80, 40); |
| 168 fPts[2].set(120, 40); |
| 169 } |
| 170 |
| 171 protected: |
| 172 SkString onShortName() { |
| 173 return SkString("emptystroke"); |
| 174 } |
| 175 |
| 176 SkISize onISize() override { return SkISize::Make(200, 240); } |
| 177 |
| 178 void onDraw(SkCanvas* canvas) override { |
| 179 const MakePathProc procs[] = { |
| 180 make_path_move, // expect red red red |
| 181 make_path_move_close, // expect black black black |
| 182 make_path_move_line, // expect black black black |
| 183 make_path_move_mix, // expect red black black, |
| 184 }; |
| 185 |
| 186 SkPaint strokePaint; |
| 187 strokePaint.setStyle(SkPaint::kStroke_Style); |
| 188 strokePaint.setStrokeWidth(21); |
| 189 strokePaint.setStrokeCap(SkPaint::kSquare_Cap); |
| 190 |
| 191 SkPaint dotPaint; |
| 192 dotPaint.setColor(SK_ColorRED); |
| 193 strokePaint.setStyle(SkPaint::kStroke_Style); |
| 194 dotPaint.setStrokeWidth(7); |
| 195 |
| 196 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) { |
| 197 SkPath path; |
| 198 procs[i](&path, fPts); |
| 199 canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, fPts, dotPaint); |
| 200 canvas->drawPath(path, strokePaint); |
| 201 canvas->translate(0, 40); |
| 202 } |
| 203 } |
| 204 |
| 205 private: |
| 206 typedef GM INHERITED; |
| 207 }; |
| 208 DEF_GM( return new EmptyStrokeGM; ) |
134 | 209 |
135 } | 210 } |
OLD | NEW |