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

Side by Side Diff: samplecode/SamplePathUtils.cpp

Issue 16829003: Adding my Bitmap2Path sample for 1on1 meeting. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Added SkRegion mode to PathUtils and Test. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SampleCode.h"
9 #include "SkCanvas.h"
10 #include "SkPathUtils.h"
11 #include "SkView.h"
12 //#include "SkPathOps.h" // loads fine here, won't in PathUtils src files
13
14 class samplePathUtils : public SampleView {
15 public:
16 samplePathUtils() {
17 bmp_paint.setAntiAlias(true); // Black paint for bitmap
18 bmp_paint.setStyle(SkPaint::kFill_Style);
19 bmp_paint.setColor(SK_ColorBLACK);
20
21 bg_paint.setAntiAlias(true); // Cyan rectangle for bitmap bg
22 bg_paint.setStyle(SkPaint::kFill_Style);
23 bg_paint.setColor(SK_ColorCYAN);
24
25 bg_rect.addRect(SkRect::MakeXYWH(0, 0, w, h),
26 SkPath::kCW_Direction);
27 }
28
29 protected:
30 static const int numModes = 3;
31
32 static const int h=16, w=16, stride=2, scale=5; // stride is in bytes (or ch ars)
33 static const int numChars = h * stride; // number of chars in entire array
34 char bits[ numChars ];
35
36 SkPaint bmp_paint, bg_paint;
37 SkPath bg_rect;
38
39 // overrides from SkEventSink
40 virtual bool onQuery(SkEvent* evt) {
41 if (SampleCode::TitleQ(*evt)) {
42 SampleCode::TitleR(evt, "PathUtils");
43 return true;
44 }
45 return this->INHERITED::onQuery(evt);
46 }
47
48 /////////////////////////////////////////////////////////////
49
50 virtual void onDrawContent(SkCanvas* canvas) {
51 static const char* bin_bmp = (char*) bits;
52 SkPathUtils::fillRandomBits( numChars, bits ); // generate random bitmap
53
54 // loop through array of funtion pointers for modes of SkPath generation
55 const line2path l2p_fns[numModes] = {SkPathUtils::line2path_pixel,
56 SkPathUtils::line2path_pixelCircle,
57 SkPathUtils::line2path_span};
58
59 for (int i = 0; i < numModes; ++i) {
60 SkPath path; // generate and simplify each path
61 SkPathUtils::bitmap2path(&path, bin_bmp, l2p_fns[i], h, w, stride);
62
63 canvas->save(); // DRAWING
64 canvas->scale(scale, scale); // scales up each bitmap
65 canvas->translate(1.5f * i * w, 0); // translates past previous bitm ap
66 canvas->drawPath(bg_rect, bg_paint); // draws background rectangle
67 canvas->drawPath(path, bmp_paint); // draw bitmap
68 canvas->restore();
69 }
70
71 // use the SkRegion method
72 SkPath pathR;
73 SkPathUtils::bitmap2path_region(&pathR, bin_bmp, h, w, stride);
74
75 canvas->save();
76 canvas->scale(scale, scale); // scales up each bitmap
77 canvas->translate(1.5f * numModes * w, 0); // translates past previous b itmap
78 canvas->drawPath(bg_rect, bg_paint); // draws background rectangle
79 canvas->drawPath(pathR, bmp_paint); // draw bitmap
80 canvas->restore();
81 }
82
83 private:
84 typedef SkView INHERITED;
85 };
86
87 //////////////////////////////////////////////////////////////////////////////
88
89 static SkView* MyFactory() { return new samplePathUtils; }
90 static SkViewRegister reg(MyFactory)
91 ;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698