aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-04-15 20:04:45 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-16 00:42:15 +0000
commit48bf6ab69d5170f1692ddedef6d4fe4be89ae4d4 (patch)
tree050017dcb3c8dd8e9c5385dc9fa5e6d664f6e482 /samplecode
parent146872868b8742ae5c27cc4ac03e2ae8bfe0cdee (diff)
show flatness vectors in sample
Bug: skia: Change-Id: I5a3882c993138dc5e1da92a7a4b1a9f96c740d1c Reviewed-on: https://skia-review.googlesource.com/121461 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SamplePath.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/samplecode/SamplePath.cpp b/samplecode/SamplePath.cpp
index 11b4167ac6..f523fe6ef3 100644
--- a/samplecode/SamplePath.cpp
+++ b/samplecode/SamplePath.cpp
@@ -590,6 +590,7 @@ public:
SkPoint* fQuad = fPts + 4;
SkScalar fT = 0.5f;
bool fShowSub = false;
+ bool fShowFlatness = false;
CubicCurve2() {
fPts[0] = { 90, 300 };
@@ -612,6 +613,7 @@ protected:
if (SampleCode::CharQ(*evt, &uni)) {
switch (uni) {
case 's': fShowSub = !fShowSub; break;
+ case 'f': fShowFlatness = !fShowFlatness; break;
case '-': fT -= 1.0f / 32; break;
case '=': fT += 1.0f / 32; break;
default: goto DONE;
@@ -645,6 +647,29 @@ protected:
canvas->drawCircle(storage[i].fX, storage[i].fY, 4, paint);
}
}
+
+ void showFlattness(SkCanvas* canvas) {
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setAntiAlias(true);
+
+ paint.setColor(0xFF888888);
+ canvas->drawLine(fPts[0], fPts[3], paint);
+ canvas->drawLine(fQuad[0], fQuad[2], paint);
+
+ paint.setColor(0xFF0000FF);
+ SkPoint pts[2];
+ pts[0] = (fQuad[0] + fQuad[1] + fQuad[1] + fQuad[2])*0.25;
+ pts[1] = (fQuad[0] + fQuad[2]) * 0.5;
+ canvas->drawLine(pts[0], pts[1], paint);
+
+ SkVector v = fPts[0] - fPts[1] - fPts[1] + fPts[2];
+ v = v * 0.75;
+ canvas->drawLine(fPts[1], fPts[1] + v, paint);
+ v = fPts[1] - fPts[2] - fPts[2] + fPts[3];
+ v = v * 0.75;
+ canvas->drawLine(fPts[2], fPts[2] + v, paint);
+ }
void onDrawContent(SkCanvas* canvas) override {
SkPaint paint;
@@ -674,6 +699,10 @@ protected:
canvas->drawText(str.c_str(), str.size(), 20, 20, paint);
}
+ if (fShowFlatness) {
+ this->showFlattness(canvas);
+ }
+
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(SK_ColorRED);
for (SkPoint p : fPts) {