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 | */ |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 7 | #include "Sample.h" |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 8 | #include "SkCanvas.h" |
| 9 | #include "SkGraphics.h" |
| 10 | #include "SkRandom.h" |
| 11 | #include "SkGradientShader.h" |
| 12 | #include "SkPicture.h" |
| 13 | |
reed | c6f28f7 | 2016-03-14 12:22:10 -0700 | [diff] [blame] | 14 | static sk_sp<SkShader> make_linear() { |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 15 | SkPoint pts[] = { 0, 0, SK_Scalar1/500, SK_Scalar1/500 }; |
| 16 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
reed | c6f28f7 | 2016-03-14 12:22:10 -0700 | [diff] [blame] | 17 | return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 18 | } |
| 19 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 20 | class ClampView : public Sample { |
reed | c6f28f7 | 2016-03-14 12:22:10 -0700 | [diff] [blame] | 21 | sk_sp<SkShader> fGrad; |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 22 | |
| 23 | public: |
| 24 | ClampView() { |
| 25 | fGrad = make_linear(); |
| 26 | } |
| 27 | |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 28 | protected: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 29 | virtual bool onQuery(Sample::Event* evt) { |
| 30 | if (Sample::TitleQ(*evt)) { |
| 31 | Sample::TitleR(evt, "Clamp"); |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 32 | 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 | |
| 52 | private: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 53 | typedef Sample INHERITED; |
reed@google.com | 7a25337 | 2011-05-04 14:34:56 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | ////////////////////////////////////////////////////////////////////////////// |
| 57 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 58 | static Sample* MyFactory() { return new ClampView; } |
| 59 | static SampleRegister reg(MyFactory); |