Drawing Graphics: 3.3 Shape Attributes: Mix Mode

Up: GEOS SDK TechDocs| Up | Prev: 3.2 Patterns and Hatching | Next: 3.4 Masks
GrGetMixMode(), GrSetMixMode()

The kernel supports several mix modes. These modes control what will happen when something is drawn on top of something else. Normally when this occurs the new drawing covers up the old one. This is known as MM_COPY, since the new drawing is copied directly onto the graphics space.

There are many other mix modes available.

MM_COPY
MM_COPY is the most common mix mode as well as the default. It draws the new drawing on top of the old as though the new drawing where on opaque paper--nothing of the old drawing shows through the region defined by the new drawing.
MM_CLEAR
The region defined by the new drawing is blanked out. The color of the new drawing does not matter.
MM_SET
The region defined by the new drawing is washed black. The color of the new drawing does not matter.
MM_INVERT
The region defined by the new drawing is inverted. The color value displayed will be the logical inverse of the old color. The color of the new drawing does not matter.
MM_NOP
The old drawing remains; nothing is drawn of the new drawing. Just about the only thing likely to change is that the pen position will be updated.
MM_XOR
The color value to display is calculated by taking the bitwise XOR of the new and old colors. If painting in white, this acts as a sort of reverse paint. Note that this bitwise XOR is applied to the index numbers of the colors, not to their RGB values.
MM_OR
The color value to display is calculated by taking the bitwise OR of the new and old colors. On a monochrome display, this corresponds to drawing on a clear plastic overlay. The OR operation is applied to the indexes of the colors as opposed to their RGB values.
MM_AND
The color value to display is calculated by taking the bitwise AND of the new and old colors. Where either drawing is blank, the result will be blank. On a monochrome display, this results in a "clipping" effect. The AND operation is applied to the indexes of the colors.

GrGetMixMode() returns the current drawing mode. GrSetMixMode() tells the system to use a new mode.

Note that the drawing modes that use logical operators to compute the color have some nice effects when used with the default system colors. Due to the values of the indexes of the gray colors, MM_OR and MM_AND used with the gray colors can be thought of as lightening and darkening operations. For instance, AND-ing C_LIGHT_GRAY together with C_LIGHT_RED color results in the darker C_RED.

When using drawing modes, it often pays to be aware of where a drawing command is drawing something as blank as opposed to where it isn't drawing at all. Filling a rectangular area of the screen with a black and white checkerboard pattern isn't exactly like drawing only the corresponding black squares. When using MM_COPY, the white areas of the checkerboard will overwrite whatever was underneath. When drawing a checkerboard with individual black squares, the background would show through no matter what background because there's nothing drawn between the squares.


Up: GEOS SDK TechDocs| Up | Prev: 3.2 Patterns and Hatching | Next: 3.4 Masks