The Glass Picture

The CPictureGlass class does animation the hard way. You pass it the canvas surface you want to draw on and the picture you want to make transparent along with the color you want to be considered the background. Optionally, you can provide x and y coordinates for the point on which you want the picture to be centered.

Behind the scenes, CPictureGlass makes a copy of the background surface that will be covered by the picture, punches a hole in it using a mask, plunks a masked copy of the picture into the hole, and puts the modified background back onto the canvas. So there you have it: transparency. Not only that, but CPictureGlass keeps a copy of the last background used and restores it before moving on to the next position. Now you have moving transparency.

CPictureGlass works kind of like a PictureBox control because the original model in the first edition of this book was that the class would work like a transparent PictureBox. Of course, you couldn’t create controls in Visual Basic version 4, so CPictureGlass had to do some hacks by delegating to a real PictureBox. This version abandons the internal PictureBox control but maintains some methods and properties that look suspiciously like those of a PictureBox.