gdiplus: Brush tests.
[wine] / dlls / gdiplus / graphics.c
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 }
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 }
84
85 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
86     INT y, INT width, INT height)
87 {
88     LOGBRUSH lb;
89     HPEN hpen;
90     HGDIOBJ old_obj;
91
92     if(!pen || !graphics)
93         return InvalidParameter;
94
95     lb.lbStyle = BS_SOLID;
96     lb.lbColor = pen->color;
97     lb.lbHatch = 0;
98
99     hpen = ExtCreatePen(PS_GEOMETRIC | PS_ENDCAP_SQUARE, (INT) pen->width,
100         &lb, 0, NULL);
101
102     old_obj = SelectObject(graphics->hdc, hpen);
103
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);
110
111     SelectObject(graphics->hdc, old_obj);
112     DeleteObject(hpen);
113
114     return Ok;
115 }