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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkRandom.h"
|
2012-07-03 02:44:02 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM(hittestpath, canvas, 700, 460) {
|
2012-07-03 02:44:02 +00:00
|
|
|
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) {
|
2015-06-04 16:27:43 +00:00
|
|
|
// get the random values deterministically
|
|
|
|
SkScalar randoms[12];
|
|
|
|
for (int index = 0; index < (int) SK_ARRAY_COUNT(randoms); ++index) {
|
|
|
|
randoms[index] = rand.nextUScalar1();
|
|
|
|
}
|
|
|
|
path.lineTo(randoms[0] * scale, randoms[1] * scale);
|
|
|
|
path.quadTo(randoms[2] * scale, randoms[3] * scale,
|
|
|
|
randoms[4] * scale, randoms[5] * scale);
|
|
|
|
path.cubicTo(randoms[6] * scale, randoms[7] * scale,
|
|
|
|
randoms[8] * scale, randoms[9] * scale,
|
|
|
|
randoms[10] * scale, randoms[11] * 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);
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|