- Fixed negative width/height off by one.
[reactos.git] / reactos / subsys / win32k / objects / brush.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: brush.c,v 1.23 2003/08/02 19:52:03 dwelch Exp $
20 */
21
22
23 #undef WIN32_LEAN_AND_MEAN
24 #include <windows.h>
25 #include <ddk/ntddk.h>
26 #include <win32k/bitmaps.h>
27 #include <win32k/brush.h>
28 //#include <win32k/debug.h>
29 #include <include/object.h>
30 #include <include/inteng.h>
31 #include <include/error.h>
32
33 #define NDEBUG
34 #include <win32k/debug1.h>
35
36 HBRUSH STDCALL W32kCreateBrushIndirect(CONST LOGBRUSH *lb)
37 {
38 PBRUSHOBJ brushPtr;
39 HBRUSH hBrush;
40
41 hBrush = BRUSHOBJ_AllocBrush();
42 if (hBrush == NULL)
43 {
44 return 0;
45 }
46
47 brushPtr = BRUSHOBJ_LockBrush (hBrush);
48 ASSERT( brushPtr ); //I want to know if this ever occurs
49
50 if( brushPtr ){
51 brushPtr->iSolidColor = lb->lbColor;
52 brushPtr->logbrush.lbStyle = lb->lbStyle;
53 brushPtr->logbrush.lbColor = lb->lbColor;
54 brushPtr->logbrush.lbHatch = lb->lbHatch;
55
56 BRUSHOBJ_UnlockBrush( hBrush );
57 return hBrush;
58 }
59 return NULL;
60 }
61
62 HBRUSH STDCALL W32kCreateDIBPatternBrush(HGLOBAL hDIBPacked,
63 UINT ColorSpec)
64 {
65 UNIMPLEMENTED;
66 #if 0
67 LOGBRUSH logbrush;
68 PBITMAPINFO info, newInfo;
69 INT size;
70
71 DPRINT("%04x\n", hbitmap );
72
73 logbrush.lbStyle = BS_DIBPATTERN;
74 logbrush.lbColor = coloruse;
75 logbrush.lbHatch = 0;
76
77 /* Make a copy of the bitmap */
78 if (!(info = (BITMAPINFO *)GlobalLock( hbitmap )))
79 {
80 return 0;
81 }
82
83
84 if (info->bmiHeader.biCompression) size = info->bmiHeader.biSizeImage;
85 else
86 size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
87 size += DIB_BitmapInfoSize(info, coloruse);
88
89 if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
90 {
91 GlobalUnlock16( hbitmap );
92 return 0;
93 }
94 newInfo = (BITMAPINFO *) GlobalLock16((HGLOBAL16)logbrush.lbHatch);
95 memcpy(newInfo, info, size);
96 GlobalUnlock16((HGLOBAL16)logbrush.lbHatch);
97 GlobalUnlock(hbitmap);
98 return W32kCreateBrushIndirect(&logbrush);
99 #endif
100 }
101
102 HBRUSH STDCALL W32kCreateDIBPatternBrushPt(CONST VOID *PackedDIB,
103 UINT Usage)
104 {
105 INT size;
106 LOGBRUSH logbrush;
107 PBITMAPINFO info;
108 PBITMAPINFO newInfo;
109
110 info = (BITMAPINFO *) PackedDIB;
111 if (info == NULL)
112 {
113 return 0;
114 }
115 DPRINT ("%p %ldx%ld %dbpp\n",
116 info,
117 info->bmiHeader.biWidth,
118 info->bmiHeader.biHeight,
119 info->bmiHeader.biBitCount);
120
121 logbrush.lbStyle = BS_DIBPATTERN;
122 logbrush.lbColor = Usage;
123 logbrush.lbHatch = 0;
124
125 /* Make a copy of the bitmap */
126
127 if (info->bmiHeader.biCompression)
128 {
129 size = info->bmiHeader.biSizeImage;
130 }
131 else
132 {
133 size = DIB_GetDIBImageBytes (info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
134 }
135 size += DIB_BitmapInfoSize (info, Usage);
136
137 logbrush.lbHatch = (LONG) GDIOBJ_AllocObj(size, GO_MAGIC_DONTCARE);
138 if (logbrush.lbHatch == 0)
139 {
140 return 0;
141 }
142 newInfo = (PBITMAPINFO) GDIOBJ_LockObj ((HGDIOBJ) logbrush.lbHatch, GO_MAGIC_DONTCARE);
143 ASSERT(newInfo);
144 memcpy(newInfo, info, size);
145 GDIOBJ_UnlockObj( (HGDIOBJ) logbrush.lbHatch, GO_MAGIC_DONTCARE );
146
147 return W32kCreateBrushIndirect (&logbrush);
148 }
149
150 HBRUSH STDCALL W32kCreateHatchBrush(INT Style,
151 COLORREF Color)
152 {
153 LOGBRUSH logbrush;
154
155 DPRINT("%d %06lx\n", Style, Color);
156
157 if (Style < 0 || Style >= NB_HATCH_STYLES)
158 {
159 return 0;
160 }
161 logbrush.lbStyle = BS_HATCHED;
162 logbrush.lbColor = Color;
163 logbrush.lbHatch = Style;
164
165 return W32kCreateBrushIndirect (&logbrush);
166 }
167
168 HBRUSH STDCALL W32kCreatePatternBrush(HBITMAP hBitmap)
169 {
170 LOGBRUSH logbrush = { BS_PATTERN, 0, 0 };
171
172 DPRINT ("%04x\n", hBitmap);
173 logbrush.lbHatch = (INT) BITMAPOBJ_CopyBitmap (hBitmap);
174 if(!logbrush.lbHatch)
175 {
176 return 0;
177 }
178 else
179 {
180 return W32kCreateBrushIndirect( &logbrush );
181 }
182 }
183
184 HBRUSH STDCALL W32kCreateSolidBrush(COLORREF Color)
185 {
186 LOGBRUSH logbrush;
187
188 logbrush.lbStyle = BS_SOLID;
189 logbrush.lbColor = Color;
190 logbrush.lbHatch = 0;
191
192 return W32kCreateBrushIndirect(&logbrush);
193 }
194
195 BOOL STDCALL W32kFixBrushOrgEx(VOID)
196 {
197 return FALSE;
198 }
199
200 BOOL STDCALL W32kPatBlt(HDC hDC,
201 INT XLeft,
202 INT YLeft,
203 INT Width,
204 INT Height,
205 DWORD ROP)
206 {
207 RECT DestRect;
208 PBRUSHOBJ BrushObj;
209 PSURFOBJ SurfObj;
210 DC *dc = DC_HandleToPtr(hDC);
211 BOOL ret;
212
213 if (dc == NULL)
214 {
215 SetLastWin32Error(ERROR_INVALID_HANDLE);
216 return(FALSE);
217 }
218
219 SurfObj = (SURFOBJ*)AccessUserObject((ULONG)dc->Surface);
220
221 BrushObj = (BRUSHOBJ*) GDIOBJ_LockObj(dc->w.hBrush, GO_BRUSH_MAGIC);
222 assert(BrushObj);
223 if (BrushObj->logbrush.lbStyle != BS_NULL)
224 {
225 if (Width > 0)
226 {
227 DestRect.left = XLeft + dc->w.DCOrgX;
228 DestRect.right = XLeft + Width + dc->w.DCOrgX;
229 }
230 else
231 {
232 DestRect.left = XLeft + Width + 1 + dc->w.DCOrgX;
233 DestRect.right = XLeft + dc->w.DCOrgX + 1;
234 }
235 if (Height > 0)
236 {
237 DestRect.top = YLeft + dc->w.DCOrgY;
238 DestRect.bottom = YLeft + Height + dc->w.DCOrgY;
239 }
240 else
241 {
242 DestRect.top = YLeft + Height + dc->w.DCOrgY + 1;
243 DestRect.bottom = YLeft + dc->w.DCOrgY + 1;
244 }
245 ret = IntEngBitBlt(SurfObj,
246 NULL,
247 NULL,
248 dc->CombinedClip,
249 NULL,
250 &DestRect,
251 NULL,
252 NULL,
253 BrushObj,
254 NULL,
255 ROP);
256 }
257 GDIOBJ_UnlockObj( dc->w.hBrush, GO_BRUSH_MAGIC );
258 DC_ReleasePtr( hDC );
259 return(ret);
260 }
261
262 BOOL STDCALL W32kSetBrushOrgEx(HDC hDC,
263 INT XOrg,
264 INT YOrg,
265 LPPOINT Point)
266 {
267 UNIMPLEMENTED;
268 }
269 /* EOF */