blob: 8ae099051b4457f11e3301211cb9a03015c0ef26 [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 */
reed8a21c9f2016-03-08 18:50:00 -08007
reed@google.com55b8e8c2011-01-13 16:22:35 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11#include "SkGradientShader.h"
12
reed8a21c9f2016-03-08 18:50:00 -080013static sk_sp<SkShader> make_grad(SkScalar w, SkScalar h) {
reed@google.com55b8e8c2011-01-13 16:22:35 +000014 SkColor colors[] = { 0xFF000000, 0xFF333333 };
15 SkPoint pts[] = { { 0, 0 }, { w, h } };
reed8a21c9f2016-03-08 18:50:00 -080016 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
reed@google.com55b8e8c2011-01-13 16:22:35 +000017}
18
reed@google.com0faac1e2011-05-11 05:58:58 +000019class BigGradientView : public SampleView {
reed@google.com55b8e8c2011-01-13 16:22:35 +000020public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000021 BigGradientView() {}
reed@google.com55b8e8c2011-01-13 16:22:35 +000022
23protected:
reed8a21c9f2016-03-08 18:50:00 -080024 bool onQuery(SkEvent* evt) override {
reed@google.com55b8e8c2011-01-13 16:22:35 +000025 if (SampleCode::TitleQ(*evt)) {
26 SampleCode::TitleR(evt, "BigGradient");
27 return true;
28 }
29 return this->INHERITED::onQuery(evt);
30 }
31
reed8a21c9f2016-03-08 18:50:00 -080032 void onDrawContent(SkCanvas* canvas) override {
reed@google.com55b8e8c2011-01-13 16:22:35 +000033 SkRect r;
34 r.set(0, 0, this->width(), this->height());
35 SkPaint p;
reed8a21c9f2016-03-08 18:50:00 -080036 p.setShader(make_grad(this->width(), this->height()));
reed@google.com55b8e8c2011-01-13 16:22:35 +000037 canvas->drawRect(r, p);
38 }
39
40private:
reed@google.com0faac1e2011-05-11 05:58:58 +000041 typedef SampleView INHERITED;
reed@google.com55b8e8c2011-01-13 16:22:35 +000042};
43
44///////////////////////////////////////////////////////////////////////////////
45
46static SkView* MyFactory() { return new BigGradientView; }
47static SkViewRegister reg(MyFactory);