180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkHitTest.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_USE_CONDENSED_INFO == 0 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo SkHitTest::fInfo[] = { 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ARRAY(bullets, Displayable), 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ARRAY(hits, Int), 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_ARRAY(targets, Displayable), 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(value, Boolean) 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GET_MEMBER(SkHitTest); 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkHitTest::SkHitTest() : value(false) { 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 28096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergerbool SkHitTest::draw(SkAnimateMaker&) { 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru hits.setCount(bullets.count()); 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru value = false; 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int bulletCount = bullets.count(); 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int targetCount = targets.count(); 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (int bIndex = 0; bIndex < bulletCount; bIndex++) { 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* bullet = bullets[bIndex]; 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkRect bBounds; 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bullet->getBounds(&bBounds); 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru hits[bIndex] = -1; 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (bBounds.fLeft == (int16_t)0x8000U) 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru continue; 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (int tIndex = 0; tIndex < targetCount; tIndex++) { 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* target = targets[tIndex]; 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkRect tBounds; 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru target->getBounds(&tBounds); 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (bBounds.intersect(tBounds)) { 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru hits[bIndex] = tIndex; 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru value = true; 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru break; 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 54096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergerbool SkHitTest::enable(SkAnimateMaker&) { 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (int bIndex = 0; bIndex < bullets.count(); bIndex++) { 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* bullet = bullets[bIndex]; 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bullet->enableBounder(); 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (int tIndex = 0; tIndex < targets.count(); tIndex++) { 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDisplayable* target = targets[tIndex]; 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru target->enableBounder(); 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkHitTest::hasEnable() const { 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 70096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergerconst SkMemberInfo* SkHitTest::preferredChild(SkDisplayTypes) { 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (bullets.count() == 0) 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getMember("bullets"); 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return getMember("targets"); // !!! cwap! need to refer to member through enum like kScope instead 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 75