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

Public Member Functions

 ShadowRefSlide ()
 
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 21 of file ShadowReferenceSlide.cpp.

Constructor & Destructor Documentation

◆ ShadowRefSlide()

ShadowRefSlide::ShadowRefSlide ( )
inline

Definition at line 31 of file ShadowReferenceSlide.cpp.

32 : fShowAmbient(true)
33 , fShowSpot(true)
34 , fUseAlt(false)
35 , fShowObject(true) {
36 fName = "ShadowReference";
37 }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void ShadowRefSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 72 of file ShadowReferenceSlide.cpp.

72 {
73 this->drawBG(canvas);
74 const SkScalar kDP = 4; // the reference image is 4x bigger than it is displayed on
75 // on the web page, so we need to reflect that here and
76 // multiply the heights and light params accordingly
77 const SkScalar kLightWidth = kDP*400;
78 const SkScalar kAmbientAlpha = 0.03f;
79 const SkScalar kSpotAlpha = 0.35f;
80
82 paint.setAntiAlias(true);
83 paint.setColor(SK_ColorWHITE);
84
85 SkPoint3 lightPos = { 175, -800, kDP * 600 };
86 SkScalar xPos = 230;
87 SkScalar yPos = 254.25f;
88 SkRect clipRect = SkRect::MakeXYWH(45, 75, 122, 250);
89 SkPoint clipDelta = SkPoint::Make(320, 0);
90 SkPoint3 zPlaneParams = SkPoint3::Make(0, 0, kDP * 2);
91
92 canvas->save();
93 canvas->clipRect(clipRect);
94 canvas->translate(xPos, yPos);
95 this->drawShadowedPath(canvas, fRRectPath, zPlaneParams, paint, kAmbientAlpha,
96 lightPos, kLightWidth, kSpotAlpha);
97 canvas->restore();
98
99 lightPos.fX += 320;
100 xPos += 320;
101 clipRect.offset(clipDelta);
102 zPlaneParams.fZ = kDP * 3;
103 canvas->save();
104 canvas->clipRect(clipRect);
105 canvas->translate(xPos, yPos);
106 this->drawShadowedPath(canvas, fRRectPath, zPlaneParams, paint, kAmbientAlpha,
107 lightPos, kLightWidth, kSpotAlpha);
108 canvas->restore();
109
110 lightPos.fX += 320;
111 xPos += 320;
112 clipRect.offset(clipDelta);
113 zPlaneParams.fZ = kDP * 4;
114 canvas->save();
115 canvas->clipRect(clipRect);
116 canvas->translate(xPos, yPos);
117 this->drawShadowedPath(canvas, fRRectPath, zPlaneParams, paint, kAmbientAlpha,
118 lightPos, kLightWidth, kSpotAlpha);
119 canvas->restore();
120
121 lightPos.fX += 320;
122 xPos += 320;
123 clipRect.offset(clipDelta);
124 zPlaneParams.fZ = kDP * 6;
125 canvas->save();
126 canvas->clipRect(clipRect);
127 canvas->translate(xPos, yPos);
128 this->drawShadowedPath(canvas, fRRectPath, zPlaneParams, paint, kAmbientAlpha,
129 lightPos, kLightWidth, kSpotAlpha);
130 canvas->restore();
131
132 lightPos.fX += 320;
133 xPos += 320;
134 clipRect.offset(clipDelta);
135 zPlaneParams.fZ = kDP * 8;
136 canvas->save();
137 canvas->clipRect(clipRect);
138 canvas->translate(xPos, yPos);
139 this->drawShadowedPath(canvas, fRRectPath, zPlaneParams, paint, kAmbientAlpha,
140 lightPos, kLightWidth, kSpotAlpha);
141 canvas->restore();
142
143 lightPos.fX += 320;
144 xPos += 320;
145 clipRect.offset(clipDelta);
146 zPlaneParams.fZ = kDP * 16;
147 canvas->save();
148 canvas->clipRect(clipRect);
149 canvas->translate(xPos, yPos);
150 this->drawShadowedPath(canvas, fRRectPath, zPlaneParams, paint, kAmbientAlpha,
151 lightPos, kLightWidth, kSpotAlpha);
152 canvas->restore();
153
154 }
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
SkScalar fX
Definition: SkPoint3.h:16
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
SkScalar fZ
Definition: SkPoint3.h:16
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

◆ load()

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

Reimplemented from Slide.

Definition at line 39 of file ShadowReferenceSlide.cpp.

39 {
40 fRRectPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-130, -128.5, 130, 128.5), 4, 4));
41 fReferenceImage = ToolUtils::GetResourceAsImage("images/shadowreference.png");
42 }
SkPath & addRRect(const SkRRect &rrect, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1000
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.h:180
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25

◆ onChar()

bool ShadowRefSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 44 of file ShadowReferenceSlide.cpp.

44 {
45 bool handled = false;
46 switch (uni) {
47 case 'W':
48 fShowAmbient = !fShowAmbient;
49 handled = true;
50 break;
51 case 'S':
52 fShowSpot = !fShowSpot;
53 handled = true;
54 break;
55 case 'T':
56 fUseAlt = !fUseAlt;
57 handled = true;
58 break;
59 case 'O':
60 fShowObject = !fShowObject;
61 handled = true;
62 break;
63 default:
64 break;
65 }
66 if (handled) {
67 return true;
68 }
69 return false;
70 }

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