1 // Copyright 2020 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(example3ps, 320, 256, false, 0) {
setpsmatrix(float sx,float kx,float ky,float sy,float tx,float ty,int h)5 static SkMatrix setpsmatrix(float sx, float kx, float ky, float sy, float tx, float ty, int h) {
6 SkMatrix m;
7
8 m.setAll(sx, -kx, -tx * sx - (ty - h) * kx, -ky, sy, (ty - h) * sy + tx * ky, 0, 0, 1);
9 return m;
10 }
11
draw(SkCanvas * canvas)12 void draw(SkCanvas* canvas) {
13 canvas->save();
14 canvas->scale(15, -15);
15 canvas->translate(0, -28);
16 SkPath path;
17 path.moveTo(2, 2);
18 path.lineTo(3, 3);
19 path.lineTo(3, 4);
20 path.lineTo(2, 4);
21 path.lineTo(1, 5);
22 path.close();
23 SkPaint p;
24 p.setAntiAlias(true);
25 p.setStrokeWidth(0.1f);
26
27 canvas->save();
28 canvas->translate(0, 18);
29 p.setColor(SK_ColorGRAY);
30 canvas->drawPath(path, p);
31 canvas->restore();
32
33 p.setStyle(SkPaint::kStroke_Style);
34 canvas->save();
35 canvas->translate(8, 19);
36 canvas->rotate(90);
37 p.setColor(SK_ColorRED);
38 canvas->drawPath(path, p);
39 canvas->restore();
40
41 canvas->save();
42 canvas->translate(5, 23);
43 canvas->rotate(-90);
44 p.setColor(SK_ColorBLUE);
45 canvas->drawPath(path, p);
46 canvas->restore();
47
48 canvas->save();
49 canvas->translate(14, 18);
50 canvas->scale(-1, 1);
51 p.setColor(0xFF007F00);
52 canvas->drawPath(path, p);
53 canvas->restore();
54 canvas->restore();
55
56 canvas->scale(15, 15);
57 canvas->translate(0, 24);
58
59 SkMatrix m;
60 unsigned char d[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
61 sk_sp<SkData> data = SkData::MakeWithoutCopy((unsigned char*)d, sizeof(d));
62 SkImageInfo info =
63 SkImageInfo::Make(3, 2, SkColorType::kGray_8_SkColorType, kOpaque_SkAlphaType);
64 sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, 3);
65
66 SkPaint bp;
67 canvas->save();
68 m = setpsmatrix(1, 0, 0, 1, -1, -24, 2);
69 // m.setAll(1, 0, -1, 0, 1, -24, 0, 0, 1);
70 canvas->concat(m);
71 canvas->drawImage(image, 0, 0, &bp);
72 canvas->restore();
73
74 canvas->save();
75 m = setpsmatrix(0, 1, 1, 0, -24, -5, 2);
76 // m.setAll(0, -1, 5, -1, 0, -22, 0, 0, 1);
77 canvas->concat(m);
78 canvas->drawImage(image, 0, 0, &bp);
79 canvas->restore();
80
81 canvas->save();
82 m = setpsmatrix(0, 1, -1, 0, 27, -8, 2);
83 // m.setAll(0, -1, 8, 1, 0, -25, 0, 0, 1);
84 canvas->concat(m);
85 canvas->drawImage(image, 0, 0, &bp);
86 canvas->restore();
87
88 canvas->save();
89 m = setpsmatrix(0, -1, -1, 0, -24, 13, 2);
90 // m.setAll(0, 1, 9, -1, 0, -22, 0, 0, 1);
91 canvas->concat(m);
92 canvas->drawImage(image, 0, 0, &bp);
93 canvas->restore();
94
95 canvas->save();
96 m = setpsmatrix(-1, 0, 0, -1, 17, 26, 2);
97 // m.setAll(-1, 0, 15, 0, -1, -22, 0, 0, 1);
98 canvas->concat(m);
99 canvas->drawImage(image, 0, 0, &bp);
100 canvas->restore();
101
102 canvas->save();
103 m = setpsmatrix(-1, 0, 0, 1, 21, -24, 2);
104 // m.setAll(-1, 0, 19, 0, 1, -24, 0, 0, 1);
105 canvas->concat(m);
106 canvas->drawImage(image, 0, 0, &bp);
107 canvas->restore();
108 }
109 } // END FIDDLE
110