Flutter Engine
The Flutter Engine
Functions
GradientShader_MakeLinear.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (GradientShader_MakeLinear, 201, 201, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( GradientShader_MakeLinear  ,
201  ,
201  ,
false  ,
 
)

Definition at line 4 of file GradientShader_MakeLinear.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 // This fiddle draws 4 instances of a LinearGradient, demonstrating
7 // how the local matrix affects the gradient as well as the flag
8 // which controls unpremul vs premul color interpolation.
9
10 SkPaint strokePaint;
12 strokePaint.setColor(SK_ColorBLACK);
13
14 SkPaint p;
15 p.setStyle(SkPaint::kFill_Style);
16
17 SkColor transparentGreen = SkColorSetARGB(0, 0, 255, 255);
18 SkColor colors[] = { transparentGreen, SK_ColorBLUE, SK_ColorRED };
19 SkScalar positions[] = { 0.0, 0.65, 1.0 };
20
21 for (int i = 0; i < 4; i++) {
22 SkScalar blockX = (i % 2) * 100;
23 SkScalar blockY = (i / 2) * 100;
24 SkPoint pts[] = { {blockX, blockY}, {blockX + 50, blockY + 100} };
25
26 int flags = 0; // interpolate colors in unpremul
27 if (i % 2 == 1) {
28 // right column will have premul
29 flags = SkGradientShader::Flags::kInterpolateColorsInPremul_Flag;
30 }
31
32 SkMatrix matr = SkMatrix::I();
33 if (i / 2 == 1) {
34 // bottom row will be rotated 45 degrees.
35 matr.setRotate(45, blockX, blockY);
36 }
37
39 pts, colors, positions, 3, SkTileMode::kMirror,
40 flags, &matr);
41
42 p.setShader(lgs);
43 auto r = SkRect::MakeLTRB(blockX, blockY, blockX + 100, blockY + 100);
44 canvas->drawRect(r, p);
45 canvas->drawRect(r, strokePaint);
46 }
47}
48} // END FIDDLE
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
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)
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
float SkScalar
Definition: extension.cpp:12
FlutterSemanticsFlag flags
PODArray< SkColor > colors
Definition: SkRecords.h:276
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646