Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
PathClipSlide.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkGraphics.h"
#include "include/core/SkPath.h"
#include "include/core/SkRegion.h"
#include "include/core/SkShader.h"
#include "include/core/SkTypeface.h"
#include "include/effects/SkGradientShader.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkTime.h"
#include "src/base/SkUTF.h"
#include "tools/viewer/ClickHandlerSlide.h"
#include <utility>

Go to the source code of this file.

Classes

class  PathClipSlide
 
class  EdgeClipSlide
 
class  EdgeClipSlide::MyClick
 
class  EdgeClipSlide::VertClick
 
class  EdgeClipSlide::DragRectClick
 
class  EdgeClipSlide::DragPolyClick
 
class  EdgeClipSlide::DoNothingClick
 

Functions

static int clip_line (const SkRect &bounds, SkPoint p0, SkPoint p1, SkPoint edges[])
 
static void draw_clipped_line (SkCanvas *canvas, const SkRect &bounds, SkPoint p0, SkPoint p1, const SkPaint &paint)
 

Function Documentation

◆ clip_line()

static int clip_line ( const SkRect bounds,
SkPoint  p0,
SkPoint  p1,
SkPoint  edges[] 
)
static

Definition at line 68 of file PathClipSlide.cpp.

68 {
69 SkPoint* edgesStart = edges;
70
71 if (p0.fY == p1.fY) {
72 return 0;
73 }
74
75 if (p0.fY > p1.fY) {
76 using std::swap;
77 swap(p0, p1);
78 }
79 // now we're monotonic in Y: p0 <= p1
80 if (p1.fY <= bounds.top() || p0.fY >= bounds.bottom()) {
81 return 0;
82 }
83
84 double dxdy = (double)(p1.fX - p0.fX) / (p1.fY - p0.fY);
85 if (p0.fY < bounds.top()) {
86 p0.fX = SkDoubleToScalar(p0.fX + dxdy * (bounds.top() - p0.fY));
87 p0.fY = bounds.top();
88 }
89 if (p1.fY > bounds.bottom()) {
90 p1.fX = SkDoubleToScalar(p1.fX + dxdy * (bounds.bottom() - p1.fY));
91 p1.fY = bounds.bottom();
92 }
93
94 // Now p0...p1 is strictly inside bounds vertically, so we just need to clip horizontally
95
96 if (p0.fX > p1.fX) {
97 using std::swap;
98 swap(p0, p1);
99 }
100 // now we're left-to-right: p0 .. p1
101
102 if (p1.fX <= bounds.left()) { // entirely to the left
103 p0.fX = p1.fX = bounds.left();
104 *edges++ = p0;
105 *edges++ = p1;
106 return 2;
107 }
108 if (p0.fX >= bounds.right()) { // entirely to the right
109 p0.fX = p1.fX = bounds.right();
110 *edges++ = p0;
111 *edges++ = p1;
112 return 2;
113 }
114
115 if (p0.fX < bounds.left()) {
116 float y = SkDoubleToScalar(p0.fY + (bounds.left() - p0.fX) / dxdy);
117 *edges++ = SkPoint::Make(bounds.left(), p0.fY);
118 *edges++ = SkPoint::Make(bounds.left(), y);
119 p0.set(bounds.left(), y);
120 }
121 if (p1.fX > bounds.right()) {
122 float y = SkDoubleToScalar(p0.fY + (bounds.right() - p0.fX) / dxdy);
123 *edges++ = p0;
124 *edges++ = SkPoint::Make(bounds.right(), y);
125 *edges++ = SkPoint::Make(bounds.right(), p1.fY);
126 } else {
127 *edges++ = p0;
128 *edges++ = p1;
129 }
130 return SkToInt(edges - edgesStart);
131}
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition SkRefCnt.h:341
#define SkDoubleToScalar(x)
Definition SkScalar.h:64
constexpr int SkToInt(S x)
Definition SkTo.h:29
double y
Optional< SkRect > bounds
Definition SkRecords.h:189
float fX
x-axis value
static constexpr SkPoint Make(float x, float y)
void set(float x, float y)
float fY
y-axis value

◆ draw_clipped_line()

static void draw_clipped_line ( SkCanvas canvas,
const SkRect bounds,
SkPoint  p0,
SkPoint  p1,
const SkPaint paint 
)
static

Definition at line 133 of file PathClipSlide.cpp.

134 {
135 SkPoint verts[6];
136 int count = clip_line(bounds, p0, p1, verts);
137
138 SkPath path;
139 path.addPoly(verts, count, false);
140 canvas->drawPath(path, paint);
141}
int count
static int clip_line(const SkRect &bounds, SkPoint p0, SkPoint p1, SkPoint edges[])
void drawPath(const SkPath &path, const SkPaint &paint)
const Paint & paint
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57