Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
ShadowUtilsSlide Class Reference
Inheritance diagram for ShadowUtilsSlide:
Slide SkRefCnt SkRefCntBase

Public Member Functions

 ShadowUtilsSlide ()
 
void load (SkScalar w, SkScalar h) override
 
bool onChar (SkUnichar uni) override
 
void draw (SkCanvas *canvas) override
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 24 of file ShadowUtilsSlide.cpp.

Constructor & Destructor Documentation

◆ ShadowUtilsSlide()

ShadowUtilsSlide::ShadowUtilsSlide ( )
inline

Definition at line 36 of file ShadowUtilsSlide.cpp.

37 : fZDelta(0)
38 , fShowAmbient(true)
39 , fShowSpot(true)
40 , fUseAlt(false)
41 , fShowObject(false)
42 , fIgnoreShadowAlpha(false) {
43 fName = "ShadowUtils";
44 }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void ShadowUtilsSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 117 of file ShadowUtilsSlide.cpp.

117 {
118 this->drawBG(canvas);
119
120 static constexpr int kW = 800;
121 static constexpr SkScalar kPad = 15.f;
122 static constexpr SkScalar kLightR = 100.f;
123 static constexpr SkScalar kHeight = 50.f;
124 static constexpr SkScalar kAmbientAlpha = 0.5f;
125 static constexpr SkScalar kSpotAlpha = 0.5f;
126 static constexpr SkPoint3 lightPos = { 250, 400, 500 };
127
128 canvas->translate(3 * kPad, 3 * kPad);
129 canvas->save();
130 SkScalar x = 0;
131 SkScalar dy = 0;
132 SkTDArray<SkMatrix> matrices;
133 matrices.append()->reset();
134 matrices.append()->setRotate(33.f, 25.f, 25.f).postScale(1.2f, 0.8f, 25.f, 25.f);
135 SkPaint greenPaint;
136 greenPaint.setColor(SK_ColorGREEN);
137 greenPaint.setAntiAlias(true);
138 SkPoint3 zPlaneParams = SkPoint3::Make(0, 0, std::max(1.0f, kHeight + fZDelta));
139
140 // convex paths
141 for (auto& m : matrices) {
143 for (const auto& path : fConvexPaths) {
144 SkRect postMBounds = path.getBounds();
145 m.mapRect(&postMBounds);
146 SkScalar w = postMBounds.width() + kHeight;
147 SkScalar dx = w + kPad;
148 if (x + dx > kW - 3 * kPad) {
149 canvas->restore();
150 canvas->translate(0, dy);
151 canvas->save();
152 x = 0;
153 dy = 0;
154 }
155
156 canvas->save();
157 canvas->concat(m);
158 this->drawShadowedPath(canvas, path, zPlaneParams, greenPaint, kAmbientAlpha,
159 lightPos, kLightR, kSpotAlpha, flags);
160 canvas->restore();
161
162 canvas->translate(dx, 0);
163 x += dx;
164 dy = std::max(dy, postMBounds.height() + kPad + kHeight);
165 }
166 }
167 }
168
169 // concave paths
170 canvas->restore();
171 canvas->translate(kPad, dy);
172 canvas->save();
173 x = kPad;
174 dy = 0;
175 for (auto& m : matrices) {
176 for (const auto& path : fConcavePaths) {
177 SkRect postMBounds = path.getBounds();
178 m.mapRect(&postMBounds);
179 SkScalar w = postMBounds.width();
180 SkScalar dx = w + kPad;
181
182 canvas->save();
183 canvas->concat(m);
184 this->drawShadowedPath(canvas, path, zPlaneParams, greenPaint, kAmbientAlpha,
185 lightPos, kLightR, kSpotAlpha, kNone_ShadowFlag);
186 canvas->restore();
187
188 canvas->translate(dx, 0);
189 x += dx;
190 dy = std::max(dy, postMBounds.height() + kPad + kHeight);
191 }
192 }
193
194 // Show where the light is in x,y as a circle (specified in device space).
195 SkMatrix invCanvasM = canvas->getTotalMatrix();
196 if (invCanvasM.invert(&invCanvasM)) {
197 canvas->save();
198 canvas->concat(invCanvasM);
199 SkPaint blackPaint;
200 blackPaint.setColor(SK_ColorBLACK);
201 blackPaint.setAntiAlias(true);
202 canvas->drawCircle(lightPos.fX, lightPos.fY, kLightR / 10.f, blackPaint);
203 canvas->restore();
204 }
205 }
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
@ kTransparentOccluder_ShadowFlag
Definition: SkShadowUtils.h:27
@ kNone_ShadowFlag
Definition: SkShadowUtils.h:24
constexpr int kPad
constexpr int kW
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
bool invert(SkMatrix *inverse) const
Definition: SkMatrix.h:1206
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
T * append()
Definition: SkTDArray.h:191
float SkScalar
Definition: extension.cpp:12
FlutterSemanticsFlag flags
static float max(float r, float g, float b)
Definition: hsl.cpp:49
double x
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
SkScalar w
SkScalar fX
Definition: SkPoint3.h:16
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
SkScalar fY
Definition: SkPoint3.h:16
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762

