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

Public Member Functions

 ShadowColorSlide ()
 
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 ShadowColorSlide.cpp.

Constructor & Destructor Documentation

◆ ShadowColorSlide()

ShadowColorSlide::ShadowColorSlide ( )
inline

Definition at line 33 of file ShadowColorSlide.cpp.

34 : fZIndex(8)
35 , fShowAmbient(true)
36 , fShowSpot(true)
37 , fUseAlt(false)
38 , fShowObject(true)
39 , fTwoPassColor(false)
40 , fDarkBackground(false) {
41 fName = "ShadowColor";
42 }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void ShadowColorSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 92 of file ShadowColorSlide.cpp.

92 {
93 const SkScalar kLightWidth = 600;
94 const SkScalar kAmbientAlpha = 0.03f;
95 const SkScalar kSpotAlpha = 0.25f;
96
97 const SkScalar kZValues[10] = { 1, 2, 3, 4, 6, 8, 9, 12, 16, 24 };
98
99 const SkColor kColors[30] = {
100 // purples
101 0xFF3A0072, 0xFF5D0099, 0xFF7F12B2, 0xFFA02AD1, 0xFFC245E5,
102 0xFFE95AF9, 0xFFFC79F0, 0xFFFDA6F0, 0xFFFFCCF8, 0xFFFFE1F9,
103 // oranges
104 0xFFEA3200, 0xFFFF4E00, 0xFFFF7300, 0xFFFF9100, 0xFFFFB000,
105 0xFFFFCE00, 0xFFFFE000, 0xFFFFF64D, 0xFFFFF98F, 0xFFFFFBCC,
106 // teals
107 0xFF004D51, 0xFF066266, 0xFF057F7F, 0xFF009999, 0xFF00B2B2,
108 0xFF15CCBE, 0xFF25E5CE, 0xFF2CFFE0, 0xFF80FFEA, 0xFFB3FFF0
109 };
110
113 paint.setAntiAlias(true);
114 if (fDarkBackground) {
115 canvas->drawColor(0xFF111111);
116 paint.setColor(SK_ColorWHITE);
117 } else {
118 canvas->drawColor(0xFFEAEAEA);
119 paint.setColor(SK_ColorBLACK);
120 }
121 if (fTwoPassColor) {
122 canvas->drawString("Two pass", 10, 15, font, paint);
123 } else {
124 canvas->drawString("One pass", 10, 15, font, paint);
125 }
126
127 SkPoint3 lightPos = { 75, -400, 600 };
128 SkPoint3 zPlaneParams = SkPoint3::Make(0, 0, kZValues[fZIndex]);
129 SkScalar yPos = 75;
130
131 for (int row = 0; row < 3; ++row) {
132 lightPos.fX = 75;
133 SkScalar xPos = 75;
134 for (int col = 0; col < 10; ++col) {
135 paint.setColor(kColors[10*row + col]);
136
137 canvas->save();
138 canvas->translate(xPos, yPos);
139 this->drawShadowedPath(canvas, fRectPath, zPlaneParams, paint, kAmbientAlpha,
140 lightPos, kLightWidth, kSpotAlpha);
141 canvas->restore();
142
143 lightPos.fX += 120;
144 xPos += 120;
145 }
146
147 lightPos.fY += 200;
148 yPos += 200;
149 }
150 }
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
SkFont DefaultFont()
const DlColor kColors[]
font
Font Metadata and Metrics.
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

◆ load()

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

Reimplemented from Slide.

Definition at line 44 of file ShadowColorSlide.cpp.

44 {
45 fRectPath.addRect(SkRect::MakeXYWH(-50, -50, 100, 100));
46 }
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Definition: SkPath.cpp:864
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ onChar()

bool ShadowColorSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 48 of file ShadowColorSlide.cpp.

48 {
49 bool handled = false;
50 switch (uni) {
51 case 'W':
52 fShowAmbient = !fShowAmbient;
53 handled = true;
54 break;
55 case 'S':
56 fShowSpot = !fShowSpot;
57 handled = true;
58 break;
59 case 'T':
60 fUseAlt = !fUseAlt;
61 handled = true;
62 break;
63 case 'O':
64 fShowObject = !fShowObject;
65 handled = true;
66 break;
67 case 'X':
68 fTwoPassColor = !fTwoPassColor;
69 handled = true;
70 break;
71 case 'Z':
72 fDarkBackground = !fDarkBackground;
73 handled = true;
74 break;
75 case '>':
76 fZIndex = std::min(9, fZIndex+1);
77 handled = true;
78 break;
79 case '<':
80 fZIndex = std::max(0, fZIndex-1);
81 handled = true;
82 break;
83 default:
84 break;
85 }
86 if (handled) {
87 return true;
88 }
89 return false;
90 }
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

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