Release 980215
[wine.git] / objects / brush.c
blob88a232b47159ef6e5c6043263bdf6e30bfa23849
1 /*
2 * GDI brush objects
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include "brush.h"
9 #include "bitmap.h"
10 #include "metafile.h"
11 #include "color.h"
12 #include "stddebug.h"
13 #include "debug.h"
16 /***********************************************************************
17 * CreateBrushIndirect16 (GDI.50)
19 HBRUSH16 WINAPI CreateBrushIndirect16( const LOGBRUSH16 * brush )
21 BRUSHOBJ * brushPtr;
22 HBRUSH16 hbrush = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC );
23 if (!hbrush) return 0;
24 brushPtr = (BRUSHOBJ *) GDI_HEAP_LOCK( hbrush );
25 brushPtr->logbrush.lbStyle = brush->lbStyle;
26 brushPtr->logbrush.lbColor = brush->lbColor;
27 brushPtr->logbrush.lbHatch = brush->lbHatch;
28 GDI_HEAP_UNLOCK( hbrush );
29 return hbrush;
33 /***********************************************************************
34 * CreateBrushIndirect32 (GDI32.27)
36 HBRUSH32 WINAPI CreateBrushIndirect32( const LOGBRUSH32 * brush )
38 BRUSHOBJ * brushPtr;
39 HBRUSH32 hbrush = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC );
40 if (!hbrush) return 0;
41 brushPtr = (BRUSHOBJ *) GDI_HEAP_LOCK( hbrush );
42 brushPtr->logbrush.lbStyle = brush->lbStyle;
43 brushPtr->logbrush.lbColor = brush->lbColor;
44 brushPtr->logbrush.lbHatch = brush->lbHatch;
45 GDI_HEAP_UNLOCK( hbrush );
46 return hbrush;
50 /***********************************************************************
51 * CreateHatchBrush16 (GDI.58)
53 HBRUSH16 WINAPI CreateHatchBrush16( INT16 style, COLORREF color )
55 LOGBRUSH32 logbrush = { BS_HATCHED, color, style };
56 dprintf_gdi(stddeb, "CreateHatchBrush16: %d %06lx\n", style, color );
57 if ((style < 0) || (style >= NB_HATCH_STYLES)) return 0;
58 return CreateBrushIndirect32( &logbrush );
62 /***********************************************************************
63 * CreateHatchBrush32 (GDI32.48)
65 HBRUSH32 WINAPI CreateHatchBrush32( INT32 style, COLORREF color )
67 LOGBRUSH32 logbrush = { BS_HATCHED, color, style };
68 dprintf_gdi(stddeb, "CreateHatchBrush32: %d %06lx\n", style, color );
69 if ((style < 0) || (style >= NB_HATCH_STYLES)) return 0;
70 return CreateBrushIndirect32( &logbrush );
74 /***********************************************************************
75 * CreatePatternBrush16 (GDI.60)
77 HBRUSH16 WINAPI CreatePatternBrush16( HBITMAP16 hbitmap )
79 return (HBRUSH16)CreatePatternBrush32( hbitmap );
83 /***********************************************************************
84 * CreatePatternBrush32 (GDI32.54)
86 HBRUSH32 WINAPI CreatePatternBrush32( HBITMAP32 hbitmap )
88 LOGBRUSH32 logbrush = { BS_PATTERN, 0, 0 };
89 BITMAPOBJ *bmp, *newbmp;
91 dprintf_gdi(stddeb, "CreatePatternBrush: %04x\n", hbitmap );
93 /* Make a copy of the bitmap */
95 if (!(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
96 return 0;
97 logbrush.lbHatch = (INT32)CreateBitmapIndirect16( &bmp->bitmap );
98 newbmp = (BITMAPOBJ *) GDI_GetObjPtr( (HGDIOBJ32)logbrush.lbHatch,
99 BITMAP_MAGIC );
100 if (!newbmp)
102 GDI_HEAP_UNLOCK( hbitmap );
103 return 0;
105 TSXCopyArea( display, bmp->pixmap, newbmp->pixmap, BITMAP_GC(bmp),
106 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 0, 0 );
107 GDI_HEAP_UNLOCK( hbitmap );
108 GDI_HEAP_UNLOCK( logbrush.lbHatch );
109 return CreateBrushIndirect32( &logbrush );
113 /***********************************************************************
114 * CreateDIBPatternBrush16 (GDI.445)
116 HBRUSH16 WINAPI CreateDIBPatternBrush16( HGLOBAL16 hbitmap, UINT16 coloruse )
118 LOGBRUSH32 logbrush = { BS_DIBPATTERN, coloruse, 0 };
119 BITMAPINFO *info, *newInfo;
120 INT32 size;
122 dprintf_gdi(stddeb, "CreateDIBPatternBrush: %04x\n", hbitmap );
124 /* Make a copy of the bitmap */
126 if (!(info = (BITMAPINFO *)GlobalLock16( hbitmap ))) return 0;
128 if (info->bmiHeader.biCompression)
129 size = info->bmiHeader.biSizeImage;
130 else
131 size = (info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) / 32
132 * 8 * info->bmiHeader.biHeight;
133 size += DIB_BitmapInfoSize( info, coloruse );
135 if (!(logbrush.lbHatch = (INT16)GlobalAlloc16( GMEM_MOVEABLE, size )))
137 GlobalUnlock16( hbitmap );
138 return 0;
140 newInfo = (BITMAPINFO *) GlobalLock16( (HGLOBAL16)logbrush.lbHatch );
141 memcpy( newInfo, info, size );
142 GlobalUnlock16( (HGLOBAL16)logbrush.lbHatch );
143 GlobalUnlock16( hbitmap );
144 return CreateBrushIndirect32( &logbrush );
148 /***********************************************************************
149 * CreateDIBPatternBrush32 (GDI32.34)
151 HBRUSH32 WINAPI CreateDIBPatternBrush32( HGLOBAL32 hbitmap, UINT32 coloruse )
153 LOGBRUSH32 logbrush = { BS_DIBPATTERN, coloruse, 0 };
154 BITMAPINFO *info, *newInfo;
155 INT32 size;
157 dprintf_gdi(stddeb, "CreateDIBPatternBrush: %04x\n", hbitmap );
159 /* Make a copy of the bitmap */
161 if (!(info = (BITMAPINFO *)GlobalLock32( hbitmap ))) return 0;
163 if (info->bmiHeader.biCompression)
164 size = info->bmiHeader.biSizeImage;
165 else
166 size = (info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) / 32
167 * 8 * info->bmiHeader.biHeight;
168 size += DIB_BitmapInfoSize( info, coloruse );
170 if (!(logbrush.lbHatch = (INT32)GlobalAlloc16( GMEM_MOVEABLE, size )))
172 GlobalUnlock16( hbitmap );
173 return 0;
175 newInfo = (BITMAPINFO *) GlobalLock16( (HGLOBAL16)logbrush.lbHatch );
176 memcpy( newInfo, info, size );
177 GlobalUnlock16( (HGLOBAL16)logbrush.lbHatch );
178 GlobalUnlock16( hbitmap );
179 return CreateBrushIndirect32( &logbrush );
183 /***********************************************************************
184 * CreateSolidBrush (GDI.66)
186 HBRUSH16 WINAPI CreateSolidBrush16( COLORREF color )
188 LOGBRUSH32 logbrush = { BS_SOLID, color, 0 };
189 dprintf_gdi(stddeb, "CreateSolidBrush16: %06lx\n", color );
190 return CreateBrushIndirect32( &logbrush );
194 /***********************************************************************
195 * CreateSolidBrush32 (GDI32.64)
197 HBRUSH32 WINAPI CreateSolidBrush32( COLORREF color )
199 LOGBRUSH32 logbrush = { BS_SOLID, color, 0 };
200 dprintf_gdi(stddeb, "CreateSolidBrush32: %06lx\n", color );
201 return CreateBrushIndirect32( &logbrush );
205 /***********************************************************************
206 * SetBrushOrg (GDI.148)
208 DWORD WINAPI SetBrushOrg( HDC16 hdc, INT16 x, INT16 y )
210 DWORD retval;
211 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
212 if (!dc) return FALSE;
213 retval = dc->w.brushOrgX | (dc->w.brushOrgY << 16);
214 dc->w.brushOrgX = x;
215 dc->w.brushOrgY = y;
216 return retval;
220 /***********************************************************************
221 * SetBrushOrgEx (GDI32.308)
223 BOOL32 WINAPI SetBrushOrgEx( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 oldorg )
225 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
227 if (!dc) return FALSE;
228 if (oldorg)
230 oldorg->x = dc->w.brushOrgX;
231 oldorg->y = dc->w.brushOrgY;
233 dc->w.brushOrgX = x;
234 dc->w.brushOrgY = y;
235 return TRUE;
238 /***********************************************************************
239 * FixBrushOrgEx (GDI32.102)
240 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
242 BOOL32 WINAPI FixBrushOrgEx( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 oldorg )
244 return SetBrushOrgEx(hdc,x,y,oldorg);
248 /***********************************************************************
249 * BRUSH_DeleteObject
251 BOOL32 BRUSH_DeleteObject( HBRUSH16 hbrush, BRUSHOBJ * brush )
253 switch(brush->logbrush.lbStyle)
255 case BS_PATTERN:
256 DeleteObject32( (HGDIOBJ32)brush->logbrush.lbHatch );
257 break;
258 case BS_DIBPATTERN:
259 GlobalFree16( (HGLOBAL16)brush->logbrush.lbHatch );
260 break;
262 return GDI_FreeObject( hbrush );
266 /***********************************************************************
267 * BRUSH_GetObject16
269 INT16 BRUSH_GetObject16( BRUSHOBJ * brush, INT16 count, LPSTR buffer )
271 LOGBRUSH16 logbrush;
273 logbrush.lbStyle = brush->logbrush.lbStyle;
274 logbrush.lbColor = brush->logbrush.lbColor;
275 logbrush.lbHatch = brush->logbrush.lbHatch;
276 if (count > sizeof(logbrush)) count = sizeof(logbrush);
277 memcpy( buffer, &logbrush, count );
278 return count;
282 /***********************************************************************
283 * BRUSH_GetObject32
285 INT32 BRUSH_GetObject32( BRUSHOBJ * brush, INT32 count, LPSTR buffer )
287 if (count > sizeof(brush->logbrush)) count = sizeof(brush->logbrush);
288 memcpy( buffer, &brush->logbrush, count );
289 return count;