Flutter Engine
The Flutter Engine
testgradient.cpp
Go to the documentation of this file.
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/gm.h"
14#include "include/core/SkRect.h"
16#include "include/core/SkSize.h"
20
21class TestGradientGM : public skiagm::GM {
22public:
24
25protected:
26 SkString getName() const override { return SkString("testgradient"); }
27
28 SkISize getISize() override { return SkISize::Make(800, 800); }
29
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
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 };
48 SkPaint newPaint(paint);
50 points, colors, nullptr, 2, SkTileMode::kClamp));
51 canvas->drawRect(rect, newPaint);
52
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);
65 canvas->drawRoundRect(rect, 10, 10, paint);
66 }
67
68private:
69 using INHERITED = skiagm::GM;
70};
71
72// Register the GM
73DEF_GM( return new TestGradientGM; )
static const int points[]
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:1705
void drawRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint)
Definition: SkCanvas.cpp:2717
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
void setShader(sk_sp< SkShader > shader)
void onDraw(SkCanvas *canvas) override
SkString getName() const override
SkISize getISize() override
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
#define DEF_GM(CODE)
Definition: gm.h:40
SkRect oval
Definition: SkRecords.h:249
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkColor > colors
Definition: SkRecords.h:276
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
void offset(float dx, float dy)
Definition: SkRect.h:1016