diff options
author | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-03 02:44:02 +0000 |
---|---|---|
committer | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-03 02:44:02 +0000 |
commit | 43c62b11ece4dc89a93f4de07f23f46332e1f1fc (patch) | |
tree | 5893d8dce8e93062ba0e4607deb74fb5222a13ce | |
parent | a2a95f9def9e3e1fcb34182ccaceec0e684c3e83 (diff) |
add gm for hittesting paths
git-svn-id: http://skia.googlecode.com/svn/trunk@4438 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gm/hittestpath.cpp | 81 | ||||
-rw-r--r-- | gyp/gmslides.gypi | 1 |
2 files changed, 82 insertions, 0 deletions
diff --git a/gm/hittestpath.cpp b/gm/hittestpath.cpp new file mode 100644 index 0000000000..a8566b7a70 --- /dev/null +++ b/gm/hittestpath.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkCanvas.h" +#include "SkCullPoints.h" +#include "SkRandom.h" + +static void test_hittest(SkCanvas* canvas, const SkPath& path, bool hires) { + SkPaint paint; + SkRect r = path.getBounds(); + + paint.setColor(SK_ColorRED); + canvas->drawPath(path, paint); + + paint.setColor(0x800000FF); + for (SkScalar y = r.fTop + 0.5 - 4; y < r.fBottom + 4; y += 1) { + for (SkScalar x = r.fLeft + 0.5 - 4; x < r.fRight + 4; x += 1) { + if (hires) { + if (SkHitTestPathEx(path, x, y)) { + canvas->drawPoint(x, y, paint); + } + } else { + if (SkHitTestPath(path, x, y, false)) { + canvas->drawPoint(x, y, paint); + } + } + } + } +} + +class HitTestPathGM : public skiagm::GM { +public: + HitTestPathGM () {} + +protected: + virtual SkString onShortName() { + return SkString("hittestpath"); + } + + virtual SkISize onISize() { return SkISize::Make(700, 460); } + + virtual void onDraw(SkCanvas* canvas) { + 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); + } + + path.setFillType(SkPath::kEvenOdd_FillType); + path.offset(20, 20); + + test_hittest(canvas, path, false); + canvas->translate(200, 0); + test_hittest(canvas, path, true); + + canvas->translate(-200, 200); + path.setFillType(SkPath::kWinding_FillType); + + test_hittest(canvas, path, false); + canvas->translate(200, 0); + test_hittest(canvas, path, true); + } + +private: + typedef GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static skiagm::GM* MyFactory(void*) { return new HitTestPathGM; } +static skiagm::GMRegistry reg(MyFactory); + + diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index 45dab51a9b..e600d04bbb 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -30,6 +30,7 @@ '../gm/gradients.cpp', '../gm/gradtext.cpp', '../gm/hairmodes.cpp', + '../gm/hittestpath.cpp', '../gm/imageblur.cpp', '../gm/lighting.cpp', '../gm/imagefiltersbase.cpp', |