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