Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
 

Detailed Description

Definition at line 328 of file MotionMarkSlide.cpp.

Constructor & Destructor Documentation

◆ CanvasArc()

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

Definition at line 330 of file MotionMarkSlide.cpp.

330 {
331 constexpr float kMaxX = 6;
332 constexpr float kMaxY = 3;
333
334 const SkColor baseColors[3] = {
335 0xff101010, 0xff808080, 0xffc0c0c0
336 };
337 const SkColor bonusColors[3] = {
338 0xffe01040, 0xff10c030, 0xffe05010
339 };
340 float distanceX = size.fWidth / kMaxX;
341 float distanceY = size.fHeight / (kMaxY + 1);
342 int randY = random->nextRangeU(0, kMaxY);
343 int randX = random->nextRangeU(0, kMaxX - 1 * (randY % 2));
344
345 fPoint = SkPoint::Make(distanceX * (randX + (randY % 2) / 2), distanceY * (randY + 0.5f));
346
347 fRadius = 20 + std::pow(random->nextF(), 5) * (std::min(distanceX, distanceY) / 1.8f);
348 fStartAngle = random->nextRangeF(0, 2*SK_ScalarPI);
349 fEndAngle = random->nextRangeF(0, 2*SK_ScalarPI);
350 fOmega = (random->nextF() - 0.5f) * 0.3f;
351 fCounterclockwise = random->nextBool();
352 // The MotionMark code appends a random element from an array and appends it to the color
353 // array, then randomly picks from that. We'll just pick that random element and use it
354 // if the index is out of bounds for the base color array.
355 SkColor bonusColor = bonusColors[(randX + sk_float_ceil2int(randY * 0.5f)) % 3];
356 int colorIndex = random->nextRangeU(0, 3);
357 fColor = colorIndex == 3 ? bonusColor : baseColors[colorIndex];
358 fLineWidth = 1 + std::pow(random->nextF(), 5) * 30;
359 fDoStroke = random->nextRangeU(0, 3) != 0;
360 }
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
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)

◆ ~CanvasArc()

CanvasArc::~CanvasArc ( )
overridedefault

Member Function Documentation

◆ animate()

void CanvasArc::animate ( double  )
inlineoverridevirtual

Implements MMObject.

Definition at line 390 of file MotionMarkSlide.cpp.

390 {
391 fStartAngle += fOmega;
392 fEndAngle += fOmega / 2;
393 }

◆ draw()

void CanvasArc::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements MMObject.

Definition at line 364 of file MotionMarkSlide.cpp.

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