push 83071add6f9f2e5b8e6b93c0b0e6ee71c20d2ad7
[wine/hacks.git] / dlls / gdiplus / graphics.c
blob674bede22b9ff1a01c611654066c0ad78b3508de
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 <stdarg.h>
20 #include <math.h>
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"
30 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
32 if(hdc == NULL)
33 return OutOfMemory;
35 if(graphics == NULL)
36 return InvalidParameter;
38 *graphics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
39 sizeof(GpGraphics));
40 (*graphics)->hdc = hdc;
41 (*graphics)->hwnd = NULL;
43 return Ok;
46 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
48 GpStatus ret;
50 if((ret = GdipCreateFromHDC(GetDC(hwnd), graphics)) != Ok)
51 return ret;
53 (*graphics)->hwnd = hwnd;
55 return Ok;
58 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
60 if(!graphics) return InvalidParameter;
61 if(graphics->hwnd)
62 ReleaseDC(graphics->hwnd, graphics->hdc);
64 HeapFree(GetProcessHeap(), 0, graphics);
66 return Ok;
69 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
70 INT y1, INT x2, INT y2)
72 HGDIOBJ old_obj;
74 if(!pen || !graphics)
75 return InvalidParameter;
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);
82 return Ok;
85 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
86 INT y, INT width, INT height)
88 LOGBRUSH lb;
89 HPEN hpen;
90 HGDIOBJ old_obj;
92 if(!pen || !graphics)
93 return InvalidParameter;
95 lb.lbStyle = BS_SOLID;
96 lb.lbColor = pen->color;
97 lb.lbHatch = 0;
99 hpen = ExtCreatePen(PS_GEOMETRIC | PS_ENDCAP_SQUARE, (INT) pen->width,
100 &lb, 0, NULL);
102 old_obj = SelectObject(graphics->hdc, hpen);
104 /* assume pen aligment centered */
105 MoveToEx(graphics->hdc, x, y, NULL);
106 LineTo(graphics->hdc, x+width, y);
107 LineTo(graphics->hdc, x+width, y+height);
108 LineTo(graphics->hdc, x, y+height);
109 LineTo(graphics->hdc, x, y);
111 SelectObject(graphics->hdc, old_obj);
112 DeleteObject(hpen);
114 return Ok;