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" |
| 26 | |
Evan Stade | b2b4b87 | 2007-07-19 18:23:04 -0700 | [diff] [blame] | 27 | GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone) |
| 28 | { |
| 29 | if(!brush || !clone) |
| 30 | return InvalidParameter; |
| 31 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 32 | switch(brush->bt){ |
| 33 | case BrushTypeSolidColor: |
| 34 | *clone = GdipAlloc(sizeof(GpSolidFill)); |
| 35 | if (!*clone) return OutOfMemory; |
Evan Stade | b2b4b87 | 2007-07-19 18:23:04 -0700 | [diff] [blame] | 36 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 37 | memcpy(*clone, brush, sizeof(GpSolidFill)); |
Evan Stade | b2b4b87 | 2007-07-19 18:23:04 -0700 | [diff] [blame] | 38 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 39 | (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb); |
| 40 | break; |
| 41 | default: |
| 42 | return NotImplemented; |
| 43 | } |
Evan Stade | b2b4b87 | 2007-07-19 18:23:04 -0700 | [diff] [blame] | 44 | |
| 45 | return Ok; |
| 46 | } |
| 47 | |
Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 48 | GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf) |
| 49 | { |
| 50 | COLORREF col = ARGB2COLORREF(color); |
| 51 | |
| 52 | if(!sf) return InvalidParameter; |
| 53 | |
| 54 | *sf = GdipAlloc(sizeof(GpSolidFill)); |
| 55 | if (!*sf) return OutOfMemory; |
| 56 | |
Evan Stade | 7af2e97 | 2007-07-19 18:22:59 -0700 | [diff] [blame] | 57 | (*sf)->brush.lb.lbStyle = BS_SOLID; |
| 58 | (*sf)->brush.lb.lbColor = col; |
| 59 | (*sf)->brush.lb.lbHatch = 0; |
| 60 | |
Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 61 | (*sf)->brush.gdibrush = CreateSolidBrush(col); |
| 62 | (*sf)->brush.bt = BrushTypeSolidColor; |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 63 | (*sf)->color = color; |
Evan Stade | cc0a676 | 2007-06-14 16:09:07 -0700 | [diff] [blame] | 64 | |
| 65 | return Ok; |
| 66 | } |
| 67 | |
| 68 | GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type) |
| 69 | { |
| 70 | if(!brush || !type) return InvalidParameter; |
| 71 | |
| 72 | *type = brush->bt; |
| 73 | |
| 74 | return Ok; |
| 75 | } |
| 76 | |
| 77 | GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush) |
| 78 | { |
| 79 | if(!brush) return InvalidParameter; |
| 80 | |
| 81 | DeleteObject(brush->gdibrush); |
| 82 | GdipFree(brush); |
| 83 | |
| 84 | return Ok; |
| 85 | } |
Evan Stade | 82abeee | 2007-07-23 20:24:13 -0700 | [diff] [blame] | 86 | |
| 87 | GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb) |
| 88 | { |
| 89 | if(!sf || !argb) |
| 90 | return InvalidParameter; |
| 91 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 92 | *argb = sf->color; |
| 93 | |
| 94 | return Ok; |
Evan Stade | 82abeee | 2007-07-23 20:24:13 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb) |
| 98 | { |
| 99 | if(!sf) |
| 100 | return InvalidParameter; |
| 101 | |
Evan Stade | 8b2ce0f | 2007-07-23 20:24:24 -0700 | [diff] [blame] | 102 | sf->color = argb; |
| 103 | sf->brush.lb.lbColor = ARGB2COLORREF(argb); |
| 104 | |
| 105 | DeleteObject(sf->brush.gdibrush); |
| 106 | sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor); |
| 107 | |
| 108 | return Ok; |
Evan Stade | 82abeee | 2007-07-23 20:24:13 -0700 | [diff] [blame] | 109 | } |