Index: samplecode/SamplePathUtils.cpp |
diff --git a/samplecode/SamplePathUtils.cpp b/samplecode/SamplePathUtils.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5dc6070c4dd9363c65f831136110466c25444459 |
--- /dev/null |
+++ b/samplecode/SamplePathUtils.cpp |
@@ -0,0 +1,91 @@ |
+/* |
+ * 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 "SampleCode.h" |
+#include "SkCanvas.h" |
+#include "SkPathUtils.h" |
+#include "SkView.h" |
+//#include "SkPathOps.h" // loads fine here, won't in PathUtils src files |
+ |
+class samplePathUtils : public SampleView { |
+public: |
+ samplePathUtils() { |
+ bmp_paint.setAntiAlias(true); // Black paint for bitmap |
+ bmp_paint.setStyle(SkPaint::kFill_Style); |
+ bmp_paint.setColor(SK_ColorBLACK); |
+ |
+ bg_paint.setAntiAlias(true); // Cyan rectangle for bitmap bg |
+ bg_paint.setStyle(SkPaint::kFill_Style); |
+ bg_paint.setColor(SK_ColorCYAN); |
+ |
+ bg_rect.addRect(SkRect::MakeXYWH(0, 0, w, h), |
+ SkPath::kCW_Direction); |
+ } |
+ |
+protected: |
+ static const int numModes = 3; |
+ |
+ static const int h=16, w=16, stride=2, scale=5; // stride is in bytes (or chars) |
+ static const int numChars = h * stride; // number of chars in entire array |
+ char bits[ numChars ]; |
+ |
+ SkPaint bmp_paint, bg_paint; |
+ SkPath bg_rect; |
+ |
+ // overrides from SkEventSink |
+ virtual bool onQuery(SkEvent* evt) { |
+ if (SampleCode::TitleQ(*evt)) { |
+ SampleCode::TitleR(evt, "PathUtils"); |
+ return true; |
+ } |
+ return this->INHERITED::onQuery(evt); |
+ } |
+ |
+ ///////////////////////////////////////////////////////////// |
+ |
+ virtual void onDrawContent(SkCanvas* canvas) { |
+ static const char* bin_bmp = (char*) bits; |
+ SkPathUtils::fillRandomBits( numChars, bits ); // generate random bitmap |
+ |
+ // loop through array of funtion pointers for modes of SkPath generation |
+ const line2path l2p_fns[numModes] = {SkPathUtils::line2path_pixel, |
+ SkPathUtils::line2path_pixelCircle, |
+ SkPathUtils::line2path_span}; |
+ |
+ for (int i = 0; i < numModes; ++i) { |
+ SkPath path; // generate and simplify each path |
+ SkPathUtils::bitmap2path(&path, bin_bmp, l2p_fns[i], h, w, stride); |
+ |
+ canvas->save(); // DRAWING |
+ canvas->scale(scale, scale); // scales up each bitmap |
+ canvas->translate(1.5f * i * w, 0); // translates past previous bitmap |
+ canvas->drawPath(bg_rect, bg_paint); // draws background rectangle |
+ canvas->drawPath(path, bmp_paint); // draw bitmap |
+ canvas->restore(); |
+ } |
+ |
+ // use the SkRegion method |
+ SkPath pathR; |
+ SkPathUtils::bitmap2path_region(&pathR, bin_bmp, h, w, stride); |
+ |
+ canvas->save(); |
+ canvas->scale(scale, scale); // scales up each bitmap |
+ canvas->translate(1.5f * numModes * w, 0); // translates past previous bitmap |
+ canvas->drawPath(bg_rect, bg_paint); // draws background rectangle |
+ canvas->drawPath(pathR, bmp_paint); // draw bitmap |
+ canvas->restore(); |
+ } |
+ |
+private: |
+ typedef SkView INHERITED; |
+}; |
+ |
+////////////////////////////////////////////////////////////////////////////// |
+ |
+static SkView* MyFactory() { return new samplePathUtils; } |
+static SkViewRegister reg(MyFactory) |
+; |