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 | 4de4d60 | 2011-07-08 20:12:55 +0000 | [diff] [blame] | 7 | #include "SampleCode.h" |
| 8 | #include "SkView.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkGradientShader.h" |
| 11 | |
| 12 | |
reed | 71a6cbf | 2015-05-04 08:32:51 -0700 | [diff] [blame] | 13 | class TwoPtConicalView : public SampleView { |
reed@google.com | 4de4d60 | 2011-07-08 20:12:55 +0000 | [diff] [blame] | 14 | public: |
reed | 71a6cbf | 2015-05-04 08:32:51 -0700 | [diff] [blame] | 15 | TwoPtConicalView() {} |
reed@google.com | 4de4d60 | 2011-07-08 20:12:55 +0000 | [diff] [blame] | 16 | |
| 17 | protected: |
| 18 | // overrides from SkEventSink |
| 19 | virtual bool onQuery(SkEvent* evt) { |
| 20 | if (SampleCode::TitleQ(*evt)) { |
reed | 71a6cbf | 2015-05-04 08:32:51 -0700 | [diff] [blame] | 21 | SampleCode::TitleR(evt, "2PtConical"); |
reed@google.com | 4de4d60 | 2011-07-08 20:12:55 +0000 | [diff] [blame] | 22 | return true; |
| 23 | } |
| 24 | return this->INHERITED::onQuery(evt); |
| 25 | } |
| 26 | |
| 27 | virtual void onDrawContent(SkCanvas* canvas) { |
| 28 | canvas->translate(SkIntToScalar(10), SkIntToScalar(20)); |
| 29 | |
| 30 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
| 31 | SkPoint c0 = { 0, 0 }; |
| 32 | SkScalar r0 = 100; |
| 33 | SkPoint c1 = { 100, 100 }; |
| 34 | SkScalar r1 = 100; |
reed@google.com | 4de4d60 | 2011-07-08 20:12:55 +0000 | [diff] [blame] | 35 | SkPaint paint; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 36 | paint.setShader(SkGradientShader::MakeTwoPointConical(c0, r0, c1, r1, colors, |
| 37 | nullptr, 2, |
| 38 | SkShader::kClamp_TileMode)); |
reed@google.com | 4de4d60 | 2011-07-08 20:12:55 +0000 | [diff] [blame] | 39 | canvas->drawPaint(paint); |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | typedef SampleView INHERITED; |
| 44 | }; |
| 45 | |
| 46 | ////////////////////////////////////////////////////////////////////////////// |
| 47 | |
reed | 71a6cbf | 2015-05-04 08:32:51 -0700 | [diff] [blame] | 48 | static SkView* MyFactory() { return new TwoPtConicalView; } |
reed@google.com | 4de4d60 | 2011-07-08 20:12:55 +0000 | [diff] [blame] | 49 | static SkViewRegister reg(MyFactory); |