Selections++ #
Moving selections weren't that hard. First I had to differentiate between floated selections and nonfloated ones. As the names suggest, the floated ones glide above the rest of the image, while nonfloated ones have nothing behind then, and must be floated before they can be moved (the region where they used to be is filled with the background color).
The actual moving wasn't that hard. At first I did an OffsetRgn for the selection regions, and did a ScrollRect to move the selection contents around. However, that didn't work so well, since when the selection was moved to the outside of the boundaries of the image, it would get cut off. So instead of using ScrollRect I used OffsetRect, to simply change the bounding rectangle of the selection.
The last thing that I did was to add support for pasting. Theoretically this shouldn't be that hard, it simply imvolves defloating the current selection (if any), copying the clipboard contents to the selection contents, and setting the appropriate region for the selection outline. However, the last part was rather tricky. But the last part was rather tricky. The simplest case would be to get a bounding rectangle of the clipboard image, and have that as the selection shape. However, this wouldn't be so nice when working with irregular shapes (such as icons copied in from the Finder, or lasso selections from other applications). The problem is that there is no easy way to get the outline of a picture. I looked at three programs, the Finder, Adobe Photoshop and Icon Machine, and they all used different formats. The one used by Icon Machine was the easiest to interpret, mostly because he described it in general terms on the homepage (he stores the picture shape in the clipboard under the data type 'Mask', as a picture, so I could just call BitMapToRegion to get the selection shape). However, in the Finder and Photoshop's case it is stored within the picture itself, but in different ways (the Finder has an actual clipping region, while photoshop has a "matte channel"). The problem is that parsing pictures by hand is not reccommended by Apple, and thus not very well documented.
Post a Comment