Evan Stade | d50be49 | 2007-06-11 11:54:03 -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 <stdarg.h> |
| 20 | #include <math.h> |
| 21 | |
| 22 | #include "windef.h" |
| 23 | #include "winbase.h" |
| 24 | #include "winuser.h" |
| 25 | #include "wingdi.h" |
| 26 | #include "gdiplus.h" |
| 27 | #include "gdiplus_private.h" |
| 28 | #include "wine/debug.h" |
| 29 | |
| 30 | GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics) |
| 31 | { |
| 32 | if(hdc == NULL) |
| 33 | return OutOfMemory; |
| 34 | |
| 35 | if(graphics == NULL) |
| 36 | return InvalidParameter; |
| 37 | |
| 38 | *graphics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, |
| 39 | sizeof(GpGraphics)); |
| 40 | (*graphics)->hdc = hdc; |
| 41 | (*graphics)->hwnd = NULL; |
| 42 | |
| 43 | return Ok; |
| 44 | } |
| 45 | |
| 46 | GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics) |
| 47 | { |
| 48 | GpStatus ret; |
| 49 | |
| 50 | if((ret = GdipCreateFromHDC(GetDC(hwnd), graphics)) != Ok) |
| 51 | return ret; |
| 52 | |
| 53 | (*graphics)->hwnd = hwnd; |
| 54 | |
| 55 | return Ok; |
| 56 | } |
| 57 | |
| 58 | GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics) |
| 59 | { |
| 60 | if(!graphics) return InvalidParameter; |
| 61 | if(graphics->hwnd) |
| 62 | ReleaseDC(graphics->hwnd, graphics->hdc); |
| 63 | |
| 64 | HeapFree(GetProcessHeap(), 0, graphics); |
| 65 | |
| 66 | return Ok; |
| 67 | } |
Evan Stade | 2689b18 | 2007-06-12 10:44:31 -0700 | [diff] [blame^] | 68 | |
| 69 | GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1, |
| 70 | INT y1, INT x2, INT y2) |
| 71 | { |
| 72 | HGDIOBJ old_obj; |
| 73 | |
| 74 | if(!pen || !graphics) |
| 75 | return InvalidParameter; |
| 76 | |
| 77 | old_obj = SelectObject(graphics->hdc, pen->gdipen); |
| 78 | MoveToEx(graphics->hdc, x1, y1, NULL); |
| 79 | LineTo(graphics->hdc, x2, y2); |
| 80 | SelectObject(graphics->hdc, old_obj); |
| 81 | |
| 82 | return Ok; |
| 83 | } |