• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "gm.h"
9 
10 #include "SkCanvas.h"
11 #include "SkGradientShader.h"
12 #include "SkRRect.h"
13 
14 class TestGradientGM : public skiagm::GM {
15 public:
TestGradientGM()16     TestGradientGM() {}
17 
18 protected:
onShortName()19     SkString onShortName() override {
20         return SkString("testgradient");
21     }
22 
onISize()23     SkISize onISize() override {
24         return SkISize::Make(800, 800);
25     }
26 
onDraw(SkCanvas * canvas)27     void onDraw(SkCanvas* canvas) override {
28         // Set up a gradient paint for a rect.
29         // And non-gradient paint for other objects.
30         canvas->drawColor(SK_ColorWHITE);
31 
32         SkPaint paint;
33         paint.setStyle(SkPaint::kFill_Style);
34         paint.setAntiAlias(true);
35         paint.setStrokeWidth(4);
36         paint.setColor(0xFFFE938C);
37 
38         SkRect rect = SkRect::MakeXYWH(10, 10, 100, 160);
39 
40         SkPoint points[2] = {
41             SkPoint::Make(0.0f, 0.0f),
42             SkPoint::Make(256.0f, 256.0f)
43         };
44         SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
45         SkPaint newPaint(paint);
46         newPaint.setShader(SkGradientShader::MakeLinear(
47                 points, colors, nullptr, 2,
48                 SkShader::kClamp_TileMode, 0, nullptr));
49         canvas->drawRect(rect, newPaint);
50 
51         SkRRect oval;
52         oval.setOval(rect);
53         oval.offset(40, 80);
54         paint.setColor(0xFFE6B89C);
55         canvas->drawRRect(oval, paint);
56 
57         paint.setColor(0xFF9CAFB7);
58         canvas->drawCircle(180, 50, 25, paint);
59 
60         rect.offset(80, 50);
61         paint.setColor(0xFF4281A4);
62         paint.setStyle(SkPaint::kStroke_Style);
63         canvas->drawRoundRect(rect, 10, 10, paint);
64     }
65 
66 private:
67     typedef skiagm::GM INHERITED;
68 };
69 
70 // Register the GM
71 DEF_GM( return new TestGradientGM; )
72