blob: be8eb61be271d522f404c099efbf3de44baa5732 [file] [log] [blame]
ethannicholasfea77632015-08-19 12:09:12 -07001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkPaint.h"
Mike Reed06d7c9d2020-08-26 12:56:51 -040011#include "include/core/SkPathBuilder.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040012#include "include/core/SkRect.h"
13#include "include/core/SkScalar.h"
14#include "include/core/SkSize.h"
15#include "include/core/SkString.h"
ethannicholasfea77632015-08-19 12:09:12 -070016
17class ScaledStrokesGM : public skiagm::GM {
18public:
19 ScaledStrokesGM() {}
20
21protected:
22
23 SkString onShortName() override {
24 return SkString("scaledstrokes");
25 }
26
27 SkISize onISize() override {
28 return SkISize::Make(640, 320);
29 }
30
31 static void draw_path(SkScalar size, SkCanvas* canvas, SkPaint paint) {
32 SkScalar c = 0.551915024494f * size;
Mike Reed06d7c9d2020-08-26 12:56:51 -040033 SkPathBuilder path;
ethannicholasfea77632015-08-19 12:09:12 -070034 path.moveTo(0.0f, size);
35 path.cubicTo(c, size, size, c, size, 0.0f);
36 path.cubicTo(size, -c, c, -size, 0.0f, -size);
37 path.cubicTo(-c, -size, -size, -c, -size, 0.0f);
38 path.cubicTo(-size, c, -c, size, 0.0f, size);
Mike Reed06d7c9d2020-08-26 12:56:51 -040039 canvas->drawPath(path.detach(), paint);
ethannicholasfea77632015-08-19 12:09:12 -070040 }
41
42 void onDraw(SkCanvas* canvas) override {
43 SkPaint paint;
44 SkPath path;
45 paint.setStyle(SkPaint::Style::kStroke_Style);
46 canvas->translate(5.0f, 5.0f);
47 const SkScalar size = 60.0f;
48 for (int i = 0; i < 2; i++) {
49 paint.setAntiAlias(i == 1);
ethannicholasfea77632015-08-19 12:09:12 -070050 for (int j = 0; j < 4; j++) {
51 SkScalar scale = 4.0f - j;
52 paint.setStrokeWidth(4.0f / scale);
53 canvas->save();
54 canvas->translate(size / 2.0f, size / 2.0f);
55 canvas->scale(scale, scale);
56 draw_path(size / 2.0f / scale, canvas, paint);
57 canvas->restore();
58
59 canvas->save();
60 canvas->translate(size / 2.0f, 80.0f + size / 2.0f);
61 canvas->scale(scale, scale);
62 canvas->drawCircle(0.0f, 0.0f, size / 2.0f / scale, paint);
63 canvas->restore();
64
65 canvas->save();
66 canvas->translate(0.0f, 160.0f);
67 canvas->scale(scale, scale);
68 canvas->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, size / scale, size / scale), paint);
69 canvas->restore();
70
71 canvas->save();
72 canvas->translate(0.0f, 240.0f);
73 canvas->scale(scale, scale);
74 canvas->drawLine(0.0f, 0.0f, size / scale, size / scale, paint);
75 canvas->restore();
76
77 canvas->translate(80.0f, 0.0f);
78 }
ethannicholasfea77632015-08-19 12:09:12 -070079 }
80
81 }
82
83private:
John Stiles7571f9e2020-09-02 22:42:33 -040084 using INHERITED = GM;
ethannicholasfea77632015-08-19 12:09:12 -070085};
86
87DEF_GM( return new ScaledStrokesGM; )