gdi32: Add a helper function to add a rectangle to a region.

This commit is contained in:
Alexandre Julliard 2011-12-28 11:04:30 +01:00
parent 0c840f66ed
commit c861284a02
3 changed files with 27 additions and 11 deletions

View File

@ -1288,8 +1288,8 @@ DWORD gradient_bitmapinfo( const BITMAPINFO *info, void *bits, TRIVERTEX *vert_a
unsigned int i; unsigned int i;
int y; int y;
TRIVERTEX vert[3]; TRIVERTEX vert[3];
RECT rc;
DWORD ret = ERROR_SUCCESS; DWORD ret = ERROR_SUCCESS;
HRGN tmp_rgn = 0;
init_dib_info_from_bitmapinfo( &dib, info, bits, default_color_table ); init_dib_info_from_bitmapinfo( &dib, info, bits, default_color_table );
@ -1300,9 +1300,11 @@ DWORD gradient_bitmapinfo( const BITMAPINFO *info, void *bits, TRIVERTEX *vert_a
{ {
get_gradient_hrect_vertices( rect, vert_array, dev_pts, vert ); get_gradient_hrect_vertices( rect, vert_array, dev_pts, vert );
gradient_rect( &dib, vert, mode, 0 ); gradient_rect( &dib, vert, mode, 0 );
if (!tmp_rgn) tmp_rgn = CreateRectRgn( vert[0].x, vert[0].y, vert[1].x, vert[1].y ); rc.left = vert[0].x;
else SetRectRgn( tmp_rgn, vert[0].x, vert[0].y, vert[1].x, vert[1].y ); rc.top = vert[0].y;
CombineRgn( rgn, rgn, tmp_rgn, RGN_OR ); rc.right = vert[1].x;
rc.bottom = vert[1].y;
add_rect_to_region( rgn, &rc );
} }
break; break;
@ -1311,9 +1313,11 @@ DWORD gradient_bitmapinfo( const BITMAPINFO *info, void *bits, TRIVERTEX *vert_a
{ {
get_gradient_vrect_vertices( rect, vert_array, dev_pts, vert ); get_gradient_vrect_vertices( rect, vert_array, dev_pts, vert );
gradient_rect( &dib, vert, mode, 0 ); gradient_rect( &dib, vert, mode, 0 );
if (!tmp_rgn) tmp_rgn = CreateRectRgn( vert[0].x, vert[0].y, vert[1].x, vert[1].y ); rc.left = vert[0].x;
else SetRectRgn( tmp_rgn, vert[0].x, vert[0].y, vert[1].x, vert[1].y ); rc.top = vert[0].y;
CombineRgn( rgn, rgn, tmp_rgn, RGN_OR ); rc.right = vert[1].x;
rc.bottom = vert[1].y;
add_rect_to_region( rgn, &rc );
} }
break; break;
@ -1323,22 +1327,23 @@ DWORD gradient_bitmapinfo( const BITMAPINFO *info, void *bits, TRIVERTEX *vert_a
get_gradient_triangle_vertices( tri, vert_array, dev_pts, vert ); get_gradient_triangle_vertices( tri, vert_array, dev_pts, vert );
if (gradient_rect( &dib, vert, mode, 0 )) if (gradient_rect( &dib, vert, mode, 0 ))
{ {
if (!tmp_rgn) tmp_rgn = CreateRectRgn( 0, 0, 0, 0 );
for (y = vert[0].y; y < vert[2].y; y++) for (y = vert[0].y; y < vert[2].y; y++)
{ {
int x1, x2 = edge_coord( y, vert[0].x, vert[0].y, vert[2].x, vert[2].y ); int x1, x2 = edge_coord( y, vert[0].x, vert[0].y, vert[2].x, vert[2].y );
if (y < vert[1].y) x1 = edge_coord( y, vert[0].x, vert[0].y, vert[1].x, vert[1].y ); if (y < vert[1].y) x1 = edge_coord( y, vert[0].x, vert[0].y, vert[1].x, vert[1].y );
else x1 = edge_coord( y, vert[1].x, vert[1].y, vert[2].x, vert[2].y ); else x1 = edge_coord( y, vert[1].x, vert[1].y, vert[2].x, vert[2].y );
SetRectRgn( tmp_rgn, min(x1,x2), y, max(x1,x2), y + 1 ); rc.left = min( x1, x2 );
CombineRgn( rgn, rgn, tmp_rgn, RGN_OR ); rc.top = y;
rc.right = max( x1, x2 );
rc.bottom = y + 1;
add_rect_to_region( rgn, &rc );
} }
} }
else ret = ERROR_INVALID_PARAMETER; else ret = ERROR_INVALID_PARAMETER;
} }
break; break;
} }
DeleteObject( tmp_rgn );
return ret; return ret;
} }

View File

@ -318,6 +318,7 @@ extern UINT WINAPI GDIRealizePalette( HDC hdc ) DECLSPEC_HIDDEN;
extern HPALETTE PALETTE_Init(void) DECLSPEC_HIDDEN; extern HPALETTE PALETTE_Init(void) DECLSPEC_HIDDEN;
/* region.c */ /* region.c */
extern BOOL add_rect_to_region( HRGN rgn, const RECT *rect ) DECLSPEC_HIDDEN;
extern INT mirror_region( HRGN dst, HRGN src, INT width ) DECLSPEC_HIDDEN; extern INT mirror_region( HRGN dst, HRGN src, INT width ) DECLSPEC_HIDDEN;
extern BOOL REGION_FrameRgn( HRGN dest, HRGN src, INT x, INT y ) DECLSPEC_HIDDEN; extern BOOL REGION_FrameRgn( HRGN dest, HRGN src, INT x, INT y ) DECLSPEC_HIDDEN;

View File

@ -1268,6 +1268,16 @@ static BOOL REGION_UnionRectWithRegion(const RECT *rect, WINEREGION *rgn)
} }
BOOL add_rect_to_region( HRGN rgn, const RECT *rect )
{
RGNOBJ *obj = GDI_GetObjPtr( rgn, OBJ_REGION );
if (!obj) return FALSE;
REGION_UnionRectWithRegion( rect, &obj->rgn );
GDI_ReleaseObj( rgn );
return TRUE;
}
/*********************************************************************** /***********************************************************************
* REGION_CreateFrameRgn * REGION_CreateFrameRgn
* *