push 0c258732cb75565633c2f709ca58b227c9f8ae60
[wine/hacks.git] / dlls / gdiplus / brush.c
blob33b48ade01cedea5525d56baa745ee1bef4971cb
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "windef.h"
20 #include "wingdi.h"
22 #include "objbase.h"
24 #include "gdiplus.h"
25 #include "gdiplus_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
30 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
32 if(!brush || !clone)
33 return InvalidParameter;
35 switch(brush->bt){
36 case BrushTypeSolidColor:
37 *clone = GdipAlloc(sizeof(GpSolidFill));
38 if (!*clone) return OutOfMemory;
40 memcpy(*clone, brush, sizeof(GpSolidFill));
42 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
43 break;
44 case BrushTypePathGradient:{
45 GpPathGradient *src, *dest;
46 INT count;
48 *clone = GdipAlloc(sizeof(GpPathGradient));
49 if (!*clone) return OutOfMemory;
51 src = (GpPathGradient*) brush,
52 dest = (GpPathGradient*) *clone;
53 count = src->pathdata.Count;
55 memcpy(dest, src, sizeof(GpPathGradient));
57 dest->pathdata.Count = count;
58 dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
59 dest->pathdata.Types = GdipAlloc(count);
61 if(!dest->pathdata.Points || !dest->pathdata.Types){
62 GdipFree(dest->pathdata.Points);
63 GdipFree(dest->pathdata.Types);
64 GdipFree(dest);
65 return OutOfMemory;
68 memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
69 memcpy(dest->pathdata.Types, src->pathdata.Types, count);
71 break;
73 default:
74 return NotImplemented;
77 return Ok;
80 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
81 INT count, GpWrapMode wrap, GpPathGradient **grad)
83 COLORREF col = ARGB2COLORREF(0xffffffff);
85 if(!points || !grad)
86 return InvalidParameter;
88 if(count <= 0)
89 return OutOfMemory;
91 *grad = GdipAlloc(sizeof(GpPathGradient));
92 if (!*grad) return OutOfMemory;
94 (*grad)->pathdata.Count = count;
95 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
96 (*grad)->pathdata.Types = GdipAlloc(count);
98 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
99 GdipFree((*grad)->pathdata.Points);
100 GdipFree((*grad)->pathdata.Types);
101 GdipFree(*grad);
102 return OutOfMemory;
105 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
106 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
108 (*grad)->brush.lb.lbStyle = BS_SOLID;
109 (*grad)->brush.lb.lbColor = col;
110 (*grad)->brush.lb.lbHatch = 0;
112 (*grad)->brush.gdibrush = CreateSolidBrush(col);
113 (*grad)->brush.bt = BrushTypePathGradient;
114 (*grad)->centercolor = 0xffffffff;
115 (*grad)->wrap = wrap;
116 (*grad)->gamma = FALSE;
117 (*grad)->center.X = 0.0;
118 (*grad)->center.Y = 0.0;
119 (*grad)->focus.X = 0.0;
120 (*grad)->focus.Y = 0.0;
122 return Ok;
125 /* FIXME: path gradient brushes not truly supported (drawn as solid brushes) */
126 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
127 GpPathGradient **grad)
129 COLORREF col = ARGB2COLORREF(0xffffffff);
131 if(!path || !grad)
132 return InvalidParameter;
134 *grad = GdipAlloc(sizeof(GpPathGradient));
135 if (!*grad) return OutOfMemory;
137 (*grad)->pathdata.Count = path->pathdata.Count;
138 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
139 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
141 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
142 GdipFree((*grad)->pathdata.Points);
143 GdipFree((*grad)->pathdata.Types);
144 GdipFree(*grad);
145 return OutOfMemory;
148 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
149 path->pathdata.Count * sizeof(PointF));
150 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
152 (*grad)->brush.lb.lbStyle = BS_SOLID;
153 (*grad)->brush.lb.lbColor = col;
154 (*grad)->brush.lb.lbHatch = 0;
156 (*grad)->brush.gdibrush = CreateSolidBrush(col);
157 (*grad)->brush.bt = BrushTypePathGradient;
158 (*grad)->centercolor = 0xffffffff;
159 (*grad)->wrap = WrapModeClamp;
160 (*grad)->gamma = FALSE;
161 /* FIXME: this should be set to the "centroid" of the path by default */
162 (*grad)->center.X = 0.0;
163 (*grad)->center.Y = 0.0;
164 (*grad)->focus.X = 0.0;
165 (*grad)->focus.Y = 0.0;
167 return Ok;
170 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
172 COLORREF col = ARGB2COLORREF(color);
174 if(!sf) return InvalidParameter;
176 *sf = GdipAlloc(sizeof(GpSolidFill));
177 if (!*sf) return OutOfMemory;
179 (*sf)->brush.lb.lbStyle = BS_SOLID;
180 (*sf)->brush.lb.lbColor = col;
181 (*sf)->brush.lb.lbHatch = 0;
183 (*sf)->brush.gdibrush = CreateSolidBrush(col);
184 (*sf)->brush.bt = BrushTypeSolidColor;
185 (*sf)->color = color;
187 return Ok;
190 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
192 if(!brush || !type) return InvalidParameter;
194 *type = brush->bt;
196 return Ok;
199 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
201 if(!brush) return InvalidParameter;
203 switch(brush->bt)
205 case BrushTypePathGradient:
206 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
207 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
208 break;
209 case BrushTypeSolidColor:
210 default:
211 break;
214 DeleteObject(brush->gdibrush);
215 GdipFree(brush);
217 return Ok;
220 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
221 GpPointF *point)
223 if(!grad || !point)
224 return InvalidParameter;
226 point->X = grad->center.X;
227 point->Y = grad->center.Y;
229 return Ok;
232 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
233 REAL *x, REAL *y)
235 if(!grad || !x || !y)
236 return InvalidParameter;
238 *x = grad->focus.X;
239 *y = grad->focus.Y;
241 return Ok;
244 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
245 BOOL *gamma)
247 if(!grad || !gamma)
248 return InvalidParameter;
250 *gamma = grad->gamma;
252 return Ok;
255 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
256 INT *count)
258 if(!grad || !count)
259 return InvalidParameter;
261 *count = grad->pathdata.Count;
263 return Ok;
266 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
267 *grad, ARGB *argb, INT *count)
269 static int calls;
271 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
272 return InvalidParameter;
274 if(!(calls++))
275 FIXME("not implemented\n");
277 return NotImplemented;
280 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
282 if(!sf || !argb)
283 return InvalidParameter;
285 *argb = sf->color;
287 return Ok;
290 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
291 ARGB argb)
293 if(!grad)
294 return InvalidParameter;
296 grad->centercolor = argb;
297 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
299 DeleteObject(grad->brush.gdibrush);
300 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
302 return Ok;
305 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
306 GpPointF *point)
308 if(!grad || !point)
309 return InvalidParameter;
311 grad->center.X = point->X;
312 grad->center.Y = point->Y;
314 return Ok;
317 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
318 REAL x, REAL y)
320 if(!grad)
321 return InvalidParameter;
323 grad->focus.X = x;
324 grad->focus.Y = y;
326 return Ok;
329 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
330 BOOL gamma)
332 if(!grad)
333 return InvalidParameter;
335 grad->gamma = gamma;
337 return Ok;
340 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
341 REAL focus, REAL scale)
343 static int calls;
345 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
346 return InvalidParameter;
348 if(!(calls++))
349 FIXME("not implemented\n");
351 return NotImplemented;
354 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
355 *grad, ARGB *argb, INT *count)
357 static int calls;
359 if(!grad || !argb || !count || (*count <= 0) ||
360 (*count > grad->pathdata.Count))
361 return InvalidParameter;
363 if(!(calls++))
364 FIXME("not implemented\n");
366 return NotImplemented;
369 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
370 GpWrapMode wrap)
372 if(!grad)
373 return InvalidParameter;
375 grad->wrap = wrap;
377 return Ok;
380 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
382 if(!sf)
383 return InvalidParameter;
385 sf->color = argb;
386 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
388 DeleteObject(sf->brush.gdibrush);
389 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
391 return Ok;