blob: 79dd25bd5c0b277f7e0cfcb17cf32eb3bdbf3cae [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#include "SkHitTest.h"
11
12#if SK_USE_CONDENSED_INFO == 0
13
14const SkMemberInfo SkHitTest::fInfo[] = {
15 SK_MEMBER_ARRAY(bullets, Displayable),
16 SK_MEMBER_ARRAY(hits, Int),
17 SK_MEMBER_ARRAY(targets, Displayable),
18 SK_MEMBER(value, Boolean)
19};
20
21#endif
22
23DEFINE_GET_MEMBER(SkHitTest);
24
25SkHitTest::SkHitTest() : value(false) {
26}
27
sugoi@google.com93c7ee32013-03-12 14:36:57 +000028bool SkHitTest::draw(SkAnimateMaker&) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 hits.setCount(bullets.count());
30 value = false;
31 int bulletCount = bullets.count();
32 int targetCount = targets.count();
33 for (int bIndex = 0; bIndex < bulletCount; bIndex++) {
34 SkDisplayable* bullet = bullets[bIndex];
35 SkRect bBounds;
36 bullet->getBounds(&bBounds);
37 hits[bIndex] = -1;
38 if (bBounds.fLeft == (int16_t)0x8000U)
39 continue;
40 for (int tIndex = 0; tIndex < targetCount; tIndex++) {
41 SkDisplayable* target = targets[tIndex];
42 SkRect tBounds;
43 target->getBounds(&tBounds);
44 if (bBounds.intersect(tBounds)) {
45 hits[bIndex] = tIndex;
46 value = true;
47 break;
48 }
49 }
50 }
51 return false;
52}
53
sugoi@google.com93c7ee32013-03-12 14:36:57 +000054bool SkHitTest::enable(SkAnimateMaker&) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000055 for (int bIndex = 0; bIndex < bullets.count(); bIndex++) {
56 SkDisplayable* bullet = bullets[bIndex];
57 bullet->enableBounder();
58 }
59 for (int tIndex = 0; tIndex < targets.count(); tIndex++) {
60 SkDisplayable* target = targets[tIndex];
61 target->enableBounder();
62 }
63 return false;
64}
65
66bool SkHitTest::hasEnable() const {
67 return true;
68}
69
sugoi@google.com93c7ee32013-03-12 14:36:57 +000070const SkMemberInfo* SkHitTest::preferredChild(SkDisplayTypes) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 if (bullets.count() == 0)
72 return getMember("bullets");
73 return getMember("targets"); // !!! cwap! need to refer to member through enum like kScope instead
74}