michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkHitTest.h" michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo SkHitTest::fInfo[] = { michael@0: SK_MEMBER_ARRAY(bullets, Displayable), michael@0: SK_MEMBER_ARRAY(hits, Int), michael@0: SK_MEMBER_ARRAY(targets, Displayable), michael@0: SK_MEMBER(value, Boolean) michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(SkHitTest); michael@0: michael@0: SkHitTest::SkHitTest() : value(false) { michael@0: } michael@0: michael@0: bool SkHitTest::draw(SkAnimateMaker&) { michael@0: hits.setCount(bullets.count()); michael@0: value = false; michael@0: int bulletCount = bullets.count(); michael@0: int targetCount = targets.count(); michael@0: for (int bIndex = 0; bIndex < bulletCount; bIndex++) { michael@0: SkDisplayable* bullet = bullets[bIndex]; michael@0: SkRect bBounds; michael@0: bullet->getBounds(&bBounds); michael@0: hits[bIndex] = -1; michael@0: if (bBounds.fLeft == (int16_t)0x8000U) michael@0: continue; michael@0: for (int tIndex = 0; tIndex < targetCount; tIndex++) { michael@0: SkDisplayable* target = targets[tIndex]; michael@0: SkRect tBounds; michael@0: target->getBounds(&tBounds); michael@0: if (bBounds.intersect(tBounds)) { michael@0: hits[bIndex] = tIndex; michael@0: value = true; michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: bool SkHitTest::enable(SkAnimateMaker&) { michael@0: for (int bIndex = 0; bIndex < bullets.count(); bIndex++) { michael@0: SkDisplayable* bullet = bullets[bIndex]; michael@0: bullet->enableBounder(); michael@0: } michael@0: for (int tIndex = 0; tIndex < targets.count(); tIndex++) { michael@0: SkDisplayable* target = targets[tIndex]; michael@0: target->enableBounder(); michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: bool SkHitTest::hasEnable() const { michael@0: return true; michael@0: } michael@0: michael@0: const SkMemberInfo* SkHitTest::preferredChild(SkDisplayTypes) { michael@0: if (bullets.count() == 0) michael@0: return getMember("bullets"); michael@0: return getMember("targets"); // !!! cwap! need to refer to member through enum like kScope instead michael@0: }