aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/scaledstrokes.cpp
blob: 1096fcb1de4e6c3e59c04d629a798b8efc3288b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"
#include "SkCanvas.h"
#include "SkRRect.h"
#include "SkPath.h"

class ScaledStrokesGM : public skiagm::GM {
public:
    ScaledStrokesGM() {}

protected:

    SkString onShortName() override {
        return SkString("scaledstrokes");
    }

    SkISize onISize() override {
        return SkISize::Make(640, 320);
    }

    static void draw_path(SkScalar size, SkCanvas* canvas, SkPaint paint) {
        SkScalar c = 0.551915024494f * size;
        SkPath path;
        path.moveTo(0.0f, size);
        path.cubicTo(c, size, size, c, size, 0.0f);
        path.cubicTo(size, -c, c, -size, 0.0f, -size);
        path.cubicTo(-c, -size, -size, -c, -size, 0.0f);
        path.cubicTo(-size, c, -c, size, 0.0f, size);
        canvas->drawPath(path, paint);
    }

    void onDraw(SkCanvas* canvas) override {
        SkPaint paint;
        SkPath path;
        paint.setStyle(SkPaint::Style::kStroke_Style);
        canvas->translate(5.0f, 5.0f);
        const SkScalar size = 60.0f;
        for (int i = 0; i < 2; i++) {
            paint.setAntiAlias(i == 1);
            for (int j = 0; j < 4; j++) {
                SkScalar scale = 4.0f - j;
                paint.setStrokeWidth(4.0f / scale);
                canvas->save();
                canvas->translate(size / 2.0f, size / 2.0f);
                canvas->scale(scale, scale);
                draw_path(size / 2.0f / scale, canvas, paint);
                canvas->restore();

                canvas->save();
                canvas->translate(size / 2.0f, 80.0f + size / 2.0f);
                canvas->scale(scale, scale);
                canvas->drawCircle(0.0f, 0.0f, size / 2.0f / scale, paint);
                canvas->restore();

                canvas->save();
                canvas->translate(0.0f, 160.0f);
                canvas->scale(scale, scale);
                canvas->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, size / scale, size / scale), paint);
                canvas->restore();

                canvas->save();
                canvas->translate(0.0f, 240.0f);
                canvas->scale(scale, scale);
                canvas->drawLine(0.0f, 0.0f, size / scale, size / scale, paint);
                canvas->restore();

                canvas->translate(80.0f, 0.0f);
            }
        }

    }

private:
    typedef GM INHERITED;
};

DEF_GM( return new ScaledStrokesGM; )