aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/hittestpath.cpp
diff options
context:
space:
mode:
authorGravatar mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-11 01:51:33 +0000
committerGravatar mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-11 01:51:33 +0000
commitbad1b2ff1d34ff86693b776f89d7b46995746127 (patch)
treec101051386499f04dfe422ab635d20533eff8d7b /gm/hittestpath.cpp
parent927ee823fc8789140184ffcf342d434e159413a1 (diff)
add SkPath::contains(x, y)
git-svn-id: http://skia.googlecode.com/svn/trunk@4526 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/hittestpath.cpp')
-rw-r--r--gm/hittestpath.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/gm/hittestpath.cpp b/gm/hittestpath.cpp
index 06f89e4dd2..83f3507da1 100644
--- a/gm/hittestpath.cpp
+++ b/gm/hittestpath.cpp
@@ -10,7 +10,7 @@
#include "SkCullPoints.h"
#include "SkRandom.h"
-static void test_hittest(SkCanvas* canvas, const SkPath& path, bool hires) {
+static void test_hittest(SkCanvas* canvas, const SkPath& path) {
SkPaint paint;
SkRect r = path.getBounds();
@@ -22,14 +22,8 @@ static void test_hittest(SkCanvas* canvas, const SkPath& path, bool hires) {
paint.setColor(0x800000FF);
for (SkScalar y = r.fTop + SK_ScalarHalf - MARGIN; y < r.fBottom + MARGIN; y += SK_Scalar1) {
for (SkScalar x = r.fLeft + SK_ScalarHalf - MARGIN; x < r.fRight + MARGIN; x += SK_Scalar1) {
- if (hires) {
- if (SkHitTestPathEx(path, x, y)) {
- canvas->drawPoint(x, y, paint);
- }
- } else {
- if (SkHitTestPath(path, x, y, false)) {
- canvas->drawPoint(x, y, paint);
- }
+ if (path.contains(x, y)) {
+ canvas->drawPoint(x, y, paint);
}
}
}
@@ -50,25 +44,25 @@ protected:
SkPath path;
SkRandom rand;
- for (int i = 0; i < 5; ++i) {
- path.lineTo(rand.nextUScalar1() * 150, rand.nextUScalar1() * 150);
- path.quadTo(rand.nextUScalar1() * 150, rand.nextUScalar1() * 150,
- rand.nextUScalar1() * 150, rand.nextUScalar1() * 150);
+ int scale = 300;
+ for (int i = 0; i < 4; ++i) {
+ path.lineTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scale);
+ path.quadTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scale,
+ rand.nextUScalar1() * scale, rand.nextUScalar1() * scale);
+ path.cubicTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scale,
+ rand.nextUScalar1() * scale, rand.nextUScalar1() * scale,
+ rand.nextUScalar1() * scale, rand.nextUScalar1() * scale);
}
path.setFillType(SkPath::kEvenOdd_FillType);
path.offset(SkIntToScalar(20), SkIntToScalar(20));
- test_hittest(canvas, path, false);
- canvas->translate(SkIntToScalar(200), 0);
- test_hittest(canvas, path, true);
-
- canvas->translate(-SkIntToScalar(200), SkIntToScalar(200));
+ test_hittest(canvas, path);
+
+ canvas->translate(SkIntToScalar(scale), 0);
path.setFillType(SkPath::kWinding_FillType);
- test_hittest(canvas, path, false);
- canvas->translate(SkIntToScalar(200), 0);
- test_hittest(canvas, path, true);
+ test_hittest(canvas, path);
}
private: