Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: gm/hittestpath.cpp

Issue 65493004: increase coverage of SkPath.cpp, remove unused code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove dead code Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "SkCanvas.h"
10 #include "SkCullPoints.h"
11 #include "SkRandom.h"
12
13 static void test_hittest(SkCanvas* canvas, const SkPath& path) {
14 SkPaint paint;
15 SkRect r = path.getBounds();
16
17 paint.setColor(SK_ColorRED);
18 canvas->drawPath(path, paint);
19
20 const SkScalar MARGIN = SkIntToScalar(4);
21
22 paint.setColor(0x800000FF);
23 for (SkScalar y = r.fTop + SK_ScalarHalf - MARGIN; y < r.fBottom + MARGIN; y += SK_Scalar1) {
24 for (SkScalar x = r.fLeft + SK_ScalarHalf - MARGIN; x < r.fRight + MARGI N; x += SK_Scalar1) {
25 if (path.contains(x, y)) {
26 canvas->drawPoint(x, y, paint);
27 }
28 }
29 }
30 }
31
32 class HitTestPathGM : public skiagm::GM {
33 public:
34 HitTestPathGM () {}
35
36 protected:
37 virtual SkString onShortName() {
38 return SkString("hittestpath");
39 }
40
41 virtual SkISize onISize() { return SkISize::Make(700, 460); }
42
43 virtual void onDraw(SkCanvas* canvas) {
44 SkPath path;
45 SkLCGRandom rand;
46
47 int scale = 300;
48 for (int i = 0; i < 4; ++i) {
49 path.lineTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scale );
50 path.quadTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scale ,
51 rand.nextUScalar1() * scale, rand.nextUScalar1() * scale );
52 path.cubicTo(rand.nextUScalar1() * scale, rand.nextUScalar1() * scal e,
53 rand.nextUScalar1() * scale, rand.nextUScalar1() * scal e,
54 rand.nextUScalar1() * scale, rand.nextUScalar1() * scal e);
55 }
56
57 path.setFillType(SkPath::kEvenOdd_FillType);
58 path.offset(SkIntToScalar(20), SkIntToScalar(20));
59
60 test_hittest(canvas, path);
61
62 canvas->translate(SkIntToScalar(scale), 0);
63 path.setFillType(SkPath::kWinding_FillType);
64
65 test_hittest(canvas, path);
66 }
67
68 private:
69 typedef GM INHERITED;
70 };
71
72 //////////////////////////////////////////////////////////////////////////////
73
74 static skiagm::GM* MyFactory(void*) { return new HitTestPathGM; }
75 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « bench/PathBench.cpp ('k') | gyp/gmslides.gypi » ('j') | include/core/SkPath.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698