01e2f89e48d583bd2aa5dec88f8fcba7b663ff68
[reactos.git] / reactos / subsys / win32k / objects / brush.c
1 /* $Id: brush.c,v 1.19 2003/02/25 23:08:54 gvg Exp $
2 */
3
4
5 #undef WIN32_LEAN_AND_MEAN
6 #include <windows.h>
7 #include <ddk/ntddk.h>
8 #include <win32k/bitmaps.h>
9 #include <win32k/brush.h>
10 //#include <win32k/debug.h>
11 #include <include/object.h>
12 #include <include/inteng.h>
13
14 #define NDEBUG
15 #include <win32k/debug1.h>
16
17 HBRUSH STDCALL W32kCreateBrushIndirect(CONST LOGBRUSH *lb)
18 {
19 PBRUSHOBJ brushPtr;
20 HBRUSH hBrush;
21
22 hBrush = BRUSHOBJ_AllocBrush();
23 if (hBrush == NULL)
24 {
25 return 0;
26 }
27
28 brushPtr = BRUSHOBJ_LockBrush (hBrush);
29 ASSERT( brushPtr ); //I want to know if this ever occurs
30
31 if( brushPtr ){
32 brushPtr->iSolidColor = lb->lbColor;
33 brushPtr->logbrush.lbStyle = lb->lbStyle;
34 brushPtr->logbrush.lbColor = lb->lbColor;
35 brushPtr->logbrush.lbHatch = lb->lbHatch;
36
37 BRUSHOBJ_UnlockBrush( hBrush );
38 return hBrush;
39 }
40 return NULL;
41 }
42
43 HBRUSH STDCALL W32kCreateDIBPatternBrush(HGLOBAL hDIBPacked,
44 UINT ColorSpec)
45 {
46 UNIMPLEMENTED;
47 #if 0
48 LOGBRUSH logbrush;
49 PBITMAPINFO info, newInfo;
50 INT size;
51
52 DPRINT("%04x\n", hbitmap );
53
54 logbrush.lbStyle = BS_DIBPATTERN;
55 logbrush.lbColor = coloruse;
56 logbrush.lbHatch = 0;
57
58 /* Make a copy of the bitmap */
59 if (!(info = (BITMAPINFO *)GlobalLock( hbitmap )))
60 {
61 return 0;
62 }
63
64
65 if (info->bmiHeader.biCompression) size = info->bmiHeader.biSizeImage;
66 else
67 size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
68 size += DIB_BitmapInfoSize(info, coloruse);
69
70 if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
71 {
72 GlobalUnlock16( hbitmap );
73 return 0;
74 }
75 newInfo = (BITMAPINFO *) GlobalLock16((HGLOBAL16)logbrush.lbHatch);
76 memcpy(newInfo, info, size);
77 GlobalUnlock16((HGLOBAL16)logbrush.lbHatch);
78 GlobalUnlock(hbitmap);
79 return W32kCreateBrushIndirect(&logbrush);
80 #endif
81 }
82
83 HBRUSH STDCALL W32kCreateDIBPatternBrushPt(CONST VOID *PackedDIB,
84 UINT Usage)
85 {
86 INT size;
87 LOGBRUSH logbrush;
88 PBITMAPINFO info;
89 PBITMAPINFO newInfo;
90
91 info = (BITMAPINFO *) PackedDIB;
92 if (info == NULL)
93 {
94 return 0;
95 }
96 DPRINT ("%p %ldx%ld %dbpp\n",
97 info,
98 info->bmiHeader.biWidth,
99 info->bmiHeader.biHeight,
100 info->bmiHeader.biBitCount);
101
102 logbrush.lbStyle = BS_DIBPATTERN;
103 logbrush.lbColor = Usage;
104 logbrush.lbHatch = 0;
105
106 /* Make a copy of the bitmap */
107
108 if (info->bmiHeader.biCompression)
109 {
110 size = info->bmiHeader.biSizeImage;
111 }
112 else
113 {
114 size = DIB_GetDIBImageBytes (info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
115 }
116 size += DIB_BitmapInfoSize (info, Usage);
117
118 logbrush.lbHatch = (LONG) GDIOBJ_AllocObj(size, GO_MAGIC_DONTCARE);
119 if (logbrush.lbHatch == 0)
120 {
121 return 0;
122 }
123 newInfo = (PBITMAPINFO) GDIOBJ_LockObj ((HGDIOBJ) logbrush.lbHatch, GO_MAGIC_DONTCARE);
124 ASSERT(newInfo);
125 memcpy(newInfo, info, size);
126 GDIOBJ_UnlockObj( (HGDIOBJ) logbrush.lbHatch, GO_MAGIC_DONTCARE );
127
128 return W32kCreateBrushIndirect (&logbrush);
129 }
130
131 HBRUSH STDCALL W32kCreateHatchBrush(INT Style,
132 COLORREF Color)
133 {
134 LOGBRUSH logbrush;
135
136 DPRINT("%d %06lx\n", Style, Color);
137
138 if (Style < 0 || Style >= NB_HATCH_STYLES)
139 {
140 return 0;
141 }
142 logbrush.lbStyle = BS_HATCHED;
143 logbrush.lbColor = Color;
144 logbrush.lbHatch = Style;
145
146 return W32kCreateBrushIndirect (&logbrush);
147 }
148
149 HBRUSH STDCALL W32kCreatePatternBrush(HBITMAP hBitmap)
150 {
151 LOGBRUSH logbrush = { BS_PATTERN, 0, 0 };
152
153 DPRINT ("%04x\n", hBitmap);
154 logbrush.lbHatch = (INT) BITMAPOBJ_CopyBitmap (hBitmap);
155 if(!logbrush.lbHatch)
156 {
157 return 0;
158 }
159 else
160 {
161 return W32kCreateBrushIndirect( &logbrush );
162 }
163 }
164
165 HBRUSH STDCALL W32kCreateSolidBrush(COLORREF Color)
166 {
167 LOGBRUSH logbrush;
168
169 logbrush.lbStyle = BS_SOLID;
170 logbrush.lbColor = Color;
171 logbrush.lbHatch = 0;
172
173 return W32kCreateBrushIndirect(&logbrush);
174 }
175
176 BOOL STDCALL W32kFixBrushOrgEx(VOID)
177 {
178 return FALSE;
179 }
180
181 BOOL STDCALL W32kPatBlt(HDC hDC,
182 INT XLeft,
183 INT YLeft,
184 INT Width,
185 INT Height,
186 DWORD ROP)
187 {
188 RECT DestRect;
189 PBRUSHOBJ BrushObj;
190 PSURFOBJ SurfObj;
191 DC *dc = DC_HandleToPtr(hDC);
192 BOOL ret;
193
194 if (dc == NULL)
195 {
196 return(FALSE);
197 }
198
199 SurfObj = (SURFOBJ*)AccessUserObject((ULONG)dc->Surface);
200
201 BrushObj = (BRUSHOBJ*) GDIOBJ_LockObj(dc->w.hBrush, GO_BRUSH_MAGIC);
202 assert(BrushObj);
203 if (BrushObj->logbrush.lbStyle != BS_NULL)
204 {
205 if (Width > 0)
206 {
207 DestRect.left = XLeft + dc->w.DCOrgX;
208 DestRect.right = XLeft + Width + dc->w.DCOrgX;
209 }
210 else
211 {
212 DestRect.left = XLeft + Width + dc->w.DCOrgX;
213 DestRect.right = XLeft + dc->w.DCOrgX;
214 }
215 if (Height > 0)
216 {
217 DestRect.top = YLeft + dc->w.DCOrgY;
218 DestRect.bottom = YLeft + Height + dc->w.DCOrgY;
219 }
220 else
221 {
222 DestRect.top = YLeft + Height + dc->w.DCOrgY;
223 DestRect.bottom = YLeft + dc->w.DCOrgY;
224 }
225 ret = IntEngBitBlt(SurfObj,
226 NULL,
227 NULL,
228 NULL,
229 NULL,
230 &DestRect,
231 NULL,
232 NULL,
233 BrushObj,
234 NULL,
235 PATCOPY);
236 }
237 GDIOBJ_UnlockObj( dc->w.hBrush, GO_BRUSH_MAGIC );
238 DC_ReleasePtr( hDC );
239 return(ret);
240 }
241
242 BOOL STDCALL W32kSetBrushOrgEx(HDC hDC,
243 INT XOrg,
244 INT YOrg,
245 LPPOINT Point)
246 {
247 UNIMPLEMENTED;
248 }