◆ load()

void ShadowUtilsSlide::load ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 46 of file ShadowUtilsSlide.cpp.

46 {
47 fConvexPaths.push_back().addRoundRect(SkRect::MakeWH(50, 50), 10, 10);
48 SkRRect oddRRect;
49 oddRRect.setNinePatch(SkRect::MakeWH(50, 50), 9, 13, 6, 16);
50 fConvexPaths.push_back().addRRect(oddRRect);
51 fConvexPaths.push_back().addRect(SkRect::MakeWH(50, 50));
52 fConvexPaths.push_back().addCircle(25, 25, 25);
53 fConvexPaths.push_back().cubicTo(100, 50, 20, 100, 0, 0);
54 fConvexPaths.push_back().addOval(SkRect::MakeWH(20, 60));
55
56 // star
57 fConcavePaths.push_back().moveTo(0.0f, -33.3333f);
58 fConcavePaths.back().lineTo(9.62f, -16.6667f);
59 fConcavePaths.back().lineTo(28.867f, -16.6667f);
60 fConcavePaths.back().lineTo(19.24f, 0.0f);
61 fConcavePaths.back().lineTo(28.867f, 16.6667f);
62 fConcavePaths.back().lineTo(9.62f, 16.6667f);
63 fConcavePaths.back().lineTo(0.0f, 33.3333f);
64 fConcavePaths.back().lineTo(-9.62f, 16.6667f);
65 fConcavePaths.back().lineTo(-28.867f, 16.6667f);
66 fConcavePaths.back().lineTo(-19.24f, 0.0f);
67 fConcavePaths.back().lineTo(-28.867f, -16.6667f);
68 fConcavePaths.back().lineTo(-9.62f, -16.6667f);
69 fConcavePaths.back().close();
70
71 // dumbbell
72 fConcavePaths.push_back().moveTo(50, 0);
73 fConcavePaths.back().cubicTo(100, 25, 60, 50, 50, 0);
74 fConcavePaths.back().cubicTo(0, -25, 40, -50, 50, 0);
75 }
SkPath & addCircle(SkScalar x, SkScalar y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1213
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
SkPath & addRRect(const SkRRect &rrect, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1000
SkPath & addRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1093
SkPath & addOval(const SkRect &oval, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1106
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Definition: SkPath.cpp:799
SkPath & close()
Definition: SkPath.cpp:823
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Definition: SkPath.cpp:864
void setNinePatch(const SkRect &rect, SkScalar leftRad, SkScalar topRad, SkScalar rightRad, SkScalar bottomRad)
Definition: SkRRect.cpp:115
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ onChar()

bool ShadowUtilsSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 77 of file ShadowUtilsSlide.cpp.

77 {
78 bool handled = false;
79 switch (uni) {
80 case 'W':
81 fShowAmbient = !fShowAmbient;
82 handled = true;
83 break;
84 case 'S':
85 fShowSpot = !fShowSpot;
86 handled = true;
87 break;
88 case 'T':
89 fUseAlt = !fUseAlt;
90 handled = true;
91 break;
92 case 'O':
93 fShowObject = !fShowObject;
94 handled = true;
95 break;
96 case '>':
97 fZDelta += 0.5f;
98 handled = true;
99 break;
100 case '<':
101 fZDelta -= 0.5f;
102 handled = true;
103 break;
104 case '?':
105 fIgnoreShadowAlpha = !fIgnoreShadowAlpha;
106 handled = true;
107 break;
108 default:
109 break;
110 }
111 if (handled) {
112 return true;
113 }
114 return false;
115 }

The documentation for this class was generated from the following file: