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  */
8 #include "SampleCode.h"
9 #include "SkView.h"
10 #include "SkCanvas.h"
11 #include "SkGradientShader.h"
12 
make_grad(SkScalar w,SkScalar h)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, nullptr, 2,
17                                           SkShader::kClamp_TileMode);
18 }
19 
20 class BigGradientView : public SampleView {
21 public:
BigGradientView()22     BigGradientView() {}
23 
24 protected:
25     // overrides from SkEventSink
onQuery(SkEvent * evt)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 
onDrawContent(SkCanvas * canvas)34     virtual void onDrawContent(SkCanvas* canvas) {
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:
43     typedef SampleView INHERITED;
44 };
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 
MyFactory()48 static SkView* MyFactory() { return new BigGradientView; }
49 static SkViewRegister reg(MyFactory);
50