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