Identation corrected, many fixes and minor improvements, initial DIB support
[reactos.git] / reactos / subsys / win32k / objects / brush.c
1 /* $Id: brush.c,v 1.11 2001/03/31 15:35:08 jfilby 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
12 // #define NDEBUG
13 #include <win32k/debug1.h>
14
15 HBRUSH STDCALL W32kCreateBrushIndirect(CONST LOGBRUSH *lb)
16 {
17 PBRUSHOBJ brushPtr;
18 HBRUSH hBrush;
19
20 brushPtr = BRUSHOBJ_AllocBrush();
21 hBrush = BRUSHOBJ_PtrToHandle (brushPtr);
22 if (hBrush == NULL)
23 {
24 return 0;
25 }
26
27 brushPtr->logbrush.lbStyle = lb->lbStyle;
28 brushPtr->logbrush.lbColor = lb->lbColor;
29 brushPtr->logbrush.lbHatch = lb->lbHatch;
30
31 BRUSHOBJ_UnlockBrush (hBrush);
32 DPRINT("%08x\n", hBrush);
33
34 return hBrush;
35 }
36
37 HBRUSH STDCALL W32kCreateDIBPatternBrush(HGLOBAL hDIBPacked,
38 UINT ColorSpec)
39 {
40 UNIMPLEMENTED;
41 #if 0
42 LOGBRUSH logbrush;
43 PBITMAPINFO info, newInfo;
44 INT size;
45
46 DPRINT("%04x\n", hbitmap );
47
48 logbrush.lbStyle = BS_DIBPATTERN;
49 logbrush.lbColor = coloruse;
50 logbrush.lbHatch = 0;
51
52 /* Make a copy of the bitmap */
53 if (!(info = (BITMAPINFO *)GlobalLock( hbitmap )))
54 {
55 return 0;
56 }
57
58
59 if (info->bmiHeader.biCompression) size = info->bmiHeader.biSizeImage;
60 else
61 size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
62 size += DIB_BitmapInfoSize(info, coloruse);
63
64 if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
65 {
66 GlobalUnlock16( hbitmap );
67 return 0;
68 }
69 newInfo = (BITMAPINFO *) GlobalLock16((HGLOBAL16)logbrush.lbHatch);
70 memcpy(newInfo, info, size);
71 GlobalUnlock16((HGLOBAL16)logbrush.lbHatch);
72 GlobalUnlock(hbitmap);
73 return W32kCreateBrushIndirect(&logbrush);
74 #endif
75 }
76
77 HBRUSH STDCALL W32kCreateDIBPatternBrushPt(CONST VOID *PackedDIB,
78 UINT Usage)
79 {
80 INT size;
81 LOGBRUSH logbrush;
82 PBITMAPINFO info;
83 PBITMAPINFO newInfo;
84
85 info = (BITMAPINFO *) PackedDIB;
86 if (info == NULL)
87 {
88 return 0;
89 }
90 DPRINT ("%p %ldx%ld %dbpp\n",
91 info,
92 info->bmiHeader.biWidth,
93 info->bmiHeader.biHeight,
94 info->bmiHeader.biBitCount);
95
96 logbrush.lbStyle = BS_DIBPATTERN;
97 logbrush.lbColor = Usage;
98 logbrush.lbHatch = 0;
99
100 /* Make a copy of the bitmap */
101
102 if (info->bmiHeader.biCompression)
103 {
104 size = info->bmiHeader.biSizeImage;
105 }
106 else
107 {
108 size = DIB_GetDIBImageBytes (info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
109 }
110 size += DIB_BitmapInfoSize (info, Usage);
111
112 logbrush.lbHatch = (INT)GDIOBJ_PtrToHandle (GDIOBJ_AllocObject (size, GO_MAGIC_DONTCARE), GO_MAGIC_DONTCARE);
113 if (logbrush.lbHatch == 0)
114 {
115 return 0;
116 }
117 newInfo = (PBITMAPINFO) GDIOBJ_HandleToPtr ((HGDIOBJ) logbrush.lbHatch, GO_MAGIC_DONTCARE);
118 memcpy(newInfo, info, size);
119 GDIOBJ_UnlockObject((HGDIOBJ)logbrush.lbHatch);
120
121 return W32kCreateBrushIndirect (&logbrush);
122 }
123
124 HBRUSH STDCALL W32kCreateHatchBrush(INT Style,
125 COLORREF Color)
126 {
127 LOGBRUSH logbrush;
128
129 DPRINT("%d %06lx\n", Style, Color);
130
131 if (Style < 0 || Style >= NB_HATCH_STYLES)
132 {
133 return 0;
134 }
135 logbrush.lbStyle = BS_HATCHED;
136 logbrush.lbColor = Color;
137 logbrush.lbHatch = Style;
138
139 return W32kCreateBrushIndirect (&logbrush);
140 }
141
142 HBRUSH STDCALL W32kCreatePatternBrush(HBITMAP hBitmap)
143 {
144 LOGBRUSH logbrush = { BS_PATTERN, 0, 0 };
145
146 DPRINT ("%04x\n", hBitmap);
147 logbrush.lbHatch = (INT) BITMAPOBJ_CopyBitmap (hBitmap);
148 if(!logbrush.lbHatch)
149 {
150 return 0;
151 }
152 else
153 {
154 return W32kCreateBrushIndirect( &logbrush );
155 }
156 }
157
158 HBRUSH STDCALL W32kCreateSolidBrush(COLORREF Color)
159 {
160 LOGBRUSH logbrush;
161
162 logbrush.lbStyle = BS_SOLID;
163 logbrush.lbColor = Color;
164 logbrush.lbHatch = 0;
165
166 return W32kCreateBrushIndirect(&logbrush);
167 }
168
169 BOOL STDCALL W32kFixBrushOrgEx(VOID)
170 {
171 return FALSE;
172 }
173
174 BOOL STDCALL W32kPatBlt(HDC hDC,
175 INT XLeft,
176 INT YLeft,
177 INT Width,
178 INT Height,
179 DWORD ROP)
180 {
181 UNIMPLEMENTED;
182 }
183
184 BOOL STDCALL W32kSetBrushOrgEx(HDC hDC,
185 INT XOrg,
186 INT YOrg,
187 LPPOINT Point)
188 {
189 UNIMPLEMENTED;
190 }