blob: 265aba0c0af0b2ab610c99ff4149c5025c7b0be3 [file] [log] [blame]
Evan Stadecc0a6762007-06-14 16:09:07 -07001/*
2 * Copyright (C) 2007 Google (Evan Stade)
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "windef.h"
20#include "wingdi.h"
Evan Stade4c5486f2007-07-31 19:15:48 -070021
22#include "objbase.h"
23
Evan Stadecc0a6762007-06-14 16:09:07 -070024#include "gdiplus.h"
25#include "gdiplus_private.h"
Evan Stadef18cdef2007-08-01 17:56:02 -070026#include "wine/debug.h"
27
28WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
Evan Stadecc0a6762007-06-14 16:09:07 -070029
Evan Stadeb2b4b872007-07-19 18:23:04 -070030GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
31{
32 if(!brush || !clone)
33 return InvalidParameter;
34
Evan Stade8b2ce0f2007-07-23 20:24:24 -070035 switch(brush->bt){
36 case BrushTypeSolidColor:
37 *clone = GdipAlloc(sizeof(GpSolidFill));
38 if (!*clone) return OutOfMemory;
Evan Stadeb2b4b872007-07-19 18:23:04 -070039
Evan Stade8b2ce0f2007-07-23 20:24:24 -070040 memcpy(*clone, brush, sizeof(GpSolidFill));
Evan Stadeb2b4b872007-07-19 18:23:04 -070041
Evan Stade8b2ce0f2007-07-23 20:24:24 -070042 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
43 break;
44 default:
45 return NotImplemented;
46 }
Evan Stadeb2b4b872007-07-19 18:23:04 -070047
48 return Ok;
49}
50
Evan Stadef18cdef2007-08-01 17:56:02 -070051/* FIXME: path gradient brushes not truly supported (drawn as solid brushes) */
52GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
53 GpPathGradient **grad)
54{
55 COLORREF col = ARGB2COLORREF(0xffffffff);
56
57 if(!path || !grad)
58 return InvalidParameter;
59
60 *grad = GdipAlloc(sizeof(GpPathGradient));
61 if (!*grad) return OutOfMemory;
62
Evan Stade490ca1c2007-08-02 17:51:49 -070063 (*grad)->pathdata.Count = path->pathdata.Count;
64 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
65 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
66
67 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
68 GdipFree((*grad)->pathdata.Points);
69 GdipFree((*grad)->pathdata.Types);
70 GdipFree(*grad);
71 return OutOfMemory;
72 }
73
74 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
75 path->pathdata.Count * sizeof(PointF));
76 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
77
Evan Stadef18cdef2007-08-01 17:56:02 -070078 (*grad)->brush.lb.lbStyle = BS_SOLID;
79 (*grad)->brush.lb.lbColor = col;
80 (*grad)->brush.lb.lbHatch = 0;
81
82 (*grad)->brush.gdibrush = CreateSolidBrush(col);
Evan Stade490ca1c2007-08-02 17:51:49 -070083 (*grad)->brush.bt = BrushTypePathGradient;
Evan Stadef18cdef2007-08-01 17:56:02 -070084 (*grad)->centercolor = 0xffffffff;
Evan Stadef0dbfe92007-08-01 17:56:10 -070085 (*grad)->wrap = WrapModeClamp;
Evan Stadef18cdef2007-08-01 17:56:02 -070086
87 return Ok;
88}
89
Evan Stadecc0a6762007-06-14 16:09:07 -070090GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
91{
92 COLORREF col = ARGB2COLORREF(color);
93
94 if(!sf) return InvalidParameter;
95
96 *sf = GdipAlloc(sizeof(GpSolidFill));
97 if (!*sf) return OutOfMemory;
98
Evan Stade7af2e972007-07-19 18:22:59 -070099 (*sf)->brush.lb.lbStyle = BS_SOLID;
100 (*sf)->brush.lb.lbColor = col;
101 (*sf)->brush.lb.lbHatch = 0;
102
Evan Stadecc0a6762007-06-14 16:09:07 -0700103 (*sf)->brush.gdibrush = CreateSolidBrush(col);
104 (*sf)->brush.bt = BrushTypeSolidColor;
Evan Stade8b2ce0f2007-07-23 20:24:24 -0700105 (*sf)->color = color;
Evan Stadecc0a6762007-06-14 16:09:07 -0700106
107 return Ok;
108}
109
110GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
111{
112 if(!brush || !type) return InvalidParameter;
113
114 *type = brush->bt;
115
116 return Ok;
117}
118
119GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
120{
121 if(!brush) return InvalidParameter;
122
123 DeleteObject(brush->gdibrush);
124 GdipFree(brush);
125
126 return Ok;
127}
Evan Stade82abeee2007-07-23 20:24:13 -0700128
Evan Stade490ca1c2007-08-02 17:51:49 -0700129GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
130 INT *count)
131{
132 if(!grad || !count)
133 return InvalidParameter;
134
135 *count = grad->pathdata.Count;
136
137 return Ok;
138}
139
Evan Stade82abeee2007-07-23 20:24:13 -0700140GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
141{
142 if(!sf || !argb)
143 return InvalidParameter;
144
Evan Stade8b2ce0f2007-07-23 20:24:24 -0700145 *argb = sf->color;
146
147 return Ok;
Evan Stade82abeee2007-07-23 20:24:13 -0700148}
149
Evan Stadef2cf5552007-08-01 17:56:05 -0700150GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
151 ARGB argb)
152{
153 if(!grad)
154 return InvalidParameter;
155
156 grad->centercolor = argb;
157 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
158
159 DeleteObject(grad->brush.gdibrush);
160 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
161
162 return Ok;
163}
164
Evan Stadef0dbfe92007-08-01 17:56:10 -0700165GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
166 GpWrapMode wrap)
167{
168 if(!grad)
169 return InvalidParameter;
170
171 grad->wrap = wrap;
172
173 return Ok;
174}
175
Evan Stade82abeee2007-07-23 20:24:13 -0700176GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
177{
178 if(!sf)
179 return InvalidParameter;
180
Evan Stade8b2ce0f2007-07-23 20:24:24 -0700181 sf->color = argb;
182 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
183
184 DeleteObject(sf->brush.gdibrush);
185 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
186
187 return Ok;
Evan Stade82abeee2007-07-23 20:24:13 -0700188}