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

Public Member Functions

 ChartSlide ()
 
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 82 of file ChartSlide.cpp.

Constructor & Destructor Documentation

◆ ChartSlide()

ChartSlide::ChartSlide ( )
inline

Definition at line 91 of file ChartSlide.cpp.

91{ fName = "Chart"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void ChartSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 93 of file ChartSlide.cpp.

93 {
94 bool sizeChanged = false;
95 if (canvas->getBaseLayerSize() != fSize) {
96 fSize = canvas->getBaseLayerSize();
97 sizeChanged = true;
98 }
99
100 SkScalar ySpread = SkIntToScalar(fSize.fHeight / 20);
101
103
104 if (sizeChanged) {
105 int dataPointCount = std::max(fSize.fWidth / kPixelsPerTick + 1, 2);
106
107 for (int i = 0; i < kNumGraphs; ++i) {
108 SkScalar y = (kNumGraphs - i) * (height - ySpread) / (kNumGraphs + 1);
109 fData[i].reset();
110 gen_data(y, ySpread, dataPointCount, fData + i);
111 }
112 }
113
114 canvas->clear(0xFFE0F0E0);
115
116 static SkRandom colorRand;
117 static SkColor gColors[kNumGraphs] = { 0x0 };
118 if (0 == gColors[0]) {
119 for (int i = 0; i < kNumGraphs; ++i) {
120 gColors[i] = colorRand.nextU() | 0xff000000;
121 }
122 }
123
124 static const SkScalar kStrokeWidth = SkIntToScalar(2);
125 SkPaint plotPaint;
126 SkPaint fillPaint;
127 plotPaint.setAntiAlias(true);
129 plotPaint.setStrokeWidth(kStrokeWidth);
132 fillPaint.setAntiAlias(true);
134
135 SkPathBuilder plotPath, fillPath;
136 SkTDArray<SkScalar>* prevData = nullptr;
137
138 for (int i = 0; i < kNumGraphs; ++i) {
139 gen_paths(fData[i],
140 prevData,
141 height,
142 0,
143 SkIntToScalar(kPixelsPerTick),
144 fShift,
145 &plotPath,
146 &fillPath);
147
148 // Make the fills partially transparent
149 fillPaint.setColor((gColors[i] & 0x00ffffff) | 0x80000000);
150 canvas->drawPath(fillPath.detach(), fillPaint);
151
152 plotPaint.setColor(gColors[i]);
153 canvas->drawPath(plotPath.detach(), plotPaint);
154
155 prevData = fData + i;
156 }
157
158 fShift += kShiftPerFrame;
159 }
static void gen_paths(const SkTDArray< SkScalar > &topData, const SkTDArray< SkScalar > *bottomData, SkScalar yBase, SkScalar xLeft, SkScalar xDelta, int leftShift, SkPathBuilder *plot, SkPathBuilder *fill)
Definition: ChartSlide.cpp:29
static void gen_data(SkScalar yAvg, SkScalar ySpread, int count, SkTDArray< SkScalar > *dataPts)
Definition: ChartSlide.cpp:16
static const SkColor gColors[]
uint32_t SkColor
Definition: SkColor.h:37
#define SkIntToScalar(x)
Definition: SkScalar.h:57
virtual SkISize getBaseLayerSize() const
Definition: SkCanvas.cpp:369
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
void setStrokeJoin(Join join)
Definition: SkPaint.cpp:189
@ kRound_Join
adds circle
Definition: SkPaint.h:360
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
uint32_t nextU()
Definition: SkRandom.h:42
void reset()
Definition: SkTDArray.h:171
float SkScalar
Definition: extension.cpp:12
static float max(float r, float g, float b)
Definition: hsl.cpp:49
double y
int32_t height
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17

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