Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



How to use a bitmap-patterned brush

If the brush style is set to a patterned brush, then a bitmap can be used for filling shapes. The following example code illustrate how this is done. The bitmap is tiled around the given origin the top left of the window is the default and clipped to the given shape. The second bitmapped brush example shows the effect of moving the origin.


Using a bitmap patterned brush, with the default origin

  1. Load the bitmap file in the standard way.

  2. Use the bitmap as the graphics contexts brush pattern.

  3. Set the brush style to TBrushStyle::EPatternedBrush.

  4. Discard the brush pattern using DiscardBrushPattern().

  5. Destroy the bitmap.

With no brush origin set, the tiling pattern starts at the top left corner of the window.

CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
CleanupStack::PushL(bitmap);
User::LeaveIfError(bitmap->Load(KAnMbmFile,KABitmapID));
// set brush pattern and style to use the bitmap
gc.UseBrushPattern(bitmap);
gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
// draw shape filled with bitmap pattern
gc.DrawRect(rect);
gc.DiscardBrushPattern();
CleanupStack::PopAndDestroy();

[Top]


Using a bitmap patterned brush, with a set origin

You can set the brush origin using SetBrushOrigin(), and tile the bitmap around this point.

The example code is exactly the same as that in previous bitmapped brush example, except that the following line is added before the rectangle is drawn:

...
TPoint pos(100,100);
gc.SetBrushOrigin(pos);
...