• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
ScaledStrokesGM()15     ScaledStrokesGM() {}
16 
17 protected:
18 
onShortName()19     SkString onShortName() override {
20         return SkString("scaledstrokes");
21     }
22 
onISize()23     SkISize onISize() override {
24         return SkISize::Make(640, 320);
25     }
26 
draw_path(SkScalar size,SkCanvas * canvas,SkPaint paint)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 
onDraw(SkCanvas * canvas)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             for (int j = 0; j < 4; j++) {
47                 SkScalar scale = 4.0f - j;
48                 paint.setStrokeWidth(4.0f / scale);
49                 canvas->save();
50                 canvas->translate(size / 2.0f, size / 2.0f);
51                 canvas->scale(scale, scale);
52                 draw_path(size / 2.0f / scale, canvas, paint);
53                 canvas->restore();
54 
55                 canvas->save();
56                 canvas->translate(size / 2.0f, 80.0f + size / 2.0f);
57                 canvas->scale(scale, scale);
58                 canvas->drawCircle(0.0f, 0.0f, size / 2.0f / scale, paint);
59                 canvas->restore();
60 
61                 canvas->save();
62                 canvas->translate(0.0f, 160.0f);
63                 canvas->scale(scale, scale);
64                 canvas->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, size / scale, size / scale), paint);
65                 canvas->restore();
66 
67                 canvas->save();
68                 canvas->translate(0.0f, 240.0f);
69                 canvas->scale(scale, scale);
70                 canvas->drawLine(0.0f, 0.0f, size / scale, size / scale, paint);
71                 canvas->restore();
72 
73                 canvas->translate(80.0f, 0.0f);
74             }
75         }
76 
77     }
78 
79 private:
80     typedef GM INHERITED;
81 };
82 
83 DEF_GM( return new ScaledStrokesGM; )
84