epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 7 | #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 | |
reed | c6f28f7 | 2016-03-14 12:22:10 -0700 | [diff] [blame] | 15 | static sk_sp<SkShader> make_linear() { |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 16 | SkPoint pts[] = { 0, 0, SK_Scalar1/500, SK_Scalar1/500 }; |
| 17 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
reed | c6f28f7 | 2016-03-14 12:22:10 -0700 | [diff] [blame] | 18 | return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | class ClampView : public SampleView { |
reed | c6f28f7 | 2016-03-14 12:22:10 -0700 | [diff] [blame] | 22 | sk_sp<SkShader> fGrad; |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 23 | |
| 24 | public: |
| 25 | ClampView() { |
| 26 | fGrad = make_linear(); |
| 27 | } |
| 28 | |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 29 | protected: |
| 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 | |
| 54 | private: |
| 55 | typedef SampleView INHERITED; |
| 56 | }; |
| 57 | |
| 58 | ////////////////////////////////////////////////////////////////////////////// |
| 59 | |
| 60 | static SkView* MyFactory() { return new ClampView; } |
| 61 | static SkViewRegister reg(MyFactory); |