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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*
* Copyright 2013 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 "SkTArray.h"
class ConicPathsGM : public skiagm::GM {
protected:
SkString onShortName() override {
return SkString("conicpaths");
}
SkISize onISize() override {
return SkISize::Make(920, 960);
}
void onOnceBeforeDraw() override {
{
const SkScalar w = SkScalarSqrt(2)/2;
SkPath* conicCirlce = &fPaths.push_back();
conicCirlce->moveTo(0, 0);
conicCirlce->conicTo(0, 50, 50, 50, w);
conicCirlce->rConicTo(50, 0, 50, -50, w);
conicCirlce->rConicTo(0, -50, -50, -50, w);
conicCirlce->rConicTo(-50, 0, -50, 50, w);
}
{
SkPath* hyperbola = &fPaths.push_back();
hyperbola->moveTo(0, 0);
hyperbola->conicTo(0, 100, 100, 100, 2);
}
{
SkPath* thinHyperbola = &fPaths.push_back();
thinHyperbola->moveTo(0, 0);
thinHyperbola->conicTo(100, 100, 5, 0, 2);
}
{
SkPath* veryThinHyperbola = &fPaths.push_back();
veryThinHyperbola->moveTo(0, 0);
veryThinHyperbola->conicTo(100, 100, 1, 0, 2);
}
{
SkPath* closedHyperbola = &fPaths.push_back();
closedHyperbola->moveTo(0, 0);
closedHyperbola->conicTo(100, 100, 0, 0, 2);
}
{
// using 1 as weight defaults to using quadTo
SkPath* nearParabola = &fPaths.push_back();
nearParabola->moveTo(0, 0);
nearParabola->conicTo(0, 100, 100, 100, 0.999f);
}
{
SkPath* thinEllipse = &fPaths.push_back();
thinEllipse->moveTo(0, 0);
thinEllipse->conicTo(100, 100, 5, 0, SK_ScalarHalf);
}
{
SkPath* veryThinEllipse = &fPaths.push_back();
veryThinEllipse->moveTo(0, 0);
veryThinEllipse->conicTo(100, 100, 1, 0, SK_ScalarHalf);
}
{
SkPath* closedEllipse = &fPaths.push_back();
closedEllipse->moveTo(0, 0);
closedEllipse->conicTo(100, 100, 0, 0, SK_ScalarHalf);
}
{
const SkScalar w = SkScalarSqrt(2)/2;
fGiantCircle.moveTo(2.1e+11f, -1.05e+11f);
fGiantCircle.conicTo(2.1e+11f, 0, 1.05e+11f, 0, w);
fGiantCircle.conicTo(0, 0, 0, -1.05e+11f, w);
fGiantCircle.conicTo(0, -2.1e+11f, 1.05e+11f, -2.1e+11f, w);
fGiantCircle.conicTo(2.1e+11f, -2.1e+11f, 2.1e+11f, -1.05e+11f, w);
}
}
void drawGiantCircle(SkCanvas* canvas) {
SkPaint paint;
canvas->drawPath(fGiantCircle, paint);
}
void onDraw(SkCanvas* canvas) override {
const SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
const SkScalar margin = 15;
canvas->translate(margin, margin);
SkPaint paint;
for (int p = 0; p < fPaths.count(); ++p) {
canvas->save();
for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) {
paint.setARGB(kAlphaValue[a], 0, 0, 0);
for (int aa = 0; aa < 2; ++aa) {
paint.setAntiAlias(SkToBool(aa));
for (int fh = 0; fh < 2; ++fh) {
paint.setStyle(fh ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
const SkRect& bounds = fPaths[p].getBounds();
canvas->save();
canvas->translate(-bounds.fLeft, -bounds.fTop);
canvas->drawPath(fPaths[p], paint);
canvas->restore();
canvas->translate(110, 0);
}
}
}
canvas->restore();
canvas->translate(0, 110);
}
canvas->restore();
this->drawGiantCircle(canvas);
}
private:
SkTArray<SkPath> fPaths;
SkPath fGiantCircle;
typedef skiagm::GM INHERITED;
};
DEF_GM( return SkNEW(ConicPathsGM); )
//////////////////////////////////////////////////////////////////////////////
|