blob: 9fa3925ff6f1e6426215a24a93dd4c973100f342 [file] [log] [blame]
Tenghui Zhuea479572017-02-09 17:45:46 -08001/*
2 * Copyright 2017 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 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkColor.h"
11#include "include/core/SkPaint.h"
12#include "include/core/SkPoint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkRRect.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkRect.h"
15#include "include/core/SkShader.h"
16#include "include/core/SkSize.h"
17#include "include/core/SkString.h"
18#include "include/core/SkTileMode.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "include/effects/SkGradientShader.h"
Tenghui Zhuea479572017-02-09 17:45:46 -080020
21class TestGradientGM : public skiagm::GM {
22public:
23 TestGradientGM() {}
24
25protected:
26 SkString onShortName() override {
27 return SkString("testgradient");
28 }
29
30 SkISize onISize() override {
31 return SkISize::Make(800, 800);
32 }
33
34 void onDraw(SkCanvas* canvas) override {
35 // Set up a gradient paint for a rect.
36 // And non-gradient paint for other objects.
37 canvas->drawColor(SK_ColorWHITE);
38
39 SkPaint paint;
40 paint.setStyle(SkPaint::kFill_Style);
41 paint.setAntiAlias(true);
42 paint.setStrokeWidth(4);
43 paint.setColor(0xFFFE938C);
44
45 SkRect rect = SkRect::MakeXYWH(10, 10, 100, 160);
46
47 SkPoint points[2] = {
48 SkPoint::Make(0.0f, 0.0f),
49 SkPoint::Make(256.0f, 256.0f)
50 };
51 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
52 SkPaint newPaint(paint);
53 newPaint.setShader(SkGradientShader::MakeLinear(
Mike Reedfae8fce2019-04-03 10:27:45 -040054 points, colors, nullptr, 2, SkTileMode::kClamp));
Tenghui Zhuea479572017-02-09 17:45:46 -080055 canvas->drawRect(rect, newPaint);
56
57 SkRRect oval;
58 oval.setOval(rect);
59 oval.offset(40, 80);
60 paint.setColor(0xFFE6B89C);
61 canvas->drawRRect(oval, paint);
62
63 paint.setColor(0xFF9CAFB7);
64 canvas->drawCircle(180, 50, 25, paint);
65
66 rect.offset(80, 50);
67 paint.setColor(0xFF4281A4);
68 paint.setStyle(SkPaint::kStroke_Style);
69 canvas->drawRoundRect(rect, 10, 10, paint);
70 }
71
72private:
73 typedef skiagm::GM INHERITED;
74};
75
76// Register the GM
77DEF_GM( return new TestGradientGM; )