Bit Editors

The CColorPicker class and the XColorPicker control are handy, but the real point of this section is to talk about one of the many projects I didn’t get around to when I wrote the first edition of this book and still haven’t got around to. I’d planned to show you a complete bit editor that would create or edit bitmaps (any size), icons (large or small), cursors (hot spot included), toolbar buttons (showing up and down states), or any other kind of bit picture. It would have done automatic conversions—bitmap to icon, large icon to small icon, icon to cursor, color to mono—and would have had all kinds of cool drawing tools. For now, however, this program exists only in my imagination. I’ll have to describe it in a very high-level pseudocode—English.

First let’s look at CColorPicker. What is it? It’s a grid of cells that knows when you click on it and then takes an action based on the chosen cell. What is a bit editor? It’s a grid of cells that knows when you click on it and then takes an action based on the chosen cell. The only difference is the action. Most bit editors have a big-bits mode in which bits are shown larger than life—much like the color cells in CColorPicker. But even in actual size, it’s still just a grid of one-pixel cells.

CColorPicker is hard-coded to either a 16 by 3 grid or an 8 by 6 grid. The CBitEdit class must be dynamic, to accommodate any size grid. It should also have bit-picture modes. In icon mode, the grid has submodes for the common sizes—16 by 16 and 32 by 32—but it can create icons of any size for hardcore Windows programmers. Icon mode must also know about masks and transparency. Cursor mode creates a 32 by 32 grid and handles transparency as well as hot spots. Bitmaps are always a custom size; in fact, you should be able to resize the grid by dragging it. The CBitEdit class needs properties to set the mode and resize the grid, subject to conversion rules. It also needs both big-bit and life-
size modes, and it should be able to display both modes at once on separate ­canvases.

CColorPicker is hard-coded to give each cell a specific color. CBitEdit must be able to read different colors into its grid from a file. It must also be able to save its grid to a file with the appropriate extension—BMP, ICO, CUR, and so on. The file format to save is determined by the bit-picture mode.

CColorPicker is hard-coded to set its Color property to the color of the cell you click. CBitEdit needs various methods to determine what happens for each click and drag. A Draw method sets the cell to the current color, and a Spray method colors the surrounding cells in a diminishing pattern. A Fill method starts at the current cell and fills all the surrounding cells up to the closest border. A Line method starts a stretch operation that determines the end points of a line. And so on.