Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 };
47 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
48 SkPaint newPaint(paint);
50 points, colors, nullptr, 2, SkTileMode::kClamp));
51 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);
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)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
void drawRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
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
const Paint & paint
#define DEF_GM(CODE)
Definition gm.h:40
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkPoint Make(float x, float y)
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