blob: fafa0fc0858f5bad4a42a543b3cd85adced1d07e [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);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000019
reed@android.com8a1c16f2008-12-17 15:59:43 +000020 void reset(const SkIRect& r);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000021
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 /** Start a contour at (x,y). Follow this with call(s) to lineTo(...)
23 */
24 void moveTo(int x, int y);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000025
reed@android.com8a1c16f2008-12-17 15:59:43 +000026 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
rmistry@google.comfbfcd562012-08-23 18:09:54 +000040
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 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);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000059
reed@android.com8a1c16f2008-12-17 15:59:43 +000060 void moveTo(int x, int y);
61 void lineTo(int x, int y);
62
63private:
64 SkCullPoints fCP;
65 SkPath* fPath;
66};
67
mike@reedtribe.orga2a95f92012-07-03 02:35:36 +000068bool SkHitTestPath(const SkPath&, SkRect& target, bool hires);
69bool SkHitTestPath(const SkPath&, SkScalar x, SkScalar y, bool hires);
mike@reedtribe.orga2a95f92012-07-03 02:35:36 +000070
reed@android.com8a1c16f2008-12-17 15:59:43 +000071#endif