Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
CanvasArc Class Reference
Inheritance diagram for CanvasArc:
MMObject

Public Member Functions

 CanvasArc (SkRandom *random, SkSize size)
 
 ~CanvasArc () override=default
 
void draw (SkCanvas *canvas) override
 
void animate (double) override
 
- Public Member Functions inherited from MMObject
virtual ~MMObject ()=default
 
virtual void draw (SkCanvas *canvas)=0
 
virtual void animate (double)=0
 

Detailed Description

Definition at line 330 of file MotionMarkSlide.cpp.

Constructor & Destructor Documentation

◆ CanvasArc()

CanvasArc::CanvasArc ( SkRandom random,
SkSize  size 
)
inline

Definition at line 332 of file MotionMarkSlide.cpp.

332 {
333 constexpr float kMaxX = 6;
334 constexpr float kMaxY = 3;
335
336 const SkColor baseColors[3] = {
337 0xff101010, 0xff808080, 0xffc0c0c0
338 };
339 const SkColor bonusColors[3] = {
340 0xffe01040, 0xff10c030, 0xffe05010
341 };
342 float distanceX = size.fWidth / kMaxX;
343 float distanceY = size.fHeight / (kMaxY + 1);
344 int randY = random->nextRangeU(0, kMaxY);
345 int randX = random->nextRangeU(0, kMaxX - 1 * (randY % 2));
346
347 fPoint = SkPoint::Make(distanceX * (randX + (randY % 2) / 2), distanceY * (randY + 0.5f));
348
349 fRadius = 20 + std::pow(random->nextF(), 5) * (std::min(distanceX, distanceY) / 1.8f);
350 fStartAngle = random->nextRangeF(0, 2*SK_ScalarPI);
351 fEndAngle = random->nextRangeF(0, 2*SK_ScalarPI);
352 fOmega = (random->nextF() - 0.5f) * 0.3f;
353 fCounterclockwise = random->nextBool();
354 // The MotionMark code appends a random element from an array and appends it to the color
355 // array, then randomly picks from that. We'll just pick that random element and use it
356 // if the index is out of bounds for the base color array.
357 SkColor bonusColor = bonusColors[(randX + sk_float_ceil2int(randY * 0.5f)) % 3];
358 int colorIndex = random->nextRangeU(0, 3);
359 fColor = colorIndex == 3 ? bonusColor : baseColors[colorIndex];
360 fLineWidth = 1 + std::pow(random->nextF(), 5) * 30;
361 fDoStroke = random->nextRangeU(0, 3) != 0;
362 }
static const int kMaxY
static const int kMaxX
uint32_t SkColor
Definition: SkColor.h:37
#define sk_float_ceil2int(x)
#define SK_ScalarPI
Definition: SkScalar.h:21
float nextF()
Definition: SkRandom.h:55
bool nextBool()
Definition: SkRandom.h:117
float nextRangeF(float min, float max)
Definition: SkRandom.h:64
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition: SkRandom.h:80
static float min(float r, float g, float b)
Definition: hsl.cpp:48
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

◆ ~CanvasArc()

CanvasArc::~CanvasArc ( )
overridedefault

Member Function Documentation

◆ animate()

void CanvasArc::animate ( double  )
inlineoverridevirtual

Implements MMObject.

Definition at line 392 of file MotionMarkSlide.cpp.

392 {
393 fStartAngle += fOmega;
394 fEndAngle += fOmega / 2;
395 }

◆ draw()

void CanvasArc::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements MMObject.

Definition at line 366 of file MotionMarkSlide.cpp.

366 {
368 paint.setAntiAlias(true);
369 paint.setColor(fColor);
370 SkRect arcRect = SkRect::MakeXYWH(fPoint.fX - fRadius, fPoint.fY - fRadius,
371 2*fRadius, 2*fRadius);
372
373 float startAngleDeg = fStartAngle * 180.f / SK_ScalarPI;
374 float endAngleDeg = fEndAngle * 180.f / SK_ScalarPI;
375 canonicalize_angle(&startAngleDeg, &endAngleDeg);
376 endAngleDeg = adjust_end_angle(startAngleDeg, endAngleDeg, fCounterclockwise);
377
378 float sweepAngle = startAngleDeg - endAngleDeg;
379
380 if (fDoStroke) {
381 paint.setStrokeWidth(fLineWidth);
383 canvas->drawArc(arcRect, startAngleDeg, sweepAngle, false, paint);
384 } else {
385 paint.setStyle(SkPaint::kFill_Style);
386 // The MotionMark code creates a path for fills via lineTo(point), arc(), lineTo(point).
387 // For now we'll just use drawArc for both but might need to revisit.
388 canvas->drawArc(arcRect, startAngleDeg, sweepAngle, true, paint);
389 }
390 }
void drawArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
Definition: SkCanvas.cpp:2728
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
const Paint & paint
Definition: color_source.cc:38
SkScalar sweepAngle
Definition: SkRecords.h:251
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

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