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 | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 7 | |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkGradientShader.h" |
| 12 | |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 13 | static sk_sp<SkShader> make_grad(SkScalar w, SkScalar h) { |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 14 | SkColor colors[] = { 0xFF000000, 0xFF333333 }; |
| 15 | SkPoint pts[] = { { 0, 0 }, { w, h } }; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 16 | return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 17 | } |
| 18 | |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 19 | class BigGradientView : public SampleView { |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 20 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 21 | BigGradientView() {} |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 22 | |
| 23 | protected: |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 24 | bool onQuery(SkEvent* evt) override { |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 25 | if (SampleCode::TitleQ(*evt)) { |
| 26 | SampleCode::TitleR(evt, "BigGradient"); |
| 27 | return true; |
| 28 | } |
| 29 | return this->INHERITED::onQuery(evt); |
| 30 | } |
| 31 | |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 32 | void onDrawContent(SkCanvas* canvas) override { |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 33 | SkRect r; |
| 34 | r.set(0, 0, this->width(), this->height()); |
| 35 | SkPaint p; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 36 | p.setShader(make_grad(this->width(), this->height())); |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 37 | canvas->drawRect(r, p); |
| 38 | } |
| 39 | |
| 40 | private: |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 41 | typedef SampleView INHERITED; |
reed@google.com | 55b8e8c | 2011-01-13 16:22:35 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /////////////////////////////////////////////////////////////////////////////// |
| 45 | |
| 46 | static SkView* MyFactory() { return new BigGradientView; } |
| 47 | static SkViewRegister reg(MyFactory); |