1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/animator/SkHitTest.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkHitTest.h" 1.14 + 1.15 +#if SK_USE_CONDENSED_INFO == 0 1.16 + 1.17 +const SkMemberInfo SkHitTest::fInfo[] = { 1.18 + SK_MEMBER_ARRAY(bullets, Displayable), 1.19 + SK_MEMBER_ARRAY(hits, Int), 1.20 + SK_MEMBER_ARRAY(targets, Displayable), 1.21 + SK_MEMBER(value, Boolean) 1.22 +}; 1.23 + 1.24 +#endif 1.25 + 1.26 +DEFINE_GET_MEMBER(SkHitTest); 1.27 + 1.28 +SkHitTest::SkHitTest() : value(false) { 1.29 +} 1.30 + 1.31 +bool SkHitTest::draw(SkAnimateMaker&) { 1.32 + hits.setCount(bullets.count()); 1.33 + value = false; 1.34 + int bulletCount = bullets.count(); 1.35 + int targetCount = targets.count(); 1.36 + for (int bIndex = 0; bIndex < bulletCount; bIndex++) { 1.37 + SkDisplayable* bullet = bullets[bIndex]; 1.38 + SkRect bBounds; 1.39 + bullet->getBounds(&bBounds); 1.40 + hits[bIndex] = -1; 1.41 + if (bBounds.fLeft == (int16_t)0x8000U) 1.42 + continue; 1.43 + for (int tIndex = 0; tIndex < targetCount; tIndex++) { 1.44 + SkDisplayable* target = targets[tIndex]; 1.45 + SkRect tBounds; 1.46 + target->getBounds(&tBounds); 1.47 + if (bBounds.intersect(tBounds)) { 1.48 + hits[bIndex] = tIndex; 1.49 + value = true; 1.50 + break; 1.51 + } 1.52 + } 1.53 + } 1.54 + return false; 1.55 +} 1.56 + 1.57 +bool SkHitTest::enable(SkAnimateMaker&) { 1.58 + for (int bIndex = 0; bIndex < bullets.count(); bIndex++) { 1.59 + SkDisplayable* bullet = bullets[bIndex]; 1.60 + bullet->enableBounder(); 1.61 + } 1.62 + for (int tIndex = 0; tIndex < targets.count(); tIndex++) { 1.63 + SkDisplayable* target = targets[tIndex]; 1.64 + target->enableBounder(); 1.65 + } 1.66 + return false; 1.67 +} 1.68 + 1.69 +bool SkHitTest::hasEnable() const { 1.70 + return true; 1.71 +} 1.72 + 1.73 +const SkMemberInfo* SkHitTest::preferredChild(SkDisplayTypes) { 1.74 + if (bullets.count() == 0) 1.75 + return getMember("bullets"); 1.76 + return getMember("targets"); // !!! cwap! need to refer to member through enum like kScope instead 1.77 +}