Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 1 | /* |
| 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 Stade | 4c5486f | 2007-07-31 19:15:48 -0700 | [diff] [blame] | 21 | |
| 22 | #include "objbase.h" |
| 23 | |
Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 24 | #include "gdiplus.h" |
| 25 | #include "gdiplus_private.h" |
Evan Stade | f18cdef | 2007-08-01 17:56:02 -0700 | [diff] [blame] | 26 | #include "wine/debug.h" |
| 27 | |
| 28 | WINE_DEFAULT_DEBUG_CHANNEL(gdiplus); |
Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 29 | |
Evan Stade | b2b4b87 | 2007-07-19 18:23:04 -0700 | [diff] [blame] | 30 | GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone) |
| 31 | { |
| 32 | if(!brush || !clone) |
| 33 | return InvalidParameter; |
| 34 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 35 | switch(brush->bt){ |
| 36 | case BrushTypeSolidColor: |
| 37 | *clone = GdipAlloc(sizeof(GpSolidFill)); |
| 38 | if (!*clone) return OutOfMemory; |
Evan Stade | b2b4b87 | 2007-07-19 18:23:04 -0700 | [diff] [blame] | 39 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 40 | memcpy(*clone, brush, sizeof(GpSolidFill)); |
Evan Stade | b2b4b87 | 2007-07-19 18:23:04 -0700 | [diff] [blame] | 41 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 42 | (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb); |
| 43 | break; |
| 44 | default: |
| 45 | return NotImplemented; |
| 46 | } |
Evan Stade | b2b4b87 | 2007-07-19 18:23:04 -0700 | [diff] [blame] | 47 | |
| 48 | return Ok; |
| 49 | } |
| 50 | |
Evan Stade | f18cdef | 2007-08-01 17:56:02 -0700 | [diff] [blame] | 51 | /* FIXME: path gradient brushes not truly supported (drawn as solid brushes) */ |
| 52 | GpStatus 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 Stade | 490ca1c | 2007-08-02 17:51:49 -0700 | [diff] [blame^] | 63 | (*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 Stade | f18cdef | 2007-08-01 17:56:02 -0700 | [diff] [blame] | 78 | (*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 Stade | 490ca1c | 2007-08-02 17:51:49 -0700 | [diff] [blame^] | 83 | (*grad)->brush.bt = BrushTypePathGradient; |
Evan Stade | f18cdef | 2007-08-01 17:56:02 -0700 | [diff] [blame] | 84 | (*grad)->centercolor = 0xffffffff; |
Evan Stade | f0dbfe9 | 2007-08-01 17:56:10 -0700 | [diff] [blame] | 85 | (*grad)->wrap = WrapModeClamp; |
Evan Stade | f18cdef | 2007-08-01 17:56:02 -0700 | [diff] [blame] | 86 | |
| 87 | return Ok; |
| 88 | } |
| 89 | |
Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 90 | GpStatus 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 Stade | 7af2e97 | 2007-07-19 18:22:59 -0700 | [diff] [blame] | 99 | (*sf)->brush.lb.lbStyle = BS_SOLID; |
| 100 | (*sf)->brush.lb.lbColor = col; |
| 101 | (*sf)->brush.lb.lbHatch = 0; |
| 102 | |
Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 103 | (*sf)->brush.gdibrush = CreateSolidBrush(col); |
| 104 | (*sf)->brush.bt = BrushTypeSolidColor; |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 105 | (*sf)->color = color; |
Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 106 | |
| 107 | return Ok; |
| 108 | } |
| 109 | |
| 110 | GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type) |
| 111 | { |
| 112 | if(!brush || !type) return InvalidParameter; |
| 113 | |
| 114 | *type = brush->bt; |
| 115 | |
| 116 | return Ok; |
| 117 | } |
| 118 | |
| 119 | GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush) |
| 120 | { |
| 121 | if(!brush) return InvalidParameter; |
| 122 | |
| 123 | DeleteObject(brush->gdibrush); |
| 124 | GdipFree(brush); |
| 125 | |
| 126 | return Ok; |
| 127 | } |
Evan Stade | 82abeee | 2007-07-23 20:24:13 -0700 | [diff] [blame] | 128 | |
Evan Stade | 490ca1c | 2007-08-02 17:51:49 -0700 | [diff] [blame^] | 129 | GpStatus 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 Stade | 82abeee | 2007-07-23 20:24:13 -0700 | [diff] [blame] | 140 | GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb) |
| 141 | { |
| 142 | if(!sf || !argb) |
| 143 | return InvalidParameter; |
| 144 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 145 | *argb = sf->color; |
| 146 | |
| 147 | return Ok; |
Evan Stade | 82abeee | 2007-07-23 20:24:13 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Evan Stade | f2cf555 | 2007-08-01 17:56:05 -0700 | [diff] [blame] | 150 | GpStatus 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 Stade | f0dbfe9 | 2007-08-01 17:56:10 -0700 | [diff] [blame] | 165 | GpStatus 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 Stade | 82abeee | 2007-07-23 20:24:13 -0700 | [diff] [blame] | 176 | GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb) |
| 177 | { |
| 178 | if(!sf) |
| 179 | return InvalidParameter; |
| 180 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 181 | 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 Stade | 82abeee | 2007-07-23 20:24:13 -0700 | [diff] [blame] | 188 | } |