fdopen: don't rewind the file after creating the FILE* handle. Added
[wine] / dlls / gdi / win16drv / graphics.c
1 /*
2  * Windows 16 bit device driver graphics functions
3  *
4  * Copyright 1997 John Harvey
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdio.h>
22
23 #include "win16drv/win16drv.h"
24 #include "wownt32.h"
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(win16drv);
28
29 /***********************************************************************
30  *           WIN16DRV_LineTo
31  */
32 BOOL
33 WIN16DRV_LineTo( PHYSDEV dev, INT x, INT y )
34 {
35     BOOL bRet ;
36     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
37     DC *dc = physDev->dc;
38     POINT16 points[2];
39
40     points[0].x = dc->CursPosX;
41     points[0].y = dc->CursPosY;
42     points[1].x = x;
43     points[1].y = y;
44     LPtoDP16( HDC_16(physDev->hdc), points, 2 );
45
46     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
47                          OS_POLYLINE, 2, points,
48                          physDev->PenInfo,
49                          NULL,
50                          win16drv_SegPtr_DrawMode, dc->hClipRgn);
51
52     dc->CursPosX = x;
53     dc->CursPosY = y;
54     return TRUE;
55 }
56
57
58 /***********************************************************************
59  *           WIN16DRV_Rectangle
60  */
61 BOOL
62 WIN16DRV_Rectangle(PHYSDEV dev, INT left, INT top, INT right, INT bottom)
63 {
64     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
65     DC *dc = physDev->dc;
66     BOOL bRet = 0;
67     POINT16 points[2];
68
69     TRACE("In WIN16DRV_Rectangle, x %d y %d\n", left, top );
70     TRACE("In WIN16DRV_Rectangle, VPortOrgX %d y %d\n",
71            dc->vportOrgX, dc->vportOrgY);
72     points[0].x = left;
73     points[0].y = top;
74     points[1].x = right;
75     points[1].y = bottom;
76     LPtoDP16( HDC_16(physDev->hdc), points, 2 );
77
78     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
79                            OS_RECTANGLE, 2, points,
80                            physDev->PenInfo,
81                            physDev->BrushInfo,
82                            win16drv_SegPtr_DrawMode, dc->hClipRgn);
83     return bRet;
84 }
85
86
87
88
89 /***********************************************************************
90  *           WIN16DRV_Polygon
91  */
92 BOOL
93 WIN16DRV_Polygon(PHYSDEV dev, const POINT* pt, INT count )
94 {
95     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
96     DC *dc = physDev->dc;
97     BOOL bRet = 0;
98     LPPOINT16 points;
99     int i;
100
101     if(count < 2) return TRUE;
102     if(pt[0].x != pt[count-1].x || pt[0].y != pt[count-1].y)
103         count++; /* Ensure polygon is closed */
104
105     points = HeapAlloc( GetProcessHeap(), 0, count * sizeof(POINT16) );
106     if(points == NULL) return FALSE;
107
108     for (i = 0; i < count - 1; i++)
109     {
110       points[i].x = pt[i].x;
111       points[i].y = pt[i].y;
112     }
113     LPtoDP16( HDC_16(physDev->hdc), points, count-1 );
114     points[count-1].x = points[0].x;
115     points[count-1].y = points[0].y;
116     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
117                          OS_WINDPOLYGON, count, points,
118                          physDev->PenInfo,
119                          physDev->BrushInfo,
120                          win16drv_SegPtr_DrawMode, dc->hClipRgn);
121     HeapFree( GetProcessHeap(), 0, points );
122     return bRet;
123 }
124
125
126 /***********************************************************************
127  *           WIN16DRV_Polyline
128  */
129 BOOL
130 WIN16DRV_Polyline(PHYSDEV dev, const POINT* pt, INT count )
131 {
132     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
133     DC *dc = physDev->dc;
134     BOOL bRet = 0;
135     LPPOINT16 points;
136     int i;
137
138     if(count < 2) return TRUE;
139
140     points = HeapAlloc( GetProcessHeap(), 0, count * sizeof(POINT16) );
141     if(points == NULL) return FALSE;
142
143     for (i = 0; i < count; i++)
144     {
145       points[i].x = pt[i].x;
146       points[i].y = pt[i].y;
147     }
148     LPtoDP16( HDC_16(physDev->hdc), points, count );
149     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
150                          OS_POLYLINE, count, points,
151                          physDev->PenInfo,
152                          NULL,
153                          win16drv_SegPtr_DrawMode, dc->hClipRgn);
154     HeapFree( GetProcessHeap(), 0, points );
155     return bRet;
156 }
157
158
159
160 /***********************************************************************
161  *           WIN16DRV_Ellipse
162  */
163 BOOL
164 WIN16DRV_Ellipse(PHYSDEV dev, INT left, INT top, INT right, INT bottom)
165 {
166     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
167     DC *dc = physDev->dc;
168     BOOL bRet = 0;
169     POINT16 points[2];
170
171     TRACE("In WIN16DRV_Ellipse, x %d y %d\n", left, top );
172     TRACE("In WIN16DRV_Ellipse, VPortOrgX %d y %d\n", dc->vportOrgX, dc->vportOrgY);
173
174     points[0].x = left;
175     points[0].y = top;
176     points[1].x = right;
177     points[1].y = bottom;
178     LPtoDP16( HDC_16(physDev->hdc), points, 2 );
179
180     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
181                          OS_ELLIPSE, 2, points,
182                          physDev->PenInfo,
183                          physDev->BrushInfo,
184                          win16drv_SegPtr_DrawMode, dc->hClipRgn);
185     return bRet;
186 }