Furthermore, the rectangles are banded such that every rectangle with a given upper-left y coordinate (y1) will have the same lower-right y coordinate (y2) and vice versa. If a rectangle has scanlines in a band, it will span the entire vertical distance of the band. This means that some areas that could be merged into a taller rectangle will be represented as several shorter rectangles to account for shorter rectangles to its left or right but within its "vertical scope".
An added constraint on the rectangles is that they must cover as much horizontal area as possible. E.g. no two rectangles in a band are allowed to touch.
Whenever possible, bands will be merged together to cover a greater vertical distance (and thus reduce the number of rectangles). Two bands can be merged only if the bottom of one touches the top of the other and they have rectangles in the same places (of the same width, of course). This maintains the y-x-banding that's so nice to have...
Example:
#ifdef _USE_NEWGAL static BLOCKHEAP my_cliprc_heap; static BOOL ch_inited = FALSE; static void GDIDemo_Region (HWND hWnd, HDC hdc) { CLIPRGN my_cliprgn1; CLIPRGN my_cliprgn2; if (!ch_inited) { /* Init the heap used by our region. */ InitFreeClipRectList (&my_cliprc_heap, 100); ch_inited = TRUE; } InitClipRgn (&my_cliprgn1, &my_cliprc_heap); InitClipRgn (&my_cliprgn2, &my_cliprc_heap); /* Create one circle region. */ InitCircleRegion (&my_cliprgn1, 100, 100, 60); /* Create one ellipse region. */ InitEllipseRegion (&my_cliprgn2, 100, 100, 50, 70); /* Fill a box to earase the background. */ SetBrushColor (hdc, PIXEL_blue); FillBox (hdc, 0, 0, DEFAULT_WIDTH, 200); /* Get the difference between two regions. */ SubtractRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2); /* Select the difference region as the current visible region of DC. */ SelectClipRegion (hdc, &my_cliprgn1); /* Fill a box, but you will only see red color in the different region. */ SetBrushColor (hdc, PIXEL_red); FillBox (hdc, 0, 0, 180, 200); /* Do more with XorRegion. */ InitCircleRegion (&my_cliprgn1, 300, 100, 60); OffsetRegion (&my_cliprgn2, 200, 0); XorRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2); SelectClipRegion (hdc, &my_cliprgn1); FillBox (hdc, 200, 0, 180, 200); /* Do more with IntersectRegion. */ InitCircleRegion (&my_cliprgn1, 500, 100, 60); OffsetRegion (&my_cliprgn2, 200, 0); IntersectRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2); SelectClipRegion (hdc, &my_cliprgn1); FillBox (hdc, 400, 0, 180, 200); /* * Empty two clipping region to free the clipping rectangles used * by them. */ EmptyClipRgn (&my_cliprgn1); EmptyClipRgn (&my_cliprgn2); /* * You should not forget to destroy the FreeClipRectList in your * applications. * Here we do not destroy the heap because we will use it in next call. * * DestroyFreeClipRectList (&my_cliprc_heap); * ch_inited = FALSE; * */ } #endif /* _USE_NEWGAL */
|
|
Allocates a clipping rectangles from the private block data heap.
|
|
|
Is an alias of ClipRgnCopy.
|
|
|
Destroys the private block data heap used to allocate clipping rectangles.
|
|
|
Frees a clipping rectangle which is allocated from the private block data heap.
|
|
|
Initializes the private block data heap used to allocate clipping rectangles.
|
|
|
Is an alias of ClipRgnIntersect.
|
|
|
Is an alias of AddClipRect.
|
|
|
Clipping rectangle structure. |
|
|
Clipping region structure, alos used for general regions. |
|
|
Data type of the pointer to a CLIPRGN.
|
|
||||||||||||
|
Unions one rectangle to a region. This function unions a rectangle to the region pointed to by pRgn.
|
|
||||||||||||
|
Copies one region to another. This function copies the region pointed to by pSrcRgn to the region pointed to by pDstRgn.
|
|
||||||||||||||||
|
Intersects two region. This function gets the intersection of two regions pointed to by pRgn1 and pRgn2 respectively and puts the result to the region pointed to by pRstRgn.
|
|
|
Creates a clipping region.
|
|
|
Empties and destroys a clipping region. This function empties and destroys a clipping region pointed to by pRgn.
|
|
|
Empties a clipping region. This function empties a clipping region pointed to by pRgn.
|
|
||||||||||||
|
Gets the bounding rectangle of a region. This function gets the bounding rect of the region pointed to by pRgn, and returns the rect in the rect pointed to by pRect.
|
|
||||||||||||||||||||
|
Initializes a region to be an enclosed circle.
|
|
||||||||||||
|
Initializes a clipping region. Before intializing a clipping region, you should initialize a private block data heap first. The region operations, such as UnionRegion function, will allocate/free the clipping rectangles from/to the heap. This function will set the heap field of pRgn to be pFreeList, and empty the region.
static BLOCKHEAP sg_MyFreeClipRectList; ... CLIPRGN my_region InitFreeClipRectList (&sg_MyFreeClipRectList, 20); InitClipRgn (&my_regioni, &sg_MyFreeClipRectList); |
|
||||||||||||||||||||||||
|
Initializes a region to be an enclosed ellipse.
|
|
||||||||||||||||
|
Initializes a region to be an enclosed polygon.
|
|
||||||||||||
|
Intersects a rectangle with a region. This function intersects the region pointed to by pRgn with a rect pointed to by pRect.
|
|
|
Determines whether a region is an empty region. This function determines whether the region pointed to by pRgn is an empty region.
|
|
||||||||||||||||
|
Offsets the region. This function offsets a given region pointed to by region.
|
|
||||||||||||||||
|
Determines whether a point is in a region. This function determines whether a point (x,y) is in the region pointed to by region.
|
|
||||||||||||
|
Determines whether a rectangle is intersected with a region. This function determines whether the rect rect is intersected with the region pointed to by region.
|
|
||||||||||||
|
Sets a region to contain only one rect. This function sets the region pRgn to contain only a rect pointed to by pRect.
|
|
||||||||||||
|
Subtracts a rectangle from a region. This function subtracts a rect pointed to by pRect from the region pointed to by pRgn.
|
|
||||||||||||||||
|
Substrcts a region from another. This function subtracts rgnS from rgnM and leave the result in rgnD.
|
|
||||||||||||||||
|
Unions two regions. This function unions two regions pointed to by src1 and src2 respectively and puts the result to the region pointed to by dst.
|
|
||||||||||||||||
|
Does the XOR operation between two regions. This function does the XOR operation between two regions pointed to by src1 and src2 and puts the result to the region pointed to by dst.
|
1.4.2