blob: 2d8e3e808485acf6cf2c920dcb771bc555e785e4 [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:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000026 SkString getName() const override { return SkString("testgradient"); }
Tenghui Zhuea479572017-02-09 17:45:46 -080027
Leandro Lovisolo8f023882023-08-15 21:13:52 +000028 SkISize getISize() override { return SkISize::Make(800, 800); }
Tenghui Zhuea479572017-02-09 17:45:46 -080029
30 void onDraw(SkCanvas* canvas) override {
31 // Set up a gradient paint for a rect.
32 // And non-gradient paint for other objects.
33 canvas->drawColor(SK_ColorWHITE);
34
35 SkPaint paint;
36 paint.setStyle(SkPaint::kFill_Style);
37 paint.setAntiAlias(true);
38 paint.setStrokeWidth(4);
39 paint.setColor(0xFFFE938C);
40
41 SkRect rect = SkRect::MakeXYWH(10, 10, 100, 160);
42
43 SkPoint points[2] = {
44 SkPoint::Make(0.0f, 0.0f),
45 SkPoint::Make(256.0f, 256.0f)
46 };
47 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
48 SkPaint newPaint(paint);
49 newPaint.setShader(SkGradientShader::MakeLinear(
Mike Reedfae8fce2019-04-03 10:27:45 -040050 points, colors, nullptr, 2, SkTileMode::kClamp));
Tenghui Zhuea479572017-02-09 17:45:46 -080051 canvas->drawRect(rect, newPaint);
52
53 SkRRect oval;
54 oval.setOval(rect);
55 oval.offset(40, 80);
56 paint.setColor(0xFFE6B89C);
57 canvas->drawRRect(oval, paint);
58
59 paint.setColor(0xFF9CAFB7);
60 canvas->drawCircle(180, 50, 25, paint);
61
62 rect.offset(80, 50);
63 paint.setColor(0xFF4281A4);
64 paint.setStyle(SkPaint::kStroke_Style);
65 canvas->drawRoundRect(rect, 10, 10, paint);
66 }
67
68private:
John Stiles7571f9e2020-09-02 22:42:33 -040069 using INHERITED = skiagm::GM;
Tenghui Zhuea479572017-02-09 17:45:46 -080070};
71
72// Register the GM
73DEF_GM( return new TestGradientGM; )