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