blob: 3046cde58fd703a2fc7960dc50c37b4bbbd973d3 [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 */
reed@google.com7a253372011-05-04 14:34:56 +00007#include "SampleCode.h"
8#include "SkView.h"
9#include "SkCanvas.h"
10#include "SkGraphics.h"
11#include "SkRandom.h"
12#include "SkGradientShader.h"
13#include "SkPicture.h"
14
reedc6f28f72016-03-14 12:22:10 -070015static sk_sp<SkShader> make_linear() {
reed@google.com7a253372011-05-04 14:34:56 +000016 SkPoint pts[] = { 0, 0, SK_Scalar1/500, SK_Scalar1/500 };
17 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
reedc6f28f72016-03-14 12:22:10 -070018 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
reed@google.com7a253372011-05-04 14:34:56 +000019}
20
21class ClampView : public SampleView {
reedc6f28f72016-03-14 12:22:10 -070022 sk_sp<SkShader> fGrad;
reed@google.com7a253372011-05-04 14:34:56 +000023
24public:
25 ClampView() {
26 fGrad = make_linear();
27 }
28
reed@google.com7a253372011-05-04 14:34:56 +000029protected:
30 // overrides from SkEventSink
31 virtual bool onQuery(SkEvent* evt) {
32 if (SampleCode::TitleQ(*evt)) {
33 SampleCode::TitleR(evt, "Clamp");
34 return true;
35 }
36 return this->INHERITED::onQuery(evt);
37 }
38
39 virtual void onDrawContent(SkCanvas* canvas) {
40 SkPaint paint;
41 paint.setShader(fGrad);
42
43// canvas->translate(this->width()/2, this->height()/2);
44 canvas->translate(64, 64);
45 canvas->drawPaint(paint);
46
47 SkPicture pic;
48 SkCanvas* c = pic.beginRecording(100, 100, 0);
49 SkCanvas::LayerIter layerIterator(c, false);
50 layerIterator.next();
51 layerIterator.done();
52 }
53
54private:
55 typedef SampleView INHERITED;
56};
57
58//////////////////////////////////////////////////////////////////////////////
59
60static SkView* MyFactory() { return new ClampView; }
61static SkViewRegister reg(MyFactory);