4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
11 #include "prototypes.h"
14 #define NB_HATCH_STYLES 6
16 static char HatchBrushes
[NB_HATCH_STYLES
][8] =
18 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HS_HORIZONTAL */
19 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HS_VERTICAL */
20 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HS_FDIAGONAL */
21 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HS_BDIAGONAL */
22 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HS_CROSS */
23 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 } /* HS_DIAGCROSS */
26 extern WORD
COLOR_ToPhysical( DC
*dc
, COLORREF color
);
29 /***********************************************************************
30 * CreateBrushIndirect (GDI.50)
32 HBRUSH
CreateBrushIndirect( LOGBRUSH
* brush
)
35 HBRUSH hbrush
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
);
36 if (!hbrush
) return 0;
37 brushPtr
= (BRUSHOBJ
*) GDI_HEAP_ADDR( hbrush
);
38 memcpy( &brushPtr
->logbrush
, brush
, sizeof(LOGBRUSH
) );
43 /***********************************************************************
44 * CreateHatchBrush (GDI.58)
46 HBRUSH
CreateHatchBrush( short style
, COLORREF color
)
48 LOGBRUSH logbrush
= { BS_HATCHED
, color
, style
};
50 printf( "CreateHatchBrush: %d %06x\n", style
, color
);
52 if ((style
< 0) || (style
>= NB_HATCH_STYLES
)) return 0;
53 return CreateBrushIndirect( &logbrush
);
57 /***********************************************************************
58 * CreatePatternBrush (GDI.60)
60 HBRUSH
CreatePatternBrush( HBITMAP hbitmap
)
62 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
63 BITMAPOBJ
*bmp
, *newbmp
;
66 printf( "CreatePatternBrush: %d\n", hbitmap
);
69 /* Make a copy of the bitmap */
71 if (!(bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
)))
73 logbrush
.lbHatch
= CreateBitmapIndirect( &bmp
->bitmap
);
74 newbmp
= (BITMAPOBJ
*) GDI_GetObjPtr( logbrush
.lbHatch
, BITMAP_MAGIC
);
75 if (!newbmp
) return 0;
76 XCopyArea( display
, bmp
->pixmap
, newbmp
->pixmap
, BITMAP_GC(bmp
),
77 0, 0, bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
, 0, 0 );
78 return CreateBrushIndirect( &logbrush
);
82 /***********************************************************************
83 * CreateDIBPatternBrush (GDI.445)
85 HBRUSH
CreateDIBPatternBrush( HANDLE hbitmap
, WORD coloruse
)
87 LOGBRUSH logbrush
= { BS_DIBPATTERN
, coloruse
, 0 };
88 BITMAPINFO
*info
, *newInfo
;
92 printf( "CreateDIBPatternBrush: %d\n", hbitmap
);
95 /* Make a copy of the bitmap */
97 if (!(info
= (BITMAPINFO
*) GlobalLock( hbitmap
))) return 0;
99 size
= info
->bmiHeader
.biSizeImage
;
101 size
= (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) / 32
102 * 8 * info
->bmiHeader
.biHeight
;
103 size
+= DIB_BitmapInfoSize( info
, coloruse
);
105 if (!(logbrush
.lbHatch
= GlobalAlloc( GMEM_MOVEABLE
, size
)))
107 GlobalUnlock( hbitmap
);
110 newInfo
= (BITMAPINFO
*) GlobalLock( logbrush
.lbHatch
);
111 memcpy( newInfo
, info
, size
);
112 GlobalUnlock( logbrush
.lbHatch
);
113 GlobalUnlock( hbitmap
);
114 return CreateBrushIndirect( &logbrush
);
118 /***********************************************************************
119 * CreateSolidBrush (GDI.66)
121 HBRUSH
CreateSolidBrush( COLORREF color
)
123 LOGBRUSH logbrush
= { BS_SOLID
, color
, 0 };
125 printf( "CreateSolidBrush: %06x\n", color
);
127 return CreateBrushIndirect( &logbrush
);
131 /***********************************************************************
132 * SetBrushOrg (GDI.148)
134 DWORD
SetBrushOrg( HDC hdc
, short x
, short y
)
137 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
138 if (!dc
) return FALSE
;
139 retval
= dc
->w
.brushOrgX
| (dc
->w
.brushOrgY
<< 16);
146 /***********************************************************************
149 BOOL
BRUSH_DeleteObject( HBRUSH hbrush
, BRUSHOBJ
* brush
)
151 switch(brush
->logbrush
.lbStyle
)
154 DeleteObject( brush
->logbrush
.lbHatch
);
157 GlobalFree( brush
->logbrush
.lbHatch
);
160 return GDI_FreeObject( hbrush
);
164 /***********************************************************************
167 int BRUSH_GetObject( BRUSHOBJ
* brush
, int count
, LPSTR buffer
)
169 if (count
> sizeof(LOGBRUSH
)) count
= sizeof(LOGBRUSH
);
170 memcpy( buffer
, &brush
->logbrush
, count
);
175 /***********************************************************************
176 * BRUSH_MakeSolidBrush
178 static void BRUSH_SelectSolidBrush( DC
*dc
, COLORREF color
)
180 if ((dc
->w
.bitsPerPixel
> 1) && !COLOR_IsSolid( color
))
183 dc
->u
.x
.brush
.pixmap
= DITHER_DitherColor( dc
, color
);
184 dc
->u
.x
.brush
.fillStyle
= FillTiled
;
185 dc
->u
.x
.brush
.pixel
= 0;
190 dc
->u
.x
.brush
.pixel
= COLOR_ToPhysical( dc
, color
);
191 dc
->u
.x
.brush
.fillStyle
= FillSolid
;
196 /***********************************************************************
197 * BRUSH_SelectPatternBrush
199 static BOOL
BRUSH_SelectPatternBrush( DC
* dc
, HBITMAP hbitmap
)
201 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
202 if (!bmp
) return FALSE
;
203 dc
->u
.x
.brush
.pixmap
= XCreatePixmap( display
, rootWindow
,
204 8, 8, bmp
->bitmap
.bmBitsPixel
);
205 XCopyArea( display
, bmp
->pixmap
, dc
->u
.x
.brush
.pixmap
,
206 BITMAP_GC(bmp
), 0, 0, 8, 8, 0, 0 );
208 if (bmp
->bitmap
.bmBitsPixel
> 1)
210 dc
->u
.x
.brush
.fillStyle
= FillTiled
;
211 dc
->u
.x
.brush
.pixel
= 0; /* Ignored */
215 dc
->u
.x
.brush
.fillStyle
= FillOpaqueStippled
;
216 dc
->u
.x
.brush
.pixel
= -1; /* Special case (see DC_SetupGCForBrush) */
223 /***********************************************************************
226 HBRUSH
BRUSH_SelectObject( HDC hdc
, DC
* dc
, HBRUSH hbrush
, BRUSHOBJ
* brush
)
229 BITMAPINFO
* bmpInfo
;
230 HBRUSH prevHandle
= dc
->w
.hBrush
;
232 dc
->w
.hBrush
= hbrush
;
234 if (dc
->u
.x
.brush
.pixmap
)
236 XFreePixmap( display
, dc
->u
.x
.brush
.pixmap
);
237 dc
->u
.x
.brush
.pixmap
= 0;
239 dc
->u
.x
.brush
.style
= brush
->logbrush
.lbStyle
;
241 switch(brush
->logbrush
.lbStyle
)
247 BRUSH_SelectSolidBrush( dc
, brush
->logbrush
.lbColor
);
251 dc
->u
.x
.brush
.pixel
= COLOR_ToPhysical( dc
, brush
->logbrush
.lbColor
);
252 dc
->u
.x
.brush
.pixmap
= XCreateBitmapFromData( display
, rootWindow
,
253 HatchBrushes
[brush
->logbrush
.lbHatch
], 8, 8 );
254 dc
->u
.x
.brush
.fillStyle
= FillStippled
;
258 BRUSH_SelectPatternBrush( dc
, brush
->logbrush
.lbHatch
);
262 if ((bmpInfo
= (BITMAPINFO
*) GlobalLock( brush
->logbrush
.lbHatch
)))
264 int size
= DIB_BitmapInfoSize( bmpInfo
, brush
->logbrush
.lbColor
);
265 hBitmap
= CreateDIBitmap( hdc
, &bmpInfo
->bmiHeader
, CBM_INIT
,
266 ((char *)bmpInfo
) + size
, bmpInfo
,
267 (WORD
) brush
->logbrush
.lbColor
);
268 BRUSH_SelectPatternBrush( dc
, hBitmap
);
269 DeleteObject( hBitmap
);
270 GlobalUnlock( brush
->logbrush
.lbHatch
);