OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "gm.h" |
| 9 #include "SkCanvas.h" |
| 10 #include "SkRRect.h" |
| 11 #include "SkPath.h" |
| 12 |
| 13 class ScaledStrokesGM : public skiagm::GM { |
| 14 public: |
| 15 ScaledStrokesGM() {} |
| 16 |
| 17 protected: |
| 18 |
| 19 SkString onShortName() override { |
| 20 return SkString("scaledstrokes"); |
| 21 } |
| 22 |
| 23 SkISize onISize() override { |
| 24 return SkISize::Make(640, 320); |
| 25 } |
| 26 |
| 27 static void draw_path(SkScalar size, SkCanvas* canvas, SkPaint paint) { |
| 28 SkScalar c = 0.551915024494f * size; |
| 29 SkPath path; |
| 30 path.moveTo(0.0f, size); |
| 31 path.cubicTo(c, size, size, c, size, 0.0f); |
| 32 path.cubicTo(size, -c, c, -size, 0.0f, -size); |
| 33 path.cubicTo(-c, -size, -size, -c, -size, 0.0f); |
| 34 path.cubicTo(-size, c, -c, size, 0.0f, size); |
| 35 canvas->drawPath(path, paint); |
| 36 } |
| 37 |
| 38 void onDraw(SkCanvas* canvas) override { |
| 39 SkPaint paint; |
| 40 SkPath path; |
| 41 paint.setStyle(SkPaint::Style::kStroke_Style); |
| 42 canvas->translate(5.0f, 5.0f); |
| 43 const SkScalar size = 60.0f; |
| 44 for (int i = 0; i < 2; i++) { |
| 45 paint.setAntiAlias(i == 1); |
| 46 canvas->save(); |
| 47 for (int j = 0; j < 4; j++) { |
| 48 SkScalar scale = 4.0f - j; |
| 49 paint.setStrokeWidth(4.0f / scale); |
| 50 canvas->save(); |
| 51 canvas->translate(size / 2.0f, size / 2.0f); |
| 52 canvas->scale(scale, scale); |
| 53 draw_path(size / 2.0f / scale, canvas, paint); |
| 54 canvas->restore(); |
| 55 |
| 56 canvas->save(); |
| 57 canvas->translate(size / 2.0f, 80.0f + size / 2.0f); |
| 58 canvas->scale(scale, scale); |
| 59 canvas->drawCircle(0.0f, 0.0f, size / 2.0f / scale, paint); |
| 60 canvas->restore(); |
| 61 |
| 62 canvas->save(); |
| 63 canvas->translate(0.0f, 160.0f); |
| 64 canvas->scale(scale, scale); |
| 65 canvas->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, size / scale, size
/ scale), paint); |
| 66 canvas->restore(); |
| 67 |
| 68 canvas->save(); |
| 69 canvas->translate(0.0f, 240.0f); |
| 70 canvas->scale(scale, scale); |
| 71 canvas->drawLine(0.0f, 0.0f, size / scale, size / scale, paint); |
| 72 canvas->restore(); |
| 73 |
| 74 canvas->translate(80.0f, 0.0f); |
| 75 } |
| 76 } |
| 77 |
| 78 } |
| 79 |
| 80 private: |
| 81 typedef GM INHERITED; |
| 82 }; |
| 83 |
| 84 DEF_GM( return new ScaledStrokesGM; ) |
OLD | NEW |