blob: 9e2c01a76db0fe6d8e9a5c5533612dc853d57981 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkCullPoints_DEFINED
11#define SkCullPoints_DEFINED
12
13#include "SkRect.h"
14
15class SkCullPoints {
16public:
17 SkCullPoints();
18 SkCullPoints(const SkIRect& r);
19
20 void reset(const SkIRect& r);
21
22 /** Start a contour at (x,y). Follow this with call(s) to lineTo(...)
23 */
24 void moveTo(int x, int y);
25
26 enum LineToResult {
27 kNo_Result, //!< line segment was completely clipped out
28 kLineTo_Result, //!< path.lineTo(pts[1]);
29 kMoveToLineTo_Result //!< path.moveTo(pts[0]); path.lineTo(pts[1]);
30 };
31 /** Connect a line to the previous call to lineTo (or moveTo).
32 */
33 LineToResult lineTo(int x, int y, SkIPoint pts[2]);
34
35private:
36 SkIRect fR; // the caller's rectangle
37 SkIPoint fAsQuad[4]; // cache of fR as 4 points
38 SkIPoint fPrevPt; // private state
39 LineToResult fPrevResult; // private state
40
41 bool sect_test(int x0, int y0, int x1, int y1) const;
42};
43
44/////////////////////////////////////////////////////////////////////////////////
45
46class SkPath;
47
48/** \class SkCullPointsPath
49
50 Similar to SkCullPoints, but this class handles the return values
51 from lineTo, and automatically builds a SkPath with the result(s).
52*/
53class SkCullPointsPath {
54public:
55 SkCullPointsPath();
56 SkCullPointsPath(const SkIRect& r, SkPath* dst);
57
58 void reset(const SkIRect& r, SkPath* dst);
59
60 void moveTo(int x, int y);
61 void lineTo(int x, int y);
62
63private:
64 SkCullPoints fCP;
65 SkPath* fPath;
66};
67
68#endif