blob: db3b24fbf5875101180e5477f58d30c2748c3a32 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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.com4de4d602011-07-08 20:12:55 +00007#include "SampleCode.h"
8#include "SkView.h"
9#include "SkCanvas.h"
10#include "SkGradientShader.h"
11
12
reed71a6cbf2015-05-04 08:32:51 -070013class TwoPtConicalView : public SampleView {
reed@google.com4de4d602011-07-08 20:12:55 +000014public:
reed71a6cbf2015-05-04 08:32:51 -070015 TwoPtConicalView() {}
reed@google.com4de4d602011-07-08 20:12:55 +000016
17protected:
18 // overrides from SkEventSink
19 virtual bool onQuery(SkEvent* evt) {
20 if (SampleCode::TitleQ(*evt)) {
reed71a6cbf2015-05-04 08:32:51 -070021 SampleCode::TitleR(evt, "2PtConical");
reed@google.com4de4d602011-07-08 20:12:55 +000022 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.com4de4d602011-07-08 20:12:55 +000035 SkPaint paint;
reed8a21c9f2016-03-08 18:50:00 -080036 paint.setShader(SkGradientShader::MakeTwoPointConical(c0, r0, c1, r1, colors,
37 nullptr, 2,
38 SkShader::kClamp_TileMode));
reed@google.com4de4d602011-07-08 20:12:55 +000039 canvas->drawPaint(paint);
40 }
41
42private:
43 typedef SampleView INHERITED;
44};
45
46//////////////////////////////////////////////////////////////////////////////
47
reed71a6cbf2015-05-04 08:32:51 -070048static SkView* MyFactory() { return new TwoPtConicalView; }
reed@google.com4de4d602011-07-08 20:12:55 +000049static SkViewRegister reg(MyFactory);