blob: 4e6e0cb0f9390b4ce0853d37632cc02f985262f7 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
Ben Wagnerb2c4ea62018-08-08 11:36:17 -04007#include "Sample.h"
reed@google.com7a253372011-05-04 14:34:56 +00008#include "SkCanvas.h"
9#include "SkGraphics.h"
10#include "SkRandom.h"
11#include "SkGradientShader.h"
12#include "SkPicture.h"
13
reedc6f28f72016-03-14 12:22:10 -070014static sk_sp<SkShader> make_linear() {
reed@google.com7a253372011-05-04 14:34:56 +000015 SkPoint pts[] = { 0, 0, SK_Scalar1/500, SK_Scalar1/500 };
16 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
reedc6f28f72016-03-14 12:22:10 -070017 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
reed@google.com7a253372011-05-04 14:34:56 +000018}
19
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040020class ClampView : public Sample {
reedc6f28f72016-03-14 12:22:10 -070021 sk_sp<SkShader> fGrad;
reed@google.com7a253372011-05-04 14:34:56 +000022
23public:
24 ClampView() {
25 fGrad = make_linear();
26 }
27
reed@google.com7a253372011-05-04 14:34:56 +000028protected:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040029 virtual bool onQuery(Sample::Event* evt) {
30 if (Sample::TitleQ(*evt)) {
31 Sample::TitleR(evt, "Clamp");
reed@google.com7a253372011-05-04 14:34:56 +000032 return true;
33 }
34 return this->INHERITED::onQuery(evt);
35 }
36
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
52private:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040053 typedef Sample INHERITED;
reed@google.com7a253372011-05-04 14:34:56 +000054};
55
56//////////////////////////////////////////////////////////////////////////////
57
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040058static Sample* MyFactory() { return new ClampView; }
59static SampleRegister reg(MyFactory);