1
/* libs/graphics/animator/SkHitTest.cpp
3
** Copyright 2006, The Android Open Source Project
5
** Licensed under the Apache License, Version 2.0 (the "License");
6
** you may not use this file except in compliance with the License.
7
** You may obtain a copy of the License at
9
** http://www.apache.org/licenses/LICENSE-2.0
11
** Unless required by applicable law or agreed to in writing, software
12
** distributed under the License is distributed on an "AS IS" BASIS,
13
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
** See the License for the specific language governing permissions and
15
** limitations under the License.
18
#include "SkHitTest.h"
20
#if SK_USE_CONDENSED_INFO == 0
22
const SkMemberInfo SkHitTest::fInfo[] = {
23
SK_MEMBER_ARRAY(bullets, Displayable),
24
SK_MEMBER_ARRAY(hits, Int),
25
SK_MEMBER_ARRAY(targets, Displayable),
26
SK_MEMBER(value, Boolean)
31
DEFINE_GET_MEMBER(SkHitTest);
33
SkHitTest::SkHitTest() : value(false) {
36
bool SkHitTest::draw(SkAnimateMaker& maker) {
37
hits.setCount(bullets.count());
39
int bulletCount = bullets.count();
40
int targetCount = targets.count();
41
for (int bIndex = 0; bIndex < bulletCount; bIndex++) {
42
SkDisplayable* bullet = bullets[bIndex];
44
bullet->getBounds(&bBounds);
46
if (bBounds.fLeft == (int16_t)0x8000U)
48
for (int tIndex = 0; tIndex < targetCount; tIndex++) {
49
SkDisplayable* target = targets[tIndex];
51
target->getBounds(&tBounds);
52
if (bBounds.intersect(tBounds)) {
53
hits[bIndex] = tIndex;
62
bool SkHitTest::enable(SkAnimateMaker& maker) {
63
for (int bIndex = 0; bIndex < bullets.count(); bIndex++) {
64
SkDisplayable* bullet = bullets[bIndex];
65
bullet->enableBounder();
67
for (int tIndex = 0; tIndex < targets.count(); tIndex++) {
68
SkDisplayable* target = targets[tIndex];
69
target->enableBounder();
74
bool SkHitTest::hasEnable() const {
78
const SkMemberInfo* SkHitTest::preferredChild(SkDisplayTypes type) {
79
if (bullets.count() == 0)
80
return getMember("bullets");
81
return getMember("targets"); // !!! cwap! need to refer to member through enum like kScope instead