blob: c2e6225f5db44c899bfe651b88c3b08913c36109 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com55b8e8c2011-01-13 16:22:35 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11#include "SkGradientShader.h"
12
13static 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, NULL, 2,
17 SkShader::kClamp_TileMode);
18}
19
reed@google.com0faac1e2011-05-11 05:58:58 +000020class BigGradientView : public SampleView {
reed@google.com55b8e8c2011-01-13 16:22:35 +000021public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000022 BigGradientView() {}
reed@google.com55b8e8c2011-01-13 16:22:35 +000023
24protected:
25 // overrides from SkEventSink
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
reed@google.com0faac1e2011-05-11 05:58:58 +000034 virtual void onDrawContent(SkCanvas* canvas) {
reed@google.com55b8e8c2011-01-13 16:22:35 +000035 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
42private:
reed@google.com0faac1e2011-05-11 05:58:58 +000043 typedef SampleView INHERITED;
reed@google.com55b8e8c2011-01-13 16:22:35 +000044};
45
46///////////////////////////////////////////////////////////////////////////////
47
48static SkView* MyFactory() { return new BigGradientView; }
49static SkViewRegister reg(MyFactory);