Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Unified Diff: samplecode/SamplePathOverstroke.cpp

Issue 2106063004: Add cubic example and draw original path (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SamplePathOverstroke.cpp
diff --git a/samplecode/SamplePathOverstroke.cpp b/samplecode/SamplePathOverstroke.cpp
index 821906565857dc9af99b3142fa839fe5a6164dcf..a2d1b89b8673815bf5949598b8c61e4382d7ecd2 100644
--- a/samplecode/SamplePathOverstroke.cpp
+++ b/samplecode/SamplePathOverstroke.cpp
@@ -9,6 +9,7 @@
#include "SkCanvas.h"
#include "SkPath.h"
+#include <iostream>
#include <cmath>
#define PI SK_ScalarPI
@@ -21,11 +22,13 @@ class OverstrokeView : public SampleView {
int fPathType; // super lazy enum
bool fClosePath;
bool fDrawFillPath;
+ bool fDumpHex;
OverstrokeView() {
fStroke = 5;
fPathType = 0;
fClosePath = false;
fDrawFillPath = false;
+ fDumpHex = false;
this->setBGColor(0xFFFFFFFF);
}
@@ -47,7 +50,7 @@ class OverstrokeView : public SampleView {
this->inval(nullptr);
return true;
case 'x':
- fPathType = (fPathType + 1) % 3;
+ fPathType = (fPathType + 1) % 4;
this->inval(nullptr);
return true;
case 'c':
@@ -58,6 +61,10 @@ class OverstrokeView : public SampleView {
fDrawFillPath = !fDrawFillPath;
this->inval(nullptr);
return true;
+ case 'D':
+ fDumpHex = !fDumpHex;
+ this->inval(nullptr);
+ return true;
default:
break;
}
@@ -79,6 +86,20 @@ class OverstrokeView : public SampleView {
return path;
}
+ SkPath cubicPath(SkPoint p1, SkPoint p2) {
+ SkASSERT(p1.y() == p2.y());
+
+ SkPath path;
+ path.moveTo(p1);
+
+ SkPoint p3 = SkPoint::Make((p1.x() + p2.x()) / 3.0f, p1.y() * 0.7f);
+ SkPoint p4 = SkPoint::Make(2.0f*(p1.x() + p2.x()) / 3.0f, p1.y() * 1.5f);
+
+ path.cubicTo(p3, p4, p2);
+
+ return path;
+ }
+
SkPath linSemicirclePath(SkPoint p1, SkPoint p2) {
SkASSERT(p1.y() == p2.y());
@@ -123,11 +144,14 @@ class OverstrokeView : public SampleView {
path = quadPath(p1, p2);
break;
case 1:
- path = linSemicirclePath(p1, p2);
+ path = cubicPath(p1, p2);
break;
case 2:
path = rectPath(p1);
break;
+ case 3:
+ path = linSemicirclePath(p1, p2);
+ break;
default:
path = quadPath(p1, p2);
break;
@@ -145,17 +169,37 @@ class OverstrokeView : public SampleView {
canvas->drawPath(path, p);
+ if (fDumpHex) {
+ std::cerr << "path dumpHex" << std::endl;
+ path.dumpHex();
+ }
+
+ SkPaint hairp;
+ hairp.setColor(SK_ColorBLACK);
+ hairp.setAntiAlias(true);
+ hairp.setStyle(SkPaint::kStroke_Style);
+
if (fDrawFillPath) {
SkPath fillpath;
p.getFillPath(path, &fillpath);
- SkPaint fillp;
- fillp.setColor(SK_ColorBLACK);
- fillp.setAntiAlias(true);
- fillp.setStyle(SkPaint::kStroke_Style);
+ canvas->drawPath(fillpath, hairp);
- canvas->drawPath(fillpath, fillp);
+ if (fDumpHex) {
+ std::cerr << "fillpath dumpHex" << std::endl;
+ fillpath.dumpHex();
+ }
}
+
+ if (fDumpHex) {
+ std::cerr << std::endl;
+
+ fDumpHex = false;
+ }
+
+ // draw original path with green hairline
+ hairp.setColor(SK_ColorGREEN);
+ canvas->drawPath(path, hairp);
}
private:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698