1 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 9 10 #include "SkHitTest.h" 11 12 #if SK_USE_CONDENSED_INFO == 0 13 14 const 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 23 DEFINE_GET_MEMBER(SkHitTest); 24 25 SkHitTest::SkHitTest() : value(false) { 26 } 27 28 bool SkHitTest::draw(SkAnimateMaker&) { 29 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 54 bool SkHitTest::enable(SkAnimateMaker&) { 55 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 66 bool SkHitTest::hasEnable() const { 67 return true; 68 } 69 70 const SkMemberInfo* SkHitTest::preferredChild(SkDisplayTypes) { 71 if (bullets.count() == 0) 72 return getMember("bullets"); 73 return getMember("targets"); // !!! cwap! need to refer to member through enum like kScope instead 74 } 75