Add Path.contains, an API to hit test a Path (#2642)

This commit is contained in:
Ian Hickson 2016-05-03 13:04:43 -07:00
parent 29c802278e
commit d85ead8ec2
3 changed files with 17 additions and 4 deletions

View File

@ -162,6 +162,13 @@ class Path extends NativeFieldWrapperClass2 {
/// reset to the origin.
void reset() native "Path_reset";
/// Tests to see if the point is within the path. (That is, whether
/// the point would be in the visible portion of the path if the
/// path was used with [Canvas.clipPath].)
///
/// Returns true if the point is in the path, and false otherwise.
bool contains(Point position) native "Path_contains";
/// Returns a copy of the path with all the segments of every
/// subpath translated by the given offset.
Path shift(Offset offset) native "Path_shift";
@ -357,7 +364,7 @@ class Canvas extends NativeFieldWrapperClass2 {
///
/// Call [restore] to pop the save stack.
void save() native "Canvas_save";
/// Saves a copy of the current transform and clip on the save
/// stack, and then creates a new group which subsequent calls will
/// become a part of. When the save stack is later popped, the group
@ -380,7 +387,7 @@ class Canvas extends NativeFieldWrapperClass2 {
///
/// Use [save] and [saveLayer] to push state onto the stack.
void restore() native "Canvas_restore";
/// Returns the number of items on the save stack, including the
/// initial state. This means it returns 1 for a clean canvas, and
/// that each call to [save] and [saveLayer] increments it, and that
@ -388,7 +395,7 @@ class Canvas extends NativeFieldWrapperClass2 {
///
/// This number cannot go below 1.
int getSaveCount() native "Canvas_getSaveCount";
void translate(double dx, double dy) native "Canvas_translate";
void scale(double sx, double sy) native "Canvas_scale";
void rotate(double radians) native "Canvas_rotate";

View File

@ -37,6 +37,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Path);
V(Path, addRRect) \
V(Path, close) \
V(Path, reset) \
V(Path, contains) \
V(Path, shift)
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)

View File

@ -8,8 +8,9 @@
#include "math.h"
#include "sky/engine/core/painting/Offset.h"
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/core/painting/Point.h"
#include "sky/engine/core/painting/RRect.h"
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/ThreadSafeRefCounted.h"
@ -19,6 +20,8 @@
// We should probably rationalise these two.
// (The existence of that class is why this is CanvasPath and not just Path.)
// The Dart side of this is in ../dart/painting.dart
namespace blink {
class DartLibraryNatives;
@ -61,6 +64,8 @@ public:
m_path.reset();
}
bool contains(const Point& point) { return m_path.contains(point.sk_point.x(), point.sk_point.y()); }
const SkPath& path() const { return m_path; }
PassRefPtr<CanvasPath> shift(const Offset& offset);