4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
11 #include "prototypes.h"
15 #define NB_HATCH_STYLES 6
17 static char HatchBrushes
[NB_HATCH_STYLES
][8] =
19 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HS_HORIZONTAL */
20 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HS_VERTICAL */
21 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HS_FDIAGONAL */
22 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HS_BDIAGONAL */
23 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HS_CROSS */
24 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 } /* HS_DIAGCROSS */
27 extern WORD
COLOR_ToPhysical( DC
*dc
, COLORREF color
);
30 /***********************************************************************
31 * CreateBrushIndirect (GDI.50)
33 HBRUSH
CreateBrushIndirect( LOGBRUSH
* brush
)
36 HBRUSH hbrush
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
);
37 if (!hbrush
) return 0;
38 brushPtr
= (BRUSHOBJ
*) GDI_HEAP_ADDR( hbrush
);
39 memcpy( &brushPtr
->logbrush
, brush
, sizeof(LOGBRUSH
) );
44 /***********************************************************************
45 * CreateHatchBrush (GDI.58)
47 HBRUSH
CreateHatchBrush( short style
, COLORREF color
)
49 LOGBRUSH logbrush
= { BS_HATCHED
, color
, style
};
51 printf( "CreateHatchBrush: %d %06x\n", style
, color
);
53 if ((style
< 0) || (style
>= NB_HATCH_STYLES
)) return 0;
54 return CreateBrushIndirect( &logbrush
);
58 /***********************************************************************
59 * CreatePatternBrush (GDI.60)
61 HBRUSH
CreatePatternBrush( HBITMAP hbitmap
)
63 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
64 BITMAPOBJ
*bmp
, *newbmp
;
67 printf( "CreatePatternBrush: %d\n", hbitmap
);
70 /* Make a copy of the bitmap */
72 if (!(bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
)))
74 logbrush
.lbHatch
= CreateBitmapIndirect( &bmp
->bitmap
);
75 newbmp
= (BITMAPOBJ
*) GDI_GetObjPtr( logbrush
.lbHatch
, BITMAP_MAGIC
);
76 if (!newbmp
) return 0;
77 XCopyArea( display
, bmp
->pixmap
, newbmp
->pixmap
, BITMAP_GC(bmp
),
78 0, 0, bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
, 0, 0 );
79 return CreateBrushIndirect( &logbrush
);
83 /***********************************************************************
84 * CreateDIBPatternBrush (GDI.445)
86 HBRUSH
CreateDIBPatternBrush( HANDLE hbitmap
, WORD coloruse
)
88 LOGBRUSH logbrush
= { BS_DIBPATTERN
, coloruse
, 0 };
89 BITMAPINFO
*info
, *newInfo
;
93 printf( "CreateDIBPatternBrush: %d\n", hbitmap
);
96 /* Make a copy of the bitmap */
98 if (!(info
= (BITMAPINFO
*) GlobalLock( hbitmap
))) return 0;
100 size
= info
->bmiHeader
.biSizeImage
;
102 size
= (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) / 32
103 * 8 * info
->bmiHeader
.biHeight
;
104 size
+= DIB_BitmapInfoSize( info
, coloruse
);
106 if (!(logbrush
.lbHatch
= GlobalAlloc( GMEM_MOVEABLE
, size
)))
108 GlobalUnlock( hbitmap
);
111 newInfo
= (BITMAPINFO
*) GlobalLock( logbrush
.lbHatch
);
112 memcpy( newInfo
, info
, size
);
113 GlobalUnlock( logbrush
.lbHatch
);
114 GlobalUnlock( hbitmap
);
115 return CreateBrushIndirect( &logbrush
);
119 /***********************************************************************
120 * CreateSolidBrush (GDI.66)
122 HBRUSH
CreateSolidBrush( COLORREF color
)
124 LOGBRUSH logbrush
= { BS_SOLID
, color
, 0 };
126 printf( "CreateSolidBrush: %06x\n", color
);
128 return CreateBrushIndirect( &logbrush
);
132 /***********************************************************************
133 * SetBrushOrg (GDI.148)
135 DWORD
SetBrushOrg( HDC hdc
, short x
, short y
)
138 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
139 if (!dc
) return FALSE
;
140 retval
= dc
->w
.brushOrgX
| (dc
->w
.brushOrgY
<< 16);
146 /***********************************************************************
147 * GetSysColorBrush (USER.281)
149 WORD
GetSysColorBrush(WORD x
)
151 return GetStockObject(GRAY_BRUSH
);
154 /***********************************************************************
157 BOOL
BRUSH_DeleteObject( HBRUSH hbrush
, BRUSHOBJ
* brush
)
159 switch(brush
->logbrush
.lbStyle
)
162 DeleteObject( brush
->logbrush
.lbHatch
);
165 GlobalFree( brush
->logbrush
.lbHatch
);
168 return GDI_FreeObject( hbrush
);
172 /***********************************************************************
175 int BRUSH_GetObject( BRUSHOBJ
* brush
, int count
, LPSTR buffer
)
177 if (count
> sizeof(LOGBRUSH
)) count
= sizeof(LOGBRUSH
);
178 memcpy( buffer
, &brush
->logbrush
, count
);
183 /***********************************************************************
184 * BRUSH_MakeSolidBrush
186 static void BRUSH_SelectSolidBrush( DC
*dc
, COLORREF color
)
188 if ((dc
->w
.bitsPerPixel
> 1) && !COLOR_IsSolid( color
))
191 dc
->u
.x
.brush
.pixmap
= DITHER_DitherColor( dc
, color
);
192 dc
->u
.x
.brush
.fillStyle
= FillTiled
;
193 dc
->u
.x
.brush
.pixel
= 0;
198 dc
->u
.x
.brush
.pixel
= COLOR_ToPhysical( dc
, color
);
199 dc
->u
.x
.brush
.fillStyle
= FillSolid
;
204 /***********************************************************************
205 * BRUSH_SelectPatternBrush
207 static BOOL
BRUSH_SelectPatternBrush( DC
* dc
, HBITMAP hbitmap
)
209 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
210 if (!bmp
) return FALSE
;
211 dc
->u
.x
.brush
.pixmap
= XCreatePixmap( display
, rootWindow
,
212 8, 8, bmp
->bitmap
.bmBitsPixel
);
213 XCopyArea( display
, bmp
->pixmap
, dc
->u
.x
.brush
.pixmap
,
214 BITMAP_GC(bmp
), 0, 0, 8, 8, 0, 0 );
216 if (bmp
->bitmap
.bmBitsPixel
> 1)
218 dc
->u
.x
.brush
.fillStyle
= FillTiled
;
219 dc
->u
.x
.brush
.pixel
= 0; /* Ignored */
223 dc
->u
.x
.brush
.fillStyle
= FillOpaqueStippled
;
224 dc
->u
.x
.brush
.pixel
= -1; /* Special case (see DC_SetupGCForBrush) */
231 /***********************************************************************
234 HBRUSH
BRUSH_SelectObject( HDC hdc
, DC
* dc
, HBRUSH hbrush
, BRUSHOBJ
* brush
)
237 BITMAPINFO
* bmpInfo
;
238 HBRUSH prevHandle
= dc
->w
.hBrush
;
240 if (dc
->header
.wMagic
== METAFILE_DC_MAGIC
)
242 switch (brush
->logbrush
.lbStyle
)
247 if (!MF_CreateBrushIndirect(dc
, hbrush
, &(brush
->logbrush
)))
253 if (!MF_CreatePatternBrush(dc
, hbrush
, &(brush
->logbrush
)))
260 dc
->w
.hBrush
= hbrush
;
262 if (dc
->u
.x
.brush
.pixmap
)
264 XFreePixmap( display
, dc
->u
.x
.brush
.pixmap
);
265 dc
->u
.x
.brush
.pixmap
= 0;
267 dc
->u
.x
.brush
.style
= brush
->logbrush
.lbStyle
;
269 switch(brush
->logbrush
.lbStyle
)
275 BRUSH_SelectSolidBrush( dc
, brush
->logbrush
.lbColor
);
279 dc
->u
.x
.brush
.pixel
= COLOR_ToPhysical( dc
, brush
->logbrush
.lbColor
);
280 dc
->u
.x
.brush
.pixmap
= XCreateBitmapFromData( display
, rootWindow
,
281 HatchBrushes
[brush
->logbrush
.lbHatch
], 8, 8 );
282 dc
->u
.x
.brush
.fillStyle
= FillStippled
;
286 BRUSH_SelectPatternBrush( dc
, brush
->logbrush
.lbHatch
);
290 if ((bmpInfo
= (BITMAPINFO
*) GlobalLock( brush
->logbrush
.lbHatch
)))
292 int size
= DIB_BitmapInfoSize( bmpInfo
, brush
->logbrush
.lbColor
);
293 hBitmap
= CreateDIBitmap( hdc
, &bmpInfo
->bmiHeader
, CBM_INIT
,
294 ((char *)bmpInfo
) + size
, bmpInfo
,
295 (WORD
) brush
->logbrush
.lbColor
);
296 BRUSH_SelectPatternBrush( dc
, hBitmap
);
297 DeleteObject( hBitmap
);
298 GlobalUnlock( brush
->logbrush
.lbHatch
);