1 /* 2 * Copyright 2011 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 "Sample.h" 9 #include "SkCanvas.h" 10 #include "SkGradientShader.h" 11 #include "SkGraphics.h" 12 #include "SkPath.h" 13 #include "SkRegion.h" 14 #include "SkShader.h" 15 #include "SkUTF.h" 16 #include "SkColorPriv.h" 17 #include "SkColorFilter.h" 18 #include "SkParsePath.h" 19 #include "SkTime.h" 20 #include "SkTypeface.h" 21 22 #include "SkGeometry.h" 23 24 class ConcavePathView : public Sample { 25 public: 26 ConcavePathView() {} 27 28 protected: 29 virtual bool onQuery(Sample::Event* evt) { 30 if (Sample::TitleQ(*evt)) { 31 Sample::TitleR(evt, "ConcavePaths"); 32 return true; 33 } 34 return this->INHERITED::onQuery(evt); 35 } 36 37 virtual void onDrawContent(SkCanvas* canvas) { 38 SkPaint paint; 39 40 paint.setAntiAlias(true); 41 paint.setStyle(SkPaint::kFill_Style); 42 43 // Concave test 44 if (1) { 45 SkPath path; 46 canvas->translate(0, 0); 47 path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); 48 path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); 49 path.lineTo(SkIntToScalar(30), SkIntToScalar(30)); 50 path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); 51 canvas->drawPath(path, paint); 52 } 53 // Reverse concave test 54 if (1) { 55 SkPath path; 56 canvas->save(); 57 canvas->translate(100, 0); 58 path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); 59 path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); 60 path.lineTo(SkIntToScalar(30), SkIntToScalar(30)); 61 path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); 62 canvas->drawPath(path, paint); 63 canvas->restore(); 64 } 65 // Bowtie (intersection) 66 if (1) { 67 SkPath path; 68 canvas->save(); 69 canvas->translate(200, 0); 70 path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); 71 path.lineTo(SkIntToScalar(80), SkIntToScalar(80)); 72 path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); 73 path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); 74 canvas->drawPath(path, paint); 75 canvas->restore(); 76 } 77 // "fake" bowtie (concave, but no intersection) 78 if (1) { 79 SkPath path; 80 canvas->save(); 81 canvas->translate(300, 0); 82 path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); 83 path.lineTo(SkIntToScalar(50), SkIntToScalar(40)); 84 path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); 85 path.lineTo(SkIntToScalar(80), SkIntToScalar(80)); 86 path.lineTo(SkIntToScalar(50), SkIntToScalar(60)); 87 path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); 88 canvas->drawPath(path, paint); 89 canvas->restore(); 90 } 91 // Fish test (intersection/concave) 92 if (1) { 93 SkPath path; 94 canvas->save(); 95 canvas->translate(0, 100); 96 path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); 97 path.lineTo(SkIntToScalar(80), SkIntToScalar(80)); 98 path.lineTo(SkIntToScalar(70), SkIntToScalar(50)); 99 path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); 100 path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); 101 path.lineTo(SkIntToScalar(0), SkIntToScalar(50)); 102 canvas->drawPath(path, paint); 103 canvas->restore(); 104 } 105 // Collinear test 106 if (1) { 107 SkPath path; 108 canvas->save(); 109 canvas->translate(100, 100); 110 path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); 111 path.lineTo(SkIntToScalar(50), SkIntToScalar(20)); 112 path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); 113 path.lineTo(SkIntToScalar(50), SkIntToScalar(80)); 114 canvas->drawPath(path, paint); 115 canvas->restore(); 116 } 117 // Hole test 118 if (1) { 119 SkPath path; 120 canvas->save(); 121 canvas->translate(200, 100); 122 path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); 123 path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); 124 path.lineTo(SkIntToScalar(80), SkIntToScalar(80)); 125 path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); 126 path.moveTo(SkIntToScalar(30), SkIntToScalar(30)); 127 path.lineTo(SkIntToScalar(30), SkIntToScalar(70)); 128 path.lineTo(SkIntToScalar(70), SkIntToScalar(70)); 129 path.lineTo(SkIntToScalar(70), SkIntToScalar(30)); 130 canvas->drawPath(path, paint); 131 canvas->restore(); 132 } 133 } 134 135 private: 136 typedef Sample INHERITED; 137 }; 138 139 ////////////////////////////////////////////////////////////////////////////// 140 141 DEF_SAMPLE( return new ConcavePathView(); ) 142