1 #include "SampleCode.h" 2 #include "SkView.h" 3 #include "SkCanvas.h" 4 #include "SkGraphics.h" 5 #include "SkRandom.h" 6 #include "SkGradientShader.h" 7 #include "SkPicture.h" 8 9 static SkShader* make_linear() { 10 SkPoint pts[] = { 0, 0, SK_Scalar1/500, SK_Scalar1/500 }; 11 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; 12 return SkGradientShader::CreateLinear(pts, colors, NULL, 2, 13 SkShader::kClamp_TileMode); 14 } 15 16 class ClampView : public SampleView { 17 SkShader* fGrad; 18 19 public: 20 ClampView() { 21 fGrad = make_linear(); 22 } 23 24 virtual ~ClampView() { 25 fGrad->unref(); 26 } 27 28 protected: 29 // overrides from SkEventSink 30 virtual bool onQuery(SkEvent* evt) { 31 if (SampleCode::TitleQ(*evt)) { 32 SampleCode::TitleR(evt, "Clamp"); 33 return true; 34 } 35 return this->INHERITED::onQuery(evt); 36 } 37 38 virtual void onDrawContent(SkCanvas* canvas) { 39 SkPaint paint; 40 paint.setShader(fGrad); 41 42 // canvas->translate(this->width()/2, this->height()/2); 43 canvas->translate(64, 64); 44 canvas->drawPaint(paint); 45 46 SkPicture pic; 47 SkCanvas* c = pic.beginRecording(100, 100, 0); 48 SkCanvas::LayerIter layerIterator(c, false); 49 layerIterator.next(); 50 layerIterator.done(); 51 } 52 53 private: 54 typedef SampleView INHERITED; 55 }; 56 57 ////////////////////////////////////////////////////////////////////////////// 58 59 static SkView* MyFactory() { return new ClampView; } 60 static SkViewRegister reg(MyFactory); 61 62