2012-07-03 02:44:02 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2012-07-11 01:51:33 +00:00
|
|
|
static void test_hittest(SkCanvas* canvas, const SkPath& path) {
|
2012-07-03 02:44:02 +00:00
|
|
|
SkPaint paint;
|
|
|
|
SkRect r = path.getBounds();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-03 02:44:02 +00:00
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawPath(path, paint);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-03 12:23:22 +00:00
|
|
|
const SkScalar MARGIN = SkIntToScalar(4);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-03 02:44:02 +00:00
|
|
|
paint.setColor(0x800000FF);
|
2012-07-03 12:23:22 +00:00
|
|
|
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) {
|
2012-07-11 01:51:33 +00:00
|
|
|
if (path.contains(x, y)) {
|
|
|
|
canvas->drawPoint(x, y, paint);
|
2012-07-03 02:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class HitTestPathGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
HitTestPathGM () {}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-03 02:44:02 +00:00
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
return kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
2012-07-03 02:44:02 +00:00
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("hittestpath");
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-03 02:44:02 +00:00
|
|
|
virtual SkISize onISize() { return SkISize::Make(700, 460); }
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-03 02:44:02 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkPath path;
|
2014-12-15 20:54:51 +00:00
|
|
|
SkRandom rand;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-11 01:51:33 +00:00
|
|
|
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);
|
2012-07-03 02:44:02 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-03 02:44:02 +00:00
|
|
|
path.setFillType(SkPath::kEvenOdd_FillType);
|
2012-07-03 12:23:22 +00:00
|
|
|
path.offset(SkIntToScalar(20), SkIntToScalar(20));
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-11 01:51:33 +00:00
|
|
|
test_hittest(canvas, path);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(scale), 0);
|
2012-07-03 02:44:02 +00:00
|
|
|
path.setFillType(SkPath::kWinding_FillType);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-11 01:51:33 +00:00
|
|
|
test_hittest(canvas, path);
|
2012-07-03 02:44:02 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-03 02:44:02 +00:00
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static skiagm::GM* MyFactory(void*) { return new HitTestPathGM; }
|
|
|
|
static skiagm::GMRegistry reg(MyFactory);
|