From 44d35eb9d3eedf70ff17225d5027416ba5ecabcf Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 18 May 2007 20:40:24 +0000 Subject: [PATCH] Moved our custom hit-testing here from MsoySprite. I was hoping to have our nice transparent-pixels-don't-count hitting for every media container, including any game icon decoration over an avatar's head, but after moving this I remembered that it may be pointless, as it *never matters*- flash simply doesn't use this method to test mouse-overness. So it may be moot, unless we do mouse-over polling like we do in the RoomView, which is too expensive to do everywhere.. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@252 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flash/MediaContainer.as | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/as/com/threerings/flash/MediaContainer.as b/src/as/com/threerings/flash/MediaContainer.as index c2b4e8f4..e4595588 100644 --- a/src/as/com/threerings/flash/MediaContainer.as +++ b/src/as/com/threerings/flash/MediaContainer.as @@ -21,7 +21,7 @@ package com.threerings.flash { -//import flash.display.Bitmap; +import flash.display.Bitmap; import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; import flash.display.Loader; @@ -136,6 +136,7 @@ public class MediaContainer extends Sprite } else { setupSwfOrImage(url); } + didShowNewMedia(); } /** @@ -160,17 +161,25 @@ public class MediaContainer extends Sprite addChildAt(disp, 0); _media = disp; updateContentDimensions(disp.width, disp.height); + didShowNewMedia(); } /** - * A place where subclasses can initialize things prior to showing - * new media. + * A place where subclasses can initialize things prior to showing new media. */ protected function willShowNewMedia () :void { _initialized = false; } + /** + * A place where subclasses can configure things after we've setup new media. + */ + protected function didShowNewMedia () :void + { + // nothing right now, but call super() you overriders. + } + /** * Configure this sprite to show a video. */ @@ -363,6 +372,53 @@ public class MediaContainer extends Sprite // do nothing in base MediaContainer } + /** + * Note: This method is NOT used in normal mouseOver calculations. + * Normal mouseOver stuff seems to be completely broken for transparent + * images: the transparent portion is a 'hit'. I've (Ray) tried + * just about everything to fix this, more than once. + * + * But if someone *does* call this method (we do, in whirled), then + * attempt to do the right thing. + */ + override public function hitTestPoint ( + x :Number, y :Number, shapeFlag :Boolean = false) :Boolean + { + // if we're holding a bitmap, do something smarter than the + // flash built-in and actually check for *GASP* transparent pixels! + try { + if (shapeFlag && _media is Loader && + // the childAllowsParent check here causes a security + // violation if it doesn't. WHAT THE FLYING FUCK. + Loader(_media).contentLoaderInfo.childAllowsParent && + (Loader(_media).content is Bitmap)) { + var b :Bitmap = Bitmap(Loader(_media).content); + var p :Point = b.globalToLocal(new Point(x, y)); + // check that it's within the content bounds, and then check the bitmap directly + if (p.x >= 0 && p.x <= getMaxContentWidth() && p.y >= 0 && + p.y <= getMaxContentHeight() && + b.bitmapData.hitTest(new Point(0, 0), 0, p)) { + return true; + + } else { + // the bitmap was not hit, see if other children were hit... + for (var ii :int = numChildren - 1; ii >= 0; ii--) { + var child :DisplayObject = getChildAt(ii); + if (child != _media && child.hitTestPoint(x, y, shapeFlag)) { + return true; + } + } + return false; + } + } + } catch (err :Error) { + // nada + } + + // normal hit testing + return super.hitTestPoint(x, y, shapeFlag); + } + override public function toString () :String { return "MediaContainer[url=" + _url + "]";