Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jrodsmitty

TransformManager set manual selection rectangle

Recommended Posts

So I haven't had any luck finding an answer to this via Google or the forums here yet, so hopefully someone can help.

 

Is there a way to specify what (other than the selected item) the selection rectangle uses to set its size, if a TransformManager is applied to a Sprite with multiple children?

 

Scenario:

I have a Sprite with 2 children: a Bitmap, and a Shape. The Shape has a blendmode of ERASE, so the user can "erase" the image below it, but if the user 'paints' outside the visible area of the image, it increases the selection box size. I only want the selection box to be sized to the image, not the size of the image + erase layer. Does that make sense?

 

Thanks in advance!

-Jarrod

Link to post
Share on other sites

Jack,

Yes, that indeed did the trick!

 

In my solution, I compare the Erase layer rect() to the Bitmap rect() and calculate/adjust the offsets accordingly. I then do this calculation on the item's TransformEvent.SELECT event, and reset the manualBoundsOffset at that point.

 


private function adjustSelectionBox(e:TransformEvent):void 
{
   // get erase layer bounds
   var eraseRect:Rectangle = _eraseLayer.getRect(_transformItem);

   // if erase layer "exists"
   if (eraseRect.width != 0 && eraseRect.height != 0)
   {
       // get image to use for sizing the selection box
       var imageRect:Rectangle = _bitmap.getRect(_transformItem);

       // if the erase layer goes "outside" the bitmap bounds, update deltas
       if (eraseRect.x < imageRect.x)
       {
           _deltaX = Math.abs(imageRect.x + eraseRect.x);
       }
       if (eraseRect.y < imageRect.y)
       {
           _deltaY = Math.abs(imageRect.y + eraseRect.y);
       }
       if ((eraseRect.x + eraseRect.width) > (imageRect.x + imageRect.width))
       {
           _deltaW = (eraseRect.x + eraseRect.width) - (imageRect.x + imageRect.width);
       }
       if ((eraseRect.y + eraseRect.height) > (imageRect.y + imageRect.height))
       {
           _deltaH = (eraseRect.y + eraseRect.height) - (imageRect.y + imageRect.height);
       }
   }
   // set new selection box
   TransformItem(_transformMngr.getItem(_transformItem)).manualBoundsOffset = new Rectangle(0, 0, -(_deltaW + _deltaX), -(_deltaH + _deltaY));
   _transformMngr.updateSelection();
}

 

Thanks again!

-Jarrod

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×