One of the coolest objects in the graphics/view framework for VisualWorks is the VisualBlock.
VisualBlock is a block with a bounds. Many of the views/widgets we put together are just a fancy displayOn: message. It came in really handy, in creating an "icon" that was two OpaqueImages side by side. Given the desire to create an "aggregate" icon by showing two OpaqueImages side by side, you have a couple of choices:
- Create a special object. A subclass of VisualComponent. Two instance variables. Add the various bounds messages. Your displayOn: message. If this is a very common thing to do in your system, then this is actually probably the right thing to do.
- Synthesize a new OpaqueImage which is the two put together. Means you have to create a separate Mask and Pixmap, draw the OpaqueImage figures/shapes onto it at the right places. Return a new OpaqueImage after turning them back into Images. Kind of yecky, and it'll work the heck out of your graphics server.
- Just use a VisualBlock. Something like:
graphic := VisualBlock block: [:gc :box | icon1 displayOn: gc at: box origin. icon2 displayOn: gc at: (box origin right: icon1 width). ] bounds: (Point zero corner: icon1 width + icon2 width @ icon1 height). ^graphic
To me, the VisualBlock is very appealing. It was quick and easy to throw together. I can experiment with different layouts. And it doesn't thrash the graphics layer.
VisualBlock exists under the current "wrappers" framework, I have no idea if there's such a thing for Pollock yet. But if there's not, I'll bet its one of the first things I slap together.