| OLD | NEW |
| (Empty) |
| 1 /* libs/graphics/animator/SkHitTest.cpp | |
| 2 ** | |
| 3 ** Copyright 2006, The Android Open Source Project | |
| 4 ** | |
| 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 | |
| 8 ** | |
| 9 ** http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 ** | |
| 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. | |
| 16 */ | |
| 17 | |
| 18 #include "SkHitTest.h" | |
| 19 | |
| 20 #if SK_USE_CONDENSED_INFO == 0 | |
| 21 | |
| 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) | |
| 27 }; | |
| 28 | |
| 29 #endif | |
| 30 | |
| 31 DEFINE_GET_MEMBER(SkHitTest); | |
| 32 | |
| 33 SkHitTest::SkHitTest() : value(false) { | |
| 34 } | |
| 35 | |
| 36 bool SkHitTest::draw(SkAnimateMaker& maker) { | |
| 37 hits.setCount(bullets.count()); | |
| 38 value = false; | |
| 39 int bulletCount = bullets.count(); | |
| 40 int targetCount = targets.count(); | |
| 41 for (int bIndex = 0; bIndex < bulletCount; bIndex++) { | |
| 42 SkDisplayable* bullet = bullets[bIndex]; | |
| 43 SkRect bBounds; | |
| 44 bullet->getBounds(&bBounds); | |
| 45 hits[bIndex] = -1; | |
| 46 if (bBounds.fLeft == (int16_t)0x8000U) | |
| 47 continue; | |
| 48 for (int tIndex = 0; tIndex < targetCount; tIndex++) { | |
| 49 SkDisplayable* target = targets[tIndex]; | |
| 50 SkRect tBounds; | |
| 51 target->getBounds(&tBounds); | |
| 52 if (bBounds.intersect(tBounds)) { | |
| 53 hits[bIndex] = tIndex; | |
| 54 value = true; | |
| 55 break; | |
| 56 } | |
| 57 } | |
| 58 } | |
| 59 return false; | |
| 60 } | |
| 61 | |
| 62 bool SkHitTest::enable(SkAnimateMaker& maker) { | |
| 63 for (int bIndex = 0; bIndex < bullets.count(); bIndex++) { | |
| 64 SkDisplayable* bullet = bullets[bIndex]; | |
| 65 bullet->enableBounder(); | |
| 66 } | |
| 67 for (int tIndex = 0; tIndex < targets.count(); tIndex++) { | |
| 68 SkDisplayable* target = targets[tIndex]; | |
| 69 target->enableBounder(); | |
| 70 } | |
| 71 return false; | |
| 72 } | |
| 73 | |
| 74 bool SkHitTest::hasEnable() const { | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 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 en
um like kScope instead | |
| 82 } | |
| 83 | |
| OLD | NEW |