|
|
|
Returns Rect of visible PDF doc within an Impressario sprite
Added on 7/25/2004
|
I'm came up with this when creating an application where "sticky notes" were to be attached to locations within PDFs. In order to track locations where the users placed notes on a document I needed to know where the visible rect of the PDF document sits within the sprite when the scrollH = 0 and scrollV = 0 (view of pdf document is smaller than the sprite).
Currently there is no property that exposes this information, so I wrote this behaviour.
Use: (Impressario sprite).getRectOfView() returns a rect of the boundary of the current view of the document contained within the sprite, even if it's smaller than the sprite. Rect is relative to the stage (or activeWindow).
-----------------
Property spriteNum
on getRectOfView() --Returns the rect of document visible within an Impressario sprite, relative to the current stage...
--Note: No sprites must exist underneath the Impressario sprite because the routine compares the color of pixels on the stage in the sprite's rect to the stage's bgColor. If you do place an sprite underneath, it must be all one color and you must change the value of in the 5th line from (the activeWindow).bgcolor to the color of that sprite.
--Use of (the activeWindow) instead of (the stage) ensures the routine is suitable for MIAWs.
pdfSprite=sprite(spriteNum)
img=(the activeWindow).image
centreX=pdfSprite.left+pdfSprite.width/2
centreY=pdfSprite.top+pdfSprite.height/2
bkdCol=(the activeWindow).bgcolor
--traverse from left until color change...
x=pdfSprite.left
repeat while img.getPixel(x,centreY)=bkdCol
x=x+1
end repeat
--traverse from top until color change...
y=pdfSprite.top
repeat while img.getPixel(centreX,y)=bkdCol
y=y+1
end repeat
return rect(x,y,pdfSprite.right-(x-pdfSprite.left),pdfSprite.bottom-(y-pdfSprite.top))
end
-----------------
|
|