OLD | NEW |
(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 #include "SkRandom.h" |
| 14 #include "SkTime.h" |
| 15 |
| 16 class samplePathUtils : public SampleView { |
| 17 public: |
| 18 samplePathUtils() { |
| 19 bmp_paint.setAntiAlias(true); // Black paint for bitmap |
| 20 bmp_paint.setStyle(SkPaint::kFill_Style); |
| 21 bmp_paint.setColor(SK_ColorBLACK); |
| 22 } |
| 23 |
| 24 protected: |
| 25 static const int numModes = 3; |
| 26 static const int h=8, w=12, stride=2, scale=10; // stride is in bytes |
| 27 static const int numChars = h * stride; // number of chars in entire array |
| 28 |
| 29 SkPaint bmp_paint; |
| 30 |
| 31 // overrides from SkEventSink |
| 32 virtual bool onQuery(SkEvent* evt) { |
| 33 if (SampleCode::TitleQ(*evt)) { |
| 34 SampleCode::TitleR(evt, "PathUtils"); |
| 35 return true; |
| 36 } |
| 37 return this->INHERITED::onQuery(evt); |
| 38 } |
| 39 |
| 40 ///////////////////////////////////////////////////////////// |
| 41 |
| 42 virtual void onDrawContent(SkCanvas* canvas) { |
| 43 // bitmap definitions |
| 44 const char bits[numModes][numChars] = { |
| 45 { 0x18, 0x00, 0x3c, 0x00, 0x7e, 0x00, 0xdb, 0x00, |
| 46 0xff, 0x00, 0x24, 0x00, 0x5a, 0x00, 0xa5, 0x00 }, |
| 47 |
| 48 { 0x20, 0x80, 0x91, 0x20, 0xbf, 0xa0, 0xee, 0xe0, |
| 49 0xff, 0xe0, 0x7f, 0xc0, 0x20, 0x80, 0x40, 0x40 }, |
| 50 |
| 51 { 0x0f, 0x00, 0x7f, 0xe0, 0xff, 0xf0, 0xe6, 0x70, |
| 52 0xff, 0xf0, 0x19, 0x80, 0x36, 0xc0, 0xc0, 0x30 } |
| 53 }; |
| 54 |
| 55 for (int i = 0; i < numModes; ++i) { |
| 56 SkPath path; // generate and simplify each path |
| 57 SkPathUtils::BitsToPath_Path(&path, (char*) &bits[i], h, w, stride); |
| 58 |
| 59 canvas->save(); // DRAWING |
| 60 canvas->scale(scale, scale); // scales up each bitmap |
| 61 canvas->translate(0, 1.5f * h * i); |
| 62 canvas->drawPath(path, bmp_paint); // draw bitmap |
| 63 canvas->restore(); |
| 64 |
| 65 // use the SkRegion method |
| 66 SkPath pathR; |
| 67 SkPathUtils::BitsToPath_Region(&pathR, (char*) &bits[i], h, w, strid
e); |
| 68 |
| 69 canvas->save(); |
| 70 canvas->scale(scale, scale); // scales up each bitmap |
| 71 canvas->translate(1.5f * w, 1.5f * h * i); // translates past previo
us bitmap |
| 72 canvas->drawPath(pathR, bmp_paint); // draw bitmap |
| 73 canvas->restore(); |
| 74 } |
| 75 } |
| 76 |
| 77 private: |
| 78 typedef SkView INHERITED; |
| 79 }; |
| 80 |
| 81 ////////////////////////////////////////////////////////////////////////////// |
| 82 |
| 83 static SkView* MyFactory() { return new samplePathUtils; } |
| 84 static SkViewRegister reg(MyFactory) |
| 85 ; |
OLD | NEW |