Tenghui Zhu | ea47957 | 2017-02-09 17:45:46 -0800 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkPaint.h" |
| 12 | #include "include/core/SkPoint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkRRect.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | #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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "include/effects/SkGradientShader.h" |
Tenghui Zhu | ea47957 | 2017-02-09 17:45:46 -0800 | [diff] [blame] | 20 | |
| 21 | class TestGradientGM : public skiagm::GM { |
| 22 | public: |
| 23 | TestGradientGM() {} |
| 24 | |
| 25 | protected: |
| 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 Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 54 | points, colors, nullptr, 2, SkTileMode::kClamp)); |
Tenghui Zhu | ea47957 | 2017-02-09 17:45:46 -0800 | [diff] [blame] | 55 | 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 | |
| 72 | private: |
| 73 | typedef skiagm::GM INHERITED; |
| 74 | }; |
| 75 | |
| 76 | // Register the GM |
| 77 | DEF_GM( return new TestGradientGM; ) |