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