| OLD | NEW |
| (Empty) |
| 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 "SampleCode.h" | |
| 9 #include "SkView.h" | |
| 10 #include "SkCanvas.h" | |
| 11 #include "SkPaint.h" | |
| 12 #include "SkPath.h" | |
| 13 #include "SkRandom.h" | |
| 14 #include "SkString.h" | |
| 15 | |
| 16 class EmptyPathView : public SampleView { | |
| 17 public: | |
| 18 EmptyPathView() {} | |
| 19 | |
| 20 protected: | |
| 21 // overrides from SkEventSink | |
| 22 virtual bool onQuery(SkEvent* evt) { | |
| 23 if (SampleCode::TitleQ(*evt)) { | |
| 24 SampleCode::TitleR(evt, "EmptyPath"); | |
| 25 return true; | |
| 26 } | |
| 27 return this->INHERITED::onQuery(evt); | |
| 28 } | |
| 29 | |
| 30 void drawEmpty(SkCanvas* canvas, | |
| 31 SkColor color, | |
| 32 const SkRect& clip, | |
| 33 SkPaint::Style style, | |
| 34 SkPath::FillType fill) { | |
| 35 SkPath path; | |
| 36 path.setFillType(fill); | |
| 37 SkPaint paint; | |
| 38 paint.setColor(color); | |
| 39 paint.setStyle(style); | |
| 40 canvas->save(); | |
| 41 canvas->clipRect(clip); | |
| 42 canvas->drawPath(path, paint); | |
| 43 canvas->restore(); | |
| 44 } | |
| 45 | |
| 46 virtual void onDrawContent(SkCanvas* canvas) { | |
| 47 struct FillAndName { | |
| 48 SkPath::FillType fFill; | |
| 49 const char* fName; | |
| 50 }; | |
| 51 static const FillAndName gFills[] = { | |
| 52 {SkPath::kWinding_FillType, "Winding"}, | |
| 53 {SkPath::kEvenOdd_FillType, "Even / Odd"}, | |
| 54 {SkPath::kInverseWinding_FillType, "Inverse Winding"}, | |
| 55 {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"}, | |
| 56 }; | |
| 57 struct StyleAndName { | |
| 58 SkPaint::Style fStyle; | |
| 59 const char* fName; | |
| 60 }; | |
| 61 static const StyleAndName gStyles[] = { | |
| 62 {SkPaint::kFill_Style, "Fill"}, | |
| 63 {SkPaint::kStroke_Style, "Stroke"}, | |
| 64 {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, | |
| 65 }; | |
| 66 | |
| 67 SkPaint titlePaint; | |
| 68 titlePaint.setColor(SK_ColorBLACK); | |
| 69 titlePaint.setAntiAlias(true); | |
| 70 titlePaint.setLCDRenderText(true); | |
| 71 titlePaint.setTextSize(24 * SK_Scalar1); | |
| 72 const char title[] = "Empty Paths Drawn Into Rectangle Clips With Indica
ted Style and Fill"; | |
| 73 canvas->drawText(title, strlen(title), | |
| 74 40 * SK_Scalar1, | |
| 75 100*SK_Scalar1, | |
| 76 titlePaint); | |
| 77 | |
| 78 SkRandom rand; | |
| 79 SkRect rect = SkRect::MakeWH(125*SK_Scalar1, 100*SK_Scalar1); | |
| 80 int i = 0; | |
| 81 canvas->save(); | |
| 82 canvas->translate(80 * SK_Scalar1, 0); | |
| 83 canvas->save(); | |
| 84 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { | |
| 85 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { | |
| 86 if (0 == i % 4) { | |
| 87 canvas->restore(); | |
| 88 canvas->translate(0, rect.height() + 50 * SK_Scalar1); | |
| 89 canvas->save(); | |
| 90 } else { | |
| 91 canvas->translate(rect.width() + 100 * SK_Scalar1, 0); | |
| 92 } | |
| 93 ++i; | |
| 94 | |
| 95 | |
| 96 SkColor color = rand.nextU(); | |
| 97 color = 0xff000000| color; // force solid | |
| 98 this->drawEmpty(canvas, color, rect, | |
| 99 gStyles[style].fStyle, gFills[fill].fFill); | |
| 100 | |
| 101 SkPaint rectPaint; | |
| 102 rectPaint.setColor(SK_ColorBLACK); | |
| 103 rectPaint.setStyle(SkPaint::kStroke_Style); | |
| 104 rectPaint.setStrokeWidth(-1); | |
| 105 rectPaint.setAntiAlias(true); | |
| 106 canvas->drawRect(rect, rectPaint); | |
| 107 | |
| 108 SkString label; | |
| 109 label.appendf("%s, %s", gStyles[style].fName, gFills[fill].fName
); | |
| 110 | |
| 111 SkPaint labelPaint; | |
| 112 labelPaint.setColor(color); | |
| 113 labelPaint.setAntiAlias(true); | |
| 114 labelPaint.setLCDRenderText(true); | |
| 115 canvas->drawText(label.c_str(), label.size(), | |
| 116 0, rect.height() + 15 * SK_Scalar1, | |
| 117 labelPaint); | |
| 118 } | |
| 119 } | |
| 120 canvas->restore(); | |
| 121 canvas->restore(); | |
| 122 } | |
| 123 | |
| 124 private: | |
| 125 typedef SampleView INHERITED; | |
| 126 }; | |
| 127 | |
| 128 ////////////////////////////////////////////////////////////////////////////// | |
| 129 | |
| 130 static SkView* MyFactory() { return new EmptyPathView; } | |
| 131 static SkViewRegister reg(MyFactory); | |
| OLD | NEW |