Flutter Engine
 
Loading...
Searching...
No Matches
impeller::DashedLinePathSource Class Reference

A PathSource that generates the various segments of a dashed line. More...

#include <dashed_line_path_source.h>

Inheritance diagram for impeller::DashedLinePathSource:
impeller::PathSource

Public Member Functions

 DashedLinePathSource (Point p0, Point p1, Scalar on_length, Scalar off_length)
 
 ~DashedLinePathSource ()
 
FillType GetFillType () const override
 
Rect GetBounds () const override
 
bool IsConvex () const override
 
void Dispatch (PathReceiver &receiver) const override
 
- Public Member Functions inherited from impeller::PathSource
virtual ~PathSource ()=default
 

Detailed Description

A PathSource that generates the various segments of a dashed line.

Definition at line 15 of file dashed_line_path_source.h.

Constructor & Destructor Documentation

◆ DashedLinePathSource()

impeller::DashedLinePathSource::DashedLinePathSource ( Point  p0,
Point  p1,
Scalar  on_length,
Scalar  off_length 
)

Definition at line 9 of file dashed_line_path_source.cc.

13 : p0_(p0), p1_(p1), on_length_(on_length), off_length_(off_length) {}

◆ ~DashedLinePathSource()

impeller::DashedLinePathSource::~DashedLinePathSource ( )
default

Member Function Documentation

◆ Dispatch()

void impeller::DashedLinePathSource::Dispatch ( PathReceiver receiver) const
overridevirtual

Implements impeller::PathSource.

Definition at line 29 of file dashed_line_path_source.cc.

29 {
30 // Exceptional conditions:
31 // - length is non-positive - result will draw only a "dot"
32 // - off_length is non-positive - no gaps, result is a solid line
33 // - on_length is negative - invalid dashing
34 // Note that a 0 length "on" dash will draw "dot"s every "off" distance
35 // apart so we still generate the dashing for that case.
36 //
37 // Note that Canvas will detect these conditions and use its own DrawLine
38 // method directly for performance reasons for a single line, but in case
39 // someone uses this PathSource with these exceptional cases, we degenerate
40 // gracefully into a single line segment path description below.
41 Scalar length = p0_.GetDistance(p1_);
42 if (length > 0.0f && on_length_ >= 0.0f && off_length_ > 0.0f) {
43 Point delta = (p1_ - p0_) / length; // length > 0 already verified
44
45 Scalar consumed = 0.0f;
46 while (consumed < length) {
47 receiver.MoveTo(p0_ + delta * consumed, false);
48
49 Scalar dash_end = consumed + on_length_;
50 if (dash_end < length) {
51 receiver.LineTo(p0_ + delta * dash_end);
52 } else {
53 receiver.LineTo(p1_);
54 // Should happen anyway due to the math, but let's make it explicit
55 // in case of bit errors. We're done with this line.
56 break;
57 }
58
59 consumed = dash_end + off_length_;
60 }
61 } else {
62 receiver.MoveTo(p0_, false);
63 receiver.LineTo(p1_);
64 }
65}
size_t length
float Scalar
Definition scalar.h:19
TPoint< Scalar > Point
Definition point.h:327
constexpr Type GetDistance(const TPoint &p) const
Definition point.h:200

References impeller::TPoint< T >::GetDistance(), length, impeller::PathReceiver::LineTo(), and impeller::PathReceiver::MoveTo().

Referenced by impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), and impeller::testing::TEST().

◆ GetBounds()

Rect impeller::DashedLinePathSource::GetBounds ( ) const
overridevirtual

Implements impeller::PathSource.

Definition at line 21 of file dashed_line_path_source.cc.

21 {
22 return Rect::MakeLTRB(p0_.x, p0_.y, p1_.x, p1_.y).GetPositive();
23}
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition rect.h:398
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129

References impeller::TRect< T >::GetPositive(), impeller::TRect< Scalar >::MakeLTRB(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), and impeller::testing::TEST().

◆ GetFillType()

FillType impeller::DashedLinePathSource::GetFillType ( ) const
overridevirtual

◆ IsConvex()

bool impeller::DashedLinePathSource::IsConvex ( ) const
overridevirtual

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