Hi there,
I've spent a good part of the last few weeks trying to use the TransformManager for an application that not only scales, rotates, and moves images, but also crops them. I find the moving, rotating and scaling part compellingly easy to achieve with the TransformManager, but it doesn't seem to be suitable for moving, rotating and scaling cropmasks, too.
The requirements:
[*:2a6p5l9k] There is a layer with an arbitrary number of images and text elements (RichText) that are created on the fly by the user[*:2a6p5l9k] above that layer there's another layer that partially obscures the image/text layer (a kind of mask/template – but not a clip mask, since the parts "masked out" still "shine through" the mask)[*:2a6p5l9k] yet on top of that is a layer that contains control elements for the images/textitems that must not be obscured by the mask/template layer[*:2a6p5l9k] images are to be scaled, rotated, moved and cropped on the fly[*:2a6p5l9k] it should be possible to grab the items even if they're mostly obscured by the template/mask layer --> the handles and borders of selected items must appear "above" the template, even if the corresponding image is "below" the template/mask[*:2a6p5l9k] images must be scaleable/croppable in-place even if they're mostly "under" the template/mask
The setup:
[*:2a6p5l9k] The TransformManager sits atop the template layer and governs placeholder elements ("proxies"), which are created along with each text item/image and added to the TM[*:2a6p5l9k] the TransformItems relate to the transparent proxies, changes in dimensions, position, and scale are updated to the corresponding image/text (through Flex's commitProperties/invalidateDisplayList mechanisms)[*:2a6p5l9k] image items are their own clipmasks, i.e. masking and clipping is achieved through negative positioning of the image inside the image box element[*:2a6p5l9k] TransformManager operates in two modes: SCALE_NORMAL has image scale, move, and rotate as a whole, SCALE_WIDTH_AND_HEIGHT should keep the image in place, preserve/freeze the scaling, lock rotation, and only move the crop mask within the boundaries of the image
The problems:
[*:2a6p5l9k] TransformManager removes and adds TransformItems when switching their scale mode between scaling and cropping, resulting in the current item to be forced out of its ongoing modification[*:2a6p5l9k] the crop mask should be confined to the image, i.e. "scaling" and moving the image mask must not lead to a situation where part of the mask are outside of the image --> the TransformManagers bounding box remains unrotated, leading to undesired mask bleeding for rotated images and actually rendering the TM's bounds mechanism unusable[*:2a6p5l9k] TransformManager uses x/y + width/height as well as transform matrices to manipulate the TransformItems, making it very hard to simply "listen" to changes in the desired properties (sometimes dragging handles results only in a modified transform matrix, Matrix doesn't implement IEventDispatcher, though, leaving you with the only option to listen for frame events)
The possible solutions:
[*:2a6p5l9k]TransformManager should support bounding boxes that are not just unrotated rectangles, allowing for easy crop mask confinement inside of an image's area[*:2a6p5l9k]TransformManager/TransformItem should emit events when the transform matrix changes[*:2a6p5l9k]maybe even a full-fledged cropping mechanism out of the box? *wink wink wink*
Thoughts are welcome, because I'm really stuck here. A colleague talked me into buying this pile of… monolithic code that I'm having a really hard time with. Hey, it costs three hundred bucks – I expect it to behave well then. Get me right, the TransformManager goes great lengths in the right direction, but it stops short. Or do you think it's not suitable for that purpose and I should get a refund?
Best regards
Constantin