blob: e319a56dc4f3d59f835a56536c0ce4b5cb945b17 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
reed@google.com7a253372011-05-04 14:34:56 +00008#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
16static SkShader* make_linear() {
17 SkPoint pts[] = { 0, 0, SK_Scalar1/500, SK_Scalar1/500 };
18 SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
halcanary96fcdcc2015-08-27 07:41:13 -070019 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
reed@google.com7a253372011-05-04 14:34:56 +000020 SkShader::kClamp_TileMode);
21}
22
23class ClampView : public SampleView {
24 SkShader* fGrad;
25
26public:
27 ClampView() {
28 fGrad = make_linear();
29 }
30
31 virtual ~ClampView() {
32 fGrad->unref();
33 }
34
35protected:
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
60private:
61 typedef SampleView INHERITED;
62};
63
64//////////////////////////////////////////////////////////////////////////////
65
66static SkView* MyFactory() { return new ClampView; }
67static SkViewRegister reg(MyFactory);